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/router/router.go

35 lines
884 B
Go
Raw Normal View History

2017-10-04 17:56:18 +04:00
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
2017-10-04 17:56:18 +04:00
package router
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
2017-10-04 17:56:18 +04:00
)
// RouteRequest decides, what to do with user input
func (r *Router) RouteRequest(update tgbotapi.Update) string {
2018-02-17 16:25:50 +04:00
c.Log.Debugln(update)
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"
}
2018-02-17 16:25:50 +04:00
c.Log.Debug("Getting chat...")
chatRaw, err := c.DataCache.GetOrCreateChat(&update)
if err != nil {
c.Log.Error(err.Error())
2017-10-21 14:14:46 +04:00
return "fail"
}
if update.Message.Chat.IsGroup() || update.Message.Chat.IsSuperGroup() {
return r.routeGroupRequest(update, playerRaw, chatRaw)
} else if update.Message.Chat.IsPrivate() {
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
}