Skip to content

Commit

Permalink
feat(cat): add cat command
Browse files Browse the repository at this point in the history
  • Loading branch information
jwford committed Feb 23, 2021
1 parent f857991 commit a90e139
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Binary file added assets/images/animals/cat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/commands/Fun/Animals/cat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { SteveCommand } from '@lib/structures/commands/SteveCommand';
import { ApplyOptions } from '@skyra/decorators';
import axios from 'axios';
import { MessageEmbed } from 'discord.js';
import { CommandOptions, KlasaMessage } from 'klasa';

@ApplyOptions<CommandOptions>({
aliases: ['kitty'],
cooldown: 30,
cooldownLevel: 'author',
description: lang => lang.tget('commandCatDescription'),
extendedHelp: lang => lang.tget('commandCatExtended'),
requiredPermissions: ['ATTACH_FILES', 'EMBED_LINKS']
})
export default class extends SteveCommand {

private catUrl = 'https://cataas.com/cat';

public async run(msg: KlasaMessage) {
const embed = new MessageEmbed();

try {
const res = await axios.get(this.catUrl, { responseType: 'arraybuffer' });
const img = Buffer.from(res.data);

embed.attachFiles([{ attachment: img, name: 'randomcat.jpg' }]).setImage('attachment://randomcat.jpg');
} catch {
embed.attachFiles(['./assets/images/animals/cat.png']).setImage('attachment://cat.png');
}


return msg.channel.send(embed);
}

}
4 changes: 4 additions & 0 deletions src/languages/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ export default class extends Language {
reminder: 'Things to be rated have a maximum length of 500 characters.'
}),
commandRateResponse: (thing, rating) => `${botName} gives \`${thing}\` a ${rating}!`,
commandCatDescription: 'Get a random cat picture',
commandCatExtended: builder.display('cat', {
extendedHelp: 'This command grabs random cat pictures from the cat API at https://cataas.com.'
}),
commandDogDescription: 'Get a random dog picture',
commandDogExtended: builder.display('dog', {
extendedHelp: 'This command grabs random dog images from the Dog API at https://dog.ceo/dog-api.'
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types/Languages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ declare module 'klasa' {
commandRateDescription: string;
commandRateExtended: string;
commandRateResponse: (thing: string, rating: number) => string;
commandCatDescription: string;
commandCatExtended: string;
commandDogDescription: string;
commandDogExtended: string;
commandRockPaperScissorsDescription: string;
Expand Down

0 comments on commit a90e139

Please sign in to comment.