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