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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (hide 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 rakin 51 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 rakin 5
10 rakin 51 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 rakin 5 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 rakin 51 if (msg instanceof CommandInteraction)
31     await msg.deferReply();
32 rakin 5
33 rakin 51 let status = parseInt((options.isInteraction ? options.options.getInteger('status') : options.args[0]) + '');
34    
35 rakin 5 if (typeof status !== 'number' || status < 100 || status > 515) {
36 rakin 51 await this.deferReply(msg, {
37 rakin 5 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 rakin 51 await this.deferReply(msg, {
52 rakin 5 content: url
53     });
54     })
55     .catch(async err => {
56     if (err.response.status === 404) {
57 rakin 51 await this.deferReply(msg, {
58 rakin 5 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 rakin 51 await this.deferReply(msg, {
69 rakin 5 embeds: [
70     new MessageEmbed()
71     .setColor('#f14a60')
72     .setDescription('Failed to fetch data from the API.')
73     ]
74     });
75     });
76     }
77 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26