Massive refactoring for future development
This commit is contained in:
48
lib/welcomer/responders.go
Normal file
48
lib/welcomer/responders.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package welcomer
|
||||
|
||||
import (
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
)
|
||||
|
||||
// PrivateWelcomeMessageUnauthorized tell new user what to do.
|
||||
func (w *Welcomer) PrivateWelcomeMessageUnauthorized(update *tgbotapi.Update) {
|
||||
message := "*Бот Инстинкта приветствует тебя!*\n\n"
|
||||
message += "Для начала работы с ботом, пожалуйста, перешли от бота игры @PokememBroBot профиль героя.\n"
|
||||
message += "Все дальнейшие действия с ботом возможны лишь при наличии профиля игрока."
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
// PrivateWelcomeMessageAuthorized greets existing user
|
||||
func (w *Welcomer) PrivateWelcomeMessageAuthorized(update *tgbotapi.Update, playerRaw *dbmapping.Player) {
|
||||
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)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if (newUsers[i].UserName == "i2_bot") || (newUsers[i].UserName == "i2_dev_bot") {
|
||||
w.groupStartMessage(update)
|
||||
}
|
||||
|
||||
newUser := newUsers[i]
|
||||
w.groupWelcomeUser(update, &newUser)
|
||||
}
|
||||
|
||||
return "ok"
|
||||
}
|
@@ -9,12 +9,12 @@ import (
|
||||
)
|
||||
|
||||
func (w *Welcomer) groupWelcomeUser(update *tgbotapi.Update, newUser *tgbotapi.User) string {
|
||||
playerRaw, ok := c.Getters.GetOrCreatePlayer(newUser.ID)
|
||||
playerRaw, ok := c.Users.GetOrCreatePlayer(newUser.ID)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
profileRaw, profileExist := c.Getters.GetProfile(playerRaw.ID)
|
||||
profileRaw, profileExist := c.Users.GetProfile(playerRaw.ID)
|
||||
|
||||
message := "*Бот Инстинкта приветствует тебя, *@"
|
||||
message += newUser.UserName
|
||||
@@ -54,19 +54,4 @@ func (w *Welcomer) groupStartMessage(update *tgbotapi.Update) string {
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// WelcomeMessage welcomes new user on group or bot itself
|
||||
func (w *Welcomer) WelcomeMessage(update *tgbotapi.Update) string {
|
||||
newUsers := *update.Message.NewChatMembers
|
||||
for i := range newUsers {
|
||||
if (newUsers[i].UserName == "i2_bot") || (newUsers[i].UserName == "i2_dev_bot") {
|
||||
w.groupStartMessage(update)
|
||||
}
|
||||
|
||||
newUser := newUsers[i]
|
||||
w.groupWelcomeUser(update, &newUser)
|
||||
}
|
||||
|
||||
return "ok"
|
||||
}
|
||||
}
|
@@ -5,10 +5,14 @@ package welcomerinterface
|
||||
|
||||
import (
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
)
|
||||
|
||||
// WelcomerInterface implements Welcomer for importing via appcontex
|
||||
type WelcomerInterface interface {
|
||||
Init()
|
||||
WelcomeMessage(update *tgbotapi.Update) string
|
||||
|
||||
PrivateWelcomeMessageUnauthorized(update *tgbotapi.Update)
|
||||
PrivateWelcomeMessageAuthorized(update *tgbotapi.Update, playerRaw *dbmapping.Player)
|
||||
GroupWelcomeMessage(update *tgbotapi.Update) string
|
||||
}
|
||||
|
Reference in New Issue
Block a user