display errors to users properly

This commit is contained in:
hippoz 2022-05-29 16:47:11 +03:00
parent 19d121a572
commit cadec6cdfe
Signed by: hippoz
GPG key ID: 7C52899193467641
2 changed files with 8 additions and 4 deletions

View file

@ -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}`
});
}
}
});

View file

@ -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}`
};
}