From f76f960bfb85ed9925b352938bc8eb66732003d6 Mon Sep 17 00:00:00 2001 From: xVyre <38956768+xVyre@users.noreply.github.com> Date: Mon, 5 Oct 2020 23:04:24 +0400 Subject: [PATCH] Fix /dog internal errors (fix #14, #17) - Also, fallback to joining args if sub-breed doesn't exist. --- server/bot/commands/api.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/bot/commands/api.ts b/server/bot/commands/api.ts index 3c2c119..4cded81 100644 --- a/server/bot/commands/api.ts +++ b/server/bot/commands/api.ts @@ -224,10 +224,15 @@ export const handleDog: Command = { // Fetch a random picture for a sub-breed. } else if (args[0] && args[1]) { try { - const { message } = await (await fetch( + let { message } = await (await fetch( `http://dog.ceo/api/breed/${args[0].toLowerCase()}/${args[1].toLowerCase()}/images/random` )).json() - if (!message || message === 'Breed not found') return 'This breed/sub-breed does not exist!' + if (message.includes('Breed not found')) { + ({ message } = await (await fetch( + `http://dog.ceo/api/breed/${args.join('').toLowerCase()}/images/random` + )).json()) + } + if (!message || message.includes('Breed not found')) return 'This breed/sub-breed does not exist!' return { embed: { image: { url: message }, color: 0x654321 }, content: `🐕 ${args[0]} ${args[1]}` @@ -239,7 +244,7 @@ export const handleDog: Command = { const { message } = await (await fetch( `http://dog.ceo/api/breed/${args[0].toLowerCase()}/images/random` )).json() - if (!message || message === 'Breed not found') return 'This breed does not exist!' + if (!message || message.includes('Breed not found')) return 'This breed does not exist!' return { embed: { image: { url: message }, color: 0x654321 }, content: '🐕 ' + args[0] } } catch (err) { return `Something went wrong 👾 Error: ${err}` } }