Skip to content

Commit

Permalink
Fix 'debug overrides add'
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Jan 10, 2025
1 parent 4dbd562 commit d57cd57
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
16 changes: 12 additions & 4 deletions Commands/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 27 additions & 3 deletions Events/InteractionEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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")
{
Expand Down Expand Up @@ -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")
{
Expand Down

0 comments on commit d57cd57

Please sign in to comment.