mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
const Command = require('../../framework/Command');
|
|
const { PermissionFlagsBits } = require('discord.js');
|
|
const request = require('node-superfetch');
|
|
const { THEDOGAPI_KEY } = process.env;
|
|
|
|
module.exports = class DogCommand extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: 'dog',
|
|
aliases: ['puppy', 'dog-fact', 'puppy-fact', 'inu', 'inu-fact'],
|
|
group: 'random-img',
|
|
description: 'Responds with a random dog image and fact.',
|
|
clientPermissions: [PermissionFlagsBits.AttachFiles],
|
|
credit: [
|
|
{
|
|
name: 'TheDogAPI',
|
|
url: 'https://thedogapi.com/',
|
|
reason: 'API',
|
|
reasonURL: 'https://docs.thedogapi.com/'
|
|
},
|
|
{
|
|
name: 'Dog API',
|
|
url: 'https://kinduff.github.io/dog-api/',
|
|
reason: 'API'
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async run(msg) {
|
|
const { body } = await request
|
|
.get('https://api.thedogapi.com/v1/images/search')
|
|
.query({ limit: 1 })
|
|
.set({ 'x-api-key': THEDOGAPI_KEY });
|
|
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 'Dogs are better than cats.';
|
|
}
|
|
}
|
|
};
|