Skip to content

Commit

Permalink
Added simple stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
j4asper committed Nov 5, 2024
1 parent a6150c4 commit 9216952
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions KanbanCord/Commands/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public async ValueTask ExecuteAsync(SlashCommandContext context)
(commands.GetMention(["clear"]), commands.GetDescription(["clear"])),
(commands.GetMention(["reset"]), commands.GetDescription(["reset"])),
(commands.GetMention(["repository"]), commands.GetDescription(["repository"])),
(commands.GetMention(["stats"]), commands.GetDescription(["stats"])),
(commands.GetMention(["task", "add"]), commands.GetDescription(["task", "add"])),
(commands.GetMention(["task", "edit"]), commands.GetDescription(["task", "edit"])),
(commands.GetMention(["task", "delete"]), commands.GetDescription(["task", "delete"])),
Expand Down
39 changes: 39 additions & 0 deletions KanbanCord/Commands/StatsCommand.cs
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);
}
}

0 comments on commit 9216952

Please sign in to comment.