/[sudobot]/trunk/src/commands/settings/SystemCommand.ts
ViewVC logotype

Annotation of /trunk/src/commands/settings/SystemCommand.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: 3835 byte(s)
chore: eslint autofix
1 rakin 344 import { CommandInteraction, Message } from 'discord.js';
2 rakin 51 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 MessageEmbed from '../../client/MessageEmbed';
7     import { fetchEmoji } from '../../utils/Emoji';
8 rakin 344 import { formatDuration, intervalToDuration } from 'date-fns';
9 rakin 51
10     export default class SystemCommand extends BaseCommand {
11     constructor() {
12 rakin 54 super('system', 'settings', []);
13 rakin 51 this.supportsInteractions = true;
14     }
15    
16     async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
17     let msg: Message;
18    
19     if (message instanceof Message) {
20     msg = await message.reply({
21     embeds: [
22     new MessageEmbed()
23     .setColor('GOLD')
24     .setDescription('Loading data...')
25     ]
26     });
27     }
28     else {
29     await message.reply({
30     embeds: [
31     new MessageEmbed()
32     .setColor('GOLD')
33     .setDescription('Loading data...')
34     ]
35     });
36     msg = <Message> await message.fetchReply();
37     }
38    
39     const latency = msg.createdTimestamp - message.createdTimestamp;
40     const apiLatency = Math.round(client.ws.ping);
41     let latencyIcon = '🟢', apiLatencyIcon = '🟢';
42    
43     if (latency >= 500) {
44     latencyIcon = '🔴';
45     }
46     else if (latency >= 350) {
47     latencyIcon = '🟡';
48     }
49    
50     if (apiLatency >= 400) {
51     apiLatencyIcon = '🔴';
52     }
53     else if (apiLatency >= 300) {
54     apiLatencyIcon = '🟡';
55     }
56    
57 rakin 284 const memoryFree = Math.round((process.memoryUsage().heapUsed / 1024 / 1024 * 100) / 100);
58 rakin 51
59     const msgoptions: any = {
60     embeds: [
61     new MessageEmbed()
62     .setAuthor({
63     iconURL: client.user!.displayAvatarURL(),
64     name: 'System status'
65     })
66     .setDescription((latencyIcon !== '🔴' ? (await fetchEmoji('check'))?.toString() + ' All systems operational' : ':x: Some systems are down/slow'))
67     .addFields([
68     {
69 rakin 58 name: 'Command Type',
70 rakin 68 value: `${!options.isInteraction ? 'Legacy (Message-based)' : 'Slash Command'}`
71 rakin 51 },
72     {
73 rakin 58 name: 'Uptime',
74 rakin 284 value: `${formatDuration(intervalToDuration({
75     start: 0,
76     end: process.uptime() * 1000
77     }))}`
78 rakin 58 },
79     {
80 rakin 51 name: 'Latency',
81     value: `${latencyIcon} ${latency}ms`
82     },
83     {
84     name: 'API Latency',
85     value: `${apiLatencyIcon} ${apiLatency}ms`
86     },
87     {
88     name: 'Available Memory',
89 rakin 76 value: `${1024 - memoryFree}MB / 1.0GB`
90 rakin 51 },
91     {
92     name: 'System Platform',
93     value: `${process.platform}`
94     },
95     {
96     name: 'NodeJS Version',
97     value: `${process.version}`
98     }
99     ])
100     ]
101     };
102    
103     if (msg instanceof CommandInteraction)
104     msgoptions.content = '';
105    
106     await this.deferReply(msg, msgoptions, true);
107     }
108     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26