aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info/botInfo.ts
blob: 8f85fe683f8504340d621e861169aee7cc0735a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
import { MessageEmbed, version as discordJSVersion } from 'discord.js';
import * as os from 'os';
import prettyBytes from 'pretty-bytes';

export default class BotInfoCommand extends BushCommand {
	public constructor() {
		super('botinfo', {
			aliases: ['botinfo', 'stats'],
			category: 'info',
			description: {
				content: 'Shows information about the bot',
				usage: 'botinfo',
				examples: ['botinfo']
			},
			slash: true,
			clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],
			userPermissions: ['SEND_MESSAGES']
		});
	}

	public override async exec(message: BushMessage | BushSlashMessage): Promise<void> {
		enum Platform {
			aix = 'AIX',
			android = 'Android',
			darwin = 'MacOS',
			freebsd = 'FreeBSD',
			linux = 'Linux',
			openbsd = 'OpenBSD',
			sunos = 'SunOS',
			win32 = 'Windows',
			cygwin = 'Cygwin',
			netbsd = 'NetBSD',
			haiku = 'Haiku'
		}

		const developers = (await util.mapIDs(client.config.owners)).map((u) => u?.tag).join('\n');
		const currentCommit = (await util.shell('git rev-parse HEAD')).stdout.replace('\n', '');
		let repoUrl = (await util.shell('git remote get-url origin')).stdout.replace('\n', '');
		repoUrl = repoUrl.substring(0, repoUrl.length - 4);
		const embed = new MessageEmbed()
			.setTitle('Bot Info:')
			.addField('**Uptime**', util.humanizeDuration(client.uptime!, 2), true)
			.addField(
				'**Memory Usage**',
				`System: ${prettyBytes(os.totalmem() - os.freemem(), { binary: true })}/${prettyBytes(os.totalmem(), {
					binary: true
				})}\nHeap: ${prettyBytes(process.memoryUsage().heapUsed, { binary: true })}/${prettyBytes(
					process.memoryUsage().heapTotal,
					{ binary: true }
				)}`,
				true
			)
			.addField('**CPU Usage**', `${client.stats.cpu}%`, true)
			.addField('**Platform**', Platform[process.platform], true)
			.addField('**Commands Used**', `${client.stats.commandsUsed}`, true)
			.addField('**Servers**', client.guilds.cache.size.toLocaleString(), true)
			.addField('**Users**', client.users.cache.size.toLocaleString(), true)
			.addField('**Discord.js Version**', discordJSVersion, true)
			.addField('**Node.js Version**', process.version.slice(1), true)
			.addField('**Commands**', client.commandHandler.modules.size.toLocaleString(), true)
			.addField('**Listeners**', client.listenerHandler.modules.size.toLocaleString(), true)
			.addField('**Inhibitors**', client.inhibitorHandler.modules.size.toLocaleString(), true)
			.addField('**Tasks**', client.taskHandler.modules.size.toLocaleString(), true)
			.addField('**Current Commit**', `[${currentCommit.substring(0, 7)}](${repoUrl}/commit/${currentCommit})`, true)
			.addField('**Developers**', developers, true)
			.setTimestamp()
			.setColor(util.colors.default);
		await message.util.reply({ embeds: [embed] });
	}
}