73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package routines
|
|
|
|
import (
|
|
message2 "git.dragon-labs.de/alphyron/group_helper/message"
|
|
"git.dragon-labs.de/alphyron/group_helper/models"
|
|
"git.dragon-labs.de/alphyron/group_helper/obj"
|
|
"git.dragon-labs.de/alphyron/group_helper/telegram"
|
|
"git.dragon-labs.de/alphyron/group_helper/util"
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
|
"log"
|
|
"math/rand"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type joinCheckerRoutine struct {
|
|
verifyData *obj.VerifyData
|
|
}
|
|
|
|
func NewJoinCheckerRoutine(verifyData *obj.VerifyData) telegram.Routine {
|
|
return joinCheckerRoutine{
|
|
verifyData: verifyData,
|
|
}
|
|
}
|
|
|
|
func (j joinCheckerRoutine) Update(botAPI *tgbotapi.BotAPI, update *tgbotapi.Update, group *models.Group) error {
|
|
|
|
if update.Message == nil { // ignore any non-Message Updates
|
|
return nil
|
|
}
|
|
|
|
if update.Message.Chat.IsPrivate() || update.Message.Chat.IsChannel() {
|
|
return nil
|
|
}
|
|
|
|
if update.Message.NewChatMembers != nil {
|
|
for _, newUser := range *update.Message.NewChatMembers {
|
|
length := 3
|
|
|
|
tasks := make([][]tgbotapi.InlineKeyboardButton, length)
|
|
|
|
for i := 0; i < length; i++ {
|
|
tasks[i] = tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData(util.GenerateCalculation(i == 0), "UserValidation: "+strconv.FormatBool(i == 0)))
|
|
}
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
rand.Shuffle(len(tasks), func(i, j int) { tasks[i], tasks[j] = tasks[j], tasks[i] })
|
|
|
|
markup := tgbotapi.NewInlineKeyboardMarkup(tasks...)
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message2.ReplaceMessage(group.UserJoinMessage, update.Message.From))
|
|
msg.ParseMode = "Markdown"
|
|
msg.ReplyMarkup = markup
|
|
|
|
message, err := botAPI.Send(msg)
|
|
|
|
if err != nil {
|
|
log.Println("Problem to send verified Messages to user")
|
|
log.Println(newUser.FirstName)
|
|
log.Println(err)
|
|
}
|
|
|
|
j.verifyData.AddUser(&obj.VerifyUser{
|
|
UserID: newUser.ID,
|
|
GroupID: group.GroupID,
|
|
LeftTime: group.KickCooldown,
|
|
MessageID: message.MessageID,
|
|
})
|
|
}
|
|
}
|
|
return nil
|
|
}
|