1 |
import { CommandInteraction, Message, MessageEmbed } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import axios from 'axios'; |
7 |
import path from 'path'; |
8 |
import { deleteFile, download } from '../../utils/util'; |
9 |
|
10 |
export default class HttpcatCommand extends BaseCommand { |
11 |
supportsInteractions: boolean = true; |
12 |
|
13 |
constructor() { |
14 |
super('httpcat', 'fun', []); |
15 |
} |
16 |
|
17 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
18 |
if (!options.isInteraction && options.args[0] === undefined) { |
19 |
await msg.reply({ |
20 |
embeds: [ |
21 |
new MessageEmbed() |
22 |
.setColor('#f14a60') |
23 |
.setDescription('This command requires at least 1 argument.') |
24 |
] |
25 |
}); |
26 |
|
27 |
return; |
28 |
} |
29 |
|
30 |
if (msg instanceof CommandInteraction) |
31 |
await msg.deferReply(); |
32 |
|
33 |
let status = parseInt((options.isInteraction ? options.options.getInteger('status') : options.args[0]) + ''); |
34 |
|
35 |
if (typeof status !== 'number' || status < 100 || status > 515) { |
36 |
await this.deferReply(msg, { |
37 |
embeds: [ |
38 |
new MessageEmbed() |
39 |
.setColor('#f14a60') |
40 |
.setDescription('Argument #1 must be a valid HTTP status code.') |
41 |
] |
42 |
}); |
43 |
|
44 |
return; |
45 |
} |
46 |
|
47 |
let url = "https://http.cat/" + status; |
48 |
|
49 |
axios.get(url) |
50 |
.then(async (data) => { |
51 |
await this.deferReply(msg, { |
52 |
content: url |
53 |
}); |
54 |
}) |
55 |
.catch(async err => { |
56 |
if (err.response.status === 404) { |
57 |
await this.deferReply(msg, { |
58 |
embeds: [ |
59 |
new MessageEmbed() |
60 |
.setColor('#f14a60') |
61 |
.setDescription('Argument #1 must be a valid HTTP status code.') |
62 |
] |
63 |
}); |
64 |
|
65 |
return; |
66 |
} |
67 |
|
68 |
await this.deferReply(msg, { |
69 |
embeds: [ |
70 |
new MessageEmbed() |
71 |
.setColor('#f14a60') |
72 |
.setDescription('Failed to fetch data from the API.') |
73 |
] |
74 |
}); |
75 |
}); |
76 |
} |
77 |
} |