From b822068f0a3122c5d0f01b3d67bd331eb1447b87 Mon Sep 17 00:00:00 2001 From: db123 Date: Thu, 25 Jun 2026 09:19:03 +0330 Subject: [PATCH] =?UTF-8?q?feat:=20enforce=20RPG=20dependency=20for=20Leag?= =?UTF-8?q?ue=20=E2=80=94=20cannot=20enable=20League=20without=20RPG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - handleSelectCallback: disabling RPG also disables League; enabling League when RPG is off shows toast error via answerCbWithText - handleLeagueToggleCmd (/leaguetoggle): rejects with message if RPG off - leagueToggleCallback (inline): rejects with message if RPG off - buildSettingsKeyboard: League status shows as 'off' when RPG is disabled (even if the DB still has LeagueOptIn=true, since RPG disable forces it false) --- internal/bot/handlers.go | 2 +- internal/bot/settings.go | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) 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 {