From f67e652ae438384f0c88ae09074766b265dc25d9 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Wed, 4 Apr 2018 21:33:30 +0400 Subject: [PATCH] Add games chat Games chat used to divide talks in Bastion from @gamee games and so on. --- config.yml.example | 1 + lib/chatter/responders.go | 10 ++++++++-- lib/chatter/restricters.go | 13 +++++++------ lib/config/config.go | 10 ++++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/config.yml.example b/config.yml.example index 6ebb64f..274be16 100644 --- a/config.yml.example +++ b/config.yml.example @@ -13,5 +13,6 @@ special_chats: bastion_id: "group_id" default_id: "group_id" headquarters_id: "group_id" + games_id: "group_id" logs: log_path: "./i2_bot.log" diff --git a/lib/chatter/responders.go b/lib/chatter/responders.go index ec65a1a..e9888a5 100644 --- a/lib/chatter/responders.go +++ b/lib/chatter/responders.go @@ -1,11 +1,12 @@ // i2_bot – Instinct PokememBro Bot -// Copyright (c) 2017 Vladimir "fat0troll" Hodakov +// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov package chatter import ( - "github.com/go-telegram-bot-api/telegram-bot-api" "strconv" + + "github.com/go-telegram-bot-api/telegram-bot-api" ) // GroupsList lists all chats where bot exist @@ -16,6 +17,7 @@ func (ct *Chatter) GroupsList(update *tgbotapi.Update) string { bastionChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.BastionID, 10, 64) defaultChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.DefaultID, 10, 64) hqChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64) + gamesChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.GamesID, 10, 64) message := "*Бот состоит в следующих групповых чатах:*\n" @@ -42,6 +44,10 @@ func (ct *Chatter) GroupsList(update *tgbotapi.Update) string { if groupChats[i].TelegramID == hqChatID { message += "Является чатом совета лиги\n" } + + if groupChats[i].TelegramID == gamesChatID { + message += "Является игровым чатом\n" + } } } diff --git a/lib/chatter/restricters.go b/lib/chatter/restricters.go index 1c727ac..e0e921a 100644 --- a/lib/chatter/restricters.go +++ b/lib/chatter/restricters.go @@ -1,5 +1,5 @@ // i2_bot – Instinct PokememBro Bot -// Copyright (c) 2017 Vladimir "fat0troll" Hodakov +// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov package chatter @@ -17,6 +17,7 @@ func (ct *Chatter) userPrivilegesCheck(update *tgbotapi.Update, user *tgbotapi.U bastionChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.BastionID, 10, 64) academyChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.AcademyID, 10, 64) hqChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64) + gamesChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.GamesID, 10, 64) if update.Message.Chat.ID == defaultChatID || update.Message.Chat.ID == hqChatID { return true @@ -32,6 +33,10 @@ func (ct *Chatter) userPrivilegesCheck(update *tgbotapi.Update, user *tgbotapi.U } } + if update.Message.Chat.ID == gamesChatID && strings.Contains(user.UserName, "bot") { + return true + } + playerRaw, err := c.DataCache.GetPlayerByTelegramID(user.ID) if err != nil { c.Log.Error(err.Error()) @@ -44,11 +49,7 @@ func (ct *Chatter) userPrivilegesCheck(update *tgbotapi.Update, user *tgbotapi.U // So, user is not a PokememBro admin. For Bastion and Academy she needs to be league player switch update.Message.Chat.ID { - case academyChatID: - if playerRaw.LeagueID == 1 && playerRaw.Status != "spy" && playerRaw.Status != "league_changed" && playerRaw.Status != "banned" { - return true - } - case bastionChatID: + case academyChatID, bastionChatID, gamesChatID: if playerRaw.LeagueID == 1 && playerRaw.Status != "spy" && playerRaw.Status != "league_changed" && playerRaw.Status != "banned" { return true } diff --git a/lib/config/config.go b/lib/config/config.go index 67a16d5..6c21653 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -1,17 +1,18 @@ // i2_bot – Instinct PokememBro Bot -// Copyright (c) 2017 Vladimir "fat0troll" Hodakov +// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov package config import ( - "bitbucket.org/pztrn/mogrus" - "gopkg.in/yaml.v2" "io/ioutil" "path/filepath" + + "bitbucket.org/pztrn/mogrus" + "gopkg.in/yaml.v2" ) // VERSION is the current bot's version -const VERSION = "0.7.2" +const VERSION = "0.7.4" // DatabaseConnection handles database connection settings in config.yaml type DatabaseConnection struct { @@ -35,6 +36,7 @@ type SpecialChats struct { BastionID string `yaml:"bastion_id"` DefaultID string `yaml:"default_id"` HeadquartersID string `yaml:"headquarters_id"` + GamesID string `yaml:"games_id"` } // LoggingConfig handles log file configuration