From 7cbbf879df3cbb5bb08445256166ab08b6f91250 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 7 Feb 2021 18:49:55 -0500 Subject: [PATCH] Validate FEN --- commands/games-mp/chess-set-up.js | 4 +++- commands/games-mp/chess.js | 8 ++------ package.json | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/commands/games-mp/chess-set-up.js b/commands/games-mp/chess-set-up.js index c7cfa0f3..caf6cbee 100644 --- a/commands/games-mp/chess-set-up.js +++ b/commands/games-mp/chess-set-up.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const validateFEN = require('fen-validator').default; module.exports = class ChessSetUpCommand extends Command { constructor(client) { @@ -12,7 +13,8 @@ module.exports = class ChessSetUpCommand extends Command { { key: 'fen', prompt: 'What FEN would you like to use for the game?', - type: 'string' + type: 'string', + validate: fen => validateFEN(fen) } ] }); diff --git a/commands/games-mp/chess.js b/commands/games-mp/chess.js index a17b43d0..e5218503 100644 --- a/commands/games-mp/chess.js +++ b/commands/games-mp/chess.js @@ -87,13 +87,9 @@ module.exports = class ChessCommand extends Command { blackPlayer = data.color === 'black' ? msg.author : opponent; await this.client.redis.del(`chess-${msg.author.id}`); } catch { - await msg.reply('An error occurred reading your saved game. Deleting it and aborting...'); - game = new jsChess.Game(); - whiteTime = time * 60000; - blackTime = time * 60000; - whitePlayer = msg.author; - blackPlayer = opponent; + this.client.games.delete(msg.channel.id); await this.client.redis.del(`chess-${msg.author.id}`); + return msg.reply('An error occurred reading your saved game. Please try again.'); } } else { game = new jsChess.Game(); diff --git a/package.json b/package.json index 5f06f4e1..ce546066 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "emoji-regex": "^9.2.1", "eslint": "^7.19.0", "expr-eval": "^2.0.2", + "fen-validator": "^1.4.1", "gifencoder": "^2.0.1", "gm": "^1.23.1", "html-entities": "^2.1.0",