2017-11-03 21:33:02 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
|
|
|
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
2017-11-14 03:44:21 +04:00
|
|
|
|
"regexp"
|
2017-11-03 21:33:02 +04:00
|
|
|
|
)
|
|
|
|
|
|
2017-11-14 03:44:21 +04:00
|
|
|
|
func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
|
2017-11-03 21:33:02 +04:00
|
|
|
|
text := update.Message.Text
|
|
|
|
|
|
|
|
|
|
// Commands with regexps
|
|
|
|
|
var pokedexMsg = regexp.MustCompile("/pokede(x|ks)\\d?\\z")
|
|
|
|
|
var pokememeInfoMsg = regexp.MustCompile("/pk(\\d+)")
|
|
|
|
|
|
|
|
|
|
if update.Message.ForwardFrom != nil {
|
|
|
|
|
if update.Message.ForwardFrom.ID != 360402625 {
|
2017-11-14 03:44:21 +04:00
|
|
|
|
c.Log.Info("Forward from another user or bot. Ignoring")
|
2017-11-03 21:33:02 +04:00
|
|
|
|
} else {
|
2017-11-14 03:44:21 +04:00
|
|
|
|
c.Log.Info("Forward from PokememBro bot! Processing...")
|
2017-11-03 21:33:02 +04:00
|
|
|
|
if playerRaw.ID != 0 {
|
2017-11-14 03:44:21 +04:00
|
|
|
|
c.Forwarder.ProcessForward(update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
} else {
|
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if update.Message.IsCommand() {
|
|
|
|
|
switch {
|
|
|
|
|
case update.Message.Command() == "start":
|
|
|
|
|
if playerRaw.ID != 0 {
|
|
|
|
|
c.Talkers.HelloMessageAuthorized(update, playerRaw)
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Talkers.HelloMessageUnauthorized(update)
|
|
|
|
|
return "ok"
|
|
|
|
|
case update.Message.Command() == "help":
|
2017-11-14 03:44:21 +04:00
|
|
|
|
c.Talkers.HelpMessage(update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
// Pokememes info
|
|
|
|
|
case pokedexMsg.MatchString(text):
|
2017-11-14 03:44:21 +04:00
|
|
|
|
c.Talkers.PokememesList(update)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
case pokememeInfoMsg.MatchString(text):
|
|
|
|
|
c.Talkers.PokememeInfo(update, playerRaw)
|
|
|
|
|
return "ok"
|
|
|
|
|
case update.Message.Command() == "me":
|
|
|
|
|
if playerRaw.ID != 0 {
|
|
|
|
|
c.Talkers.ProfileMessage(update, playerRaw)
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
case update.Message.Command() == "best":
|
|
|
|
|
c.Talkers.BestPokememesList(update, playerRaw)
|
|
|
|
|
return "ok"
|
|
|
|
|
case update.Message.Command() == "send_all":
|
2017-11-14 03:44:21 +04:00
|
|
|
|
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
|
|
|
|
c.Talkers.AdminBroadcastMessageCompose(update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
case update.Message.Command() == "send_confirm":
|
2017-11-14 03:44:21 +04:00
|
|
|
|
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
|
|
|
|
c.Talkers.AdminBroadcastMessageSend(update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 22:51:50 +04:00
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
case update.Message.Command() == "group_chats":
|
2017-11-14 03:44:21 +04:00
|
|
|
|
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
2017-11-19 22:16:11 +04:00
|
|
|
|
c.Chatter.GroupsList(update)
|
2017-11-13 22:51:50 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-19 22:16:11 +04:00
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
case update.Message.Command() == "squads":
|
|
|
|
|
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
|
|
|
|
c.Squader.SquadsList(update)
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
case update.Message.Command() == "make_squad":
|
|
|
|
|
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
|
|
|
|
return c.Squader.CreateSquad(update)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 03:44:21 +04:00
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
case update.Message.Command() == "pin":
|
|
|
|
|
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
|
|
|
|
return c.Pinner.PinMessageToAllChats(update)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
c.Talkers.AnyMessageUnauthorized(update)
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|