Cleanup, .clparew can now be ran everyone, modules load appropriate guild configs, IEnumerable<GuildConfig> replaces with NadekoBot.AllGuildConfigs
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
@ -7,7 +6,6 @@ using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NLog;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services
|
||||
@ -16,12 +14,14 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
public readonly ConcurrentHashSet<ulong> DeleteMessagesOnCommand;
|
||||
private readonly Logger _log;
|
||||
private readonly NadekoBot _bot;
|
||||
|
||||
public AdministrationService(IEnumerable<GuildConfig> gcs, CommandHandler cmdHandler)
|
||||
public AdministrationService(NadekoBot bot, CommandHandler cmdHandler)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_bot = bot;
|
||||
|
||||
DeleteMessagesOnCommand = new ConcurrentHashSet<ulong>(gcs.Where(g => g.DeleteMessageOnCommand).Select(g => g.GuildId));
|
||||
DeleteMessagesOnCommand = new ConcurrentHashSet<ulong>(bot.AllGuildConfigs.Where(g => g.DeleteMessageOnCommand).Select(g => g.GuildId));
|
||||
cmdHandler.CommandExecuted += DelMsgOnCmd_Handler;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NLog;
|
||||
|
||||
namespace NadekoBot.Modules.Administration.Services
|
||||
@ -18,13 +16,13 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
//guildid/roleid
|
||||
public ConcurrentDictionary<ulong, ulong> AutoAssignedRoles { get; }
|
||||
|
||||
public AutoAssignRoleService(DiscordSocketClient client, IEnumerable<GuildConfig> gcs)
|
||||
public AutoAssignRoleService(DiscordSocketClient client, NadekoBot bot)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_client = client;
|
||||
|
||||
AutoAssignedRoles = new ConcurrentDictionary<ulong, ulong>(
|
||||
gcs.Where(x => x.AutoAssignRoleId != 0)
|
||||
bot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0)
|
||||
.ToDictionary(k => k.GuildId, v => v.AutoAssignRoleId));
|
||||
|
||||
_client.UserJoined += (user) =>
|
||||
|
@ -19,14 +19,14 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly DbService _db;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public GameVoiceChannelService(DiscordSocketClient client, DbService db, IEnumerable<GuildConfig> gcs)
|
||||
public GameVoiceChannelService(DiscordSocketClient client, DbService db, NadekoBot bot)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_db = db;
|
||||
_client = client;
|
||||
|
||||
GameVoiceChannels = new ConcurrentHashSet<ulong>(
|
||||
gcs.Where(gc => gc.GameVoiceChannel != null)
|
||||
bot.AllGuildConfigs.Where(gc => gc.GameVoiceChannel != null)
|
||||
.Select(gc => gc.GameVoiceChannel.Value));
|
||||
|
||||
_client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
|
||||
|
@ -16,9 +16,9 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private ConcurrentDictionary<ulong, TimeZoneInfo> _timezones;
|
||||
private readonly DbService _db;
|
||||
|
||||
public GuildTimezoneService(DiscordSocketClient client, IEnumerable<GuildConfig> gcs, DbService db)
|
||||
public GuildTimezoneService(DiscordSocketClient client, NadekoBot bot, DbService db)
|
||||
{
|
||||
_timezones = gcs
|
||||
_timezones = bot.AllGuildConfigs
|
||||
.Select(x =>
|
||||
{
|
||||
TimeZoneInfo tz;
|
||||
@ -33,10 +33,10 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
{
|
||||
tz = null;
|
||||
}
|
||||
return (x.GuildId, tz);
|
||||
return (x.GuildId, Timezone: tz);
|
||||
})
|
||||
.Where(x => x.Item2 != null)
|
||||
.ToDictionary(x => x.Item1, x => x.Item2)
|
||||
.Where(x => x.Timezone != null)
|
||||
.ToDictionary(x => x.GuildId, x => x.Timezone)
|
||||
.ToConcurrent();
|
||||
|
||||
var curUser = client.CurrentUser;
|
||||
|
@ -50,7 +50,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly GuildTimezoneService _tz;
|
||||
|
||||
public LogCommandService(DiscordSocketClient client, NadekoStrings strings,
|
||||
IEnumerable<GuildConfig> gcs, DbService db, MuteService mute, ProtectionService prot, GuildTimezoneService tz)
|
||||
NadekoBot bot, DbService db, MuteService mute, ProtectionService prot, GuildTimezoneService tz)
|
||||
{
|
||||
_client = client;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_prot = prot;
|
||||
_tz = tz;
|
||||
|
||||
GuildLogSettings = gcs
|
||||
GuildLogSettings = bot.AllGuildConfigs
|
||||
.ToDictionary(g => g.GuildId, g => g.LogSetting)
|
||||
.ToConcurrent();
|
||||
|
||||
|
@ -38,22 +38,25 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly DbService _db;
|
||||
|
||||
public MuteService(DiscordSocketClient client, IEnumerable<GuildConfig> gcs, DbService db)
|
||||
public MuteService(DiscordSocketClient client, NadekoBot bot, DbService db)
|
||||
{
|
||||
_client = client;
|
||||
_db = db;
|
||||
|
||||
GuildMuteRoles = gcs
|
||||
.Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName))
|
||||
.ToDictionary(c => c.GuildId, c => c.MuteRoleName)
|
||||
.ToConcurrent();
|
||||
GuildMuteRoles = bot
|
||||
.AllGuildConfigs
|
||||
.Where(c => !string.IsNullOrWhiteSpace(c.MuteRoleName))
|
||||
.ToDictionary(c => c.GuildId, c => c.MuteRoleName)
|
||||
.ToConcurrent();
|
||||
|
||||
MutedUsers = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(gcs.ToDictionary(
|
||||
k => k.GuildId,
|
||||
v => new ConcurrentHashSet<ulong>(v.MutedUsers.Select(m => m.UserId))
|
||||
MutedUsers = new ConcurrentDictionary<ulong, ConcurrentHashSet<ulong>>(bot
|
||||
.AllGuildConfigs
|
||||
.ToDictionary(
|
||||
k => k.GuildId,
|
||||
v => new ConcurrentHashSet<ulong>(v.MutedUsers.Select(m => m.UserId))
|
||||
));
|
||||
|
||||
foreach (var conf in gcs)
|
||||
foreach (var conf in bot.AllGuildConfigs)
|
||||
{
|
||||
foreach (var x in conf.UnmuteTimers)
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
@ -26,13 +25,13 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly MuteService _mute;
|
||||
|
||||
public ProtectionService(DiscordSocketClient client, IEnumerable<GuildConfig> gcs, MuteService mute)
|
||||
public ProtectionService(DiscordSocketClient client, NadekoBot bot, MuteService mute)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_client = client;
|
||||
_mute = mute;
|
||||
|
||||
foreach (var gc in gcs)
|
||||
foreach (var gc in bot.AllGuildConfigs)
|
||||
{
|
||||
var raid = gc.AntiRaidSetting;
|
||||
var spam = gc.AntiSpamSetting;
|
||||
|
@ -23,17 +23,17 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly Logger _log;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public SlowmodeService(DiscordSocketClient client, IEnumerable<GuildConfig> gcs)
|
||||
public SlowmodeService(DiscordSocketClient client, NadekoBot bot)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_client = client;
|
||||
|
||||
IgnoredRoles = new ConcurrentDictionary<ulong, HashSet<ulong>>(
|
||||
gcs.ToDictionary(x => x.GuildId,
|
||||
bot.AllGuildConfigs.ToDictionary(x => x.GuildId,
|
||||
x => new HashSet<ulong>(x.SlowmodeIgnoredRoles.Select(y => y.RoleId))));
|
||||
|
||||
IgnoredUsers = new ConcurrentDictionary<ulong, HashSet<ulong>>(
|
||||
gcs.ToDictionary(x => x.GuildId,
|
||||
bot.AllGuildConfigs.ToDictionary(x => x.GuildId,
|
||||
x => new HashSet<ulong>(x.SlowmodeIgnoredUsers.Select(y => y.UserId))));
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_creds = creds;
|
||||
_bc = bc;
|
||||
|
||||
var _ = Task.Run(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await bot.Ready.Task.ConfigureAwait(false);
|
||||
|
||||
@ -57,14 +57,12 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
}
|
||||
});
|
||||
|
||||
var ___ = Task.Run(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await bot.Ready.Task.ConfigureAwait(false);
|
||||
|
||||
await Task.Delay(5000);
|
||||
|
||||
_client.Guilds.SelectMany(g => g.Users);
|
||||
|
||||
if(client.ShardId == 0)
|
||||
LoadOwnerChannels();
|
||||
});
|
||||
|
@ -19,7 +19,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
|
||||
public ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, IRole>> VcRoles { get; }
|
||||
|
||||
public VcRoleService(DiscordSocketClient client, IEnumerable<GuildConfig> gcs, DbService db)
|
||||
public VcRoleService(DiscordSocketClient client, NadekoBot bot, DbService db)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_db = db;
|
||||
@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_client.UserVoiceStateUpdated += ClientOnUserVoiceStateUpdated;
|
||||
VcRoles = new ConcurrentDictionary<ulong, ConcurrentDictionary<ulong, IRole>>();
|
||||
var missingRoles = new List<VcRoleInfo>();
|
||||
foreach (var gconf in gcs)
|
||||
foreach (var gconf in bot.AllGuildConfigs)
|
||||
{
|
||||
var g = _client.GetGuild(gconf.GuildId);
|
||||
if (g == null)
|
||||
|
@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
private readonly DbService _db;
|
||||
private readonly Logger _log;
|
||||
|
||||
public VplusTService(DiscordSocketClient client, IEnumerable<GuildConfig> gcs, NadekoStrings strings,
|
||||
public VplusTService(DiscordSocketClient client, NadekoBot bot, NadekoStrings strings,
|
||||
DbService db)
|
||||
{
|
||||
_client = client;
|
||||
@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Administration.Services
|
||||
_db = db;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
VoicePlusTextCache = new ConcurrentHashSet<ulong>(gcs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId));
|
||||
VoicePlusTextCache = new ConcurrentHashSet<ulong>(bot.AllGuildConfigs.Where(g => g.VoicePlusTextEnabled).Select(g => g.GuildId));
|
||||
_client.UserVoiceStateUpdated += UserUpdatedEventHandler;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user