✨ Implement Verifier and checker for right answer
This commit is contained in:
parent
12812cbb21
commit
c702115fe6
1
main.go
1
main.go
@ -70,6 +70,7 @@ func InitialRoutineManager(bot *tgbotapi.BotAPI, commandManager *cli.CommandMana
|
|||||||
rm.RegisterRoutine(routines.NewCommandRoutine(commandManager))
|
rm.RegisterRoutine(routines.NewCommandRoutine(commandManager))
|
||||||
rm.RegisterRoutine(routines.NewDatabaseRoutine(service))
|
rm.RegisterRoutine(routines.NewDatabaseRoutine(service))
|
||||||
rm.RegisterRoutine(routines.NewJoinCheckerRoutine())
|
rm.RegisterRoutine(routines.NewJoinCheckerRoutine())
|
||||||
|
rm.RegisterRoutine(routines.NewVerifierRoutine(service))
|
||||||
|
|
||||||
return rm
|
return rm
|
||||||
}
|
}
|
||||||
|
65
telegram/routines/verifier.go
Normal file
65
telegram/routines/verifier.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package routines
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.dragon-labs.de/alphyron/group_helper/logic"
|
||||||
|
"git.dragon-labs.de/alphyron/group_helper/models"
|
||||||
|
"git.dragon-labs.de/alphyron/group_helper/telegram"
|
||||||
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type verifierRoutine struct {
|
||||||
|
groupHelperService logic.GroupHelperService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVerifierRoutine(groupHelperService logic.GroupHelperService) telegram.Routine {
|
||||||
|
return verifierRoutine{
|
||||||
|
groupHelperService: groupHelperService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v verifierRoutine) Update(botAPI *tgbotapi.BotAPI, update *tgbotapi.Update, group *models.Group) error {
|
||||||
|
if update.CallbackQuery == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(update.CallbackQuery.Data, "UserValidation:") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
success, err := strconv.ParseBool(strings.TrimPrefix(update.CallbackQuery.Data, "UserValidation: "))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if success {
|
||||||
|
|
||||||
|
//TODO check if the user is realy in countdown handler
|
||||||
|
/*if isInGroup {
|
||||||
|
_, err = botAPI.AnswerCallbackQuery(tgbotapi.NewCallback(update.CallbackQuery.ID, "You are already verified!"))
|
||||||
|
return err
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Delete after accept the Message
|
||||||
|
botAPI.DeleteMessage(tgbotapi.DeleteMessageConfig{
|
||||||
|
ChatID: update.CallbackQuery.Message.Chat.ID,
|
||||||
|
MessageID: update.CallbackQuery.Message.MessageID,
|
||||||
|
})
|
||||||
|
botAPI.AnswerCallbackQuery(tgbotapi.NewCallback(update.CallbackQuery.ID, "You are now verified. Welcome to the chat!"))
|
||||||
|
|
||||||
|
verifyMessage := group.UserVerifiedMessage
|
||||||
|
//TODO Replace placeholder
|
||||||
|
|
||||||
|
msg := tgbotapi.NewMessage(update.CallbackQuery.Message.Chat.ID, verifyMessage)
|
||||||
|
msg.ParseMode = "Markdown"
|
||||||
|
_, err := botAPI.Send(msg)
|
||||||
|
|
||||||
|
//TODO Remove the user from the validator so dont get banned
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
_, err = botAPI.AnswerCallbackQuery(tgbotapi.NewCallback(update.CallbackQuery.ID, "Wrong answer"))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user