This commit is contained in:
Dragon Fire
2021-01-23 16:00:45 -05:00
parent 6b8cf922d1
commit b08c6f13fa
+1 -3
View File
@@ -69,13 +69,13 @@ module.exports = class ChessCommand extends Command {
${user}, what move do you want to make (ex. A1A2)? Type \`end\` to forfeit. ${user}, what move do you want to make (ex. A1A2)? Type \`end\` to forfeit.
_You are ${gameState.check ? '**in check!**' : 'not in check.'}_ _You are ${gameState.check ? '**in check!**' : 'not in check.'}_
`, { files: [{ attachment: this.displayBoard(gameState), name: 'chess.png' }] }); `, { files: [{ attachment: this.displayBoard(gameState), name: 'chess.png' }] });
const moves = game.moves();
const pickFilter = res => { const pickFilter = res => {
if (res.author.id !== user.id) return false; if (res.author.id !== user.id) return false;
const choice = res.content.toUpperCase(); const choice = res.content.toUpperCase();
if (choice === 'END') return true; if (choice === 'END') return true;
const move = choice.match(turnRegex); const move = choice.match(turnRegex);
if (!move) return false; if (!move) return false;
const moves = game.moves();
if (!moves[move[1]] || !moves[move[1]].includes(move[2])) { if (!moves[move[1]] || !moves[move[1]].includes(move[2])) {
reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌'); reactIfAble(res, res.author, FAILURE_EMOJI_ID, '❌');
return false; return false;
@@ -88,11 +88,9 @@ module.exports = class ChessCommand extends Command {
}); });
if (!turn.size) { if (!turn.size) {
if (lastTurnTimeout) { if (lastTurnTimeout) {
await msg.say('Game ended due to inactivity.');
break; break;
} else { } else {
await msg.say('Sorry, time is up! Playing random move.'); await msg.say('Sorry, time is up! Playing random move.');
const moves = game.moves();
const available = Object.keys(moves); const available = Object.keys(moves);
const piece = available[Math.floor(Math.random() * available.length)]; const piece = available[Math.floor(Math.random() * available.length)];
const move = moves[piece][Math.floor(Math.random() * moves[piece].length)]; const move = moves[piece][Math.floor(Math.random() * moves[piece].length)];