hdkv
/
i2_bot
Archived
1
Fork 0

Three special chats in config

master
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"
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"

View File

@ -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

View File

@ -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"

View File

@ -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)
}
}
}

View File

@ -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)
}