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

195 lines
6.0 KiB
Go
Raw Normal View History

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package router
import (
2018-01-21 23:28:53 +04:00
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
2018-01-23 20:13:16 +04:00
"github.com/go-telegram-bot-api/telegram-bot-api"
2017-11-14 03:44:21 +04:00
"regexp"
)
2017-11-14 03:44:21 +04:00
func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
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")
var profileMsg = regexp.MustCompile("/profile(\\d+)\\z")
2017-11-24 00:16:22 +04:00
var squadInfoMsg = regexp.MustCompile("/show_squad(\\d+)\\z")
var orderSendMsg = regexp.MustCompile("/send_order(\\d+)\\z")
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")
} else {
2017-11-14 03:44:21 +04:00
c.Log.Info("Forward from PokememBro bot! Processing...")
if playerRaw.ID != 0 {
2017-11-14 03:44:21 +04:00
c.Forwarder.ProcessForward(update, playerRaw)
} else {
return c.Talkers.AnyMessageUnauthorized(update)
}
}
} else {
if update.Message.IsCommand() {
switch {
case update.Message.Command() == "start":
if playerRaw.LeagueID != 0 {
if playerRaw.Status == "special" {
c.Welcomer.PrivateWelcomeMessageSpecial(update, playerRaw)
return "ok"
}
c.Welcomer.PrivateWelcomeMessageAuthorized(update, playerRaw)
return "ok"
}
c.Welcomer.PrivateWelcomeMessageUnauthorized(update)
return "ok"
2017-12-02 19:50:56 +04:00
case update.Message.Command() == "help":
2017-11-14 03:44:21 +04:00
c.Talkers.HelpMessage(update, playerRaw)
return "ok"
2017-12-02 19:50:56 +04:00
case update.Message.Command() == "academy":
c.Talkers.AcademyMessage(update, playerRaw)
2017-12-02 19:50:56 +04:00
return "ok"
case update.Message.Command() == "bastion":
c.Talkers.BastionMessage(update, playerRaw)
2017-12-02 19:50:56 +04:00
return "ok"
case pokedexMsg.MatchString(text):
c.Pokedexer.PokememesList(update)
return "ok"
case pokememeInfoMsg.MatchString(text):
c.Pokedexer.PokememeInfo(update, playerRaw)
return "ok"
2017-12-04 23:14:41 +04:00
case update.Message.Command() == "delete_pokememe":
if c.Users.PlayerBetterThan(playerRaw, "owner") {
return c.Pokedexer.DeletePokememe(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "me":
if playerRaw.ID != 0 {
c.Users.ProfileMessage(update, playerRaw)
return "ok"
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "best":
c.Pokedexer.BestPokememesList(update, playerRaw)
return "ok"
case update.Message.Command() == "reminders":
return c.Reminder.AlarmsList(update, playerRaw)
case update.Message.Command() == "send_all":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
c.Broadcaster.AdminBroadcastMessageCompose(update, playerRaw)
return "ok"
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "send_league":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
c.Broadcaster.AdminBroadcastMessageCompose(update, playerRaw)
return "ok"
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "send_confirm":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
go c.Broadcaster.AdminBroadcastMessageSend(update, playerRaw)
return "ok"
}
return c.Talkers.AnyMessageUnauthorized(update)
2017-11-26 08:31:56 +04:00
case update.Message.Command() == "chats":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
c.Chatter.GroupsList(update)
return "ok"
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "squads":
2017-11-24 00:16:22 +04:00
return c.Squader.SquadsList(update, playerRaw)
case update.Message.Command() == "make_squad":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
2017-11-24 00:16:22 +04:00
return c.Squader.CreateSquad(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
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") {
return c.Pinner.PinMessageToSomeChats(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "pin_all":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
2017-11-24 00:16:22 +04:00
return c.Pinner.PinMessageToAllChats(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
2017-11-24 00:16:22 +04:00
case update.Message.Command() == "orders":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
return c.Orders.ListAllOrders(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
case orderSendMsg.MatchString(text):
if c.Users.PlayerBetterThan(playerRaw, "admin") {
return c.Orders.SendOrder(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
2017-11-24 00:16:22 +04:00
case usersMsg.MatchString(text):
if c.Users.PlayerBetterThan(playerRaw, "academic") {
2017-11-24 00:16:22 +04:00
return c.Users.UsersList(update)
2017-11-14 03:44:21 +04:00
}
return c.Talkers.AnyMessageUnauthorized(update)
case profileMsg.MatchString(text):
if c.Users.PlayerBetterThan(playerRaw, "academic") {
return c.Users.ForeignProfileMessage(update)
}
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") {
return c.Users.FindByLevel(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "find_user":
if c.Users.PlayerBetterThan(playerRaw, "academic") {
return c.Users.FindByName(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
2017-11-24 00:16:22 +04:00
case update.Message.Command() == "squad_add_user":
return c.Squader.AddUserToSquad(update, playerRaw)
case update.Message.Command() == "squad_add_commander":
return c.Squader.AddUserToSquad(update, playerRaw)
case squadInfoMsg.MatchString(text):
return c.Squader.SquadInfo(update, playerRaw)
2017-12-03 14:37:54 +04:00
case update.Message.Command() == "five_offer":
if c.Users.PlayerBetterThan(playerRaw, "admin") {
return c.Talkers.FiveOffer(update)
}
return c.Talkers.AnyMessageUnauthorized(update)
}
}
}
return "fail"
}