-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using DSharpPlus.Commands; | ||
using DSharpPlus.Commands.Processors.SlashCommands; | ||
using DSharpPlus.Entities; | ||
using KanbanCord.Extensions; | ||
using KanbanCord.Helpers; | ||
|
||
namespace KanbanCord.Commands; | ||
|
||
public class StatsCommand | ||
{ | ||
[Command("stats")] | ||
[Description("Displays the stats of the bot.")] | ||
public async ValueTask ExecuteAsync(SlashCommandContext context) | ||
{ | ||
var botVersion = EnvironmentHelpers.GetApplicationVersion(); | ||
|
||
GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true); | ||
var heapMemory = $"{GC.GetTotalMemory(true) / 1024 / 1024:n0} MB"; | ||
|
||
using var process = Process.GetCurrentProcess(); | ||
var uptime = DateTimeOffset.UtcNow.Subtract(process.StartTime); | ||
var uptimeDays = uptime.Days; | ||
var remainingHours = uptime.Hours % 24; | ||
|
||
var latency = context.Client.GetConnectionLatency(context.Guild!.Id).Milliseconds; | ||
|
||
var embed = new DiscordEmbedBuilder() | ||
.WithDefaultColor() | ||
.WithThumbnail(context.Client.CurrentUser.AvatarUrl) | ||
.AddField("Latency:", latency == 0 ? "waiting for heartbeat..." : $"{latency} ms") | ||
.AddField("Memory Usage:", heapMemory) | ||
.AddField("Uptime:", $"{uptimeDays} days, {remainingHours} hours") | ||
.AddField("Bot Version:", botVersion); | ||
|
||
await context.RespondAsync(embed); | ||
} | ||
} |