Files
xiao/commands/random/cat.js
T
Daniel Odendahl Jr 8725e348be snekfetch -> superagent
2018-06-07 16:02:53 +00:00

29 lines
836 B
JavaScript

const Command = require('../../structures/Command');
const request = require('superagent');
const { THE_CAT_API_KEY } = process.env;
module.exports = class CatCommand extends Command {
constructor(client) {
super(client, {
name: 'cat',
aliases: ['neko', 'kitty'],
group: 'random',
memberName: 'cat',
description: 'Responds with a random cat image.',
clientPermissions: ['ATTACH_FILES']
});
}
async run(msg) {
try {
const { body, headers } = await request
.get('http://thecatapi.com/api/images/get')
.query({ api_key: THE_CAT_API_KEY });
const format = headers['content-type'].replace(/image\//i, '');
return msg.say({ files: [{ attachment: body, name: `cat.${format}` }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};