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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26