Add external dog and cat fact apis

This commit is contained in:
Dragon Fire
2024-04-26 00:20:55 -04:00
parent 819cbf31f0
commit b7e2e9f938
2 changed files with 32 additions and 2 deletions
+16 -1
View File
@@ -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)];
}
}
};
+16 -1
View File
@@ -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)];
}
}
};