/[sudobot]/branches/2.x/src/commands/fun/HttpcatCommand.ts
ViewVC logotype

Contents of /branches/2.x/src/commands/fun/HttpcatCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 2538 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
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 coolDown = 4000;
13
14 constructor() {
15 super('httpcat', 'fun', []);
16 }
17
18 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19 if (!options.isInteraction && options.args[0] === undefined) {
20 await msg.reply({
21 embeds: [
22 new MessageEmbed()
23 .setColor('#f14a60')
24 .setDescription('This command requires at least 1 argument.')
25 ]
26 });
27
28 return;
29 }
30
31 if (msg instanceof CommandInteraction)
32 await msg.deferReply();
33
34 let status = parseInt((options.isInteraction ? options.options.getInteger('status') : options.args[0]) + '');
35
36 if (typeof status !== 'number' || status < 100 || status > 515) {
37 await this.deferReply(msg, {
38 embeds: [
39 new MessageEmbed()
40 .setColor('#f14a60')
41 .setDescription('Argument #1 must be a valid HTTP status code.')
42 ]
43 });
44
45 return;
46 }
47
48 let url = "https://http.cat/" + status;
49
50 axios.get(url)
51 .then(async (data) => {
52 await this.deferReply(msg, {
53 content: url
54 });
55 })
56 .catch(async err => {
57 if (err.response.status === 404) {
58 await this.deferReply(msg, {
59 embeds: [
60 new MessageEmbed()
61 .setColor('#f14a60')
62 .setDescription('Argument #1 must be a valid HTTP status code.')
63 ]
64 });
65
66 return;
67 }
68
69 await this.deferReply(msg, {
70 embeds: [
71 new MessageEmbed()
72 .setColor('#f14a60')
73 .setDescription('Failed to fetch data from the API.')
74 ]
75 });
76 });
77 }
78 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26