Fixed NewBot

This commit is contained in:
nefrace 2023-02-14 11:16:17 +03:00
parent 75454a3233
commit 1c4a0adb61
1 changed files with 10 additions and 8 deletions

View File

@ -55,14 +55,16 @@ func (b *Kicker) NewBot(chatID int64) echotron.Bot {
store := tongo.NewStore[db.Chat](Client) store := tongo.NewStore[db.Chat](Client)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
chat := db.Chat{
chat, err := store.GetOne(ctx, tongo.E("chat_id", chatID))
if err != nil {
chat = &db.Chat{
Item: tongo.NewID(), Item: tongo.NewID(),
ChatId: chatID, ChatId: chatID,
Title: "", Title: "",
TopicId: 0, TopicId: 0,
} }
if _, err := store.GetOne(ctx, tongo.E("chat_id", chatID)); err != nil { if _, err := store.InsertOne(ctx, chat); err != nil {
if _, err := store.InsertOne(ctx, &chat); err != nil {
return &bot{} return &bot{}
} }
} }