From 07abf53fd588cec512973cd438ef2290abe21d9b Mon Sep 17 00:00:00 2001 From: Milkshake Date: Mon, 1 Jul 2024 17:31:09 -0400 Subject: [PATCH] Add /baninfo and /muteinfo (#207) --- .../InteractionCommands/DebugInteractions.cs | 22 ++++++++ Helpers/BanHelpers.cs | 52 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/Commands/InteractionCommands/DebugInteractions.cs b/Commands/InteractionCommands/DebugInteractions.cs index a6f48eb1..eb7c80d1 100644 --- a/Commands/InteractionCommands/DebugInteractions.cs +++ b/Commands/InteractionCommands/DebugInteractions.cs @@ -108,5 +108,27 @@ public async Task UserInfoSlashCommand(InteractionContext ctx, [Option("user", " { await ctx.RespondAsync(embed: await DiscordHelpers.GenerateUserEmbed(user, ctx.Guild), ephemeral: !publicMessage); } + + [SlashCommand("muteinfo", "Show information about the mute for a user.")] + [SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)] + [SlashCommandPermissions(DiscordPermissions.ModerateMembers)] + public async Task MuteInfoSlashCommand( + InteractionContext ctx, + [Option("user", "The user whose mute information to show.")] DiscordUser targetUser, + [Option("public", "Whether to show the output publicly. Default: false")] bool isPublic = false) + { + await ctx.RespondAsync(embed: await MuteHelpers.MuteStatusEmbed(targetUser, ctx.Guild), ephemeral: !isPublic); + } + + [SlashCommand("baninfo", "Show information about the ban for a user.")] + [SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)] + [SlashCommandPermissions(DiscordPermissions.ModerateMembers)] + public async Task BanInfoSlashCommand( + InteractionContext ctx, + [Option("user", "The user whose ban information to show.")] DiscordUser targetUser, + [Option("public", "Whether to show the output publicly. Default: false")] bool isPublic = false) + { + await ctx.RespondAsync(embed: await BanHelpers.BanStatusEmbed(targetUser, ctx.Guild), ephemeral: !isPublic); + } } } diff --git a/Helpers/BanHelpers.cs b/Helpers/BanHelpers.cs index eb748bb5..5e007720 100644 --- a/Helpers/BanHelpers.cs +++ b/Helpers/BanHelpers.cs @@ -153,5 +153,57 @@ public static async Task BanSilently(DiscordGuild targetGuild, ulong targe } + public static async Task BanStatusEmbed(DiscordUser user, DiscordGuild guild) + { + DiscordMember member = default; + DiscordEmbedBuilder embedBuilder = new(); + var guildBans = await guild.GetBansAsync(); + var userBan = guildBans.FirstOrDefault(x => x.User.Id == user.Id); + + embedBuilder.WithFooter( + $"User ID: {user.Id}", + null + ) + .WithAuthor( + $"Ban status for {DiscordHelpers.UniqueUsername(user)}", + null, + await LykosAvatarMethods.UserOrMemberAvatarURL(user, Program.homeGuild, "png") + ); + + if (await Program.db.HashExistsAsync("bans", user.Id)) + { + MemberPunishment ban = JsonConvert.DeserializeObject(Program.db.HashGet("bans", user.Id)); + + embedBuilder.WithDescription("User is banned.") + .AddField("Banned", ban.ActionTime is null ? "Unknown time (Ban is too old)" : $"", true) + .WithColor(new DiscordColor(0xFEC13D)); + + if (ban.ExpireTime is null) + embedBuilder.AddField("Ban expires", "Never", true); + else + embedBuilder.AddField("Ban expires", $"", true); + + embedBuilder.AddField("Banned by", $"<@{ban.ModId}>", true); + + embedBuilder.AddField("Reason", ban.Reason is null ? "No reason provided" : ban.Reason, false); + } + else + { + if (userBan is null) + { + embedBuilder.WithDescription("User is not banned.") + .WithColor(color: DiscordColor.DarkGreen); + } + else + { + embedBuilder.WithDescription($"User was banned without using {Program.discord.CurrentUser.Username}, so limited information is available.") + .WithColor(new DiscordColor(0xFEC13D)); + embedBuilder.AddField("Reason", string.IsNullOrWhiteSpace(userBan.Reason) ? "No reason provided" : userBan.Reason, false); + } + } + + return embedBuilder.Build(); + } + } }