Skip to content

Commit 20d08b1

Browse files
committed
refactor: streamline stats display using components and remove embed structure
1 parent e267749 commit 20d08b1

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

src/commands/General/stats.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,68 @@
1-
import { Color } from '#constants';
2-
import { Embed, RadonCommand, Timestamp } from '#lib/structures';
1+
import { RadonCommand, Timestamp } from '#lib/structures';
32
import { ApplyOptions } from '@sapphire/decorators';
43
import { version as sapphireVersion } from '@sapphire/framework';
54
import { roundNumber } from '@sapphire/utilities';
6-
import { version } from 'discord.js';
5+
import { ContainerBuilder, MessageFlags, version, bold, heading, HeadingLevel } from 'discord.js';
76
import { uptime } from 'node:os';
87

98
@ApplyOptions<RadonCommand.Options>({
109
description: 'Provides some stats about me'
1110
})
1211
export class UserCommand extends RadonCommand {
1312
public override messageRun(message: RadonCommand.Message<true>) {
14-
return message.channel.send({
15-
embeds: [this.statsEmbed()]
13+
return message.reply({
14+
components: [this.buildContainer()],
15+
flags: MessageFlags.IsComponentsV2
1616
});
1717
}
1818

19-
public statsEmbed() {
20-
const titles = {
21-
stats: 'Statistics',
22-
uptime: 'Uptime',
23-
serverUsage: 'Server Usage',
24-
misc: 'Misc'
25-
};
19+
private buildContainer() {
20+
const stats = this.buildStats();
21+
const container = new ContainerBuilder();
22+
23+
for (const [section, entries] of Object.entries(stats)) {
24+
container.addTextDisplayComponents((textDisplay) =>
25+
textDisplay.setContent(
26+
`${heading(section, HeadingLevel.Two)}\n` +
27+
Object.entries(entries)
28+
.map(([key, value]) => `- ${bold(key)}: ${value}`)
29+
.join('\n')
30+
)
31+
);
32+
if (section !== 'Misc') container.addSeparatorComponents((s) => s);
33+
}
34+
35+
return container;
36+
}
37+
38+
private buildStats() {
2639
const stats = this.generalStatistics;
2740
const uptime = this.uptimeStatistics;
2841
const usage = this.usageStatistics;
2942
const misc = this.miscStatistics;
3043

31-
const fields = {
32-
stats: `• **Users**: ${stats.users}\n• **Servers**: ${stats.guilds}\n• **Channels**: ${stats.channels}\n• **Discord.js**: ${stats.version}\n• **Node.js**: ${stats.nodeJs}\n• **Framework**: ${stats.sapphireVersion}`,
33-
uptime: `• **Host**: ${uptime.host}\n• **Total**: ${uptime.total}\n• **Client**: ${uptime.client}`,
34-
serverUsage: `• **Heap**: ${usage.ramUsed}MB (Total: ${usage.ramTotal}MB)`,
35-
misc: `• **Lines of code**: ${misc.lines}\n• **Files**: ${misc.files}`
36-
};
37-
38-
return new Embed()._color(Color.General)._fields([
39-
{
40-
name: titles.stats,
41-
value: fields.stats
44+
return {
45+
Statistics: {
46+
Users: stats.users.toString(),
47+
Servers: stats.guilds.toString(),
48+
Channels: stats.channels.toString(),
49+
'Discord.js': stats.version,
50+
'Node.js': stats.nodeJs,
51+
Framework: stats.sapphireVersion
4252
},
43-
{
44-
name: titles.uptime,
45-
value: fields.uptime
53+
Uptime: {
54+
Host: uptime.host,
55+
Total: uptime.total,
56+
Client: uptime.client
4657
},
47-
{
48-
name: titles.serverUsage,
49-
value: fields.serverUsage
58+
'Server Usage': {
59+
Heap: `${usage.ramUsed}MB (Total: ${usage.ramTotal}MB)`
5060
},
51-
{
52-
name: titles.misc,
53-
value: fields.misc
61+
Misc: {
62+
'Lines of code': misc.lines,
63+
Files: misc.files
5464
}
55-
]);
65+
};
5666
}
5767

5868
private get generalStatistics(): StatsGeneral {

0 commit comments

Comments
 (0)