hdkv
/
i2_bot
Archived
1
Fork 0

Add games chat

Games chat used to divide talks in Bastion from @gamee games and so on.
master
Vladimir Hodakov 2018-04-04 21:33:30 +04:00
parent af525b207f
commit f67e652ae4
4 changed files with 22 additions and 12 deletions

View File

@ -13,5 +13,6 @@ special_chats:
bastion_id: "group_id" bastion_id: "group_id"
default_id: "group_id" default_id: "group_id"
headquarters_id: "group_id" headquarters_id: "group_id"
games_id: "group_id"
logs: logs:
log_path: "./i2_bot.log" log_path: "./i2_bot.log"

View File

@ -1,11 +1,12 @@
// i2_bot Instinct PokememBro Bot // i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov // Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
package chatter package chatter
import ( import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"strconv" "strconv"
"github.com/go-telegram-bot-api/telegram-bot-api"
) )
// GroupsList lists all chats where bot exist // 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) bastionChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.BastionID, 10, 64)
defaultChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.DefaultID, 10, 64) defaultChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.DefaultID, 10, 64)
hqChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64) hqChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64)
gamesChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.GamesID, 10, 64)
message := "*Бот состоит в следующих групповых чатах:*\n" message := "*Бот состоит в следующих групповых чатах:*\n"
@ -42,6 +44,10 @@ func (ct *Chatter) GroupsList(update *tgbotapi.Update) string {
if groupChats[i].TelegramID == hqChatID { if groupChats[i].TelegramID == hqChatID {
message += "Является чатом совета лиги\n" message += "Является чатом совета лиги\n"
} }
if groupChats[i].TelegramID == gamesChatID {
message += "Является игровым чатом\n"
}
} }
} }

View File

@ -1,5 +1,5 @@
// i2_bot Instinct PokememBro Bot // i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov // Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
package chatter 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) bastionChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.BastionID, 10, 64)
academyChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.AcademyID, 10, 64) academyChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.AcademyID, 10, 64)
hqChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 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 { if update.Message.Chat.ID == defaultChatID || update.Message.Chat.ID == hqChatID {
return true 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) playerRaw, err := c.DataCache.GetPlayerByTelegramID(user.ID)
if err != nil { if err != nil {
c.Log.Error(err.Error()) 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 // So, user is not a PokememBro admin. For Bastion and Academy she needs to be league player
switch update.Message.Chat.ID { switch update.Message.Chat.ID {
case academyChatID: case academyChatID, bastionChatID, gamesChatID:
if playerRaw.LeagueID == 1 && playerRaw.Status != "spy" && playerRaw.Status != "league_changed" && playerRaw.Status != "banned" {
return true
}
case bastionChatID:
if playerRaw.LeagueID == 1 && playerRaw.Status != "spy" && playerRaw.Status != "league_changed" && playerRaw.Status != "banned" { if playerRaw.LeagueID == 1 && playerRaw.Status != "spy" && playerRaw.Status != "league_changed" && playerRaw.Status != "banned" {
return true return true
} }

View File

@ -1,17 +1,18 @@
// i2_bot Instinct PokememBro Bot // i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov // Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
package config package config
import ( import (
"bitbucket.org/pztrn/mogrus"
"gopkg.in/yaml.v2"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"bitbucket.org/pztrn/mogrus"
"gopkg.in/yaml.v2"
) )
// VERSION is the current bot's version // 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 // DatabaseConnection handles database connection settings in config.yaml
type DatabaseConnection struct { type DatabaseConnection struct {
@ -35,6 +36,7 @@ type SpecialChats struct {
BastionID string `yaml:"bastion_id"` BastionID string `yaml:"bastion_id"`
DefaultID string `yaml:"default_id"` DefaultID string `yaml:"default_id"`
HeadquartersID string `yaml:"headquarters_id"` HeadquartersID string `yaml:"headquarters_id"`
GamesID string `yaml:"games_id"`
} }
// LoggingConfig handles log file configuration // LoggingConfig handles log file configuration