From 07306cb0f0ee3bda207ca5970f6661728622070d Mon Sep 17 00:00:00 2001 From: db123 Date: Wed, 24 Jun 2026 10:00:27 +0330 Subject: [PATCH] remove reply keyboard; keep Clock In/Out as inline buttons only - Removed smartKeyboard, defaultKeyboard, updateReplyKeyboard - Removed statusMsg/keyboardMsg tracking from Handler - sendText now sends plain messages (no reply keyboard) - handleActionMsg sends result with mainKeyboard() inline keyboard - handleActionCallback edits message with backKeyboard (unchanged) - handleStart sends welcome + menu with mainKeyboard - SendDailyReport sends plain text report - Removed text-trigger 'Clock In'/'Clock Out' message handlers (only /clockin and /clockout commands remain) --- internal/bot/handlers.go | 77 +++++----------------------------------- 1 file changed, 8 insertions(+), 69 deletions(-) diff --git a/internal/bot/handlers.go b/internal/bot/handlers.go index 5fa3f4a..e9b4b0c 100644 --- a/internal/bot/handlers.go +++ b/internal/bot/handlers.go @@ -21,7 +21,6 @@ type Handler struct { DB *db.Store AllowedUsers map[int64]bool lastMsgTime map[int64]time.Time - keyboardMsg map[int64]int mu sync.Mutex } @@ -31,7 +30,6 @@ 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), } } @@ -52,10 +50,11 @@ func (h *Handler) handleActionMsg(msg *tgbotapi.Message, fn actionFunc) { text, err := fn(msg.Chat.ID) if err != nil { h.sendText(msg.Chat.ID, err.Error()) - } else { - h.sendSuccessWithMenu(msg.Chat.ID, text) - h.updateReplyKeyboard(msg.Chat.ID) + return } + reply := tgbotapi.NewMessage(msg.Chat.ID, text) + reply.ReplyMarkup = mainKeyboard() + h.Bot.Send(reply) } func (h *Handler) handleActionCallback(chatID int64, msgID int, callbackID string, fn actionFunc) { @@ -68,7 +67,6 @@ func (h *Handler) handleActionCallback(chatID int64, msgID int, callbackID strin kb := backKeyboard() edit.ReplyMarkup = &kb h.Bot.Send(edit) - h.updateReplyKeyboard(chatID) } func (h *Handler) HandleMessage(update tgbotapi.Update) { @@ -87,9 +85,9 @@ func (h *Handler) HandleMessage(update tgbotapi.Update) { switch msg.Text { case "/start": h.handleStart(msg) - case "/clockin", "Clock In": + case "/clockin": h.handleActionMsg(msg, h.clockIn) - case "/clockout", "Clock Out": + case "/clockout": h.handleActionMsg(msg, h.clockOut) case "/worktype": h.handleWorkTypeMsg(msg) @@ -352,31 +350,12 @@ func (h *Handler) handleStart(msg *tgbotapi.Message) { return } slog.Info("start", "user_id", user.ID, "chat_id", msg.Chat.ID) - reply := tgbotapi.NewMessage(msg.Chat.ID, "We hope you have a happy day working.") - reply.ReplyMarkup = h.smartKeyboard(msg.Chat.ID) - h.Bot.Send(reply) + h.sendText(msg.Chat.ID, "We hope you have a happy day working.") menu := tgbotapi.NewMessage(msg.Chat.ID, h.buildStatusText(msg.Chat.ID)) menu.ReplyMarkup = mainKeyboard() h.Bot.Send(menu) } -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.mu.Lock() - h.keyboardMsg[chatID] = sent.MessageID - h.mu.Unlock() - } -} - func (h *Handler) handleWorkTypeMsg(msg *tgbotapi.Message) { user, day, err := h.getUserToday(msg.Chat.ID) if err != nil { @@ -445,7 +424,6 @@ func (h *Handler) selectWorkType(chatID int64, msgID int, callbackID, idStr stri if err := h.DB.UpdateDay(day); err != nil { return } - h.updateReplyKeyboard(chatID) text := fmt.Sprintf("Work type set to: %s", wt.Name) edit := tgbotapi.NewEditMessageText(chatID, msgID, text) kb := backKeyboard() @@ -544,7 +522,6 @@ func (h *Handler) selectAccent(chatID int64, msgID int, callbackID, name string) if err := h.DB.UpdateUser(user); err != nil { return } - h.updateReplyKeyboard(chatID) text := fmt.Sprintf("Accent set to: %s", name) edit := tgbotapi.NewEditMessageText(chatID, msgID, text) kb := tgbotapi.NewInlineKeyboardMarkup( @@ -634,7 +611,6 @@ func (h *Handler) selectCalendar(chatID int64, msgID int, callbackID, name strin if err := h.DB.UpdateUser(user); err != nil { return } - h.updateReplyKeyboard(chatID) text, kb := h.buildSettingsKeyboard(user) edit := tgbotapi.NewEditMessageText(chatID, msgID, text) edit.ReplyMarkup = &kb @@ -1366,39 +1342,10 @@ func (h *Handler) SendDailyReport(userID int64, chatID int64) { } text := h.buildDailyReport(user, day, events) reply := tgbotapi.NewMessage(chatID, text) - reply.ReplyMarkup = h.smartKeyboard(chatID) h.Bot.Send(reply) h.DB.MarkReportSent(user.ID, today) } -func (h *Handler) smartKeyboard(chatID int64) tgbotapi.ReplyKeyboardMarkup { - user, err := h.getOrCreateUser(chatID) - if err != nil { - return defaultKeyboard() - } - last, err := h.DB.GetLastEvent(user.ID) - if err != nil || last == nil || last.EventType == "out" { - return tgbotapi.NewReplyKeyboard( - tgbotapi.NewKeyboardButtonRow( - tgbotapi.NewKeyboardButton("Clock In"), - ), - ) - } - return tgbotapi.NewReplyKeyboard( - tgbotapi.NewKeyboardButtonRow( - tgbotapi.NewKeyboardButton("Clock Out"), - ), - ) -} - -func defaultKeyboard() tgbotapi.ReplyKeyboardMarkup { - return tgbotapi.NewReplyKeyboard( - tgbotapi.NewKeyboardButtonRow( - tgbotapi.NewKeyboardButton("Clock In"), - ), - ) -} - func mainKeyboard() tgbotapi.InlineKeyboardMarkup { return tgbotapi.NewInlineKeyboardMarkup( tgbotapi.NewInlineKeyboardRow( @@ -1437,13 +1384,5 @@ func formatDuration(seconds int64) string { } func (h *Handler) sendText(chatID int64, text string) { - reply := tgbotapi.NewMessage(chatID, text) - reply.ReplyMarkup = h.smartKeyboard(chatID) - h.Bot.Send(reply) -} - -func (h *Handler) sendSuccessWithMenu(chatID int64, text string) { - reply := tgbotapi.NewMessage(chatID, text) - reply.ReplyMarkup = mainKeyboard() - h.Bot.Send(reply) + h.Bot.Send(tgbotapi.NewMessage(chatID, text)) }