/[sudobot]/branches/2.x/src/commands/settings/SystemCommand.ts
ViewVC logotype

Annotation of /branches/2.x/src/commands/settings/SystemCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3736 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 import { CommandInteraction, GuildMember, Interaction, Message } 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 MessageEmbed from '../../client/MessageEmbed';
7     import { fetchEmoji } from '../../utils/Emoji';
8     import { timeProcess } from '../../utils/util';
9    
10     export default class SystemCommand extends BaseCommand {
11     constructor() {
12     super('system', 'settings', []);
13     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     const memoryFree = Math.round(process.memoryUsage().heapUsed / 1024 / 1024 * 100) / 100;
58    
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     name: 'Command Type',
70     value: `${!options.isInteraction ? 'Legacy (Message-based)' : 'Slash Command'}`
71     },
72     {
73     name: 'Uptime',
74     value: `${timeProcess(parseInt(process.uptime().toFixed(2)))}`
75     },
76     {
77     name: 'Latency',
78     value: `${latencyIcon} ${latency}ms`
79     },
80     {
81     name: 'API Latency',
82     value: `${apiLatencyIcon} ${apiLatency}ms`
83     },
84     {
85     name: 'Available Memory',
86     value: `${1024 - memoryFree}MB / 1.0GB`
87     },
88     {
89     name: 'System Platform',
90     value: `${process.platform}`
91     },
92     {
93     name: 'NodeJS Version',
94     value: `${process.version}`
95     }
96     ])
97     ]
98     };
99    
100     if (msg instanceof CommandInteraction)
101     msgoptions.content = '';
102    
103     await this.deferReply(msg, msgoptions, true);
104     }
105     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26