/[sudobot]/trunk/commands/httpdog.js
ViewVC logotype

Annotation of /trunk/commands/httpdog.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (hide annotations)
Mon Jul 29 17:28:11 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: text/javascript
File size: 1733 byte(s)
Added base commands
1 rakin 5 const MessageEmbed = require("../src/MessageEmbed");
2     const axios = require('axios').default;
3    
4     module.exports = {
5     async handle(msg, cm) {
6     if (cm.args[0] === undefined) {
7     await msg.reply({
8     embeds: [
9     new MessageEmbed()
10     .setColor('#f14a60')
11     .setDescription('This command requires at least 1 argument.')
12     ]
13     });
14    
15     return;
16     }
17    
18     let status = parseInt(cm.args[0]);
19    
20     if (typeof status !== 'number' || status < 100 || status > 515) {
21     await msg.reply({
22     embeds: [
23     new MessageEmbed()
24     .setColor('#f14a60')
25     .setDescription('Argument #1 must be a valid HTTP status code.')
26     ]
27     });
28    
29     return;
30     }
31    
32     let url = "https://http.dog/" + status + '.jpg';
33    
34     axios.get(url)
35     .then(async (data) => {
36     await msg.reply({
37     content: url
38     });
39     })
40     .catch(async err => {
41     if (err.response.status === 404) {
42     await msg.reply({
43     embeds: [
44     new MessageEmbed()
45     .setColor('#f14a60')
46     .setDescription('Argument #1 must be a valid HTTP status code.')
47     ]
48     });
49    
50     return;
51     }
52    
53     await msg.reply({
54     embeds: [
55     new MessageEmbed()
56     .setColor('#f14a60')
57     .setDescription('Failed to fetch data from the API.')
58     ]
59     });
60     });
61     }
62     };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26