diff --git a/internal/bot/handlers.go b/internal/bot/handlers.go index 6fd671d..3739c02 100644 --- a/internal/bot/handlers.go +++ b/internal/bot/handlers.go @@ -214,7 +214,7 @@ func (h *Handler) HandleMessage(ctx context.Context, msg *models.Message) { case "/rpgtoggle": h.handleRPGSettingsMsg(ctx, msg) case "/leaguetoggle": - h.handleLeagueSettingsMsg(ctx, msg) + h.handleLeagueToggleCmd(ctx, msg) case "/setusername": h.handleSetUsername(ctx, msg) default: diff --git a/internal/bot/settings.go b/internal/bot/settings.go index 88a368b..00c33de 100644 --- a/internal/bot/settings.go +++ b/internal/bot/settings.go @@ -189,7 +189,9 @@ func (h *Handler) buildSettingsKeyboard(user *db.User, st *db.UserSettings, brea rpgStatus = "on" } leagueStatus := "off" - if st.LeagueOptIn { + if !st.RPGEnabled { + leagueStatus = "off" + } else if st.LeagueOptIn { leagueStatus = "on" } rows := [][]models.InlineKeyboardButton{ @@ -494,13 +496,22 @@ func (h *Handler) handleRPGSettingsMsg(ctx context.Context, msg *models.Message) h.sendWithKB(ctx, msg.Chat.ID, text, kb) } -// handleLeagueSettingsMsg shows the League enable/disable picker (command). -func (h *Handler) handleLeagueSettingsMsg(ctx context.Context, msg *models.Message) { +// handleLeagueToggleCmd handles /leaguetoggle — checks RPG is enabled first. +func (h *Handler) handleLeagueToggleCmd(ctx context.Context, msg *models.Message) { user, err := h.getOrCreateUser(msg.Chat.ID) if err != nil { h.sendText(ctx, msg.Chat.ID, "Error loading profile") return } + st, err := h.DB.GetOrCreateSettings(user.ID) + if err != nil { + h.sendText(ctx, msg.Chat.ID, "Error loading settings") + return + } + if !st.RPGEnabled { + h.sendText(ctx, msg.Chat.ID, "League requires the RPG system. Enable RPG first with /rpgtoggle.") + return + } text, kb := h.buildLeagueToggleKeyboard(user.ID) h.sendWithKB(ctx, msg.Chat.ID, text, kb) } @@ -523,6 +534,14 @@ func (h *Handler) leagueToggleCallback(ctx context.Context, chatID int64, msgID if err != nil { return } + st, err := h.DB.GetOrCreateSettings(user.ID) + if err != nil { + return + } + if !st.RPGEnabled { + h.editText(ctx, chatID, msgID, "League requires the RPG system. Enable RPG first in Settings.", nil) + return + } text, kb := h.buildLeagueToggleKeyboard(user.ID) h.editText(ctx, chatID, msgID, text, &kb) } @@ -646,8 +665,14 @@ func (h *Handler) handleSelectCallback(ctx context.Context, chatID int64, msgID st.RPGEnabled = value if value { h.DB.GetOrCreateRPGStats(user.ID) + } else { + st.LeagueOptIn = false } case "league_enable": + if value && !st.RPGEnabled { + h.answerCbWithText(ctx, callbackID, "Enable RPG first") + return + } st.LeagueOptIn = value } if err := h.DB.UpdateSettings(st); err != nil {