Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed Nov 3, 2024
1 parent 7c06255 commit a1d1d80
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
22 changes: 12 additions & 10 deletions src/Commands/Common/InfoCommand/InfoCommand.Bot.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
Expand All @@ -16,13 +17,13 @@ namespace OoLunar.Tomoe.Commands.Common
{
public sealed partial class InfoCommand
{
[GeneratedRegex(", (?=[^,]*$)", RegexOptions.Compiled)]
private static partial Regex _getLastCommaRegex();

private static readonly string _operatingSystem = $"{Environment.OSVersion} {RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant()}";
private static readonly string _botVersion = typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
private static readonly string _dSharpPlusVersion = typeof(DiscordClient).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;

[GeneratedRegex(", (?=[^,]*$)", RegexOptions.Compiled)]
private static partial Regex _getLastCommaRegex();

/// <summary>
/// Sends bot statistics.
/// </summary>
Expand All @@ -35,20 +36,21 @@ public async ValueTask BotInfoAsync(CommandContext context)
Color = new DiscordColor("#6b73db")
};

CultureInfo usersCulture = await context.GetCultureAsync();
Process currentProcess = Process.GetCurrentProcess();
currentProcess.Refresh();

embedBuilder.AddField("Heap Memory", GC.GetTotalMemory(false).Bytes().ToString(await context.GetCultureAsync()), true);
embedBuilder.AddField("Process Memory", currentProcess.WorkingSet64.Bytes().ToString(await context.GetCultureAsync()), true);
embedBuilder.AddField("Allocation Rate", $"{_allocationRateTracker.AllocationRate.Bytes().ToString(await context.GetCultureAsync())}/s", true);
embedBuilder.AddField("Heap Memory", GC.GetTotalMemory(false).Bytes().ToString(usersCulture), true);
embedBuilder.AddField("Process Memory", currentProcess.WorkingSet64.Bytes().ToString(usersCulture), true);
embedBuilder.AddField("Allocation Rate", $"{_allocationRateTracker.AllocationRate.Bytes().ToString(usersCulture)}/s", true);

embedBuilder.AddField("Runtime Version", RuntimeInformation.FrameworkDescription, true);
embedBuilder.AddField("Operating System", _operatingSystem, true);
embedBuilder.AddField("Uptime", _getLastCommaRegex().Replace((Process.GetCurrentProcess().StartTime - DateTime.Now).Humanize(3, await context.GetCultureAsync()), " and "), true);
embedBuilder.AddField("Uptime", _getLastCommaRegex().Replace((Process.GetCurrentProcess().StartTime - DateTime.Now).Humanize(3, usersCulture), " and "), true);

embedBuilder.AddField("Discord Latency", _getLastCommaRegex().Replace(context.Client.GetConnectionLatency(context.Guild?.Id ?? 0).Humanize(3, await context.GetCultureAsync()), " and "), true);
embedBuilder.AddField("Guild Count", (await GuildMemberModel.CountGuildsAsync()).ToString("N0", await context.GetCultureAsync()), true);
embedBuilder.AddField("User Count", (await GuildMemberModel.CountMembersAsync()).ToString("N0", await context.GetCultureAsync()), true);
embedBuilder.AddField("Discord Latency", _getLastCommaRegex().Replace(context.Client.GetConnectionLatency(context.Guild?.Id ?? 0).Humanize(3, usersCulture), " and "), true);
embedBuilder.AddField("Guild Count", (await GuildMemberModel.CountGuildsAsync()).ToString("N0", usersCulture), true);
embedBuilder.AddField("User Count", (await GuildMemberModel.CountMembersAsync()).ToString("N0", usersCulture), true);

StringBuilder stringBuilder = new();
stringBuilder.Append(context.Client.CurrentUser.Mention);
Expand Down
13 changes: 10 additions & 3 deletions src/Commands/Common/InfoCommand/InfoCommand.Guild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ public async Task GuildInfoAsync(CommandContext context, [SlashAutoCompleteProvi
}
catch (DiscordException)
{
await context.RespondAsync($"That guild is a private server. Since I am not in the guild, I cannot return any information about it.");
await context.RespondAsync($"Either that server doesn't exist or it's a private server. Regardless, I cannot find any information about it.");
return;
}

embedBuilder.Title = guildPreview.Name;
embedBuilder.Footer = new() { IconUrl = $"https://cdn.discordapp.com/splashes/{guildId}/{guildPreview.Splash}.png" };
embedBuilder.Footer = new()
{
IconUrl = $"https://cdn.discordapp.com/splashes/{guildId}/{guildPreview.Splash}.png"
};

if (guildPreview.Icon is not null)
{
embedBuilder.Thumbnail = new() { Url = $"https://cdn.discordapp.com/icons/{guildId}/{guildPreview.Icon}.{(guildPreview.Icon.StartsWith("a_") ? "gif" : "png")}" };
Expand Down Expand Up @@ -88,7 +92,10 @@ private async Task ProvideGuildInfoAsync(CultureInfo cultureInfo, DiscordEmbedBu
{
if (guild.IconUrl is not null)
{
embedBuilder.Thumbnail = new() { Url = guild.GetIconUrl(ImageFormat.Auto, 4096) };
embedBuilder.Thumbnail = new()
{
Url = guild.GetIconUrl(ImageFormat.Auto, 4096)
};
}

string features = string.Join(", ", guild.Features.Select(feature => feature.ToLowerInvariant().Titleize()));
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Common/InfoCommand/InfoCommand.Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static async Task RoleInfoAsync(CommandContext context, DiscordRole role)
IconUrl = context.User.AvatarUrl,
Url = context.User.AvatarUrl
},
Color = role.Color.Value == 0x000000 ? null : role.Color
Color = role.Color.Value == default ? null : role.Color
};

embedBuilder.AddField("Color", role.Color.ToString(), true);
Expand Down
10 changes: 7 additions & 3 deletions src/Commands/Common/InfoCommand/InfoCommand.User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.Commands;
using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Commands.Trees.Metadata;
using DSharpPlus.Entities;
using DSharpPlus.Exceptions;
Expand All @@ -18,16 +19,19 @@ public sealed partial class InfoCommand
/// Sends information about the provided user.
/// </summary>
/// <param name="user">Which user to get information about. Leave empty to get information about yourself.</param>
[Command("user"), TextAlias("member")]
[Command("user"), TextAlias("member"), SlashCommandTypes(DiscordApplicationCommandType.SlashCommand, DiscordApplicationCommandType.UserContextMenu)]
public static async Task UserInfoAsync(CommandContext context, DiscordUser? user = null)
{
user ??= context.User;
GuildMemberModel? memberModel = await GuildMemberModel.FindMemberAsync(user.Id, context.Guild!.Id);
DiscordEmbedBuilder embedBuilder = new()
{
Color = new DiscordColor("#6b73db"),
Title = $"Info about {user.GetDisplayName()}",
Thumbnail = new() { Url = user.AvatarUrl },
Color = new DiscordColor("#6b73db")
Thumbnail = new()
{
Url = user.AvatarUrl
}
};

embedBuilder.AddField("User Id", Formatter.InlineCode(user.Id.ToString(CultureInfo.InvariantCulture)), true);
Expand Down

0 comments on commit a1d1d80

Please sign in to comment.