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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2465 byte(s)
chore: eslint autofix
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
8 export default class HttpdogCommand extends BaseCommand {
9 supportsInteractions: boolean = true;
10 coolDown = 4000;
11
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 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 if (msg instanceof CommandInteraction)
30 await msg.deferReply();
31
32 let status = parseInt((options.isInteraction ? options.options.getInteger('status') : options.args[0]) + '');
33
34 if (typeof status !== 'number' || status < 100 || status > 515) {
35 await this.deferReply(msg, {
36 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 await this.deferReply(msg, {
51 content: url
52 });
53 })
54 .catch(async err => {
55 if (err.response.status === 404) {
56 await this.deferReply(msg, {
57 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 await this.deferReply(msg, {
68 embeds: [
69 new MessageEmbed()
70 .setColor('#f14a60')
71 .setDescription('Failed to fetch data from the API.')
72 ]
73 });
74 });
75 }
76 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26