/[sudobot]/trunk/src/commands/fun/HttpcatCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/fun/HttpcatCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (show annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2517 byte(s)
Release version 2.0
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 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26