diff --git a/commands/games/roulette.js b/commands/games/roulette.js new file mode 100644 index 00000000..e29878c2 --- /dev/null +++ b/commands/games/roulette.js @@ -0,0 +1,68 @@ +const { Command } = require('discord.js-commando'); +const { oneLine } = require('common-tags'); +const { wait } = require('../../util/Util'); +const red = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]; +const black = [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35]; +const numbers = [0].concat(red, black); +const dozens = ['1-12', '13-24', '25-36']; +const halves = ['1-18', '19-36']; +const columns = ['1st', '2nd', '3rd']; +const parity = ['even', 'odd']; +const colors = ['red', 'black']; + +module.exports = class RouletteCommand extends Command { + constructor(client) { + super(client, { + name: 'roulette', + group: 'games', + memberName: 'roulette', + description: 'Play a game of roulette.', + args: [ + { + key: 'space', + prompt: 'What space do you want to bet on?', + type: 'string', + validate: space => { + if (numbers.includes(parseInt(space, 10))) return true; + if (dozens.includes(space)) return true; + if (halves.includes(space)) return true; + if (columns.includes(space.toLowerCase())) return true; + if (parity.includes(space.toLowerCase())) return true; + if (colors.includes(space.toLowerCase())) return true; + return oneLine` + Invalid space, please enter either a specific number from 0-36, a range of dozens (e.g. 1-12), a range of + halves (e.g. 1-18), a column (e.g. 1st), a color (e.g. black), or a parity (e.g. even). + `; + }, + parse: space => space.toLowerCase() + } + ] + }); + } + + async run(msg, { choice }) { + await msg.say('The roulette starts spinning...'); + const number = Math.floor(Math.random() * 37); + const color = !number ? null : red.includes(number) ? 'RED' : 'BLACK'; + const win = this.verifyWin(choice, number); + await wait(5000); + return msg.reply(`The result is **${number}${color ? ` ${color}` : ''}**. ${win ? 'You win!' : 'You lose...'}`); + } + + verifyWin(choice, result) { + const number = parseInt(choice, 10); + if (numbers.includes(number)) return result === number; + if (dozens.includes(choice) || halves.includes(choice)) { + const range = choice.split('-'); + return result >= range[0] && range[1] <= result; + } + if (colors.includes(choice)) { + if (!result) return false; + if (choice === 'black') return black.includes(result); + if (choice === 'red') return red.includes(result); + } + if (parity.includes(choice)) return parity[result % 2] === choice; + if (columns.includes(choice)) return columns[(result - 1) % 3] === choice; + return false; + } +}; diff --git a/commands/random/roulette.js b/commands/random/user-roulette.js similarity index 61% rename from commands/random/roulette.js rename to commands/random/user-roulette.js index 00ce5339..212163fd 100644 --- a/commands/random/roulette.js +++ b/commands/random/user-roulette.js @@ -1,11 +1,12 @@ const { Command } = require('discord.js-commando'); -module.exports = class RouletteCommand extends Command { +module.exports = class UserRouletteCommand extends Command { constructor(client) { super(client, { - name: 'roulette', + name: 'user-roulette', + aliases: ['member-roulette', 'random-user', 'random-member'], group: 'random', - memberName: 'roulette', + memberName: 'user-roulette', description: 'Randomly chooses a member of the server.', guildOnly: true }); diff --git a/package.json b/package.json index 881a9b42..a7ef9e9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "56.6.1", + "version": "57.0.0", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": {