diff --git a/src/NadekoBot.Tests/NadekoBot.Tests.csproj b/src/NadekoBot.Tests/NadekoBot.Tests.csproj
index 06b68d4b1..81056fc9e 100644
--- a/src/NadekoBot.Tests/NadekoBot.Tests.csproj
+++ b/src/NadekoBot.Tests/NadekoBot.Tests.csproj
@@ -3,6 +3,7 @@
net6.0
10.0
+ True
false
diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs
index 20cfd3391..32e1cd30d 100644
--- a/src/NadekoBot/Bot.cs
+++ b/src/NadekoBot/Bot.cs
@@ -6,11 +6,8 @@ using NadekoBot.Common;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Extensions;
-using System;
-using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
-using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
@@ -19,83 +16,81 @@ using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Common.Configs;
using NadekoBot.Db;
using NadekoBot.Modules.Administration.Services;
-using NadekoBot.Modules.Searches;
-using Serilog;
-namespace NadekoBot
+namespace NadekoBot;
+
+public sealed class Bot
{
- public sealed class Bot
+ private readonly IBotCredentials _creds;
+ private readonly CommandService _commandService;
+ private readonly DbService _db;
+ private readonly IBotCredsProvider _credsProvider;
+
+ public event Func JoinedGuild = delegate { return Task.CompletedTask; };
+
+ public DiscordSocketClient Client { get; }
+ public ImmutableArray AllGuildConfigs { get; private set; }
+
+ private IServiceProvider Services { get; set; }
+
+ public string Mention { get; private set; }
+ public bool IsReady { get; private set; }
+
+ public Bot(int shardId, int? totalShards)
{
- private readonly IBotCredentials _creds;
- private readonly CommandService _commandService;
- private readonly DbService _db;
- private readonly IBotCredsProvider _credsProvider;
-
- public event Func JoinedGuild = delegate { return Task.CompletedTask; };
-
- public DiscordSocketClient Client { get; }
- public ImmutableArray AllGuildConfigs { get; private set; }
+ if (shardId < 0)
+ throw new ArgumentOutOfRangeException(nameof(shardId));
- private IServiceProvider Services { get; set; }
-
- public string Mention { get; private set; }
- public bool IsReady { get; private set; }
-
- public Bot(int shardId, int? totalShards)
- {
- if (shardId < 0)
- throw new ArgumentOutOfRangeException(nameof(shardId));
-
- _credsProvider = new BotCredsProvider(totalShards);
- _creds = _credsProvider.GetCreds();
+ _credsProvider = new BotCredsProvider(totalShards);
+ _creds = _credsProvider.GetCreds();
- _db = new DbService(_creds);
+ _db = new DbService(_creds);
- if (shardId == 0)
- {
- _db.Setup();
- }
+ if (shardId == 0)
+ {
+ _db.Setup();
+ }
- Client = new DiscordSocketClient(new DiscordSocketConfig
- {
- MessageCacheSize = 50,
- LogLevel = LogSeverity.Warning,
- ConnectionTimeout = int.MaxValue,
- TotalShards = _creds.TotalShards,
- ShardId = shardId,
- AlwaysDownloadUsers = false,
- ExclusiveBulkDelete = true,
- });
+ Client = new DiscordSocketClient(new DiscordSocketConfig
+ {
+ MessageCacheSize = 50,
+ LogLevel = LogSeverity.Warning,
+ ConnectionTimeout = int.MaxValue,
+ TotalShards = _creds.TotalShards,
+ ShardId = shardId,
+ AlwaysDownloadUsers = false,
+ ExclusiveBulkDelete = true,
+ });
- _commandService = new CommandService(new CommandServiceConfig()
- {
- CaseSensitiveCommands = false,
- DefaultRunMode = RunMode.Sync,
- });
+ _commandService = new CommandService(new CommandServiceConfig()
+ {
+ CaseSensitiveCommands = false,
+ DefaultRunMode = RunMode.Sync,
+ });
#if GLOBAL_NADEKO || DEBUG
- Client.Log += Client_Log;
+ Client.Log += Client_Log;
#endif
- }
+ }
- public List GetCurrentGuildIds()
+ public List GetCurrentGuildIds()
+ {
+ return Client.Guilds.Select(x => x.Id).ToList();
+ }
+
+ private void AddServices()
+ {
+ var startingGuildIdList = GetCurrentGuildIds();
+ var sw = Stopwatch.StartNew();
+ var _bot = Client.CurrentUser;
+
+ using (var uow = _db.GetDbContext())
{
- return Client.Guilds.Select(x => x.Id).ToList();
+ uow.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId);
+ AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
}
-
- private void AddServices()
- {
- var startingGuildIdList = GetCurrentGuildIds();
- var sw = Stopwatch.StartNew();
- var _bot = Client.CurrentUser;
-
- using (var uow = _db.GetDbContext())
- {
- uow.EnsureUserCreated(_bot.Id, _bot.Username, _bot.Discriminator, _bot.AvatarId);
- AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
- }
- var svcs = new ServiceCollection()
+ var svcs = new ServiceCollection()
.AddTransient(_ => _credsProvider.GetCreds()) // bot creds
.AddSingleton(_credsProvider)
.AddSingleton(_db) // database
@@ -118,248 +113,247 @@ namespace NadekoBot
#else
.AddSingleton()
#endif
- ;
+ ;
- svcs.AddHttpClient();
- svcs.AddHttpClient("memelist").ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
- {
- AllowAutoRedirect = false
- });
+ svcs.AddHttpClient();
+ svcs.AddHttpClient("memelist").ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
+ {
+ AllowAutoRedirect = false
+ });
- if (Environment.GetEnvironmentVariable("NADEKOBOT_IS_COORDINATED") != "1")
- {
- svcs.AddSingleton();
- }
- else
- {
- svcs.AddSingleton()
- .AddSingleton(x => x.GetRequiredService())
- .AddSingleton(x => x.GetRequiredService());
- }
+ if (Environment.GetEnvironmentVariable("NADEKOBOT_IS_COORDINATED") != "1")
+ {
+ svcs.AddSingleton();
+ }
+ else
+ {
+ svcs.AddSingleton()
+ .AddSingleton(x => x.GetRequiredService())
+ .AddSingleton(x => x.GetRequiredService());
+ }
- svcs.AddSingleton()
- .AddSingleton(x => x.GetRequiredService())
- .AddSingleton()
- .AddSingleton(x => x.GetRequiredService())
- .AddSingleton(x => x.GetRequiredService())
- .AddSingleton();
+ svcs.AddSingleton()
+ .AddSingleton(x => x.GetRequiredService())
+ .AddSingleton()
+ .AddSingleton(x => x.GetRequiredService())
+ .AddSingleton(x => x.GetRequiredService())
+ .AddSingleton();
- svcs.Scan(scan => scan
- .FromAssemblyOf()
- .AddClasses(classes => classes
- .AssignableToAny(
- // services
- typeof(INService),
+ svcs.Scan(scan => scan
+ .FromAssemblyOf()
+ .AddClasses(classes => classes
+ .AssignableToAny(
+ // services
+ typeof(INService),
- // behaviours
- typeof(IEarlyBehavior),
- typeof(ILateBlocker),
- typeof(IInputTransformer),
- typeof(ILateExecutor))
+ // behaviours
+ typeof(IEarlyBehavior),
+ typeof(ILateBlocker),
+ typeof(IInputTransformer),
+ typeof(ILateExecutor))
#if GLOBAL_NADEKO
.WithoutAttribute()
#endif
- )
- .AsSelfWithInterfaces()
- .WithSingletonLifetime()
- );
+ )
+ .AsSelfWithInterfaces()
+ .WithSingletonLifetime()
+ );
- //initialize Services
- Services = svcs.BuildServiceProvider();
- var exec = Services.GetRequiredService();
- exec.Initialize();
+ //initialize Services
+ Services = svcs.BuildServiceProvider();
+ var exec = Services.GetRequiredService();
+ exec.Initialize();
- if (Client.ShardId == 0)
- {
- ApplyConfigMigrations();
- }
+ if (Client.ShardId == 0)
+ {
+ ApplyConfigMigrations();
+ }
- _ = LoadTypeReaders(typeof(Bot).Assembly);
+ _ = LoadTypeReaders(typeof(Bot).Assembly);
- sw.Stop();
- Log.Information($"All services loaded in {sw.Elapsed.TotalSeconds:F2}s");
- }
+ sw.Stop();
+ Log.Information($"All services loaded in {sw.Elapsed.TotalSeconds:F2}s");
+ }
- private void ApplyConfigMigrations()
+ private void ApplyConfigMigrations()
+ {
+ // execute all migrators
+ var migrators = Services.GetServices();
+ foreach (var migrator in migrators)
{
- // execute all migrators
- var migrators = Services.GetServices();
- foreach (var migrator in migrators)
- {
- migrator.EnsureMigrated();
- }
- }
-
- private IEnumerable