From 11a2b2107e140a6f26b931bb2620551fa9350b92 Mon Sep 17 00:00:00 2001 From: standard Date: Thu, 6 Feb 2025 15:31:22 +0100 Subject: [PATCH] The chess server is always returning a JSON --- assets/js/pages/console/index.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/assets/js/pages/console/index.js b/assets/js/pages/console/index.js index 30228b81..069020ff 100644 --- a/assets/js/pages/console/index.js +++ b/assets/js/pages/console/index.js @@ -3,23 +3,21 @@ import * as connect from '../../connect.js'; import AbstractWebSocket from '../../websockets/AbstractWebSocket.js'; class ConsoleWebSocket extends AbstractWebSocket { + hints = [ + "Let me suggest you read the docs.", + "Sorry, I am not an AI prompt.", + "This command cannot be processed.", + ]; + async connect(port) { await super.connect(`${connect.ws()}:${port}`); this.socket.onmessage = (res) => { const data = JSON.parse(res.data); const msg = Object.keys(data)[0]; this.response[msg] = data[msg]; - if (msg === 'error') { - const hints = [ - "Let me suggest you read the docs.", - "Sorry, I am not an AI prompt.", - "This command cannot be processed.", - ]; - consoleForm.print(hints[Math.floor(Math.random() * hints.length)]); - } else { - const output = typeof data[msg] === 'string' ? data[msg] : JSON.stringify(data[msg]); - consoleForm.print(output); - } + msg === 'error' + ? consoleForm.print(this.hints[Math.floor(Math.random() * this.hints.length)]) + : consoleForm.print(JSON.stringify(data[msg])); }; } }