Added userLeft handler

This commit is contained in:
nefrace 2022-02-04 11:37:55 +03:00
parent ba6f7bf2a3
commit deca52ca8d
1 changed files with 19 additions and 0 deletions

View File

@ -46,6 +46,21 @@ func userJoined(c tb.Context) error {
return nil 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{ var HandlersV1 = []Handler{
{ {
Endpoint: tb.OnText, Endpoint: tb.OnText,
@ -113,4 +128,8 @@ var HandlersV1 = []Handler{
Endpoint: tb.OnUserJoined, Endpoint: tb.OnUserJoined,
Handler: userJoined, Handler: userJoined,
}, },
{
Endpoint: tb.OnUserLeft,
Handler: userLeft,
},
} }