Use TheDogAPI

This commit is contained in:
Dragon Fire
2024-03-24 18:50:39 -04:00
parent 35f8b1743e
commit bde997e275
3 changed files with 12 additions and 10 deletions
+1
View File
@@ -39,6 +39,7 @@ GOV_KEY=
SPOTIFY_KEY=
SPOTIFY_SECRET=
THECATAPI_KEY=
THEDOGAPI_KEY=
WEBSTER_KEY=
XIAO_GITHUB_REPO_NAME=
XIAO_GITHUB_REPO_USERNAME=
+1 -4
View File
@@ -27,10 +27,7 @@ module.exports = class CatCommand extends Command {
try {
const { body } = await request
.get('https://api.thecatapi.com/v1/images/search')
.query({
limit: 1,
mime_types: 'jpg,png'
})
.query({ limit: 1 })
.set({ 'x-api-key': THECATAPI_KEY });
return msg.say(facts[Math.floor(Math.random() * facts.length)], { files: [body[0].url] });
} catch (err) {
+10 -6
View File
@@ -1,6 +1,7 @@
const Command = require('../../framework/Command');
const request = require('node-superfetch');
const facts = require('../../assets/json/dog-fact');
const { THEDOGAPI_KEY } = process.env;
module.exports = class DogCommand extends Command {
constructor(client) {
@@ -13,10 +14,10 @@ module.exports = class DogCommand extends Command {
clientPermissions: ['ATTACH_FILES'],
credit: [
{
name: 'Dog CEO',
url: 'https://dog.ceo/',
reason: 'Dog API',
reasonURL: 'https://dog.ceo/dog-api/'
name: 'TheDogAPI',
url: 'https://thedogapi.com/',
reason: 'API',
reasonURL: 'https://docs.thedogapi.com/'
}
]
});
@@ -24,8 +25,11 @@ module.exports = class DogCommand extends Command {
async run(msg) {
try {
const { body } = await request.get('https://dog.ceo/api/breeds/image/random');
return msg.say(facts[Math.floor(Math.random() * facts.length)], { files: [body.message] });
const { body } = await request
.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] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}