Fixed botAdded

This commit is contained in:
nefrace 2023-02-14 11:07:45 +03:00
parent 23d4e9893e
commit 75454a3233
1 changed files with 13 additions and 8 deletions

View File

@ -91,7 +91,7 @@ func checkCaptcha(b *bot, update *echotron.Update) error {
b.DeleteMessage(message.Chat.ID, message.ID) b.DeleteMessage(message.Chat.ID, message.ID)
text := fmt.Sprintf("*[%s](tg://user?id=%d)*, сначала пройди капчу\\!", user.FirstName, user.UserId) 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}) 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 return nil
} }
} }
@ -136,15 +136,20 @@ func checkCaptcha(b *bot, update *echotron.Update) error {
func botAdded(b *bot, update *echotron.Update) error { func botAdded(b *bot, update *echotron.Update) error {
m := update.Message m := update.Message
chat := db.Chat{ store := tongo.NewStore[db.Chat](Client)
ChatId: m.Chat.ID,
Title: m.Chat.Title,
TopicId: 0,
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
d := db.GetDatabase() chat, err := store.GetOne(ctx, tongo.E("chat_id", m.Chat.ID))
err := d.NewChat(ctx, chat) 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 { if err != nil {
log.Print(err) log.Print(err)
} }