mute role will be applied to newly created channels now too

This commit is contained in:
Kwoth 2017-04-10 02:29:33 +02:00
parent e5131e0416
commit a0e363ff66

View File

@ -1,5 +1,6 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Services; using NadekoBot.Services;
@ -32,6 +33,9 @@ namespace NadekoBot.Modules.Administration
Chat, Chat,
All All
} }
private static readonly OverwritePermissions denyOverwrite = new OverwritePermissions(sendMessages: PermValue.Deny, attachFiles: PermValue.Deny);
private static readonly new Logger _log = LogManager.GetCurrentClassLogger();
static MuteCommands() static MuteCommands()
{ {
@ -152,21 +156,26 @@ namespace NadekoBot.Modules.Administration
muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName) ?? muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName) ??
await guild.CreateRoleAsync(defaultMuteRoleName, GuildPermissions.None).ConfigureAwait(false); 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); .ConfigureAwait(false);
await Task.Delay(200).ConfigureAwait(false);
} }
catch }
{ catch
// ignored {
} // ignored
await Task.Delay(200).ConfigureAwait(false);
} }
} }
return muteRole; return muteRole;
} }