2017-11-03 21:33:02 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
2018-04-04 21:58:57 +04:00
|
|
|
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
2017-11-03 21:33:02 +04:00
|
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
2018-03-31 16:45:09 +04:00
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2018-05-02 00:47:55 +04:00
|
|
|
|
"regexp"
|
2018-02-17 07:03:58 +04:00
|
|
|
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
2018-05-02 00:47:55 +04:00
|
|
|
|
"strconv"
|
2017-11-03 21:33:02 +04:00
|
|
|
|
)
|
|
|
|
|
|
2018-03-31 16:45:09 +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+)")
|
2017-11-29 18:54:13 +04:00
|
|
|
|
var usersMsg = regexp.MustCompile("/users(\\d+|)\\z")
|
2017-12-01 10:55:18 +04:00
|
|
|
|
var profileMsg = regexp.MustCompile("/profile(\\d+)\\z")
|
2017-11-24 00:16:22 +04:00
|
|
|
|
var squadInfoMsg = regexp.MustCompile("/show_squad(\\d+)\\z")
|
2017-11-26 15:28:55 +04:00
|
|
|
|
var orderSendMsg = regexp.MustCompile("/send_order(\\d+)\\z")
|
2017-11-03 21:33:02 +04:00
|
|
|
|
|
2018-02-11 18:58:41 +04:00
|
|
|
|
if playerRaw.Status == "banned" {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.BanError(&update)
|
2018-02-11 18:58:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
if update.Message.ForwardFrom != nil {
|
2018-05-02 00:47:55 +04:00
|
|
|
|
if update.Message.ForwardFrom.ID == 360402625 {
|
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 {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Forwarder.ProcessForward(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
} else {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
}
|
2018-05-02 00:47:55 +04:00
|
|
|
|
} else if update.Message.ForwardFrom.ID == 392622454 {
|
|
|
|
|
// Pokememes test bot with actual pokedeks
|
|
|
|
|
c.Log.Info("Forward from PokememBro test bot! Processing...")
|
|
|
|
|
if playerRaw.ID != 0 {
|
|
|
|
|
c.Forwarder.ProcessForward(&update, playerRaw)
|
|
|
|
|
} else {
|
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
c.Log.Info("Forward from another user or bot (" + strconv.Itoa(update.Message.ForwardFrom.ID) + "). Ignoring")
|
2017-11-03 21:33:02 +04:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if update.Message.IsCommand() {
|
|
|
|
|
switch {
|
|
|
|
|
case update.Message.Command() == "start":
|
2017-11-25 03:00:34 +04:00
|
|
|
|
if playerRaw.LeagueID != 0 {
|
2017-11-26 15:28:55 +04:00
|
|
|
|
if playerRaw.Status == "special" {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Welcomer.PrivateWelcomeMessageSpecial(&update, playerRaw)
|
2017-11-26 15:28:55 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Welcomer.PrivateWelcomeMessageAuthorized(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Welcomer.PrivateWelcomeMessageUnauthorized(&update)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
2017-12-02 19:50:56 +04:00
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
case update.Message.Command() == "help":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Talkers.HelpMessage(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
2018-03-06 21:38:25 +04:00
|
|
|
|
case update.Message.Command() == "faq":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.FAQMessage(&update)
|
2017-12-02 19:50:56 +04:00
|
|
|
|
case update.Message.Command() == "academy":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Talkers.AcademyMessage(&update, playerRaw)
|
2017-12-02 19:50:56 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
case update.Message.Command() == "bastion":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Talkers.BastionMessage(&update, playerRaw)
|
2017-12-02 19:50:56 +04:00
|
|
|
|
return "ok"
|
2018-04-04 21:58:57 +04:00
|
|
|
|
case update.Message.Command() == "games_chat":
|
|
|
|
|
c.Talkers.GamesMessage(&update, playerRaw)
|
|
|
|
|
return "ok"
|
2017-12-02 19:50:56 +04:00
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
case pokedexMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Pokedexer.PokememesList(&update)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
case pokememeInfoMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Pokedexer.PokememeInfo(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
2017-12-04 23:14:41 +04:00
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
case update.Message.Command() == "me":
|
|
|
|
|
if playerRaw.ID != 0 {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Users.ProfileMessage(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
2018-02-05 12:37:46 +04:00
|
|
|
|
case update.Message.Command() == "top":
|
|
|
|
|
if playerRaw.ID != 0 {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Statistics.TopList(&update, playerRaw)
|
2018-02-05 12:37:46 +04:00
|
|
|
|
}
|
2017-11-03 21:33:02 +04:00
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2018-02-05 12:37:46 +04:00
|
|
|
|
case update.Message.Command() == "top_my":
|
|
|
|
|
if playerRaw.ID != 0 {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Statistics.TopList(&update, playerRaw)
|
2018-02-05 12:37:46 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2018-02-05 12:37:46 +04:00
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
case update.Message.Command() == "best":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
2018-02-07 15:00:04 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
case update.Message.Command() == "advice":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
2018-02-07 15:59:28 +04:00
|
|
|
|
case update.Message.Command() == "best_all":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
2018-02-07 15:59:28 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
case update.Message.Command() == "advice_all":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
2018-02-07 15:59:28 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
case update.Message.Command() == "best_nofilter":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
2018-02-07 15:59:28 +04:00
|
|
|
|
return "ok"
|
2017-12-23 01:40:36 +04:00
|
|
|
|
case update.Message.Command() == "reminders":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Reminder.AlarmsList(&update, playerRaw)
|
2017-12-23 01:40:36 +04:00
|
|
|
|
|
2017-11-03 21:33:02 +04:00
|
|
|
|
case update.Message.Command() == "send_all":
|
2017-11-21 06:06:32 +04:00
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Broadcaster.AdminBroadcastMessageCompose(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-25 03:00:34 +04:00
|
|
|
|
case update.Message.Command() == "send_league":
|
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Broadcaster.AdminBroadcastMessageCompose(&update, playerRaw)
|
2017-11-25 03:00:34 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
case update.Message.Command() == "send_confirm":
|
2017-11-21 06:06:32 +04:00
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
go c.Broadcaster.AdminBroadcastMessageSend(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-26 08:31:56 +04:00
|
|
|
|
case update.Message.Command() == "chats":
|
2017-11-21 06:06:32 +04:00
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
c.Chatter.GroupsList(&update)
|
2017-11-13 22:51:50 +04:00
|
|
|
|
return "ok"
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-19 22:16:11 +04:00
|
|
|
|
case update.Message.Command() == "squads":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Squader.SquadsList(&update, playerRaw)
|
2017-11-19 22:16:11 +04:00
|
|
|
|
|
2017-11-24 00:16:22 +04:00
|
|
|
|
case update.Message.Command() == "pin":
|
2017-11-26 08:31:56 +04:00
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Pinner.PinMessageToSomeChats(&update)
|
2017-11-26 08:31:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-26 08:31:56 +04:00
|
|
|
|
case update.Message.Command() == "pin_all":
|
2017-11-21 06:06:32 +04:00
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Pinner.PinMessageToAllChats(&update)
|
2017-11-19 22:16:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-24 00:16:22 +04:00
|
|
|
|
|
2017-11-26 15:28:55 +04:00
|
|
|
|
case update.Message.Command() == "orders":
|
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Orders.ListAllOrders(&update)
|
2017-11-26 15:28:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-26 15:28:55 +04:00
|
|
|
|
case orderSendMsg.MatchString(text):
|
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Orders.SendOrder(&update)
|
2017-11-26 15:28:55 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-26 15:28:55 +04:00
|
|
|
|
|
2017-11-24 00:16:22 +04:00
|
|
|
|
case usersMsg.MatchString(text):
|
2017-12-01 10:55:18 +04:00
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Users.UsersList(&update)
|
2017-11-14 03:44:21 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-12-02 13:45:24 +04:00
|
|
|
|
|
2017-12-01 10:55:18 +04:00
|
|
|
|
case profileMsg.MatchString(text):
|
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Users.ForeignProfileMessage(&update)
|
2017-12-01 10:55:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-11-24 00:16:22 +04:00
|
|
|
|
|
2018-01-23 20:13:16 +04:00
|
|
|
|
case update.Message.Command() == "find_level":
|
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Users.FindByLevel(&update)
|
2018-01-23 20:13:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-12-02 13:45:24 +04:00
|
|
|
|
case update.Message.Command() == "find_user":
|
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Users.FindByName(&update)
|
2017-12-02 13:45:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2018-02-05 13:00:18 +04:00
|
|
|
|
case update.Message.Command() == "find_top_attack":
|
|
|
|
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Users.FindByTopAttack(&update)
|
2018-02-05 13:00:18 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
2017-12-02 13:45:24 +04:00
|
|
|
|
|
2017-11-24 00:16:22 +04:00
|
|
|
|
case update.Message.Command() == "squad_add_user":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Squader.AddUserToSquad(&update, playerRaw)
|
2017-11-24 00:16:22 +04:00
|
|
|
|
case update.Message.Command() == "squad_add_commander":
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Squader.AddUserToSquad(&update, playerRaw)
|
2017-11-24 00:16:22 +04:00
|
|
|
|
|
|
|
|
|
case squadInfoMsg.MatchString(text):
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return c.Squader.SquadInfo(&update, playerRaw)
|
2017-11-03 21:33:02 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|