Make battle and tic-tac-toe less annoying

This commit is contained in:
Daniel Odendahl Jr
2018-05-21 15:38:26 +00:00
parent 7e6ffe66d2
commit 9066eacde8
5 changed files with 29 additions and 31 deletions
+5 -5
View File
@@ -22,14 +22,14 @@ module.exports = class AkinatorCommand extends Command {
if (this.sessions.has(msg.channel.id)) return msg.reply('Only one game may be occuring per channel.');
try {
let ans = null;
this.sessions.set(msg.channel.id, { progress: 0 });
while (this.sessions.get(msg.channel.id).progress < 95) {
this.sessions.set(msg.channel.id, { progression: 0 });
while (this.sessions.get(msg.channel.id).progression < 95) {
const data = ans === null ? await this.createSession(msg.channel) : await this.progress(msg.channel, ans);
if (!data || !data.answers || this.sessions.get(msg.channel.id).step >= 80) break;
const answers = data.answers.map(answer => answer.answer.toLowerCase());
answers.push('end');
await msg.say(stripIndents`
**${++data.step}.** ${data.question}
**${++data.step}.** ${data.question} (${Math.round(Number.parseInt(data.progression, 10))}%)
${data.answers.map(answer => answer.answer).join(' | ')}
`);
const filter = res => res.author.id === msg.author.id && answers.includes(res.content.toLowerCase());
@@ -80,7 +80,7 @@ module.exports = class AkinatorCommand extends Command {
id: data.identification.session,
signature: data.identification.signature,
step: 0,
progress: Number.parseInt(data.step_information.progression, 10)
progression: Number.parseInt(data.step_information.progression, 10)
});
return data.step_information;
}
@@ -103,7 +103,7 @@ module.exports = class AkinatorCommand extends Command {
id: session.id,
signature: session.signature,
step: Number.parseInt(data.step, 10),
progress: Number.parseInt(data.progression, 10)
progression: Number.parseInt(data.progression, 10)
});
return data;
}
+1 -2
View File
@@ -44,8 +44,7 @@ module.exports = class BalloonPopCommand extends Command {
++turns;
if (!opponent.bot || (opponent.bot && userTurn)) {
await msg.say(`${user}, do you pump the balloon?`);
const verification = await verify(msg.channel, user);
pump = verification;
pump = await verify(msg.channel, user);
} else {
pump = Boolean(Math.floor(Math.random() * 2));
}
+3 -1
View File
@@ -61,7 +61,9 @@ module.exports = class BattleCommand extends Command {
**${msg.author.username}**: ${userHP}HP
**${opponent.username}**: ${oppoHP}HP
`);
const turn = await msg.channel.awaitMessages(res => res.author.id === user.id, {
const filter = res =>
res.author.id === user.id && ['fight', 'guard', 'special', 'run'].includes(res.content.toLowerCase());
const turn = await msg.channel.awaitMessages(filter, {
max: 1,
time: 30000
});
+19 -22
View File
@@ -51,7 +51,11 @@ module.exports = class TicTacToeCommand extends Command {
${sides[6]} | ${sides[7]} | ${sides[8]}
\`\`\`
`);
const turn = await msg.channel.awaitMessages(res => res.author.id === user.id, {
const filter = res => {
const choice = res.content;
return res.author.id === user.id && sides.includes(choice) && !taken.includes(choice);
};
const turn = await msg.channel.awaitMessages(filter, {
max: 1,
time: 30000
});
@@ -60,27 +64,20 @@ module.exports = class TicTacToeCommand extends Command {
userTurn = !userTurn;
continue;
}
const choice = turn.first().content.toLowerCase();
if (choice === 'end') break;
if (taken.includes(choice)) {
await msg.say('That spot is already taken!');
} else if (!sides.includes(choice)) {
await msg.say('I don\'t think that is a valid spot...');
} else {
sides[Number.parseInt(choice, 10)] = sign;
taken.push(choice);
if (
(sides[0] === sides[1] && sides[0] === sides[2])
|| (sides[0] === sides[3] && sides[0] === sides[6])
|| (sides[3] === sides[4] && sides[3] === sides[5])
|| (sides[1] === sides[4] && sides[1] === sides[7])
|| (sides[6] === sides[7] && sides[6] === sides[8])
|| (sides[2] === sides[5] && sides[2] === sides[8])
|| (sides[0] === sides[4] && sides[0] === sides[8])
|| (sides[2] === sides[4] && sides[2] === sides[6])
) winner = userTurn ? msg.author : opponent;
userTurn = !userTurn;
}
const choice = turn.first().content;
sides[Number.parseInt(choice, 10)] = sign;
taken.push(choice);
if (
(sides[0] === sides[1] && sides[0] === sides[2])
|| (sides[0] === sides[3] && sides[0] === sides[6])
|| (sides[3] === sides[4] && sides[3] === sides[5])
|| (sides[1] === sides[4] && sides[1] === sides[7])
|| (sides[6] === sides[7] && sides[6] === sides[8])
|| (sides[2] === sides[5] && sides[2] === sides[8])
|| (sides[0] === sides[4] && sides[0] === sides[8])
|| (sides[2] === sides[4] && sides[2] === sides[6])
) winner = userTurn ? msg.author : opponent;
userTurn = !userTurn;
}
this.playing.delete(msg.channel.id);
return msg.say(winner ? `Congrats, ${winner}!` : 'Oh... The cat won.');
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "77.0.2",
"version": "77.0.3",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {