fix: unsilence all error returns from SQL Exec, Bot API calls, and migrations

This commit is contained in:
2026-06-24 20:03:24 +03:30
parent 4165839477
commit e7e4dc7bfe
8 changed files with 227 additions and 193 deletions

View File

@@ -7,7 +7,6 @@ import (
"strings"
"time"
bot "github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
"worktimeBot/internal/db"
@@ -59,7 +58,7 @@ func (h *Handler) handleAccentMsg(ctx context.Context, msg *models.Message) {
return
}
text, kb := h.buildAccentKeyboard(user)
h.Bot.SendMessage(ctx, &bot.SendMessageParams{ChatID: msg.Chat.ID, Text: text, ReplyMarkup: &kb})
h.sendWithKB(ctx, msg.Chat.ID, text, kb)
}
// handleSetTimezone validates and updates the user's IANA timezone.
@@ -98,18 +97,13 @@ func (h *Handler) handleSetTimezone(ctx context.Context, msg *models.Message) {
// settingsCallback shows the settings inline menu.
func (h *Handler) settingsCallback(ctx context.Context, chatID int64, msgID int, callbackID string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
user, err := h.getOrCreateUser(chatID)
if err != nil {
return
}
text, kb := h.buildSettingsKeyboard(user)
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: text,
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, text, &kb)
}
// buildSettingsKeyboard returns the settings menu text and inline keyboard.
@@ -132,23 +126,18 @@ func (h *Handler) buildSettingsKeyboard(user *db.User) (string, models.InlineKey
// accentCallback shows the accent color picker (inline edit).
func (h *Handler) accentCallback(ctx context.Context, chatID int64, msgID int, callbackID string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
user, err := h.getOrCreateUser(chatID)
if err != nil {
return
}
text, kb := h.buildAccentKeyboard(user)
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: text,
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, text, &kb)
}
// timezoneCallback shows the current timezone and instructions to change it.
func (h *Handler) timezoneCallback(ctx context.Context, chatID int64, msgID int, callbackID string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
user, err := h.getOrCreateUser(chatID)
if err != nil {
return
@@ -159,12 +148,7 @@ func (h *Handler) timezoneCallback(ctx context.Context, chatID int64, msgID int,
{{Text: "Back to Settings", CallbackData: "back_settings"}},
},
}
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: text,
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, text, &kb)
}
// buildAccentKeyboard returns the accent color picker keyboard.
@@ -197,7 +181,7 @@ func (h *Handler) buildAccentKeyboard(user *db.User) (string, models.InlineKeybo
// selectAccent sets the user's export accent color after validation.
func (h *Handler) selectAccent(ctx context.Context, chatID int64, msgID int, callbackID, name string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
user, err := h.getOrCreateUser(chatID)
if err != nil {
return
@@ -215,17 +199,12 @@ func (h *Handler) selectAccent(ctx context.Context, chatID int64, msgID int, cal
{{Text: "Back to Settings", CallbackData: "back_settings"}},
},
}
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: fmt.Sprintf("Accent set to: %s", name),
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, fmt.Sprintf("Accent set to: %s", name), &kb)
}
// reportTimeCallback shows the current report time setting.
func (h *Handler) reportTimeCallback(ctx context.Context, chatID int64, msgID int, callbackID string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
user, err := h.getOrCreateUser(chatID)
if err != nil {
return
@@ -236,44 +215,29 @@ func (h *Handler) reportTimeCallback(ctx context.Context, chatID int64, msgID in
{{Text: "Back to Settings", CallbackData: "back_settings"}},
},
}
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: text,
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, text, &kb)
}
// backToSettings returns to the main settings menu.
func (h *Handler) backToSettings(ctx context.Context, chatID int64, msgID int, callbackID string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
user, err := h.getOrCreateUser(chatID)
if err != nil {
return
}
text, kb := h.buildSettingsKeyboard(user)
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: text,
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, text, &kb)
}
// calTypeCallback shows the calendar type selector.
func (h *Handler) calTypeCallback(ctx context.Context, chatID int64, msgID int, callbackID string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
user, err := h.getOrCreateUser(chatID)
if err != nil {
return
}
text, kb := h.buildCalendarKeyboard(user)
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: text,
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, text, &kb)
}
// buildCalendarKeyboard returns the calendar type selector keyboard.
@@ -302,7 +266,7 @@ func (h *Handler) buildCalendarKeyboard(user *db.User) (string, models.InlineKey
// selectCalendar sets the user's calendar after validation.
func (h *Handler) selectCalendar(ctx context.Context, chatID int64, msgID int, callbackID, name string) {
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: callbackID})
h.answerCb(ctx, callbackID)
valid := map[string]bool{"gregorian": true, "jalali": true, "hijri": true}
if !valid[name] {
return
@@ -316,10 +280,5 @@ func (h *Handler) selectCalendar(ctx context.Context, chatID int64, msgID int, c
return
}
text, kb := h.buildSettingsKeyboard(user)
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID,
MessageID: msgID,
Text: text,
ReplyMarkup: &kb,
})
h.editText(ctx, chatID, msgID, text, &kb)
}