Some refactoring. Added numbers emoji compatibility

This commit is contained in:
nefrace 2022-07-21 11:15:38 +03:00
parent 4555d4fa59
commit b221253a6c
1 changed files with 50 additions and 55 deletions

View File

@ -60,10 +60,7 @@ func userLeft(c tb.Context) error {
return nil
}
var HandlersV1 = []Handler{
{
Endpoint: tb.OnText,
Handler: func(c tb.Context) error {
func checkCaptcha(c tb.Context) error {
sender := c.Sender()
message := c.Message()
bot := c.Bot()
@ -71,9 +68,10 @@ var HandlersV1 = []Handler{
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if user, err := d.GetUser(ctx, db.User{Id: sender.ID, ChatId: message.Chat.ID}); err == nil {
text := message.Text
text_runes := []rune(message.Text)
guess := string(text_runes[0])
solved := false
if num, err := strconv.Atoi(text); err == nil {
if num, err := strconv.Atoi(guess); err == nil {
if num == int(user.CorrectAnswer) {
_ = d.RemoveUser(ctx, user)
solved = true
@ -92,21 +90,9 @@ var HandlersV1 = []Handler{
}
}
return nil
},
},
// {
// Endpoint: "/gen",
// Handler: func(c tb.Context) error {
// captcha := captchagen.GenCaptcha()
// reader := captcha.ToReader()
// caption := fmt.Sprintf("Правильный ответ: %d", captcha.CorrectAnswer)
// c.Reply(&tb.Photo{File: tb.FromReader(reader), Caption: caption})
// return nil
// },
// },
{
Endpoint: tb.OnAddedToGroup,
Handler: func(c tb.Context) error {
}
func botAdded(c tb.Context) error {
m := c.Message()
chat := db.Chat{
Id: m.Chat.ID,
@ -120,7 +106,16 @@ var HandlersV1 = []Handler{
log.Print(err)
}
return nil
}
var HandlersV1 = []Handler{
{
Endpoint: tb.OnText,
Handler: checkCaptcha,
},
{
Endpoint: tb.OnAddedToGroup,
Handler: botAdded,
},
{