mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 05:54:33 +02:00
6cf7ae85f0
For some reason notPlayer would use the current player that said no, this might just be for me but i'm going to propose this change anyhow
72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
const Command = require('../../structures/Command');
|
|
const { stripIndents } = require('common-tags');
|
|
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: 'mp-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 {
|
|
if (!opponent.bot) {
|
|
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;
|
|
let quit = false;
|
|
while (!winner) {
|
|
const player = userTurn ? msg.author : opponent;
|
|
const notPlayer = userTurn ? opponent : msg.author;
|
|
if (gun[round]) {
|
|
await msg.say(`**${player.tag}** pulls the trigger... **And dies!**`);
|
|
winner = notPlayer;
|
|
} else {
|
|
await msg.say(stripIndents`
|
|
**${player.tag}** pulls the trigger... **And lives...**
|
|
${opponent.bot ? 'Continue?' : `Will you take the gun, ${notPlayer}?`} (${8 - round - 1} shots left)
|
|
`);
|
|
const keepGoing = await verify(msg.channel, opponent.bot ? msg.author : notPlayer);
|
|
if (!keepGoing) {
|
|
winner = player;
|
|
quit = true;
|
|
}
|
|
round++;
|
|
userTurn = !userTurn;
|
|
}
|
|
}
|
|
this.client.games.delete(msg.channel.id);
|
|
if (quit) return msg.say(`${winner} wins, because their opponent was a coward.`);
|
|
return msg.say(`The winner is ${winner}!`);
|
|
} catch (err) {
|
|
this.client.games.delete(msg.channel.id);
|
|
throw err;
|
|
}
|
|
}
|
|
};
|