From 3b057060351d38ad60cfc9ed8d2b070c41f69f0e Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 15 Jul 2017 16:43:50 +0000 Subject: [PATCH] Gunfight Command --- commands/games/battle.js | 2 +- commands/games/gunfight.js | 59 ++++++++++++++++++++++++++++++++++++++ commands/random/today.js | 2 +- package.json | 2 +- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 commands/games/gunfight.js diff --git a/commands/games/battle.js b/commands/games/battle.js index f6388f3a..3d89ca01 100644 --- a/commands/games/battle.js +++ b/commands/games/battle.js @@ -24,7 +24,7 @@ module.exports = class BattleCommand extends Command { } async run(msg, args) { // eslint-disable-line complexity - const opponent = args.opponent; + const { opponent } = args; if (opponent.bot) return msg.say('Bots may not be fought.'); if (opponent.id === msg.author.id) return msg.say('You may not fight yourself.'); if (this.fighting.has(msg.guild.id)) return msg.say('Only one fight may be occurring per server.'); diff --git a/commands/games/gunfight.js b/commands/games/gunfight.js new file mode 100644 index 00000000..aee0496b --- /dev/null +++ b/commands/games/gunfight.js @@ -0,0 +1,59 @@ +const Command = require('../../structures/Command'); + +module.exports = class GunfightCommand extends Command { + constructor(client) { + super(client, { + name: 'gunfight', + aliases: ['western-gunfight'], + group: 'games', + memberName: 'battle', + description: 'Engage in a western gunfight against another user.', + guildOnly: true, + args: [ + { + key: 'opponent', + prompt: 'Who would you like to gunfight?', + type: 'user' + } + ] + }); + + this.fighting = new Set(); + } + + async run(msg, args) { + const { opponent } = args; + if (opponent.bot) return msg.say('Bots may not be fought.'); + if (opponent.id === msg.author.id) return msg.say('You may not fight yourself.'); + if (this.fighting.has(msg.guild.id)) return msg.say('Only one fight may be occurring per server.'); + this.fighting.add(msg.guild.id); + try { + await msg.say(`${opponent}, do you accept this challenge? **__Y__es** or **No**?`); + const verify = await msg.channel.awaitMessages((res) => res.author.id === opponent.id, { + max: 1, + time: 30000 + }); + if (!verify.size || !['yes', 'y'].includes(verify.first().content.toLowerCase())) { + this.fighting.delete(msg.guild.id); + return msg.say('Looks like they declined...'); + } + await msg.say('Get Ready...'); + const length = Math.floor(Math.random() * (30000 - 1000 + 1) + 1000); + this.client.setTimeout(async () => { + await msg.say('TYPE `FIRE` NOW!'); + const filter = (res) => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === 'fire'; // eslint-disable-line max-len + const winner = await msg.channel.awaitMessages(filter, { + max: 1, + time: 30000 + }); + this.fighting.delete(msg.guild.id); + if (!winner.size) return msg.say('Oh... No one won.'); + else return msg.say(`And the winner is ${winner.first().author.username}!`); + }, length); + return null; + } catch (err) { + this.fighting.delete(msg.guild.id); + return msg.say(`Oh no, an Error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/random/today.js b/commands/random/today.js index 049b35b3..908dc619 100644 --- a/commands/random/today.js +++ b/commands/random/today.js @@ -31,7 +31,7 @@ module.exports = class TodayCommand extends Command { if (day < 32 && day > 0) return true; else return 'Please enter a valid day.'; } - }, + } ] }); } diff --git a/package.json b/package.json index f912cd01..ddc668ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "27.2.1", + "version": "27.3.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {