Files
xiao/commands/games/box-choosing.js
T
Daniel Odendahl Jr 313f9c46de Box Choosing Command
2018-07-10 00:46:06 +00:00

60 lines
1.7 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();
}
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 = line.paths[line.options.indexOf(choose.first().content.toLowerCase())];
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;
}
}
};