Migration to Tongo, new logic for user storage #3
@ -52,20 +52,20 @@ type Kicker struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (b *Kicker) NewBot(chatID int64) echotron.Bot {
 | 
					func (b *Kicker) NewBot(chatID int64) echotron.Bot {
 | 
				
			||||||
	d := db.GetDatabase()
 | 
						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 := db.Chat{
 | 
				
			||||||
 | 
							Item:    tongo.NewID(),
 | 
				
			||||||
		ChatId:  chatID,
 | 
							ChatId:  chatID,
 | 
				
			||||||
		Title:   "",
 | 
							Title:   "",
 | 
				
			||||||
		TopicId: 0,
 | 
							TopicId: 0,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !d.ChatExists(ctx, chat) {
 | 
						if _, err := store.GetOne(ctx, tongo.E("chat_id", chatID)); err != nil {
 | 
				
			||||||
		if err := d.NewChat(ctx, chat); err != nil {
 | 
							if _, err := store.InsertOne(ctx, &chat); err != nil {
 | 
				
			||||||
			return &bot{}
 | 
								return &bot{}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	chat, _ = d.GetChat(ctx, chatID)
 | 
					 | 
				
			||||||
	CaptchaTopic := chat.TopicId
 | 
						CaptchaTopic := chat.TopicId
 | 
				
			||||||
	result := &bot{
 | 
						result := &bot{
 | 
				
			||||||
		chatID,
 | 
							chatID,
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user