Pins to supergroups, managed by admins
This commit is contained in:
@@ -4,9 +4,6 @@
|
||||
package welcomer
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/appcontext"
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/welcomer/welcomerinterface"
|
||||
)
|
||||
@@ -15,7 +12,7 @@ var (
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
// Welcomer is a function-handling struct for talkers
|
||||
// Welcomer is a function-handling struct for welcomer
|
||||
type Welcomer struct{}
|
||||
|
||||
// New is a appcontext initialization function
|
||||
@@ -25,7 +22,7 @@ func New(ac *appcontext.Context) {
|
||||
c.RegisterWelcomerInterface(welcomerinterface.WelcomerInterface(m))
|
||||
}
|
||||
|
||||
// Init is an initialization function for talkers
|
||||
// Init is an initialization function for welcomer
|
||||
func (w *Welcomer) Init() {
|
||||
log.Printf("Initializing Welcomer...")
|
||||
c.Log.Info("Initializing Welcomer...")
|
||||
}
|
||||
|
@@ -4,21 +4,19 @@
|
||||
package welcomer
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (w *Welcomer) alertUserWithoutProfile(update tgbotapi.Update) string {
|
||||
func (w *Welcomer) alertUserWithoutProfile(update *tgbotapi.Update, newUser *tgbotapi.User) string {
|
||||
alertGroupID, _ := strconv.ParseInt(c.Cfg.Notifications.GroupID, 10, 64)
|
||||
chat, ok := c.Getters.GetOrCreateChat(&update)
|
||||
chat, ok := c.Getters.GetOrCreateChat(update)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
message := "*Новый вход пользователя без профиля в чат с ботом!*\n"
|
||||
message += "В чат _" + chat.Name + "_ вошёл некто @" + update.Message.NewChatMember.UserName
|
||||
message += "В чат _" + chat.Name + "_ вошёл некто @" + newUser.UserName
|
||||
message += ". Он получил уведомление о том, что ему нужно создать профиль в боте."
|
||||
|
||||
msg := tgbotapi.NewMessage(alertGroupID, message)
|
||||
@@ -29,15 +27,15 @@ func (w *Welcomer) alertUserWithoutProfile(update tgbotapi.Update) string {
|
||||
return "ok"
|
||||
}
|
||||
|
||||
func (w *Welcomer) alertSpyUser(update tgbotapi.Update) string {
|
||||
func (w *Welcomer) alertSpyUser(update *tgbotapi.Update, newUser *tgbotapi.User) string {
|
||||
alertGroupID, _ := strconv.ParseInt(c.Cfg.Notifications.GroupID, 10, 64)
|
||||
chat, ok := c.Getters.GetOrCreateChat(&update)
|
||||
chat, ok := c.Getters.GetOrCreateChat(update)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
message := "*Шпион в деле!*\n"
|
||||
message += "В чат _" + chat.Name + "_ вошёл некто @" + update.Message.NewChatMember.UserName
|
||||
message += "В чат _" + chat.Name + "_ вошёл некто @" + newUser.UserName
|
||||
message += ". У него профиль другой лиги. Ждём обновлений."
|
||||
|
||||
msg := tgbotapi.NewMessage(alertGroupID, message)
|
||||
|
@@ -4,14 +4,12 @@
|
||||
package welcomer
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (w *Welcomer) groupWelcomeUser(update tgbotapi.Update) string {
|
||||
playerRaw, ok := c.Getters.GetOrCreatePlayer(update.Message.NewChatMember.ID)
|
||||
func (w *Welcomer) groupWelcomeUser(update *tgbotapi.Update, newUser *tgbotapi.User) string {
|
||||
playerRaw, ok := c.Getters.GetOrCreatePlayer(newUser.ID)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
@@ -19,7 +17,7 @@ func (w *Welcomer) groupWelcomeUser(update tgbotapi.Update) string {
|
||||
profileRaw, profileExist := c.Getters.GetProfile(playerRaw.ID)
|
||||
|
||||
message := "*Бот Инстинкта приветствует тебя, *@"
|
||||
message += update.Message.NewChatMember.UserName
|
||||
message += newUser.UserName
|
||||
message += "*!*\n\n"
|
||||
|
||||
if profileExist {
|
||||
@@ -29,13 +27,13 @@ func (w *Welcomer) groupWelcomeUser(update tgbotapi.Update) string {
|
||||
} else {
|
||||
message += "Обнови профиль, отправив его боту в личку. Так надо."
|
||||
|
||||
w.alertSpyUser(update)
|
||||
w.alertSpyUser(update, newUser)
|
||||
}
|
||||
} else {
|
||||
// newbie
|
||||
message += "Добавь себе бота @i2\\_bot в список контактов и скинь в него игровой профиль. Это важно для успешной игры!\n"
|
||||
|
||||
w.alertUserWithoutProfile(update)
|
||||
w.alertUserWithoutProfile(update, newUser)
|
||||
}
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
@@ -46,7 +44,7 @@ func (w *Welcomer) groupWelcomeUser(update tgbotapi.Update) string {
|
||||
return "ok"
|
||||
}
|
||||
|
||||
func (w *Welcomer) groupStartMessage(update tgbotapi.Update) string {
|
||||
func (w *Welcomer) groupStartMessage(update *tgbotapi.Update) string {
|
||||
message := "*Бот Инстинкта приветствует этот чатик!*\n\n"
|
||||
message += "На слубже здравого смысла с " + time.Now().Format("02.01.2006 15:04:05") + "."
|
||||
|
||||
@@ -59,10 +57,16 @@ func (w *Welcomer) groupStartMessage(update tgbotapi.Update) string {
|
||||
}
|
||||
|
||||
// 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)
|
||||
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 w.groupWelcomeUser(update)
|
||||
return "ok"
|
||||
}
|
||||
|
@@ -4,12 +4,11 @@
|
||||
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
|
||||
WelcomeMessage(update *tgbotapi.Update) string
|
||||
}
|
||||
|
Reference in New Issue
Block a user