feat: enforce RPG dependency for League — cannot enable League without RPG

- 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)
This commit is contained in:
2026-06-25 09:19:03 +03:30
parent 80de661f5b
commit b822068f0a
2 changed files with 29 additions and 4 deletions

View File

@@ -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:

View File

@@ -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 {