From 4660d02a328efd84cf0b10263996207dfa0fa9cd Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Sun, 11 Feb 2018 18:58:41 +0400 Subject: [PATCH] Added "banned" status for players --- lib/router/callback_request.go | 4 ++++ lib/router/inline.go | 2 +- lib/router/private_request.go | 4 ++++ lib/talkers/errors.go | 12 ++++++++++++ lib/talkers/talkersinterface/talkersinterface.go | 3 ++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/router/callback_request.go b/lib/router/callback_request.go index b43ed56..56a8152 100644 --- a/lib/router/callback_request.go +++ b/lib/router/callback_request.go @@ -16,6 +16,10 @@ func (r *Router) RouteCallback(update *tgbotapi.Update) string { return "fail" } + if playerRaw.Status == "banned" { + return c.Talkers.BanError(update) + } + var enableAlarmCallback = regexp.MustCompile("enable_reminder_(\\d+)\\z") var disableAlarmCallback = regexp.MustCompile("disable_reminder_(\\d+)\\z") diff --git a/lib/router/inline.go b/lib/router/inline.go index dc28f2f..fffc722 100644 --- a/lib/router/inline.go +++ b/lib/router/inline.go @@ -19,7 +19,7 @@ func (r *Router) RouteInline(update *tgbotapi.Update) string { results := make([]interface{}, 0) - if playerRaw.LeagueID != 1 { + if (playerRaw.LeagueID != 1) || (playerRaw.Status == "banned") { article := tgbotapi.NewInlineQueryResultArticle("0", "Команда боту @PokememBroBot:", "👤Герой") article.Description = "👤Герой" diff --git a/lib/router/private_request.go b/lib/router/private_request.go index 7da2c94..44d2285 100644 --- a/lib/router/private_request.go +++ b/lib/router/private_request.go @@ -20,6 +20,10 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi var squadInfoMsg = regexp.MustCompile("/show_squad(\\d+)\\z") var orderSendMsg = regexp.MustCompile("/send_order(\\d+)\\z") + if playerRaw.Status == "banned" { + return c.Talkers.BanError(update) + } + if update.Message.ForwardFrom != nil { if update.Message.ForwardFrom.ID != 360402625 { c.Log.Info("Forward from another user or bot. Ignoring") diff --git a/lib/talkers/errors.go b/lib/talkers/errors.go index ba698d7..d1f2066 100644 --- a/lib/talkers/errors.go +++ b/lib/talkers/errors.go @@ -20,6 +20,18 @@ func (t *Talkers) AnyMessageUnauthorized(update *tgbotapi.Update) string { return "fail" } +// BanError throws error for persona non grata +func (t *Talkers) BanError(update *tgbotapi.Update) string { + message := "Вам здесь не рады. Использование бота для вас запрещено." + + msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) + msg.ParseMode = "Markdown" + + c.Bot.Send(msg) + + return "fail" +} + // BotError throws when bot can't do something func (t *Talkers) BotError(update *tgbotapi.Update) string { message := "Ой, внутренняя ошибка в боте :(\n\n" diff --git a/lib/talkers/talkersinterface/talkersinterface.go b/lib/talkers/talkersinterface/talkersinterface.go index 6da7b68..99eae15 100644 --- a/lib/talkers/talkersinterface/talkersinterface.go +++ b/lib/talkers/talkersinterface/talkersinterface.go @@ -4,8 +4,8 @@ package talkersinterface import ( - "github.com/go-telegram-bot-api/telegram-bot-api" "git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping" + "github.com/go-telegram-bot-api/telegram-bot-api" ) // TalkersInterface implements Talkers for importing via appcontex @@ -18,6 +18,7 @@ type TalkersInterface interface { FiveOffer(update *tgbotapi.Update) string AnyMessageUnauthorized(update *tgbotapi.Update) string + BanError(update *tgbotapi.Update) string BotError(update *tgbotapi.Update) string LongMessage(update *tgbotapi.Update) string