Russian Roulette Command

This commit is contained in:
Dragon Fire
2019-11-11 23:06:38 -05:00
parent 050b5056f1
commit 86a77ffcaf
3 changed files with 61 additions and 2 deletions
+2 -1
View File
@@ -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.
+58
View File
@@ -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;
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "108.0.0",
"version": "108.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {