From 47bc2088262d932c98498367957cf59dbf12e591 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 8 Nov 2016 22:40:20 +0100 Subject: [PATCH] changing mute role no longer requires restart of .antispam/.antiraid --- .../Commands/AntiRaidCommands.cs | 24 ++++++++++++------- src/NadekoBot/Resources/CommandStrings.resx | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs index 07d3b775..60b6b412 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AntiRaidCommands.cs @@ -36,7 +36,6 @@ namespace NadekoBot.Modules.Administration public int UserThreshold { get; set; } public int Seconds { get; set; } public PunishmentAction Action { get; set; } - public IRole MuteRole { get; set; } public int UsersCount { get; set; } public ConcurrentHashSet RaidUsers { get; set; } = new ConcurrentHashSet(); } @@ -45,7 +44,6 @@ namespace NadekoBot.Modules.Administration { public PunishmentAction Action { get; set; } public int MessageThreshold { get; set; } = 3; - public IRole MuteRole { get; set; } public ConcurrentDictionary UserStats { get; set; } = new ConcurrentDictionary(); } @@ -114,7 +112,7 @@ namespace NadekoBot.Modules.Administration { if (spamSettings.UserStats.TryRemove(msg.Author.Id, out stats)) { - await PunishUsers(spamSettings.Action, spamSettings.MuteRole, ProtectionType.Spamming, (IGuildUser)msg.Author) + await PunishUsers(spamSettings.Action, await GetMuteRole(channel.Guild), ProtectionType.Spamming, (IGuildUser)msg.Author) .ConfigureAwait(false); } } @@ -145,7 +143,7 @@ namespace NadekoBot.Modules.Administration var users = settings.RaidUsers.ToArray(); settings.RaidUsers.Clear(); - await PunishUsers(settings.Action, settings.MuteRole, ProtectionType.Raiding, users).ConfigureAwait(false); + await PunishUsers(settings.Action, await GetMuteRole(usr.Guild), ProtectionType.Raiding, users).ConfigureAwait(false); } await Task.Delay(1000 * settings.Seconds).ConfigureAwait(false); @@ -221,10 +219,9 @@ namespace NadekoBot.Modules.Administration return; } - IRole muteRole; try { - muteRole = await GetMuteRole(channel.Guild).ConfigureAwait(false); + await GetMuteRole(channel.Guild).ConfigureAwait(false); } catch (Exception ex) { @@ -240,7 +237,6 @@ namespace NadekoBot.Modules.Administration Action = action, Seconds = seconds, UserThreshold = userThreshold, - MuteRole = muteRole, }; antiRaidGuilds.AddOrUpdate(channel.Guild.Id, setting, (id, old) => setting); @@ -265,10 +261,22 @@ namespace NadekoBot.Modules.Administration } else { + try + { + await GetMuteRole(channel.Guild).ConfigureAwait(false); + } + catch (Exception ex) + { + await channel.SendMessageAsync("Failed creating a mute role. Give me ManageRoles permission" + + "or create 'nadeko-mute' role with disabled SendMessages and try again.") + .ConfigureAwait(false); + _log.Warn(ex); + return; + } + if (antiSpamGuilds.TryAdd(channel.Guild.Id, new AntiSpamSetting() { Action = action, - MuteRole = await GetMuteRole(channel.Guild).ConfigureAwait(false), MessageThreshold = messageCount, })) await channel.SendMessageAsync("`Anti-Spam feature enabled on this server.`").ConfigureAwait(false); diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index c14896e3..ad45c5ee 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2470,7 +2470,7 @@ setmuterole - Sets a name of the role which will be assigned to people who should be muted. Default is nadeko-mute. After specifying this role, restart commands which use mute as punishment. + Sets a name of the role which will be assigned to people who should be muted. Default is nadeko-mute. `{0}setmuterole Silenced`