Vladimir Hodakov
b8226d8aa8
Recent game update changed pokememes view in pokedeks, so we need to reflect it by updating parser. Introducing DataCache - a silver bullet for eliminating lags linked to database queries. Less queries, more in RAM, faster work. Needs testing in production environment.
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
// i2_bot – Instinct PokememBro Bot
|
||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||
|
||
package connections
|
||
|
||
import (
|
||
"bitbucket.org/pztrn/mogrus"
|
||
"git.wtfteam.pro/fat0troll/i2_bot/lib/config"
|
||
_ "github.com/go-sql-driver/mysql"
|
||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||
"github.com/jmoiron/sqlx"
|
||
)
|
||
|
||
// BotInit initializes connection to Telegram
|
||
func BotInit(cfg *config.Config, lg *mogrus.LoggerHandler) *tgbotapi.BotAPI {
|
||
bot, err := tgbotapi.NewBotAPI(cfg.Telegram.APIToken)
|
||
if err != nil {
|
||
lg.Fatal(err.Error())
|
||
}
|
||
|
||
bot.Debug = true
|
||
|
||
lg.Info("Bot version: " + config.VERSION)
|
||
lg.Info("Authorized on account @", bot.Self.UserName)
|
||
|
||
return bot
|
||
}
|
||
|
||
// DBInit initializes database connection
|
||
func DBInit(cfg *config.Config, lg *mogrus.LoggerHandler) *sqlx.DB {
|
||
database, err := sqlx.Connect("mysql", cfg.Database.User+":"+cfg.Database.Password+"@tcp("+cfg.Database.Host+":"+cfg.Database.Port+")/"+cfg.Database.Database+"?parseTime=true&charset=utf8mb4,utf8")
|
||
if err != nil {
|
||
lg.Fatal(err)
|
||
}
|
||
lg.Info("Database connection established!")
|
||
return database
|
||
}
|