Reworked tasks

This commit is contained in:
nefrace 2022-02-04 12:56:31 +03:00
parent 6be72fb3c6
commit f5b7253fa6
3 changed files with 13 additions and 13 deletions

View File

@ -94,16 +94,16 @@ 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: "/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 {

View File

@ -13,6 +13,7 @@ import (
func TaskKickOldUsers(b tb.Bot) {
d := db.GetDatabase()
db.Log("STARTING KICKING TASK", db.EmptyStruct{})
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
now := time.Now().Unix()
@ -29,6 +30,6 @@ func TaskKickOldUsers(b tb.Bot) {
tbUser := tb.User{ID: user.Id}
member := tb.ChatMember{User: &tbUser}
b.Ban(&chat, &member)
time.Sleep(250 * time.Millisecond)
d.RemoveUser(ctx, user)
}
}

View File

@ -30,9 +30,8 @@ func main() {
Bot := kicker.Kicker{Token: token}
Bot.Init()
Bot.AddHandlers(kicker.HandlersV1)
Bot.Bot.Start()
scheduler := gocron.NewScheduler(time.UTC)
scheduler.Every(1).Minutes().Do(func() { kicker.TaskKickOldUsers(*Bot.Bot) })
scheduler.StartAsync()
Bot.Bot.Start()
}