diff --git a/src/Commands/Common/InfoCommand/InfoCommand.Bot.cs b/src/Commands/Common/InfoCommand/InfoCommand.Bot.cs index a8ccab3..0d0b6fa 100644 --- a/src/Commands/Common/InfoCommand/InfoCommand.Bot.cs +++ b/src/Commands/Common/InfoCommand/InfoCommand.Bot.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Globalization; using System.Reflection; using System.Runtime.InteropServices; using System.Text; @@ -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()!.InformationalVersion; private static readonly string _dSharpPlusVersion = typeof(DiscordClient).Assembly.GetCustomAttribute()!.InformationalVersion; - [GeneratedRegex(", (?=[^,]*$)", RegexOptions.Compiled)] - private static partial Regex _getLastCommaRegex(); - /// /// Sends bot statistics. /// @@ -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); diff --git a/src/Commands/Common/InfoCommand/InfoCommand.Guild.cs b/src/Commands/Common/InfoCommand/InfoCommand.Guild.cs index 5f253df..b322ae9 100644 --- a/src/Commands/Common/InfoCommand/InfoCommand.Guild.cs +++ b/src/Commands/Common/InfoCommand/InfoCommand.Guild.cs @@ -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")}" }; @@ -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())); diff --git a/src/Commands/Common/InfoCommand/InfoCommand.Role.cs b/src/Commands/Common/InfoCommand/InfoCommand.Role.cs index c60d1eb..e838d70 100644 --- a/src/Commands/Common/InfoCommand/InfoCommand.Role.cs +++ b/src/Commands/Common/InfoCommand/InfoCommand.Role.cs @@ -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); diff --git a/src/Commands/Common/InfoCommand/InfoCommand.User.cs b/src/Commands/Common/InfoCommand/InfoCommand.User.cs index 9157154..bc88871 100644 --- a/src/Commands/Common/InfoCommand/InfoCommand.User.cs +++ b/src/Commands/Common/InfoCommand/InfoCommand.User.cs @@ -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; @@ -18,16 +19,19 @@ public sealed partial class InfoCommand /// Sends information about the provided user. /// /// Which user to get information about. Leave empty to get information about yourself. - [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);