From deca52ca8d4a4941e8984152e7fba59d7c56d58f Mon Sep 17 00:00:00 2001 From: nefrace Date: Fri, 4 Feb 2022 11:37:55 +0300 Subject: [PATCH] Added userLeft handler --- kicker/handlers.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/kicker/handlers.go b/kicker/handlers.go index 253d3d7..6a688a0 100644 --- a/kicker/handlers.go +++ b/kicker/handlers.go @@ -46,6 +46,21 @@ func userJoined(c tb.Context) error { return nil } +func userLeft(c tb.Context) error { + bot := c.Bot() + message := c.Message() + sender := c.Sender() + d := db.GetDatabase() + 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 { + d.RemoveUser(ctx, user) + bot.Delete(&tb.Message{Chat: message.Chat, ID: user.CaptchaMessage}) + db.Log("user left", user) + } + return nil +} + var HandlersV1 = []Handler{ { Endpoint: tb.OnText, @@ -113,4 +128,8 @@ var HandlersV1 = []Handler{ Endpoint: tb.OnUserJoined, Handler: userJoined, }, + { + Endpoint: tb.OnUserLeft, + Handler: userLeft, + }, }