From ca147a99a366172fa8ae8b4dde7d24d95e86a166 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Sun, 26 Nov 2017 16:54:06 +0400 Subject: [PATCH] Three special chats in config --- config.yml.example | 6 ++++-- lib/config/config.go | 16 +++++++++------- lib/welcomer/notifications.go | 4 ++-- lib/welcomer/responders.go | 6 +++++- lib/welcomer/welcomer.go | 4 ++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/config.yml.example b/config.yml.example index fc32e77..107d36b 100644 --- a/config.yml.example +++ b/config.yml.example @@ -6,7 +6,9 @@ database_connection: user: "i2_bot" password: "i2_bot" database: "i2_bot" -notifications: - group_id: "group_id" +special_chats: + bastion_id: "group_id" + default_id: "group_id" + headquarters_id: "group_id" logs: log_path: "./i2_bot.log" diff --git a/lib/config/config.go b/lib/config/config.go index 850f1f5..4c44193 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -27,9 +27,11 @@ type TelegramConnection struct { APIToken string `yaml:"api_token"` } -// NotificationsConnection handles settings for notifications -type NotificationsConnection struct { - GroupID string `yaml:"group_id"` +// SpecialChats handles settings for special chats +type SpecialChats struct { + BastionID string `yaml:"bastion_id"` + DefaultID string `yaml:"default_id"` + HeadquartersID string `yaml:"headquarters_id"` } // LoggingConfig handles log file configuration @@ -39,10 +41,10 @@ type LoggingConfig struct { // Config is a struct which represents config.yaml structure type Config struct { - Telegram TelegramConnection `yaml:"telegram_connection"` - Database DatabaseConnection `yaml:"database_connection"` - Notifications NotificationsConnection `yaml:"notifications"` - Logs LoggingConfig `yaml:"logs"` + Telegram TelegramConnection `yaml:"telegram_connection"` + Database DatabaseConnection `yaml:"database_connection"` + SpecialChats SpecialChats `yaml:"special_chats"` + Logs LoggingConfig `yaml:"logs"` } // Init is a configuration initializer diff --git a/lib/welcomer/notifications.go b/lib/welcomer/notifications.go index b46727a..07eea11 100644 --- a/lib/welcomer/notifications.go +++ b/lib/welcomer/notifications.go @@ -9,7 +9,7 @@ import ( ) func (w *Welcomer) alertUserWithoutProfile(update *tgbotapi.Update, newUser *tgbotapi.User) string { - alertGroupID, _ := strconv.ParseInt(c.Cfg.Notifications.GroupID, 10, 64) + alertGroupID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64) chat, ok := c.Chatter.GetOrCreateChat(update) if !ok { return "fail" @@ -28,7 +28,7 @@ func (w *Welcomer) alertUserWithoutProfile(update *tgbotapi.Update, newUser *tgb } func (w *Welcomer) alertSpyUser(update *tgbotapi.Update, newUser *tgbotapi.User) string { - alertGroupID, _ := strconv.ParseInt(c.Cfg.Notifications.GroupID, 10, 64) + alertGroupID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64) chat, ok := c.Chatter.GetOrCreateChat(update) if !ok { return "fail" diff --git a/lib/welcomer/responders.go b/lib/welcomer/responders.go index 0d22b8d..43badeb 100644 --- a/lib/welcomer/responders.go +++ b/lib/welcomer/responders.go @@ -6,6 +6,7 @@ package welcomer import ( "github.com/go-telegram-bot-api/telegram-bot-api" "lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping" + "strconv" ) // PrivateWelcomeMessageUnauthorized tell new user what to do. @@ -51,7 +52,10 @@ func (w *Welcomer) GroupWelcomeMessage(update *tgbotapi.Update) string { if (newUser.UserName == "i2_bot") || (newUser.UserName == "i2_dev_bot") { w.groupStartMessage(update) } else { - w.groupWelcomeUser(update, &newUser) + defaultGroupID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64) + if update.Message.Chat.ID == defaultGroupID { + w.groupWelcomeUser(update, &newUser) + } } } diff --git a/lib/welcomer/welcomer.go b/lib/welcomer/welcomer.go index 62ed616..148d4e2 100644 --- a/lib/welcomer/welcomer.go +++ b/lib/welcomer/welcomer.go @@ -25,13 +25,13 @@ func (w *Welcomer) groupWelcomeUser(update *tgbotapi.Update, newUser *tgbotapi.U message += "Рад тебя видеть! Не забывай обновлять профиль почаще, и да пребудет с тобой Рандом!\n" message += "Последнее обновление твоего профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05") + "." } else { - message += "Обнови профиль, отправив его боту в личку. Так надо." + message += "Обнови профиль, отправив его мне в личку." w.alertSpyUser(update, newUser) } } else { // newbie - message += "Добавь себе бота @i2\\_bot в список контактов и скинь в него игровой профиль. Это важно для успешной игры!\n" + message += "Перешли мне свой профиль для дальнейших инструкций.\n" w.alertUserWithoutProfile(update, newUser) }