Skip to content

Commit

Permalink
Fix /dog internal errors (fix #14, #17)
Browse files Browse the repository at this point in the history
- Also, fallback to joining args if sub-breed doesn't exist.
  • Loading branch information
0xVR authored Oct 5, 2020
1 parent 2783133 commit f76f960
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/bot/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`
Expand All @@ -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}` }
}
Expand Down

0 comments on commit f76f960

Please sign in to comment.