2017-10-04 17:56:18 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
2018-03-31 16:45:09 +04:00
|
|
|
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
2017-10-04 17:56:18 +04:00
|
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
2018-03-31 17:34:24 +04:00
|
|
|
|
"strconv"
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// RouteRequest decides, what to do with user input
|
2018-03-31 16:45:09 +04:00
|
|
|
|
func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
2018-02-17 16:25:50 +04:00
|
|
|
|
c.Log.Debugln(update)
|
2018-01-29 23:50:25 +04:00
|
|
|
|
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.Message.From.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
2017-10-18 07:03:34 +04:00
|
|
|
|
// Silently fail
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
2018-02-17 16:25:50 +04:00
|
|
|
|
c.Log.Debug("Getting chat...")
|
2018-03-31 16:45:09 +04:00
|
|
|
|
chatRaw, err := c.DataCache.GetOrCreateChat(&update)
|
2018-02-17 07:03:58 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
2017-10-21 14:14:46 +04:00
|
|
|
|
return "fail"
|
2017-10-18 09:39:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
if update.Message.Chat.IsGroup() || update.Message.Chat.IsSuperGroup() {
|
2018-03-31 17:34:24 +04:00
|
|
|
|
c.Log.Debug("Routing group request in group with ID = " + strconv.Itoa(int(chatRaw.TelegramID)))
|
2018-02-17 07:03:58 +04:00
|
|
|
|
return r.routeGroupRequest(update, playerRaw, chatRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
} else if update.Message.Chat.IsPrivate() {
|
2018-03-31 17:34:24 +04:00
|
|
|
|
c.Log.Debug("Routing private request for user with ID = " + strconv.Itoa(int(chatRaw.TelegramID)))
|
2018-02-17 07:03:58 +04:00
|
|
|
|
return r.routePrivateRequest(update, playerRaw, chatRaw)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
2017-10-04 17:56:18 +04:00
|
|
|
|
|
2017-10-18 07:03:34 +04:00
|
|
|
|
return "ok"
|
2017-10-04 17:56:18 +04:00
|
|
|
|
}
|