diff --git a/commands/random-img/cat.js b/commands/random-img/cat.js index 81c01a83..a0038798 100644 --- a/commands/random-img/cat.js +++ b/commands/random-img/cat.js @@ -19,6 +19,11 @@ module.exports = class CatCommand extends Command { url: 'https://thecatapi.com/', reason: 'API', reasonURL: 'https://docs.thecatapi.com/' + }, + { + name: 'Cat Facts API', + url: 'https://catfact.ninja/', + reason: 'API' } ] }); @@ -29,6 +34,16 @@ module.exports = class CatCommand extends Command { .get('https://api.thecatapi.com/v1/images/search') .query({ limit: 1 }) .set({ 'x-api-key': THECATAPI_KEY }); - return msg.say(facts[Math.floor(Math.random() * facts.length)], { files: [body[0].url] }); + const fact = await this.getFact(); + return msg.say(fact, { files: [body[0].url] }); + } + + async getFact() { + try { + const { body } = await request.get('https://catfact.ninja/fact'); + return body.fact; + } catch { + return facts[Math.floor(Math.random() * facts.length)]; + } } }; diff --git a/commands/random-img/dog.js b/commands/random-img/dog.js index c0bca82a..6713ffcc 100644 --- a/commands/random-img/dog.js +++ b/commands/random-img/dog.js @@ -19,6 +19,11 @@ module.exports = class DogCommand extends Command { url: 'https://thedogapi.com/', reason: 'API', reasonURL: 'https://docs.thedogapi.com/' + }, + { + name: 'Dog API', + url: 'https://kinduff.github.io/dog-api/', + reason: 'API' } ] }); @@ -29,6 +34,16 @@ module.exports = class DogCommand extends Command { .get('https://api.thedogapi.com/v1/images/search') .query({ limit: 1 }) .set({ 'x-api-key': THEDOGAPI_KEY }); - return msg.say(facts[Math.floor(Math.random() * facts.length)], { files: [body[0].url] }); + const fact = await this.getFact(); + return msg.say(fact, { files: [body[0].url] }); + } + + async getFact() { + try { + const { body } = await request.get('https://dog-api.kinduff.com/api/facts'); + return body.facts[0]; + } catch { + return facts[Math.floor(Math.random() * facts.length)]; + } } };