Skip to content

Commit 468f9a0

Browse files
conaticusJatoMixo
andauthored
Merge Develop (#63)
Co-authored-by: JatoMixo <[email protected]>
1 parent 9e0bc7c commit 468f9a0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Boolean/Modules/BotInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using Boolean.Util;
23
using Discord;
34
using Discord.Interactions;
@@ -57,4 +58,39 @@ public async Task Contribute()
5758

5859
await RespondAsync(embed: embed.Build(), ephemeral: true);
5960
}
61+
62+
// We might later want to consider making this maintainers only (as people could use this to exploit the bot)
63+
[SlashCommand("status", "Shows the bot's compute usage (CPU, RAM, etc)")]
64+
public async Task Status()
65+
{
66+
var botProcess = Process.GetCurrentProcess();
67+
var ramUsageGb = botProcess.WorkingSet64 / (float) Math.Pow(1024, 3);
68+
69+
// Calculate the CPU usage
70+
var startTime = DateTime.UtcNow;
71+
var startCpuUsage = botProcess.TotalProcessorTime;
72+
73+
await Task.Delay(500);
74+
75+
var endTime = DateTime.UtcNow;
76+
var endCpuUsage = botProcess.TotalProcessorTime;
77+
78+
var cpuUsage = (float) (endCpuUsage - startCpuUsage).TotalMilliseconds
79+
/ (float) (Environment.ProcessorCount * (endTime - startTime).TotalMilliseconds);
80+
81+
var embed = new EmbedBuilder
82+
{
83+
Title = "Bot Status",
84+
Color = EmbedColors.Normal,
85+
};
86+
87+
var uptime = DateTime.Now - botProcess.StartTime;
88+
89+
embed
90+
.AddField("RAM", $"`{Math.Round(ramUsageGb, 2)} GB`", true)
91+
.AddField("CPU Usage", $"`{Math.Round(cpuUsage * 100, 2)}%`", true)
92+
.AddField("Up Time", $"{uptime.Days} days, {uptime.Hours} hours, {uptime.Minutes} minutes, {uptime.Seconds} seconds", false);
93+
94+
await RespondAsync(embed: embed.Build(), ephemeral: true);
95+
}
6096
}

0 commit comments

Comments
 (0)