From 75454a3233b96b5aa2f081ce1435e5634829510f Mon Sep 17 00:00:00 2001 From: nefrace Date: Tue, 14 Feb 2023 11:07:45 +0300 Subject: [PATCH] Fixed botAdded --- kicker/handlers.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/kicker/handlers.go b/kicker/handlers.go index 663de8a..bce4ff1 100644 --- a/kicker/handlers.go +++ b/kicker/handlers.go @@ -91,7 +91,7 @@ func checkCaptcha(b *bot, update *echotron.Update) error { b.DeleteMessage(message.Chat.ID, message.ID) text := fmt.Sprintf("*[%s](tg://user?id=%d)*, сначала пройди капчу\\!", user.FirstName, user.UserId) res, _ := b.SendMessage(text, message.Chat.ID, &echotron.MessageOptions{ParseMode: echotron.MarkdownV2, MessageThreadID: message.ThreadID}) - go waitAndDelete(&b.API, res.Result, 30*time.Second) + go waitAndDelete(&b.API, res.Result, 10*time.Second) return nil } } @@ -136,15 +136,20 @@ func checkCaptcha(b *bot, update *echotron.Update) error { func botAdded(b *bot, update *echotron.Update) error { m := update.Message - chat := db.Chat{ - ChatId: m.Chat.ID, - Title: m.Chat.Title, - TopicId: 0, - } + store := tongo.NewStore[db.Chat](Client) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - d := db.GetDatabase() - err := d.NewChat(ctx, chat) + chat, err := store.GetOne(ctx, tongo.E("chat_id", m.Chat.ID)) + if err != nil { + chat = &db.Chat{ + Item: tongo.NewID(), + ChatId: m.Chat.ID, + Title: m.Chat.Title, + TopicId: 0, + } + } + + _, err = store.InsertOne(ctx, chat) if err != nil { log.Print(err) }