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

Contents of /trunk/src/commands/settings/SystemCommand.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: 3835 byte(s)
chore: eslint autofix
1 import { CommandInteraction, 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 { formatDuration, intervalToDuration } from 'date-fns';
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: `${formatDuration(intervalToDuration({
75 start: 0,
76 end: process.uptime() * 1000
77 }))}`
78 },
79 {
80 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 value: `${1024 - memoryFree}MB / 1.0GB`
90 },
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