MCPcopy Create free account
hub / github.com/esmBot/esmBot / run

Method run

commands/general/stats.js:10–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9class StatsCommand extends Command {
10 async run() {
11 if (!this.permissions.has("EMBED_LINKS")) {
12 this.success = false;
13 return this.getString("permissions.noEmbedLinks");
14 }
15 const uptime = process.uptime() * 1000;
16 const connUptime = this.client.uptime;
17 const owners = process.env.OWNER?.split(",") ?? [];
18 let owner;
19 if (owners.length !== 0) {
20 owner = this.client.users.get(owners[0]) ?? (await this.client.rest.users.get(owners[0]));
21 }
22 const servers = await getServers(this.client);
23 const processMem = `${(process.memoryUsage().heapUsed / 1000 / 1000).toFixed(2)} MB`;
24 const runtime = detectRuntime();
25 return {
26 embeds: [
27 {
28 author: {
29 name: this.getString("commands.responses.stats.header"),
30 iconURL: this.client.user.avatarURL(),
31 },
32 description: this.getString("managedBy", { params: { owner: owner?.username ?? "N/A" } }),
33 color: 0xff0000,
34 fields: [
35 {
36 name: this.getString("commands.responses.stats.version"),
37 value: `v${packageJson.version}${process.env.NODE_ENV === "development" ? `-dev (${process.env.GIT_REV})` : ""}`,
38 },
39 {
40 name: this.getString("commands.responses.stats.processUsage"),
41 value: processMem,
42 inline: true,
43 },
44 {
45 name: this.getString("commands.responses.stats.totalUsage"),
46 value: (await this.getMem()) ?? processMem,
47 inline: true,
48 },
49 {
50 name: this.getString("commands.responses.stats.botUptime"),
51 value: this.getString("timeFormat", {
52 params: {
53 days: Math.trunc(uptime / 86400000).toString(),
54 hours: (Math.trunc(uptime / 3600000) % 24).toString(),
55 minutes: (Math.trunc(uptime / 60000) % 60).toString(),
56 seconds: (Math.trunc(uptime / 1000) % 60).toString(),
57 },
58 }),
59 },
60 {
61 name: this.getString("commands.responses.stats.connectionUptime"),
62 value: this.getString("timeFormat", {
63 params: {
64 days: Math.trunc(connUptime / 86400000).toString(),
65 hours: (Math.trunc(connUptime / 3600000) % 24).toString(),
66 minutes: (Math.trunc(connUptime / 60000) % 60).toString(),
67 seconds: (Math.trunc(connUptime / 1000) % 60).toString(),

Callers

nothing calls this directly

Calls 4

getMemMethod · 0.95
getServersFunction · 0.85
detectRuntimeFunction · 0.85
getStringMethod · 0.80

Tested by

no test coverage detected