private async Task UnlockCommand(CommandContext ctx, DiscordChannel channel, String reason = "usedefault", Boolean silent = false) { if (!ctx.Member.HasPermission("insanitybot.moderation.unlock")) { await ctx.Channel.SendMessageAsync(InsanityBot.LanguageConfig["insanitybot.error.lacking_permission"]); return; } String UnlockReason = reason switch { "usedefault" => GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.no_reason_given"], ctx), _ => GetFormattedString(reason, ctx) }; DiscordEmbedBuilder embedBuilder = null; DiscordEmbedBuilder moderationEmbedBuilder = new() { Title = "UNLOCK", Color = DiscordColor.Blue, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot 2020-2021" } }; moderationEmbedBuilder.AddField("Moderator", ctx.Member.Mention, true) .AddField("Channel", channel.Mention, true) .AddField("Reason", UnlockReason, true); try { List <DiscordOverwrite> overwrites = channel.GetChannelData(); ChannelData cachedData = channel.GetCachedChannelData(); UInt64 exemptRole; if ((exemptRole = Convert.ToUInt64(InsanityBot.Config["insanitybot.identifiers.moderation.lock_exempt_role_id"])) != 0) { await channel.AddOverwriteAsync(InsanityBot.HomeGuild.GetRole(exemptRole), allow : DSharpPlus.Permissions.None, reason : "InsanityBot - unlocking channel, removing whitelist"); } foreach (UInt64 v in cachedData.LockedRoles) { await channel.AddOverwriteAsync(InsanityBot.HomeGuild.GetRole(v), deny : DSharpPlus.Permissions.None, reason : "InsanityBot - unlocking channel, removing permission overwrites"); } foreach (UInt64 v in cachedData.LockedRoles) { await channel.AddOverwriteAsync(InsanityBot.HomeGuild.GetRole(v), allow : DSharpPlus.Permissions.None, reason : "InsanityBot - unlocking channel, removing permission overwrites"); } foreach (DiscordOverwrite v in overwrites) { await channel.AddOverwriteAsync(await v.GetRoleAsync(), v.Allowed, v.Denied, "InsanityBot - unlocking channel, restoring previous permissions"); } embedBuilder = new DiscordEmbedBuilder { Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.unlock.success"], ctx), Color = DiscordColor.Blue, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot 2020-2021" } }; } catch (Exception e) { embedBuilder = new DiscordEmbedBuilder { Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.unlock.failure"], ctx), Color = DiscordColor.Red, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "InsanityBot 2020-2021" } }; InsanityBot.Client.Logger.LogError($"{e}: {e.Message}"); } finally { if (!silent) { await ctx.Channel.SendMessageAsync(embed : embedBuilder.Build()); } } } } }