Work on squads, alerts on new user with empty or spy profile
Closes #1 Closes #2
This commit is contained in:
31
lib/welcomer/exported.go
Normal file
31
lib/welcomer/exported.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package welcomer
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/appcontext"
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/welcomer/welcomerinterface"
|
||||
)
|
||||
|
||||
var (
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
// Welcomer is a function-handling struct for talkers
|
||||
type Welcomer struct{}
|
||||
|
||||
// New is a appcontext initialization function
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
m := &Welcomer{}
|
||||
c.RegisterWelcomerInterface(welcomerinterface.WelcomerInterface(m))
|
||||
}
|
||||
|
||||
// Init is an initialization function for talkers
|
||||
func (w *Welcomer) Init() {
|
||||
log.Printf("Initializing Welcomer...")
|
||||
}
|
49
lib/welcomer/notifications.go
Normal file
49
lib/welcomer/notifications.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package welcomer
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (w *Welcomer) alertUserWithoutProfile(update tgbotapi.Update) string {
|
||||
alertGroupID, _ := strconv.ParseInt(c.Cfg.Notifications.GroupID, 10, 64)
|
||||
chat, ok := c.Getters.GetOrCreateChat(&update)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
message := "*Новый вход пользователя без профиля в чат с ботом!*\n"
|
||||
message += "В чат _" + chat.Name + "_ вошёл некто @" + update.Message.NewChatMember.UserName
|
||||
message += ". Он получил уведомление о том, что ему нужно создать профиль в боте."
|
||||
|
||||
msg := tgbotapi.NewMessage(alertGroupID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
func (w *Welcomer) alertSpyUser(update tgbotapi.Update) string {
|
||||
alertGroupID, _ := strconv.ParseInt(c.Cfg.Notifications.GroupID, 10, 64)
|
||||
chat, ok := c.Getters.GetOrCreateChat(&update)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
message := "*Шпион в деле!*\n"
|
||||
message += "В чат _" + chat.Name + "_ вошёл некто @" + update.Message.NewChatMember.UserName
|
||||
message += ". У него профиль другой лиги. Ждём обновлений."
|
||||
|
||||
msg := tgbotapi.NewMessage(alertGroupID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
}
|
68
lib/welcomer/welcomer.go
Normal file
68
lib/welcomer/welcomer.go
Normal file
@@ -0,0 +1,68 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package welcomer
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (w *Welcomer) groupWelcomeUser(update tgbotapi.Update) string {
|
||||
playerRaw, ok := c.Getters.GetOrCreatePlayer(update.Message.NewChatMember.ID)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
profileRaw, profileExist := c.Getters.GetProfile(playerRaw.ID)
|
||||
|
||||
message := "*Бот Инстинкта приветствует тебя, *@"
|
||||
message += update.Message.NewChatMember.UserName
|
||||
message += "*!*\n\n"
|
||||
|
||||
if profileExist {
|
||||
if playerRaw.LeagueID == 1 {
|
||||
message += "Рад тебя видеть! Не забывай обновлять профиль почаще, и да пребудет с тобой Рандом!\n"
|
||||
message += "Последнее обновление твоего профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05") + "."
|
||||
} else {
|
||||
message += "Обнови профиль, отправив его боту в личку. Так надо."
|
||||
|
||||
w.alertSpyUser(update)
|
||||
}
|
||||
} else {
|
||||
// newbie
|
||||
message += "Добавь себе бота @i2\\_bot в список контактов и скинь в него игровой профиль. Это важно для успешной игры!\n"
|
||||
|
||||
w.alertUserWithoutProfile(update)
|
||||
}
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
func (w *Welcomer) groupStartMessage(update tgbotapi.Update) string {
|
||||
message := "*Бот Инстинкта приветствует этот чатик!*\n\n"
|
||||
message += "На слубже здравого смысла с " + time.Now().Format("02.01.2006 15:04:05") + "."
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// WelcomeMessage welcomes new user on group or bot itself
|
||||
func (w *Welcomer) WelcomeMessage(update tgbotapi.Update) string {
|
||||
if (update.Message.NewChatMember.UserName == "i2_bot") || (update.Message.NewChatMember.UserName == "i2_dev_bot") {
|
||||
return w.groupStartMessage(update)
|
||||
}
|
||||
|
||||
return w.groupWelcomeUser(update)
|
||||
}
|
15
lib/welcomer/welcomerinterface/welcomerinterface.go
Normal file
15
lib/welcomer/welcomerinterface/welcomerinterface.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package welcomerinterface
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
// WelcomerInterface implements Welcomer for importing via appcontex
|
||||
type WelcomerInterface interface {
|
||||
Init()
|
||||
WelcomeMessage(update tgbotapi.Update) string
|
||||
}
|
Reference in New Issue
Block a user