Archived
1

Three special chats in config

This commit is contained in:
Vladimir Hodakov 2017-11-26 16:54:06 +04:00
parent a0bfc6b32f
commit ca147a99a3
5 changed files with 22 additions and 14 deletions

View File

@ -6,7 +6,9 @@ database_connection:
user: "i2_bot" user: "i2_bot"
password: "i2_bot" password: "i2_bot"
database: "i2_bot" database: "i2_bot"
notifications: special_chats:
group_id: "group_id" bastion_id: "group_id"
default_id: "group_id"
headquarters_id: "group_id"
logs: logs:
log_path: "./i2_bot.log" log_path: "./i2_bot.log"

View File

@ -27,9 +27,11 @@ type TelegramConnection struct {
APIToken string `yaml:"api_token"` APIToken string `yaml:"api_token"`
} }
// NotificationsConnection handles settings for notifications // SpecialChats handles settings for special chats
type NotificationsConnection struct { type SpecialChats struct {
GroupID string `yaml:"group_id"` BastionID string `yaml:"bastion_id"`
DefaultID string `yaml:"default_id"`
HeadquartersID string `yaml:"headquarters_id"`
} }
// LoggingConfig handles log file configuration // LoggingConfig handles log file configuration
@ -39,10 +41,10 @@ type LoggingConfig struct {
// Config is a struct which represents config.yaml structure // Config is a struct which represents config.yaml structure
type Config struct { type Config struct {
Telegram TelegramConnection `yaml:"telegram_connection"` Telegram TelegramConnection `yaml:"telegram_connection"`
Database DatabaseConnection `yaml:"database_connection"` Database DatabaseConnection `yaml:"database_connection"`
Notifications NotificationsConnection `yaml:"notifications"` SpecialChats SpecialChats `yaml:"special_chats"`
Logs LoggingConfig `yaml:"logs"` Logs LoggingConfig `yaml:"logs"`
} }
// Init is a configuration initializer // Init is a configuration initializer

View File

@ -9,7 +9,7 @@ import (
) )
func (w *Welcomer) alertUserWithoutProfile(update *tgbotapi.Update, newUser *tgbotapi.User) string { 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) chat, ok := c.Chatter.GetOrCreateChat(update)
if !ok { if !ok {
return "fail" 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 { 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) chat, ok := c.Chatter.GetOrCreateChat(update)
if !ok { if !ok {
return "fail" return "fail"

View File

@ -6,6 +6,7 @@ package welcomer
import ( import (
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping" "lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
"strconv"
) )
// PrivateWelcomeMessageUnauthorized tell new user what to do. // 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") { if (newUser.UserName == "i2_bot") || (newUser.UserName == "i2_dev_bot") {
w.groupStartMessage(update) w.groupStartMessage(update)
} else { } else {
w.groupWelcomeUser(update, &newUser) defaultGroupID, _ := strconv.ParseInt(c.Cfg.SpecialChats.HeadquartersID, 10, 64)
if update.Message.Chat.ID == defaultGroupID {
w.groupWelcomeUser(update, &newUser)
}
} }
} }

View File

@ -25,13 +25,13 @@ func (w *Welcomer) groupWelcomeUser(update *tgbotapi.Update, newUser *tgbotapi.U
message += "Рад тебя видеть! Не забывай обновлять профиль почаще, и да пребудет с тобой Рандом!\n" message += "Рад тебя видеть! Не забывай обновлять профиль почаще, и да пребудет с тобой Рандом!\n"
message += "Последнее обновление твоего профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05") + "." message += "Последнее обновление твоего профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05") + "."
} else { } else {
message += "Обнови профиль, отправив его боту в личку. Так надо." message += "Обнови профиль, отправив его мне в личку."
w.alertSpyUser(update, newUser) w.alertSpyUser(update, newUser)
} }
} else { } else {
// newbie // newbie
message += "Добавь себе бота @i2\\_bot в список контактов и скинь в него игровой профиль. Это важно для успешной игры!\n" message += "Перешли мне свой профиль для дальнейших инструкций.\n"
w.alertUserWithoutProfile(update, newUser) w.alertUserWithoutProfile(update, newUser)
} }