From 9066eacde8b32cb7d560b0a833193c3c2538fef1 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 21 May 2018 15:38:26 +0000 Subject: [PATCH] Make battle and tic-tac-toe less annoying --- commands/games/akinator.js | 10 ++++----- commands/games/balloon-pop.js | 3 +-- commands/games/battle.js | 4 +++- commands/games/tic-tac-toe.js | 41 ++++++++++++++++------------------- package.json | 2 +- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/commands/games/akinator.js b/commands/games/akinator.js index ab5152a1..34d74836 100644 --- a/commands/games/akinator.js +++ b/commands/games/akinator.js @@ -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; } diff --git a/commands/games/balloon-pop.js b/commands/games/balloon-pop.js index 0134ab29..df437ef2 100644 --- a/commands/games/balloon-pop.js +++ b/commands/games/balloon-pop.js @@ -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)); } diff --git a/commands/games/battle.js b/commands/games/battle.js index 6f7a2818..a002f74d 100644 --- a/commands/games/battle.js +++ b/commands/games/battle.js @@ -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 }); diff --git a/commands/games/tic-tac-toe.js b/commands/games/tic-tac-toe.js index 73fd2bbb..0ae53e7d 100644 --- a/commands/games/tic-tac-toe.js +++ b/commands/games/tic-tac-toe.js @@ -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.'); diff --git a/package.json b/package.json index 7ae2ce7c..ae8710ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "77.0.2", + "version": "77.0.3", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {