All administration submodules now inherit NadekoSubmodule, and woops, forgot to commit discord.net connection change

This commit is contained in:
Kwoth 2017-02-14 15:41:23 +01:00
parent b6d93c3105
commit e5d85dd818
13 changed files with 42 additions and 46 deletions

@ -1 +1 @@
Subproject commit 9ce5c4757efc6cb6bb8959e851abcdcbe03217be Subproject commit d2229228b92117899d65cd549a1f2853057b255b

View File

@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class AutoAssignRoleCommands : ModuleBase public class AutoAssignRoleCommands : NadekoSubmodule
{ {
private static Logger _log { get; } private static Logger _log { get; }
//guildid/roleid //guildid/roleid

View File

@ -15,16 +15,13 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class DMForwardCommands : ModuleBase public class DMForwardCommands : NadekoSubmodule
{ {
private static bool ForwardDMs { get; set; } private static bool ForwardDMs { get; set; }
private static bool ForwardDMsToAllOwners { get; set; } private static bool ForwardDMsToAllOwners { get; set; }
private static readonly Logger _log;
static DMForwardCommands() static DMForwardCommands()
{ {
_log = LogManager.GetCurrentClassLogger();
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {

View File

@ -15,7 +15,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class LocalizationCommands : ModuleBase public class LocalizationCommands : NadekoSubmodule
{ {
private ImmutableDictionary<string, string> SupportedLocales { get; } = new Dictionary<string, string>() private ImmutableDictionary<string, string> SupportedLocales { get; } = new Dictionary<string, string>()
{ {

View File

@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class LogCommands : ModuleBase public class LogCommands : NadekoSubmodule
{ {
private const string clockEmojiUrl = "https://cdn.discordapp.com/attachments/155726317222887425/258309524966866945/clock.png"; private const string clockEmojiUrl = "https://cdn.discordapp.com/attachments/155726317222887425/258309524966866945/clock.png";

View File

@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class Migration : ModuleBase public class Migration : NadekoSubmodule
{ {
private const int CURRENT_VERSION = 1; private const int CURRENT_VERSION = 1;

View File

@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class MuteCommands : ModuleBase public class MuteCommands : NadekoSubmodule
{ {
private static ConcurrentDictionary<ulong, string> GuildMuteRoles { get; } = new ConcurrentDictionary<ulong, string>(); private static ConcurrentDictionary<ulong, string> GuildMuteRoles { get; } = new ConcurrentDictionary<ulong, string>();
@ -58,12 +58,11 @@ namespace NadekoBot.Modules.Administration
if (muted == null || !muted.Contains(usr.Id)) if (muted == null || !muted.Contains(usr.Id))
return; return;
else await MuteUser(usr).ConfigureAwait(false);
await MuteUser(usr).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
_log.Warn(ex); LogManager.GetCurrentClassLogger().Warn(ex);
} }
} }

View File

@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class PlayingRotateCommands : ModuleBase public class PlayingRotateCommands : NadekoSubmodule
{ {
private static Logger _log { get; } private static Logger _log { get; }
public static List<PlayingStatus> RotatingStatusMessages { get; } public static List<PlayingStatus> RotatingStatusMessages { get; }

View File

@ -76,12 +76,12 @@ namespace NadekoBot.Modules.Administration
} }
[Group] [Group]
public class ProtectionCommands : ModuleBase public class ProtectionCommands : NadekoSubmodule
{ {
private static ConcurrentDictionary<ulong, AntiRaidStats> antiRaidGuilds = private static readonly ConcurrentDictionary<ulong, AntiRaidStats> _antiRaidGuilds =
new ConcurrentDictionary<ulong, AntiRaidStats>(); new ConcurrentDictionary<ulong, AntiRaidStats>();
// guildId | (userId|messages) // guildId | (userId|messages)
private static ConcurrentDictionary<ulong, AntiSpamStats> antiSpamGuilds = private static readonly ConcurrentDictionary<ulong, AntiSpamStats> _antiSpamGuilds =
new ConcurrentDictionary<ulong, AntiSpamStats>(); new ConcurrentDictionary<ulong, AntiSpamStats>();
private static Logger _log { get; } private static Logger _log { get; }
@ -98,11 +98,11 @@ namespace NadekoBot.Modules.Administration
if (raid != null) if (raid != null)
{ {
var raidStats = new AntiRaidStats() { AntiRaidSettings = raid }; var raidStats = new AntiRaidStats() { AntiRaidSettings = raid };
antiRaidGuilds.TryAdd(gc.GuildId, raidStats); _antiRaidGuilds.TryAdd(gc.GuildId, raidStats);
} }
if (spam != null) if (spam != null)
antiSpamGuilds.TryAdd(gc.GuildId, new AntiSpamStats() { AntiSpamSettings = spam }); _antiSpamGuilds.TryAdd(gc.GuildId, new AntiSpamStats() { AntiSpamSettings = spam });
} }
NadekoBot.Client.MessageReceived += (imsg) => NadekoBot.Client.MessageReceived += (imsg) =>
@ -119,7 +119,7 @@ namespace NadekoBot.Modules.Administration
try try
{ {
AntiSpamStats spamSettings; AntiSpamStats spamSettings;
if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings) || if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings) ||
spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new AntiSpamIgnore() spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new AntiSpamIgnore()
{ {
ChannelId = channel.Id ChannelId = channel.Id
@ -151,7 +151,7 @@ namespace NadekoBot.Modules.Administration
if (usr.IsBot) if (usr.IsBot)
return Task.CompletedTask; return Task.CompletedTask;
AntiRaidStats settings; AntiRaidStats settings;
if (!antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings)) if (!_antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings))
return Task.CompletedTask; return Task.CompletedTask;
if (!settings.RaidUsers.Add(usr)) if (!settings.RaidUsers.Add(usr))
return Task.CompletedTask; return Task.CompletedTask;
@ -245,7 +245,7 @@ namespace NadekoBot.Modules.Administration
} }
AntiRaidStats throwaway; AntiRaidStats throwaway;
if (antiRaidGuilds.TryRemove(Context.Guild.Id, out throwaway)) if (_antiRaidGuilds.TryRemove(Context.Guild.Id, out throwaway))
{ {
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -281,7 +281,7 @@ namespace NadekoBot.Modules.Administration
} }
}; };
antiRaidGuilds.AddOrUpdate(Context.Guild.Id, stats, (key, old) => stats); _antiRaidGuilds.AddOrUpdate(Context.Guild.Id, stats, (key, old) => stats);
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -304,7 +304,7 @@ namespace NadekoBot.Modules.Administration
return; return;
AntiSpamStats throwaway; AntiSpamStats throwaway;
if (antiSpamGuilds.TryRemove(Context.Guild.Id, out throwaway)) if (_antiSpamGuilds.TryRemove(Context.Guild.Id, out throwaway))
{ {
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -340,7 +340,7 @@ namespace NadekoBot.Modules.Administration
} }
}; };
antiSpamGuilds.AddOrUpdate(Context.Guild.Id, stats, (key, old) => stats); _antiSpamGuilds.AddOrUpdate(Context.Guild.Id, stats, (key, old) => stats);
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -376,7 +376,7 @@ namespace NadekoBot.Modules.Administration
if (spam.IgnoredChannels.Add(obj)) if (spam.IgnoredChannels.Add(obj))
{ {
AntiSpamStats temp; AntiSpamStats temp;
if (antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp)) if (_antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp))
temp.AntiSpamSettings.IgnoredChannels.Add(obj); temp.AntiSpamSettings.IgnoredChannels.Add(obj);
added = true; added = true;
} }
@ -384,7 +384,7 @@ namespace NadekoBot.Modules.Administration
{ {
spam.IgnoredChannels.Remove(obj); spam.IgnoredChannels.Remove(obj);
AntiSpamStats temp; AntiSpamStats temp;
if (antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp)) if (_antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp))
temp.AntiSpamSettings.IgnoredChannels.Remove(obj); temp.AntiSpamSettings.IgnoredChannels.Remove(obj);
added = false; added = false;
} }
@ -403,10 +403,10 @@ namespace NadekoBot.Modules.Administration
public async Task AntiList() public async Task AntiList()
{ {
AntiSpamStats spam; AntiSpamStats spam;
antiSpamGuilds.TryGetValue(Context.Guild.Id, out spam); _antiSpamGuilds.TryGetValue(Context.Guild.Id, out spam);
AntiRaidStats raid; AntiRaidStats raid;
antiRaidGuilds.TryGetValue(Context.Guild.Id, out raid); _antiRaidGuilds.TryGetValue(Context.Guild.Id, out raid);
if (spam == null && raid == null) if (spam == null && raid == null)
{ {

View File

@ -13,7 +13,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class RatelimitCommand : ModuleBase public class RatelimitCommand : NadekoSubmodule
{ {
public static ConcurrentDictionary<ulong, Ratelimiter> RatelimitingChannels = new ConcurrentDictionary<ulong, Ratelimiter>(); public static ConcurrentDictionary<ulong, Ratelimiter> RatelimitingChannels = new ConcurrentDictionary<ulong, Ratelimiter>();
private static Logger _log { get; } private static Logger _log { get; }

View File

@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class SelfAssignedRolesCommands : ModuleBase public class SelfAssignedRolesCommands : NadekoSubmodule
{ {
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -14,7 +14,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
class SelfCommands : ModuleBase public class SelfCommands : NadekoSubmodule
{ {
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[OwnerOnly] [OwnerOnly]

View File

@ -19,19 +19,20 @@ namespace NadekoBot.Modules.Administration
public partial class Administration public partial class Administration
{ {
[Group] [Group]
public class VoicePlusTextCommands : ModuleBase public class VoicePlusTextCommands : NadekoSubmodule
{ {
private static Regex channelNameRegex = new Regex(@"[^a-zA-Z0-9 -]", RegexOptions.Compiled); private new static readonly Logger _log;
private static ConcurrentHashSet<ulong> voicePlusTextCache { get; } private static readonly Regex _channelNameRegex = new Regex(@"[^a-zA-Z0-9 -]", RegexOptions.Compiled);
private static ConcurrentDictionary<ulong, SemaphoreSlim> guildLockObjects = new ConcurrentDictionary<ulong, SemaphoreSlim>(); private static readonly ConcurrentHashSet<ulong> _voicePlusTextCache;
private static readonly ConcurrentDictionary<ulong, SemaphoreSlim> _guildLockObjects = new ConcurrentDictionary<ulong, SemaphoreSlim>();
static VoicePlusTextCommands() static VoicePlusTextCommands()
{ {
var _log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
voicePlusTextCache = new ConcurrentHashSet<ulong>(NadekoBot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId)); _voicePlusTextCache = new ConcurrentHashSet<ulong>(NadekoBot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId));
NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler; NadekoBot.Client.UserVoiceStateUpdated += UserUpdatedEventHandler;
sw.Stop(); sw.Stop();
@ -51,7 +52,7 @@ namespace NadekoBot.Modules.Administration
if (before.VoiceChannel == after.VoiceChannel) if (before.VoiceChannel == after.VoiceChannel)
return Task.CompletedTask; return Task.CompletedTask;
if (!voicePlusTextCache.Contains(guild.Id)) if (!_voicePlusTextCache.Contains(guild.Id))
return Task.CompletedTask; return Task.CompletedTask;
var _ = Task.Run(async () => var _ = Task.Run(async () =>
@ -71,13 +72,13 @@ namespace NadekoBot.Modules.Administration
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
uow.GuildConfigs.For(guild.Id, set => set).VoicePlusTextEnabled = false; uow.GuildConfigs.For(guild.Id, set => set).VoicePlusTextEnabled = false;
voicePlusTextCache.TryRemove(guild.Id); _voicePlusTextCache.TryRemove(guild.Id);
await uow.CompleteAsync().ConfigureAwait(false); await uow.CompleteAsync().ConfigureAwait(false);
} }
return; return;
} }
var semaphore = guildLockObjects.GetOrAdd(guild.Id, (key) => new SemaphoreSlim(1, 1)); var semaphore = _guildLockObjects.GetOrAdd(guild.Id, (key) => new SemaphoreSlim(1, 1));
try try
{ {
@ -109,8 +110,7 @@ namespace NadekoBot.Modules.Administration
roleToAdd = await guild.CreateRoleAsync(roleName, GuildPermissions.None).ConfigureAwait(false); roleToAdd = await guild.CreateRoleAsync(roleName, GuildPermissions.None).ConfigureAwait(false);
ITextChannel textChannel = guild.TextChannels ITextChannel textChannel = guild.TextChannels
.Where(t => t.Name == GetChannelName(afterVch.Name).ToLowerInvariant()) .FirstOrDefault(t => t.Name == GetChannelName(afterVch.Name).ToLowerInvariant());
.FirstOrDefault();
if (textChannel == null) if (textChannel == null)
{ {
var created = (await guild.CreateTextChannelAsync(GetChannelName(afterVch.Name).ToLowerInvariant()).ConfigureAwait(false)); var created = (await guild.CreateTextChannelAsync(GetChannelName(afterVch.Name).ToLowerInvariant()).ConfigureAwait(false));
@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Administration
} }
private static string GetChannelName(string voiceName) => private static string GetChannelName(string voiceName) =>
channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice"; _channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice";
private static string GetRoleName(IVoiceChannel ch) => private static string GetRoleName(IVoiceChannel ch) =>
"nvoice-" + ch.Id; "nvoice-" + ch.Id;
@ -186,7 +186,7 @@ namespace NadekoBot.Modules.Administration
} }
if (!isEnabled) if (!isEnabled)
{ {
voicePlusTextCache.TryRemove(guild.Id); _voicePlusTextCache.TryRemove(guild.Id);
foreach (var textChannel in (await guild.GetTextChannelsAsync().ConfigureAwait(false)).Where(c => c.Name.EndsWith("-voice"))) foreach (var textChannel in (await guild.GetTextChannelsAsync().ConfigureAwait(false)).Where(c => c.Name.EndsWith("-voice")))
{ {
try { await textChannel.DeleteAsync().ConfigureAwait(false); } catch { } try { await textChannel.DeleteAsync().ConfigureAwait(false); } catch { }
@ -201,7 +201,7 @@ namespace NadekoBot.Modules.Administration
await Context.Channel.SendConfirmAsync(" Successfuly **removed** voice + text feature.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync(" Successfuly **removed** voice + text feature.").ConfigureAwait(false);
return; return;
} }
voicePlusTextCache.Add(guild.Id); _voicePlusTextCache.Add(guild.Id);
await Context.Channel.SendConfirmAsync("🆗 Successfuly **enabled** voice + text feature.").ConfigureAwait(false); await Context.Channel.SendConfirmAsync("🆗 Successfuly **enabled** voice + text feature.").ConfigureAwait(false);
} }