1
+ using System . Diagnostics ;
1
2
using Boolean . Util ;
2
3
using Discord ;
3
4
using Discord . Interactions ;
@@ -57,4 +58,39 @@ public async Task Contribute()
57
58
58
59
await RespondAsync ( embed : embed . Build ( ) , ephemeral : true ) ;
59
60
}
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
+ }
60
96
}
0 commit comments