diff --git a/config/default.js b/config/default.js index 4008f81..e1ab3bd 100644 --- a/config/default.js +++ b/config/default.js @@ -24,6 +24,10 @@ module.exports = { mode: 'first', // first or timeout rounds: 10, timeout: 60, + bounds: { + rounds: [1, 30], + timeout: [5, 300], + }, }, duck: { interval: [10, 3600], // seconds diff --git a/src/games/trivia.js b/src/games/trivia.js index 2c73729..73a3f88 100644 --- a/src/games/trivia.js +++ b/src/games/trivia.js @@ -182,7 +182,19 @@ function onCommand(args, context) { if (subcommand && settings[subcommand]) { if (args[0]) { - settings[subcommand] = typeof settings[subcommand] === 'number' ? (Number(args[0]) || settings[subcommand]) : args[0]; + const bounds = config.trivia.bounds[subcommand]; + const curatedSetting = typeof settings[subcommand] === 'number' ? Number(args[0]) : args[0]; + + if (Number.isNaN(curatedSetting)) { + context.sendMessage(`${subcommand} must be a valid number`, context.room.id); + } + + if (Array.isArray(bounds) && typeof settings[subcommand] === 'number' && (curatedSetting < bounds[0] || curatedSetting > bounds[1])) { + context.sendMessage(`${subcommand} must be between ${bounds[0]} and ${bounds[1]}`, context.room.id); + return; + } + + settings[subcommand] = curatedSetting; context.sendMessage(`${subcommand} set to ${settings[subcommand]}`, context.room.id); } else if (help[subcommand]) {