From 86a77ffcaf63af7d1e4001f53149efe2d69f58f4 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 11 Nov 2019 23:06:38 -0500 Subject: [PATCH] Russian Roulette Command --- README.md | 3 +- commands/games/russian-roulette.js | 58 ++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 commands/games/russian-roulette.js diff --git a/README.md b/README.md index d12ca6dd..5009faf9 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Xiao is a Discord bot coded in JavaScript with * [Rando Cardrissian](https://github.com/dragonfire535/rando-cardrissian) is a Cards Against Humanity bot, whose features were originally built into Xiao. * [Storyteller](https://github.com/dragonfire535/storyteller) is a Mafia bot made for Discord's 2019 Hack Week, whose features were originally built into Xiao. -## Commands (343) +## Commands (344) ### Utility: * **eval:** Executes JavaScript code. @@ -275,6 +275,7 @@ Xiao is a Discord bot coded in JavaScript with * **quiz:** Answer a quiz question. * **rock-paper-scissors:** Play Rock-Paper-Scissors. * **roulette:** Play a game of roulette. +* **russian-roulette:** Who will pull the trigger and die first? * **slots:** Play a game of slots. * **sorting-hat:** Take a quiz to determine your Hogwarts house. * **tic-tac-toe:** Play a game of tic-tac-toe with another user. diff --git a/commands/games/russian-roulette.js b/commands/games/russian-roulette.js new file mode 100644 index 00000000..560401a3 --- /dev/null +++ b/commands/games/russian-roulette.js @@ -0,0 +1,58 @@ +const Command = require('../../structures/Command'); +const { shuffle, verify } = require('../../util/Util'); + +module.exports = class RussianRouletteCommand extends Command { + constructor(client) { + super(client, { + name: 'russian-roulette', + aliases: ['r-roulette', 'russia-gun'], + group: 'games', + memberName: 'russian-roulette', + description: 'Who will pull the trigger and die first?', + args: [ + { + key: 'opponent', + prompt: 'What user would you like to gunfight?', + type: 'user', + default: () => this.client.user + } + ] + }); + } + + async run(msg, { opponent }) { + if (opponent.id === msg.author.id) return msg.reply('You may not challenge yourself.'); + const current = this.client.games.get(msg.channel.id); + if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`); + this.client.games.set(msg.channel.id, { name: this.name }); + try { + await msg.say(`${opponent}, do you accept this challenge?`); + const verification = await verify(msg.channel, opponent); + if (!verification) { + this.client.games.delete(msg.channel.id); + return msg.say('Looks like they declined...'); + } + let userTurn = true; + const gun = shuffle([true, false, false, false, false, false, false, false]); + let round = 0; + let winner = null; + while (!winner) { + const player = userTurn ? msg.author : opponent; + await msg.say(`${player.tag} pulls the trigger... And **${gun[round] ? 'dies!**' : 'lives...** Continue?'}`); + if (gun[round]) { + winner = userTurn ? opponent : msg.author; + } else { + const keepGoing = await verify(msg.channel, opponent.bot ? msg.author : player); + if (!keepGoing) winner = userTurn ? opponent : msg.author; + round++; + userTurn = !userTurn; + } + } + this.client.games.delete(msg.channel.id); + return msg.say(`The winner is ${winner}!`); + } catch (err) { + this.client.games.delete(msg.channel.id); + throw err; + } + } +}; diff --git a/package.json b/package.json index 9cb841ae..055846ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "108.0.0", + "version": "108.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {