diff --git a/internal/bot/handlers.go b/internal/bot/handlers.go index 7d03d04..5fa3f4a 100644 --- a/internal/bot/handlers.go +++ b/internal/bot/handlers.go @@ -21,6 +21,7 @@ type Handler struct { DB *db.Store AllowedUsers map[int64]bool lastMsgTime map[int64]time.Time + keyboardMsg map[int64]int mu sync.Mutex } @@ -30,6 +31,7 @@ func NewHandler(bot *tgbotapi.BotAPI, store *db.Store, allowed map[int64]bool) * DB: store, AllowedUsers: allowed, lastMsgTime: make(map[int64]time.Time), + keyboardMsg: make(map[int64]int), } } @@ -359,11 +361,19 @@ func (h *Handler) handleStart(msg *tgbotapi.Message) { } func (h *Handler) updateReplyKeyboard(chatID int64) { + h.mu.Lock() + oldID := h.keyboardMsg[chatID] + h.mu.Unlock() + if oldID != 0 { + h.Bot.Request(tgbotapi.NewDeleteMessage(chatID, oldID)) + } msg := tgbotapi.NewMessage(chatID, "\u200C") msg.ReplyMarkup = h.smartKeyboard(chatID) sent, err := h.Bot.Send(msg) if err == nil { - h.Bot.Request(tgbotapi.NewDeleteMessage(chatID, sent.MessageID)) + h.mu.Lock() + h.keyboardMsg[chatID] = sent.MessageID + h.mu.Unlock() } }