/[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 393 - (hide annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 3189 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
1 rakin 393 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20 rakin 51 import { CommandInteraction, Message, MessageEmbed } from 'discord.js';
21     import BaseCommand from '../../utils/structures/BaseCommand';
22     import DiscordClient from '../../client/Client';
23     import CommandOptions from '../../types/CommandOptions';
24     import InteractionOptions from '../../types/InteractionOptions';
25     import axios from 'axios';
26 rakin 5
27 rakin 51 export default class HttpdogCommand extends BaseCommand {
28     supportsInteractions: boolean = true;
29 rakin 56 coolDown = 4000;
30 rakin 51
31     constructor() {
32     super('httpdog', 'fun', []);
33     }
34    
35     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
36     if (!options.isInteraction && options.args[0] === undefined) {
37 rakin 5 await msg.reply({
38     embeds: [
39     new MessageEmbed()
40     .setColor('#f14a60')
41     .setDescription('This command requires at least 1 argument.')
42     ]
43     });
44    
45     return;
46     }
47    
48 rakin 51 if (msg instanceof CommandInteraction)
49     await msg.deferReply();
50 rakin 5
51 rakin 51 let status = parseInt((options.isInteraction ? options.options.getInteger('status') : options.args[0]) + '');
52    
53 rakin 5 if (typeof status !== 'number' || status < 100 || status > 515) {
54 rakin 51 await this.deferReply(msg, {
55 rakin 5 embeds: [
56     new MessageEmbed()
57     .setColor('#f14a60')
58     .setDescription('Argument #1 must be a valid HTTP status code.')
59     ]
60     });
61    
62     return;
63     }
64    
65     let url = "https://http.dog/" + status + '.jpg';
66    
67     axios.get(url)
68     .then(async (data) => {
69 rakin 51 await this.deferReply(msg, {
70 rakin 5 content: url
71     });
72     })
73     .catch(async err => {
74     if (err.response.status === 404) {
75 rakin 51 await this.deferReply(msg, {
76 rakin 5 embeds: [
77     new MessageEmbed()
78     .setColor('#f14a60')
79     .setDescription('Argument #1 must be a valid HTTP status code.')
80     ]
81     });
82    
83     return;
84     }
85    
86 rakin 51 await this.deferReply(msg, {
87 rakin 5 embeds: [
88     new MessageEmbed()
89     .setColor('#f14a60')
90     .setDescription('Failed to fetch data from the API.')
91     ]
92     });
93     });
94     }
95 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26