From a0e363ff660637e53442acdb7853a905f8ae3f77 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 10 Apr 2017 02:29:33 +0200 Subject: [PATCH] mute role will be applied to newly created channels now too --- .../Administration/Commands/MuteCommands.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs index 0a130383..9399fc90 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MuteCommands.cs @@ -1,5 +1,6 @@ using Discord; using Discord.Commands; +using Discord.WebSocket; using Microsoft.EntityFrameworkCore; using NadekoBot.Attributes; using NadekoBot.Services; @@ -32,6 +33,9 @@ namespace NadekoBot.Modules.Administration Chat, All } + private static readonly OverwritePermissions denyOverwrite = new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny); + + private static readonly new Logger _log = LogManager.GetCurrentClassLogger(); static MuteCommands() { @@ -152,21 +156,26 @@ namespace NadekoBot.Modules.Administration muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName) ?? await guild.CreateRoleAsync(defaultMuteRoleName, GuildPermissions.None).ConfigureAwait(false); } + } - foreach (var toOverwrite in (await guild.GetTextChannelsAsync())) + foreach (var toOverwrite in (await guild.GetTextChannelsAsync())) + { + try { - try + if (!toOverwrite.PermissionOverwrites.Select(x => x.Permissions).Contains(denyOverwrite)) { - await toOverwrite.AddPermissionOverwriteAsync(muteRole, new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny)) + await toOverwrite.AddPermissionOverwriteAsync(muteRole, denyOverwrite) .ConfigureAwait(false); + + await Task.Delay(200).ConfigureAwait(false); } - catch - { - // ignored - } - await Task.Delay(200).ConfigureAwait(false); + } + catch + { + // ignored } } + return muteRole; }