2017-10-04 17:56:18 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
// stdlib
|
|
|
|
|
"time"
|
2017-10-18 07:03:34 +04:00
|
|
|
|
// 3rd-party
|
2017-10-07 19:58:14 +04:00
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2017-10-18 07:03:34 +04:00
|
|
|
|
// local
|
2017-10-04 17:56:18 +04:00
|
|
|
|
"./lib/appcontext"
|
2017-10-13 00:31:12 +04:00
|
|
|
|
"./lib/getters"
|
2017-10-06 02:56:06 +04:00
|
|
|
|
"./lib/migrations"
|
|
|
|
|
"./lib/parsers"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
"./lib/router"
|
2017-10-07 02:23:25 +04:00
|
|
|
|
"./lib/talkers"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
c *appcontext.Context
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
c := appcontext.New()
|
|
|
|
|
c.Init()
|
|
|
|
|
router.New(c)
|
2017-10-06 02:56:06 +04:00
|
|
|
|
migrations.New(c)
|
|
|
|
|
c.RunDatabaseMigrations()
|
|
|
|
|
parsers.New(c)
|
2017-10-07 02:23:25 +04:00
|
|
|
|
talkers.New(c)
|
2017-10-13 00:31:12 +04:00
|
|
|
|
getters.New(c)
|
2017-10-04 17:56:18 +04:00
|
|
|
|
|
|
|
|
|
u := tgbotapi.NewUpdate(0)
|
|
|
|
|
u.Timeout = 60
|
|
|
|
|
|
|
|
|
|
updates, _ := c.Bot.GetUpdatesChan(u)
|
|
|
|
|
|
|
|
|
|
for update := range updates {
|
2017-10-06 02:56:06 +04:00
|
|
|
|
if update.Message == nil || update.Message.From == nil {
|
2017-10-04 17:56:18 +04:00
|
|
|
|
continue
|
|
|
|
|
} else if update.Message.Date < (int(time.Now().Unix()) - 1) {
|
|
|
|
|
// Ignore old messages
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 07:03:34 +04:00
|
|
|
|
c.Router.RouteRequest(update)
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|
|
|
|
|
}
|