All administration submodules now inherit NadekoSubmodule, and woops, forgot to commit discord.net connection change
This commit is contained in:
parent
b6d93c3105
commit
e5d85dd818
@ -1 +1 @@
|
||||
Subproject commit 9ce5c4757efc6cb6bb8959e851abcdcbe03217be
|
||||
Subproject commit d2229228b92117899d65cd549a1f2853057b255b
|
@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class AutoAssignRoleCommands : ModuleBase
|
||||
public class AutoAssignRoleCommands : NadekoSubmodule
|
||||
{
|
||||
private static Logger _log { get; }
|
||||
//guildid/roleid
|
||||
|
@ -15,16 +15,13 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class DMForwardCommands : ModuleBase
|
||||
public class DMForwardCommands : NadekoSubmodule
|
||||
{
|
||||
private static bool ForwardDMs { get; set; }
|
||||
private static bool ForwardDMsToAllOwners { get; set; }
|
||||
|
||||
private static readonly Logger _log;
|
||||
|
||||
static DMForwardCommands()
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class LocalizationCommands : ModuleBase
|
||||
public class LocalizationCommands : NadekoSubmodule
|
||||
{
|
||||
private ImmutableDictionary<string, string> SupportedLocales { get; } = new Dictionary<string, string>()
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class LogCommands : ModuleBase
|
||||
public class LogCommands : NadekoSubmodule
|
||||
{
|
||||
private const string clockEmojiUrl = "https://cdn.discordapp.com/attachments/155726317222887425/258309524966866945/clock.png";
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class Migration : ModuleBase
|
||||
public class Migration : NadekoSubmodule
|
||||
{
|
||||
private const int CURRENT_VERSION = 1;
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class MuteCommands : ModuleBase
|
||||
public class MuteCommands : NadekoSubmodule
|
||||
{
|
||||
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))
|
||||
return;
|
||||
else
|
||||
await MuteUser(usr).ConfigureAwait(false);
|
||||
await MuteUser(usr).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.Warn(ex);
|
||||
LogManager.GetCurrentClassLogger().Warn(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class PlayingRotateCommands : ModuleBase
|
||||
public class PlayingRotateCommands : NadekoSubmodule
|
||||
{
|
||||
private static Logger _log { get; }
|
||||
public static List<PlayingStatus> RotatingStatusMessages { get; }
|
||||
|
@ -76,12 +76,12 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
|
||||
[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>();
|
||||
// guildId | (userId|messages)
|
||||
private static ConcurrentDictionary<ulong, AntiSpamStats> antiSpamGuilds =
|
||||
private static readonly ConcurrentDictionary<ulong, AntiSpamStats> _antiSpamGuilds =
|
||||
new ConcurrentDictionary<ulong, AntiSpamStats>();
|
||||
|
||||
private static Logger _log { get; }
|
||||
@ -98,11 +98,11 @@ namespace NadekoBot.Modules.Administration
|
||||
if (raid != null)
|
||||
{
|
||||
var raidStats = new AntiRaidStats() { AntiRaidSettings = raid };
|
||||
antiRaidGuilds.TryAdd(gc.GuildId, raidStats);
|
||||
_antiRaidGuilds.TryAdd(gc.GuildId, raidStats);
|
||||
}
|
||||
|
||||
if (spam != null)
|
||||
antiSpamGuilds.TryAdd(gc.GuildId, new AntiSpamStats() { AntiSpamSettings = spam });
|
||||
_antiSpamGuilds.TryAdd(gc.GuildId, new AntiSpamStats() { AntiSpamSettings = spam });
|
||||
}
|
||||
|
||||
NadekoBot.Client.MessageReceived += (imsg) =>
|
||||
@ -119,7 +119,7 @@ namespace NadekoBot.Modules.Administration
|
||||
try
|
||||
{
|
||||
AntiSpamStats spamSettings;
|
||||
if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings) ||
|
||||
if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings) ||
|
||||
spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new AntiSpamIgnore()
|
||||
{
|
||||
ChannelId = channel.Id
|
||||
@ -151,7 +151,7 @@ namespace NadekoBot.Modules.Administration
|
||||
if (usr.IsBot)
|
||||
return Task.CompletedTask;
|
||||
AntiRaidStats settings;
|
||||
if (!antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings))
|
||||
if (!_antiRaidGuilds.TryGetValue(usr.Guild.Id, out settings))
|
||||
return Task.CompletedTask;
|
||||
if (!settings.RaidUsers.Add(usr))
|
||||
return Task.CompletedTask;
|
||||
@ -245,7 +245,7 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
|
||||
AntiRaidStats throwaway;
|
||||
if (antiRaidGuilds.TryRemove(Context.Guild.Id, out throwaway))
|
||||
if (_antiRaidGuilds.TryRemove(Context.Guild.Id, out throwaway))
|
||||
{
|
||||
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())
|
||||
{
|
||||
@ -304,7 +304,7 @@ namespace NadekoBot.Modules.Administration
|
||||
return;
|
||||
|
||||
AntiSpamStats throwaway;
|
||||
if (antiSpamGuilds.TryRemove(Context.Guild.Id, out throwaway))
|
||||
if (_antiSpamGuilds.TryRemove(Context.Guild.Id, out throwaway))
|
||||
{
|
||||
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())
|
||||
{
|
||||
@ -376,7 +376,7 @@ namespace NadekoBot.Modules.Administration
|
||||
if (spam.IgnoredChannels.Add(obj))
|
||||
{
|
||||
AntiSpamStats temp;
|
||||
if (antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp))
|
||||
if (_antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp))
|
||||
temp.AntiSpamSettings.IgnoredChannels.Add(obj);
|
||||
added = true;
|
||||
}
|
||||
@ -384,7 +384,7 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
spam.IgnoredChannels.Remove(obj);
|
||||
AntiSpamStats temp;
|
||||
if (antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp))
|
||||
if (_antiSpamGuilds.TryGetValue(Context.Guild.Id, out temp))
|
||||
temp.AntiSpamSettings.IgnoredChannels.Remove(obj);
|
||||
added = false;
|
||||
}
|
||||
@ -403,10 +403,10 @@ namespace NadekoBot.Modules.Administration
|
||||
public async Task AntiList()
|
||||
{
|
||||
AntiSpamStats spam;
|
||||
antiSpamGuilds.TryGetValue(Context.Guild.Id, out spam);
|
||||
_antiSpamGuilds.TryGetValue(Context.Guild.Id, out spam);
|
||||
|
||||
AntiRaidStats raid;
|
||||
antiRaidGuilds.TryGetValue(Context.Guild.Id, out raid);
|
||||
_antiRaidGuilds.TryGetValue(Context.Guild.Id, out raid);
|
||||
|
||||
if (spam == null && raid == null)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class RatelimitCommand : ModuleBase
|
||||
public class RatelimitCommand : NadekoSubmodule
|
||||
{
|
||||
public static ConcurrentDictionary<ulong, Ratelimiter> RatelimitingChannels = new ConcurrentDictionary<ulong, Ratelimiter>();
|
||||
private static Logger _log { get; }
|
||||
|
@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class SelfAssignedRolesCommands : ModuleBase
|
||||
public class SelfAssignedRolesCommands : NadekoSubmodule
|
||||
{
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@ -14,7 +14,7 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
class SelfCommands : ModuleBase
|
||||
public class SelfCommands : NadekoSubmodule
|
||||
{
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
|
@ -19,19 +19,20 @@ namespace NadekoBot.Modules.Administration
|
||||
public partial class Administration
|
||||
{
|
||||
[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()
|
||||
{
|
||||
var _log = LogManager.GetCurrentClassLogger();
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
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;
|
||||
|
||||
sw.Stop();
|
||||
@ -51,7 +52,7 @@ namespace NadekoBot.Modules.Administration
|
||||
if (before.VoiceChannel == after.VoiceChannel)
|
||||
return Task.CompletedTask;
|
||||
|
||||
if (!voicePlusTextCache.Contains(guild.Id))
|
||||
if (!_voicePlusTextCache.Contains(guild.Id))
|
||||
return Task.CompletedTask;
|
||||
|
||||
var _ = Task.Run(async () =>
|
||||
@ -71,13 +72,13 @@ namespace NadekoBot.Modules.Administration
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
uow.GuildConfigs.For(guild.Id, set => set).VoicePlusTextEnabled = false;
|
||||
voicePlusTextCache.TryRemove(guild.Id);
|
||||
_voicePlusTextCache.TryRemove(guild.Id);
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var semaphore = guildLockObjects.GetOrAdd(guild.Id, (key) => new SemaphoreSlim(1, 1));
|
||||
var semaphore = _guildLockObjects.GetOrAdd(guild.Id, (key) => new SemaphoreSlim(1, 1));
|
||||
|
||||
try
|
||||
{
|
||||
@ -109,8 +110,7 @@ namespace NadekoBot.Modules.Administration
|
||||
roleToAdd = await guild.CreateRoleAsync(roleName, GuildPermissions.None).ConfigureAwait(false);
|
||||
|
||||
ITextChannel textChannel = guild.TextChannels
|
||||
.Where(t => t.Name == GetChannelName(afterVch.Name).ToLowerInvariant())
|
||||
.FirstOrDefault();
|
||||
.FirstOrDefault(t => t.Name == GetChannelName(afterVch.Name).ToLowerInvariant());
|
||||
if (textChannel == null)
|
||||
{
|
||||
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) =>
|
||||
channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice";
|
||||
_channelNameRegex.Replace(voiceName, "").Trim().Replace(" ", "-").TrimTo(90, true) + "-voice";
|
||||
|
||||
private static string GetRoleName(IVoiceChannel ch) =>
|
||||
"nvoice-" + ch.Id;
|
||||
@ -186,7 +186,7 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
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")))
|
||||
{
|
||||
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);
|
||||
return;
|
||||
}
|
||||
voicePlusTextCache.Add(guild.Id);
|
||||
_voicePlusTextCache.Add(guild.Id);
|
||||
await Context.Channel.SendConfirmAsync("🆗 Successfuly **enabled** voice + text feature.").ConfigureAwait(false);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user