2017-10-04 17:56:18 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
2017-10-18 07:03:34 +04:00
|
|
|
|
// stdlib
|
|
|
|
|
"log"
|
|
|
|
|
// 3rd party
|
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
|
|
|
|
// Router is a function-handling struct for router
|
2017-10-18 07:03:34 +04:00
|
|
|
|
type Router struct{}
|
2017-10-04 17:56:18 +04:00
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// RouteRequest decides, what to do with user input
|
2017-10-04 17:56:18 +04:00
|
|
|
|
func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
playerRaw, ok := c.Getters.GetOrCreatePlayer(update.Message.From.ID)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if !ok {
|
|
|
|
|
// Silently fail
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
2017-10-21 14:14:46 +04:00
|
|
|
|
chatRaw, ok := c.Getters.GetOrCreateChat(&update)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "fail"
|
2017-10-18 09:39:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-21 14:14:46 +04:00
|
|
|
|
log.Printf("Received message from chat ")
|
|
|
|
|
log.Println(chatRaw.TelegramID)
|
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
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
|
|
|
|
}
|