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:
@@ -214,7 +214,7 @@ func (h *Handler) HandleMessage(ctx context.Context, msg *models.Message) {
|
|||||||
case "/rpgtoggle":
|
case "/rpgtoggle":
|
||||||
h.handleRPGSettingsMsg(ctx, msg)
|
h.handleRPGSettingsMsg(ctx, msg)
|
||||||
case "/leaguetoggle":
|
case "/leaguetoggle":
|
||||||
h.handleLeagueSettingsMsg(ctx, msg)
|
h.handleLeagueToggleCmd(ctx, msg)
|
||||||
case "/setusername":
|
case "/setusername":
|
||||||
h.handleSetUsername(ctx, msg)
|
h.handleSetUsername(ctx, msg)
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -189,7 +189,9 @@ func (h *Handler) buildSettingsKeyboard(user *db.User, st *db.UserSettings, brea
|
|||||||
rpgStatus = "on"
|
rpgStatus = "on"
|
||||||
}
|
}
|
||||||
leagueStatus := "off"
|
leagueStatus := "off"
|
||||||
if st.LeagueOptIn {
|
if !st.RPGEnabled {
|
||||||
|
leagueStatus = "off"
|
||||||
|
} else if st.LeagueOptIn {
|
||||||
leagueStatus = "on"
|
leagueStatus = "on"
|
||||||
}
|
}
|
||||||
rows := [][]models.InlineKeyboardButton{
|
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)
|
h.sendWithKB(ctx, msg.Chat.ID, text, kb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleLeagueSettingsMsg shows the League enable/disable picker (command).
|
// handleLeagueToggleCmd handles /leaguetoggle — checks RPG is enabled first.
|
||||||
func (h *Handler) handleLeagueSettingsMsg(ctx context.Context, msg *models.Message) {
|
func (h *Handler) handleLeagueToggleCmd(ctx context.Context, msg *models.Message) {
|
||||||
user, err := h.getOrCreateUser(msg.Chat.ID)
|
user, err := h.getOrCreateUser(msg.Chat.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.sendText(ctx, msg.Chat.ID, "Error loading profile")
|
h.sendText(ctx, msg.Chat.ID, "Error loading profile")
|
||||||
return
|
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)
|
text, kb := h.buildLeagueToggleKeyboard(user.ID)
|
||||||
h.sendWithKB(ctx, msg.Chat.ID, text, kb)
|
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 {
|
if err != nil {
|
||||||
return
|
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)
|
text, kb := h.buildLeagueToggleKeyboard(user.ID)
|
||||||
h.editText(ctx, chatID, msgID, text, &kb)
|
h.editText(ctx, chatID, msgID, text, &kb)
|
||||||
}
|
}
|
||||||
@@ -646,8 +665,14 @@ func (h *Handler) handleSelectCallback(ctx context.Context, chatID int64, msgID
|
|||||||
st.RPGEnabled = value
|
st.RPGEnabled = value
|
||||||
if value {
|
if value {
|
||||||
h.DB.GetOrCreateRPGStats(user.ID)
|
h.DB.GetOrCreateRPGStats(user.ID)
|
||||||
|
} else {
|
||||||
|
st.LeagueOptIn = false
|
||||||
}
|
}
|
||||||
case "league_enable":
|
case "league_enable":
|
||||||
|
if value && !st.RPGEnabled {
|
||||||
|
h.answerCbWithText(ctx, callbackID, "Enable RPG first")
|
||||||
|
return
|
||||||
|
}
|
||||||
st.LeagueOptIn = value
|
st.LeagueOptIn = value
|
||||||
}
|
}
|
||||||
if err := h.DB.UpdateSettings(st); err != nil {
|
if err := h.DB.UpdateSettings(st); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user