2017-10-06 02:56:06 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
2017-11-21 06:06:32 +04:00
|
|
|
|
package welcomer
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
|
|
|
|
import (
|
2017-11-26 16:54:06 +04:00
|
|
|
|
"strconv"
|
2018-05-02 07:25:39 +04:00
|
|
|
|
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2018-05-19 12:14:25 +04:00
|
|
|
|
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
2017-10-06 02:56:06 +04:00
|
|
|
|
)
|
|
|
|
|
|
2017-11-21 06:06:32 +04:00
|
|
|
|
// PrivateWelcomeMessageUnauthorized tell new user what to do.
|
|
|
|
|
func (w *Welcomer) PrivateWelcomeMessageUnauthorized(update *tgbotapi.Update) {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
message := "*Бот Инстинкта приветствует тебя!*\n\n"
|
2018-05-02 08:48:22 +04:00
|
|
|
|
message += "Для начала работы с ботом, пожалуйста, перешли от бота игры @PokememBroBot свою статистику.\n"
|
|
|
|
|
message += "Все дальнейшие действия с ботом возможны лишь при наличии профиля игрока внутри его базы данных.\n\n"
|
2017-12-06 14:03:04 +04:00
|
|
|
|
|
2018-05-02 08:48:22 +04:00
|
|
|
|
message += "_Нажми на кнопку, получишь результат\nИ твоя мечта осуществится\nНажми на кнопку…_\n"
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
msg.ParseMode = "Markdown"
|
2018-05-02 08:48:22 +04:00
|
|
|
|
keyboard := tgbotapi.InlineKeyboardMarkup{}
|
|
|
|
|
var row []tgbotapi.InlineKeyboardButton
|
|
|
|
|
btn := tgbotapi.NewInlineKeyboardButtonSwitch("Отправить команду @PokememBroBot", "Статы")
|
|
|
|
|
row = append(row, btn)
|
|
|
|
|
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row)
|
|
|
|
|
|
|
|
|
|
msg.ReplyMarkup = keyboard
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
2017-10-18 07:03:34 +04:00
|
|
|
|
c.Bot.Send(msg)
|
2017-10-06 02:56:06 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 06:06:32 +04:00
|
|
|
|
// PrivateWelcomeMessageAuthorized greets existing user
|
|
|
|
|
func (w *Welcomer) PrivateWelcomeMessageAuthorized(update *tgbotapi.Update, playerRaw *dbmapping.Player) {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
message := "*Бот Инстинкта приветствует тебя. Снова.*\n\n"
|
|
|
|
|
message += "Привет, " + update.Message.From.FirstName + " " + update.Message.From.LastName + "!\n"
|
|
|
|
|
message += "Последнее обновление информации о тебе: " + playerRaw.UpdatedAt.Format("02.01.2006 15:04:05 -0700")
|
|
|
|
|
message += "\nПосмотреть информацию о себе: /me"
|
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
msg.ParseMode = "Markdown"
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
2017-10-18 07:03:34 +04:00
|
|
|
|
c.Bot.Send(msg)
|
2017-10-06 02:56:06 +04:00
|
|
|
|
}
|
2017-11-21 06:06:32 +04:00
|
|
|
|
|
2017-11-26 15:28:55 +04:00
|
|
|
|
// PrivateWelcomeMessageSpecial greets existing user with `special` access
|
|
|
|
|
func (w *Welcomer) PrivateWelcomeMessageSpecial(update *tgbotapi.Update, playerRaw *dbmapping.Player) {
|
|
|
|
|
message := "*Бот Инстинкта приветствует тебя. Снова.*\n\n"
|
|
|
|
|
message += "Привет, " + update.Message.From.FirstName + " " + update.Message.From.LastName + "!\n"
|
|
|
|
|
message += "\nБудь аккуратен, суперюзер!"
|
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
|
|
|
msg.ParseMode = "Markdown"
|
|
|
|
|
|
|
|
|
|
c.Bot.Send(msg)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 06:06:32 +04:00
|
|
|
|
// GroupWelcomeMessage welcomes new user on group or bot itself
|
|
|
|
|
func (w *Welcomer) GroupWelcomeMessage(update *tgbotapi.Update) string {
|
|
|
|
|
newUsers := *update.Message.NewChatMembers
|
|
|
|
|
for i := range newUsers {
|
2017-11-26 15:45:55 +04:00
|
|
|
|
newUser := newUsers[i]
|
|
|
|
|
if (newUser.UserName == "i2_bot") || (newUser.UserName == "i2_dev_bot") {
|
2017-11-21 06:06:32 +04:00
|
|
|
|
w.groupStartMessage(update)
|
2017-11-26 15:45:55 +04:00
|
|
|
|
} else {
|
2017-11-29 16:36:06 +04:00
|
|
|
|
defaultGroupID, _ := strconv.ParseInt(c.Cfg.SpecialChats.DefaultID, 10, 64)
|
2017-11-26 17:28:26 +04:00
|
|
|
|
|
2017-11-26 16:54:06 +04:00
|
|
|
|
if update.Message.Chat.ID == defaultGroupID {
|
|
|
|
|
w.groupWelcomeUser(update, &newUser)
|
|
|
|
|
}
|
2017-11-21 06:06:32 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "ok"
|
|
|
|
|
}
|