Files
xiao/commands/games/box-choosing.js
T
2018-08-03 18:30:23 -04:00

71 lines
2.0 KiB
JavaScript

const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const { verify } = require('../../util/Util');
const script = require('../../assets/json/box-choosing');
module.exports = class BoxChoosingCommand extends Command {
constructor(client) {
super(client, {
name: 'box-choosing',
aliases: ['box-choose', 'boxes'],
group: 'games',
memberName: 'box-choosing',
description: 'Do you believe that there are choices in life? Taken from Higurashi Chapter 4.'
});
this.playing = new Set();
this.blue = new Set();
this.red = new Set();
}
async run(msg) {
if (this.playing.has(msg.channel.id)) return msg.reply('Only one game may be occurring per channel.');
this.playing.add(msg.channel.id);
try {
let i = 0;
let path = 'before';
while (true) { // eslint-disable-line no-constant-condition
const line = script[path][i];
if (line.end) {
this.playing.delete(msg.channel.id);
return msg.say(line.text);
} else {
await msg.say(typeof line === 'object' ? line.text : stripIndents`
${line}
_Proceed?_
`);
}
if (line.options) {
const filter = res => res.author.id === msg.author.id && line.options.includes(res.content.toLowerCase());
const choose = await msg.channel.awaitMessages(filter, {
max: 1,
time: 120000
});
if (!choose.size) break;
path = '';
if (this.red.has(msg.author.id) && this.blue.has(msg.author.id)) {
path += 'both';
this.red.delete(msg.author.id);
this.blue.delete(msg.author.id);
} else {
const choice = line.paths[line.options.indexOf(choose.first().content.toLowerCase())];
path += choice;
this[choice].add(msg.author.id);
}
i = 0;
} else {
const verification = await verify(msg.channel, msg.author, 120000);
if (!verification) break;
i++;
}
}
this.playing.delete(msg.channel.id);
return msg.say('See you soon!');
} catch (err) {
this.playing.delete(msg.channel.id);
throw err;
}
}
};