2017-10-04 17:56:18 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package appcontext
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
// 3rd-party
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
2017-10-07 19:58:14 +04:00
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
// local
|
|
|
|
|
"../config"
|
|
|
|
|
"../connections"
|
|
|
|
|
// interfaces
|
2017-10-06 02:56:06 +04:00
|
|
|
|
"../migrations/migrationsinterface"
|
|
|
|
|
"../parsers/parsersinterface"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
"../router/routerinterface"
|
2017-10-07 02:23:25 +04:00
|
|
|
|
"../talkers/talkersinterface"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Context struct {
|
|
|
|
|
Cfg *config.Config
|
|
|
|
|
Bot *tgbotapi.BotAPI
|
2017-10-06 02:56:06 +04:00
|
|
|
|
Migrations migrationsinterface.MigrationsInterface
|
2017-10-04 17:56:18 +04:00
|
|
|
|
Router routerinterface.RouterInterface
|
2017-10-06 02:56:06 +04:00
|
|
|
|
Parsers parsersinterface.ParsersInterface
|
2017-10-04 17:56:18 +04:00
|
|
|
|
Db *sqlx.DB
|
2017-10-07 02:23:25 +04:00
|
|
|
|
Talkers talkersinterface.TalkersInterface
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Context) Init() {
|
|
|
|
|
c.Cfg = config.New()
|
|
|
|
|
c.Cfg.Init()
|
|
|
|
|
c.Bot = connections.BotInit(c.Cfg)
|
|
|
|
|
c.Db = connections.DBInit(c.Cfg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Context) RegisterRouterInterface(ri routerinterface.RouterInterface) {
|
|
|
|
|
c.Router = ri
|
|
|
|
|
c.Router.Init()
|
|
|
|
|
}
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
|
|
|
|
func (c *Context) RegisterMigrationsInterface(mi migrationsinterface.MigrationsInterface) {
|
|
|
|
|
c.Migrations = mi
|
|
|
|
|
c.Migrations.Init()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Context) RegisterParsersInterface(pi parsersinterface.ParsersInterface) {
|
|
|
|
|
c.Parsers = pi
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-07 02:23:25 +04:00
|
|
|
|
func (c *Context) RegisterTalkersInterface(ti talkersinterface.TalkersInterface) {
|
|
|
|
|
c.Talkers = ti
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-06 02:56:06 +04:00
|
|
|
|
func (c *Context) RunDatabaseMigrations() {
|
|
|
|
|
c.Migrations.SetDialect("mysql")
|
|
|
|
|
c.Migrations.Migrate()
|
|
|
|
|
}
|