From f5b7253fa6b5dc49c1ac316d4089e7aeaaba9fc2 Mon Sep 17 00:00:00 2001 From: nefrace Date: Fri, 4 Feb 2022 12:56:31 +0300 Subject: [PATCH] Reworked tasks --- kicker/handlers.go | 20 ++++++++++---------- kicker/tasks.go | 3 ++- main.go | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/kicker/handlers.go b/kicker/handlers.go index 6a688a0..ec5f489 100644 --- a/kicker/handlers.go +++ b/kicker/handlers.go @@ -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 { diff --git a/kicker/tasks.go b/kicker/tasks.go index 5792a3b..8ddae89 100644 --- a/kicker/tasks.go +++ b/kicker/tasks.go @@ -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) } } diff --git a/main.go b/main.go index 38121e1..c58c675 100644 --- a/main.go +++ b/main.go @@ -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() }