Cleanup, .clparew can now be ran everyone, modules load appropriate guild configs, IEnumerable<GuildConfig> replaces with NadekoBot.AllGuildConfigs
This commit is contained in:
@ -51,7 +51,9 @@ namespace NadekoBot.Services
|
||||
public ConcurrentHashSet<ulong> UsersOnShortCooldown { get; } = new ConcurrentHashSet<ulong>();
|
||||
private readonly Timer _clearUsersOnShortCooldown;
|
||||
|
||||
public CommandHandler(DiscordSocketClient client, DbService db, IBotConfigProvider bc, IEnumerable<GuildConfig> gcs, CommandService commandService, IBotCredentials credentials, NadekoBot bot)
|
||||
public CommandHandler(DiscordSocketClient client, DbService db,
|
||||
IBotConfigProvider bc, CommandService commandService,
|
||||
IBotCredentials credentials, NadekoBot bot)
|
||||
{
|
||||
_client = client;
|
||||
_commandService = commandService;
|
||||
@ -67,7 +69,7 @@ namespace NadekoBot.Services
|
||||
}, null, GlobalCommandsCooldown, GlobalCommandsCooldown);
|
||||
|
||||
DefaultPrefix = bc.BotConfig.DefaultPrefix;
|
||||
_prefixes = gcs
|
||||
_prefixes = bot.AllGuildConfigs
|
||||
.Where(x => x.Prefix != null)
|
||||
.ToDictionary(x => x.GuildId, x => x.Prefix)
|
||||
.ToConcurrent();
|
||||
|
@ -29,8 +29,6 @@ namespace NadekoBot.Services.Database
|
||||
public DbSet<Quote> Quotes { get; set; }
|
||||
public DbSet<Donator> Donators { get; set; }
|
||||
public DbSet<GuildConfig> GuildConfigs { get; set; }
|
||||
public DbSet<ClashWar> ClashOfClans { get; set; }
|
||||
public DbSet<ClashCaller> ClashCallers { get; set; }
|
||||
public DbSet<Reminder> Reminders { get; set; }
|
||||
public DbSet<SelfAssignedRole> SelfAssignableRoles { get; set; }
|
||||
public DbSet<BotConfig> BotConfig { get; set; }
|
||||
|
@ -21,13 +21,15 @@ namespace NadekoBot.Services
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly Logger _log;
|
||||
|
||||
public GreetSettingsService(DiscordSocketClient client, IEnumerable<GuildConfig> guildConfigs, DbService db)
|
||||
public GreetSettingsService(DiscordSocketClient client, NadekoBot bot, DbService db)
|
||||
{
|
||||
_db = db;
|
||||
_client = client;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
GuildConfigsCache = new ConcurrentDictionary<ulong, GreetSettings>(guildConfigs.ToDictionary(g => g.GuildId, GreetSettings.Create));
|
||||
GuildConfigsCache = new ConcurrentDictionary<ulong, GreetSettings>(
|
||||
bot.AllGuildConfigs
|
||||
.ToDictionary(g => g.GuildId, GreetSettings.Create));
|
||||
|
||||
_client.UserJoined += UserJoined;
|
||||
_client.UserLeft += UserLeft;
|
||||
@ -180,10 +182,8 @@ namespace NadekoBot.Services
|
||||
|
||||
public GreetSettings GetOrAddSettingsForGuild(ulong guildId)
|
||||
{
|
||||
GreetSettings settings;
|
||||
GuildConfigsCache.TryGetValue(guildId, out settings);
|
||||
|
||||
if (settings != null)
|
||||
if(GuildConfigsCache.TryGetValue(guildId, out var settings) &&
|
||||
settings != null)
|
||||
return settings;
|
||||
|
||||
using (var uow = _db.UnitOfWork)
|
||||
|
@ -28,11 +28,11 @@ namespace NadekoBot.Services.Impl
|
||||
}
|
||||
|
||||
private Localization() { }
|
||||
public Localization(IBotConfigProvider bcp, IEnumerable<GuildConfig> gcs, DbService db)
|
||||
public Localization(IBotConfigProvider bcp, NadekoBot bot, DbService db)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
var cultureInfoNames = gcs.ToDictionary(x => x.GuildId, x => x.Locale);
|
||||
var cultureInfoNames = bot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale);
|
||||
var defaultCulture = bcp.BotConfig.Locale;
|
||||
|
||||
_db = db;
|
||||
@ -123,8 +123,7 @@ namespace NadekoBot.Services.Impl
|
||||
{
|
||||
if (guildId == null)
|
||||
return DefaultCultureInfo;
|
||||
CultureInfo info = null;
|
||||
GuildCultureInfos.TryGetValue(guildId.Value, out info);
|
||||
GuildCultureInfos.TryGetValue(guildId.Value, out CultureInfo info);
|
||||
return info ?? DefaultCultureInfo;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ namespace NadekoBot.Services.Impl
|
||||
|
||||
private readonly Timer _carbonitexTimer;
|
||||
private readonly Timer _dataTimer;
|
||||
private readonly ShardsCoordinator _sc;
|
||||
private readonly ConnectionMultiplexer _redis;
|
||||
|
||||
public StatsService(DiscordSocketClient client, CommandHandler cmdHandler,
|
||||
@ -51,7 +50,6 @@ namespace NadekoBot.Services.Impl
|
||||
{
|
||||
_client = client;
|
||||
_creds = creds;
|
||||
_sc = nadeko.ShardCoord;
|
||||
_redis = cache.Redis;
|
||||
|
||||
_started = DateTime.UtcNow;
|
||||
@ -134,7 +132,7 @@ namespace NadekoBot.Services.Impl
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
if (_sc != null)
|
||||
if (_client.ShardId == 0)
|
||||
{
|
||||
_carbonitexTimer = new Timer(async (state) =>
|
||||
{
|
||||
|
@ -48,8 +48,6 @@ namespace NadekoBot
|
||||
|
||||
public INServiceProvider Services { get; private set; }
|
||||
|
||||
public ShardsCoordinator ShardCoord { get; private set; }
|
||||
|
||||
private readonly BotConfig _botConfig;
|
||||
public IDataCache Cache { get; private set; }
|
||||
|
||||
@ -143,9 +141,6 @@ namespace NadekoBot
|
||||
.AddManual(Client)
|
||||
.AddManual(CommandService)
|
||||
.AddManual(botConfigProvider)
|
||||
//todo this needs to reload whenever a new service is supposed to be loaded
|
||||
//except at startup for obvious reasons
|
||||
.AddManual<IEnumerable<GuildConfig>>(AllGuildConfigs) //todo wrap this
|
||||
.AddManual<NadekoBot>(this)
|
||||
.AddManual<IUnitOfWork>(uow)
|
||||
.AddManual<IDataCache>(Cache);
|
||||
@ -255,9 +250,6 @@ namespace NadekoBot
|
||||
|
||||
public async Task RunAsync(params string[] args)
|
||||
{
|
||||
if (Client.ShardId == 0)
|
||||
_log.Info("Starting NadekoBot v" + StatsService.BotVersion);
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
await LoginAsync(Credentials.Token).ConfigureAwait(false);
|
||||
@ -450,7 +442,12 @@ namespace NadekoBot
|
||||
{
|
||||
if (_packageModules.ContainsKey(name))
|
||||
return false;
|
||||
|
||||
|
||||
var startingGuildIdList = Client.Guilds.Select(x => (long)x.Id).ToList();
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
|
||||
}
|
||||
var package = Assembly.LoadFile(Path.Combine(AppContext.BaseDirectory,
|
||||
"modules",
|
||||
$"NadekoBot.Modules.{name}",
|
||||
|
@ -54,6 +54,16 @@ namespace NadekoBot.Services
|
||||
return this;
|
||||
}
|
||||
|
||||
public INServiceProvider UpdateManual<T>(T obj)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
_services.Remove(typeof(T));
|
||||
_services.TryAdd(typeof(T), obj);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public IEnumerable<Type> LoadFrom(Assembly assembly)
|
||||
{
|
||||
List<Type> addedTypes = new List<Type>();
|
||||
|
@ -27,7 +27,11 @@ namespace NadekoBot.Services
|
||||
LogSetup.SetupLogger();
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_creds = new BotCredentials();
|
||||
|
||||
_log.Info("Starting NadekoBot v" + StatsService.BotVersion);
|
||||
|
||||
_key = _creds.RedisKey();
|
||||
_redis = ConnectionMultiplexer.Connect("127.0.0.1");
|
||||
|
||||
//setup initial shard statuses
|
||||
_defaultShardState = new ShardComMessage()
|
||||
|
Reference in New Issue
Block a user