Files
xiao/commands/games-sp/box-choosing.js
T
2024-03-30 11:59:42 -04:00

84 lines
2.2 KiB
JavaScript

const Command = require('../../framework/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'],
group: 'games-sp',
memberName: 'box-choosing',
description: 'Do you believe that there are choices in life? Taken from Higurashi Chapter 4.',
game: true,
credit: [
{
name: '07th Expansion',
url: 'http://07th-expansion.net/',
reason: 'Original Game'
},
{
name: 'MangaGamer.com',
url: 'https://www.mangagamer.com/',
reason: 'Original Translation',
reasonURL: 'https://store.steampowered.com/app/526490/Higurashi_When_They_Cry_Hou__Ch4_Himatsubushi/'
}
]
});
this.blue = new Set();
this.red = new Set();
}
async run(msg) {
let i = 0;
let path = 'before';
let end = false;
while (!end) {
const line = script[path][i];
if (!line) {
end = true;
break;
}
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) {
end = true;
break;
}
path = '';
const pick = line.paths[line.options.indexOf(choose.first().content.toLowerCase())];
if ((this.red.has(msg.author.id) && pick !== 'red') || (this.blue.has(msg.author.id) && pick !== 'blue')) {
path += 'both';
if (this.red.has(msg.author.id)) this.red.delete(msg.author.id);
if (this.blue.has(msg.author.id)) this.blue.delete(msg.author.id);
} else {
this[pick].add(msg.author.id);
setTimeout(() => { if (this[pick].has(msg.author.id)) this[pick].delete(msg.author.id); }, 600000);
}
path += pick;
i = 0;
} else {
const verification = await verify(msg.channel, msg.author, { time: 120000 });
if (!verification) {
end = true;
break;
}
i++;
}
}
return msg.say(script.end);
}
};