Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/connections/connections.go

41 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package connections
import (
// stdlib
"log"
// 3rd-party
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"github.com/go-telegram-bot-api/telegram-bot-api"
// local
"lab.pztrn.name/fat0troll/i2_bot/lib/config"
)
// BotInit initializes connection to Telegram
func BotInit(cfg *config.Config) *tgbotapi.BotAPI {
bot, err := tgbotapi.NewBotAPI(cfg.Telegram.APIToken)
if err != nil {
log.Panic(err)
}
bot.Debug = true
log.Printf("Bot version: " + config.VERSION)
log.Printf("Authorized on account %s", bot.Self.UserName)
return bot
}
// DBInit initializes database connection
func DBInit(cfg *config.Config) *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 {
log.Fatal(err)
}
log.Printf("Database connection established!")
return database
}