From d57cd57296c6f37381a718f903ff73552441201c Mon Sep 17 00:00:00 2001 From: FloatingMilkshake Date: Fri, 10 Jan 2025 09:17:16 -0500 Subject: [PATCH] Fix 'debug overrides add' --- Commands/Debug.cs | 16 ++++++++++++---- Events/InteractionEvents.cs | 30 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Commands/Debug.cs b/Commands/Debug.cs index 118fb3dd..1a21562d 100644 --- a/Commands/Debug.cs +++ b/Commands/Debug.cs @@ -351,16 +351,24 @@ public async Task Add(CommandContext ctx, [Description("Denied permissions. Use a permission integer. See https://discordlookup.com/permissions-calculator.")] int deniedPermissions) { // Confirm permission overrides before we do anything. - var parsedAllowedPerms = (DiscordPermission)allowedPermissions; - var parsedDeniedPerms = (DiscordPermission)deniedPermissions; + var parsedAllowedPerms = new DiscordPermissions(allowedPermissions); + var parsedDeniedPerms = new DiscordPermissions(deniedPermissions); + + var allowedPermsStr = parsedAllowedPerms.ToString("name"); + if (string.IsNullOrWhiteSpace(allowedPermsStr)) + allowedPermsStr = "None"; + + var deniedPermsStr = parsedDeniedPerms.ToString("name"); + if (string.IsNullOrWhiteSpace(deniedPermsStr)) + deniedPermsStr = "None"; var confirmButton = new DiscordButtonComponent(DiscordButtonStyle.Success, "debug-overrides-add-confirm-callback", "Yes"); var cancelButton = new DiscordButtonComponent(DiscordButtonStyle.Danger, "debug-overrides-add-cancel-callback", "No"); var confirmationMessage = await ctx.RespondAsync(new DiscordMessageBuilder().WithContent( $"{Program.cfgjson.Emoji.ShieldHelp} Just to confirm, you want to add the following override for {user.Mention} to {channel.Mention}?\n" + - $"**Allowed:** {parsedAllowedPerms}\n" + - $"**Denied:** {parsedDeniedPerms}\n") + $"**Allowed:** {allowedPermsStr}\n" + + $"**Denied:** {deniedPermsStr}\n") .AddComponents([confirmButton, cancelButton])); OverridesPendingAddition.Add(confirmationMessage.Id, new PendingUserOverride diff --git a/Events/InteractionEvents.cs b/Events/InteractionEvents.cs index 24eaa94f..7cf553c1 100644 --- a/Events/InteractionEvents.cs +++ b/Events/InteractionEvents.cs @@ -109,8 +109,16 @@ await LogChannelHelper.LogDeletedMessagesAsync( if (overwrites.ContainsKey(channelId.ToString())) { // Require extra confirmation for merging permissions! + var currentAllowedPerms = (overwrites[channelId.ToString()].Allowed).ToString("name"); + if (string.IsNullOrWhiteSpace(currentAllowedPerms)) + currentAllowedPerms = "None"; + + var currentDeniedPerms = (overwrites[channelId.ToString()].Denied).ToString("name"); + if (string.IsNullOrWhiteSpace(currentDeniedPerms)) + currentDeniedPerms = "None"; + var mergeConfirmResponse = new DiscordMessageBuilder() - .WithContent($"{cfgjson.Emoji.Warning} **Caution:** This user already has an override for <#{channelId}>! Do you want to merge the permissions? Here are their **current** permissions:\n**Allowed:** {overwrites[channelId.ToString()].Allowed}\n**Denied:** {overwrites[channelId.ToString()].Denied}") + .WithContent($"{cfgjson.Emoji.Warning} **Caution:** This user already has an override for <#{channelId}>! Do you want to merge the permissions? Here are their **current** permissions:\n**Allowed:** {currentAllowedPerms}\n**Denied:** {currentDeniedPerms}") .AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Danger, "debug-overrides-add-merge-confirm-callback", "Merge"), new DiscordButtonComponent(DiscordButtonStyle.Primary, "debug-overrides-add-cancel-callback", "Cancel")); await e.Message.ModifyAsync(mergeConfirmResponse); @@ -128,7 +136,15 @@ await LogChannelHelper.LogDeletedMessagesAsync( overridesPendingAddition.Remove(e.Message.Id); // Respond - await e.Message.ModifyAsync(new DiscordMessageBuilder().WithContent($"{cfgjson.Emoji.Success} Successfully added the following override for <@{newOverwrite.Id}> to <#{pendingOverride.ChannelId}>!\n**Allowed:** {newOverwrite.Allowed}\n**Denied:** {newOverwrite.Denied}")); + var allowedPermsStr = newOverwrite.Allowed.ToString("name"); + if (string.IsNullOrWhiteSpace(allowedPermsStr)) + allowedPermsStr = "None"; + + var deniedPermsStr = newOverwrite.Denied.ToString("name"); + if (string.IsNullOrWhiteSpace(deniedPermsStr)) + deniedPermsStr = "None"; + + await e.Message.ModifyAsync(new DiscordMessageBuilder().WithContent($"{cfgjson.Emoji.Success} Successfully added the following override for <@{newOverwrite.Id}> to <#{pendingOverride.ChannelId}>!\n**Allowed:** {allowedPermsStr}\n**Denied:** {deniedPermsStr}")); } else if (e.Id == "debug-overrides-add-cancel-callback") { @@ -198,7 +214,15 @@ await LogChannelHelper.LogDeletedMessagesAsync( await db.HashSetAsync("overrides", mockOverwrite.Id, JsonConvert.SerializeObject(overwrites)); // Respond - await e.Message.ModifyAsync(new DiscordMessageBuilder().WithContent($"{cfgjson.Emoji.Success} Override successfully added. <@{newOverwrite.Id}> already had an override in <#{pendingOverride.ChannelId}>, so here are their new permissions:\n**Allowed:** {newOverwrite.Allowed}\n**Denied:** {newOverwrite.Denied}")); + var allowedPermsStr = newOverwrite.Allowed.ToString("name"); + if (string.IsNullOrWhiteSpace(allowedPermsStr)) + allowedPermsStr = "None"; + + var deniedPermsStr = newOverwrite.Denied.ToString("name"); + if (string.IsNullOrWhiteSpace(deniedPermsStr)) + deniedPermsStr = "None"; + + await e.Message.ModifyAsync(new DiscordMessageBuilder().WithContent($"{cfgjson.Emoji.Success} Override successfully added. <@{newOverwrite.Id}> already had an override in <#{pendingOverride.ChannelId}>, so here are their new permissions:\n**Allowed:** {allowedPermsStr}\n**Denied:** {deniedPermsStr}")); } else if (e.Id == "insiders-info-roles-menu-callback") {