From 085feae3dcc6ac78f26a3272602ad7530b5c444b Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 17 Mar 2020 19:34:14 -0400 Subject: [PATCH] Add Forefeit to tic-tac-toe, Bug Fixes --- commands/mp-games/connect-four.js | 5 ++--- commands/mp-games/tic-tac-toe.js | 10 ++++++++-- package.json | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/commands/mp-games/connect-four.js b/commands/mp-games/connect-four.js index 4bf278a2..ba5bba03 100644 --- a/commands/mp-games/connect-four.js +++ b/commands/mp-games/connect-four.js @@ -59,12 +59,11 @@ module.exports = class ConnectFourCommand extends Command { ${nums.join('')} `); const filter = res => { + if (res.author.id !== user.id) return false const choice = res.content; if (choice.toLowerCase() === 'end') return true; const i = Number.parseInt(choice, 10) - 1; - if (!board[colLevels[i]]) return false; - if (board[colLevels[i]][i] === undefined) return false; - return res.author.id === user.id; + return board[colLevels[i]] && board[colLevels[i]][i] !== undefined; }; const turn = await msg.channel.awaitMessages(filter, { max: 1, diff --git a/commands/mp-games/tic-tac-toe.js b/commands/mp-games/tic-tac-toe.js index 7eb084b8..5ba94d14 100644 --- a/commands/mp-games/tic-tac-toe.js +++ b/commands/mp-games/tic-tac-toe.js @@ -41,7 +41,7 @@ module.exports = class TicTacToeCommand extends Command { const user = userTurn ? msg.author : opponent; const sign = userTurn ? 'X' : 'O'; await msg.say(stripIndents` - ${user}, which side do you pick? + ${user}, which side do you pick? Type \`end\` to forefeit. \`\`\` ${sides[0]} | ${sides[1]} | ${sides[2]} ————————— @@ -51,8 +51,10 @@ module.exports = class TicTacToeCommand extends Command { \`\`\` `); const filter = res => { + if (res.author.id !== user.id) return false; const choice = res.content; - return res.author.id === user.id && sides.includes(choice) && !taken.includes(choice); + if (choice.toLowerCase() === 'end') return true; + return sides.includes(choice) && !taken.includes(choice); }; const turn = await msg.channel.awaitMessages(filter, { max: 1, @@ -64,6 +66,10 @@ module.exports = class TicTacToeCommand extends Command { continue; } const choice = turn.first().content; + if (choice.toLowerCase() === 'end') { + winner = userTurn ? opponent : msg.author; + break; + } sides[Number.parseInt(choice, 10) - 1] = sign; taken.push(choice); if (this.verifyWin(sides)) winner = userTurn ? msg.author : opponent; diff --git a/package.json b/package.json index faa5f5d7..ecac48cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.9.0", + "version": "112.9.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {