|
1 | | -import { Color } from '#constants'; |
2 | | -import { Embed, RadonCommand, Timestamp } from '#lib/structures'; |
| 1 | +import { RadonCommand, Timestamp } from '#lib/structures'; |
3 | 2 | import { ApplyOptions } from '@sapphire/decorators'; |
4 | 3 | import { version as sapphireVersion } from '@sapphire/framework'; |
5 | 4 | import { roundNumber } from '@sapphire/utilities'; |
6 | | -import { version } from 'discord.js'; |
| 5 | +import { ContainerBuilder, MessageFlags, version, bold, heading, HeadingLevel } from 'discord.js'; |
7 | 6 | import { uptime } from 'node:os'; |
8 | 7 |
|
9 | 8 | @ApplyOptions<RadonCommand.Options>({ |
10 | 9 | description: 'Provides some stats about me' |
11 | 10 | }) |
12 | 11 | export class UserCommand extends RadonCommand { |
13 | 12 | 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 |
16 | 16 | }); |
17 | 17 | } |
18 | 18 |
|
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() { |
26 | 39 | const stats = this.generalStatistics; |
27 | 40 | const uptime = this.uptimeStatistics; |
28 | 41 | const usage = this.usageStatistics; |
29 | 42 | const misc = this.miscStatistics; |
30 | 43 |
|
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 |
42 | 52 | }, |
43 | | - { |
44 | | - name: titles.uptime, |
45 | | - value: fields.uptime |
| 53 | + Uptime: { |
| 54 | + Host: uptime.host, |
| 55 | + Total: uptime.total, |
| 56 | + Client: uptime.client |
46 | 57 | }, |
47 | | - { |
48 | | - name: titles.serverUsage, |
49 | | - value: fields.serverUsage |
| 58 | + 'Server Usage': { |
| 59 | + Heap: `${usage.ramUsed}MB (Total: ${usage.ramTotal}MB)` |
50 | 60 | }, |
51 | | - { |
52 | | - name: titles.misc, |
53 | | - value: fields.misc |
| 61 | + Misc: { |
| 62 | + 'Lines of code': misc.lines, |
| 63 | + Files: misc.files |
54 | 64 | } |
55 | | - ]); |
| 65 | + }; |
56 | 66 | } |
57 | 67 |
|
58 | 68 | private get generalStatistics(): StatsGeneral { |
|
0 commit comments