From cadec6cdfecb16efec3f12e1d0472d0c05a63c47 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sun, 29 May 2022 16:47:11 +0300 Subject: [PATCH] display errors to users properly --- src/bot.js | 7 ++++++- src/commands/interperter.js | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bot.js b/src/bot.js index df4d509..ea9b5fc 100644 --- a/src/bot.js +++ b/src/bot.js @@ -12,11 +12,16 @@ export function makeBot() { client.on("MESSAGE_CREATE", (message) => { if (message.content.startsWith("$ ")) { const command = message.content.substring(2, message.content.length); - handleCommand(command, (_streamName, streamContent) => { + const result = handleCommand(command, (_streamName, streamContent) => { client.api("POST", `/channels/${message.channel_id}/messages`, { content: streamContent }); }); + if (result.error) { + client.api("POST", `/channels/${message.channel_id}/messages`, { + content: `error: ${result.error}` + }); + } } }); diff --git a/src/commands/interperter.js b/src/commands/interperter.js index eea4a55..36dc3ca 100644 --- a/src/commands/interperter.js +++ b/src/commands/interperter.js @@ -191,14 +191,13 @@ export function handleCommand(message, displayFunc) { const { error: tokError, tokens } = tokenize(message); if (tokError) { return { - error: `error: tokenize: ${tokError}` + error: `tokenize: ${tokError}` }; } const { error: insError, instructions } = tokensToInstructions(tokens); - console.log(instructions); if (insError) { return { - error: `error: tokensToInstructions: ${insError}` + error: `tokensToInstructions: ${insError}` }; }