@@ -6,6 +6,11 @@ import {
66} from "discord.js" ;
77import { BattleStatsManager } from "../utils/battleStatsManager.js" ;
88
9+ function clampLimit ( value : number , max : number ) : number {
10+ if ( ! Number . isFinite ( value ) ) return 10 ;
11+ return Math . max ( 1 , Math . min ( max , value ) ) ;
12+ }
13+
914export const data = new SlashCommandBuilder ( )
1015 . setName ( "battlestats" )
1116 . setDescription ( "View deathbattle statistics and leaderboards" )
@@ -50,6 +55,14 @@ export const data = new SlashCommandBuilder()
5055 { name : "Ranked" , value : "ranked" } ,
5156 )
5257 . setRequired ( false ) ,
58+ )
59+ . addIntegerOption ( ( option ) =>
60+ option
61+ . setName ( "limit" )
62+ . setDescription ( "How many warriors to show (defaults to 10, max 25)" )
63+ . setMinValue ( 1 )
64+ . setMaxValue ( 25 )
65+ . setRequired ( false ) ,
5366 ) ,
5467 )
5568 . addSubcommand ( ( subcommand ) =>
@@ -76,6 +89,14 @@ export const data = new SlashCommandBuilder()
7689 { name : "All" , value : "all" } ,
7790 )
7891 . setRequired ( false ) ,
92+ )
93+ . addIntegerOption ( ( option ) =>
94+ option
95+ . setName ( "limit" )
96+ . setDescription ( "How many battles to show (defaults to 10, max 25)" )
97+ . setMinValue ( 1 )
98+ . setMaxValue ( 25 )
99+ . setRequired ( false ) ,
79100 ) ,
80101 ) ;
81102
@@ -188,8 +209,13 @@ export async function execute(
188209 case "leaderboard" : {
189210 const mode = interaction . options . getString ( "mode" ) || "normal" ;
190211 const isRanked = mode === "ranked" ;
212+ const limit = clampLimit (
213+ interaction . options . getInteger ( "limit" ) || 10 ,
214+ 25 ,
215+ ) ;
216+
191217 const leaderboard = await BattleStatsManager . getLeaderboard (
192- 10 ,
218+ limit ,
193219 isRanked ,
194220 ) ;
195221
@@ -238,6 +264,10 @@ export async function execute(
238264 const targetUser =
239265 interaction . options . getUser ( "user" ) || interaction . user ;
240266 const mode = interaction . options . getString ( "mode" ) || "all" ;
267+ const limit = clampLimit (
268+ interaction . options . getInteger ( "limit" ) || 10 ,
269+ 25 ,
270+ ) ;
241271
242272 let rankedFilter : boolean | undefined ;
243273 if ( mode === "normal" ) rankedFilter = false ;
@@ -246,7 +276,7 @@ export async function execute(
246276
247277 const history = await BattleStatsManager . getUserBattleHistory (
248278 targetUser . id ,
249- 10 ,
279+ limit ,
250280 rankedFilter ,
251281 ) ;
252282
0 commit comments