mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-03 16:24:27 -05:00 
			
		
		
		
	- fixed remote coordinator being initialized when local one is supposed to be used
- Fixed services loading multiple times - cleaned up service adding with scrutor - INService moved from some interfaces to concrete implementation
This commit is contained in:
		@@ -20,7 +20,6 @@ using Discord.Net;
 | 
				
			|||||||
using NadekoBot.Common.ModuleBehaviors;
 | 
					using NadekoBot.Common.ModuleBehaviors;
 | 
				
			||||||
using NadekoBot.Common.Configs;
 | 
					using NadekoBot.Common.Configs;
 | 
				
			||||||
using NadekoBot.Db;
 | 
					using NadekoBot.Db;
 | 
				
			||||||
using NadekoBot.Modules.Gambling.Services;
 | 
					 | 
				
			||||||
using Serilog;
 | 
					using Serilog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot
 | 
					namespace NadekoBot
 | 
				
			||||||
@@ -108,17 +107,15 @@ namespace NadekoBot
 | 
				
			|||||||
                .AddRedis(_creds.RedisOptions) // redis
 | 
					                .AddRedis(_creds.RedisOptions) // redis
 | 
				
			||||||
                .AddSingleton(Client) // discord socket client
 | 
					                .AddSingleton(Client) // discord socket client
 | 
				
			||||||
                .AddSingleton(_commandService)
 | 
					                .AddSingleton(_commandService)
 | 
				
			||||||
                .AddSingleton(this) // pepega
 | 
					                .AddSingleton(this)
 | 
				
			||||||
                .AddSingleton<IDataCache, RedisCache>()
 | 
					                .AddSingleton<IDataCache, RedisCache>()
 | 
				
			||||||
                .AddSingleton<ISeria, JsonSeria>()
 | 
					                .AddSingleton<ISeria, JsonSeria>()
 | 
				
			||||||
                .AddSingleton<IPubSub, RedisPubSub>()
 | 
					                .AddSingleton<IPubSub, RedisPubSub>()
 | 
				
			||||||
                .AddSingleton<IConfigSeria, YamlSeria>()
 | 
					                .AddSingleton<IConfigSeria, YamlSeria>()
 | 
				
			||||||
                .AddBotStringsServices()
 | 
					                .AddBotStringsServices()
 | 
				
			||||||
                .AddConfigServices()
 | 
					                .AddConfigServices()
 | 
				
			||||||
                .AddConfigMigrators() // todo remove config migrators
 | 
					                .AddConfigMigrators()
 | 
				
			||||||
                .AddMemoryCache()
 | 
					                .AddMemoryCache()
 | 
				
			||||||
                .AddSingleton<IShopService, ShopService>()
 | 
					 | 
				
			||||||
                .AddSingleton<IBehaviourExecutor, BehaviorExecutor>()
 | 
					 | 
				
			||||||
                // music
 | 
					                // music
 | 
				
			||||||
                .AddMusic()
 | 
					                .AddMusic()
 | 
				
			||||||
                ;
 | 
					                ;
 | 
				
			||||||
@@ -142,32 +139,19 @@ namespace NadekoBot
 | 
				
			|||||||
            // todo no public bot attribute
 | 
					            // todo no public bot attribute
 | 
				
			||||||
            svcs.Scan(scan => scan
 | 
					            svcs.Scan(scan => scan
 | 
				
			||||||
                .FromAssemblyOf<IReadyExecutor>()
 | 
					                .FromAssemblyOf<IReadyExecutor>()
 | 
				
			||||||
                .AddClasses(classes => classes.AssignableTo<IReadyExecutor>())
 | 
					 | 
				
			||||||
                .AsSelf()
 | 
					 | 
				
			||||||
                .AsImplementedInterfaces()
 | 
					 | 
				
			||||||
                .WithSingletonLifetime()
 | 
					 | 
				
			||||||
                
 | 
					 | 
				
			||||||
                // behaviours
 | 
					 | 
				
			||||||
                .AddClasses(classes => classes.AssignableToAny(
 | 
					                .AddClasses(classes => classes.AssignableToAny(
 | 
				
			||||||
 | 
					                    // services
 | 
				
			||||||
 | 
					                    typeof(INService),
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    // behaviours
 | 
				
			||||||
                    typeof(IEarlyBehavior),
 | 
					                    typeof(IEarlyBehavior),
 | 
				
			||||||
                    typeof(ILateBlocker),
 | 
					                    typeof(ILateBlocker),
 | 
				
			||||||
                    typeof(IInputTransformer),
 | 
					                    typeof(IInputTransformer),
 | 
				
			||||||
                    typeof(ILateExecutor)))
 | 
					                    typeof(ILateExecutor)))
 | 
				
			||||||
                .AsSelf()
 | 
					                .AsSelfWithInterfaces()
 | 
				
			||||||
                .AsImplementedInterfaces()
 | 
					 | 
				
			||||||
                .WithSingletonLifetime()
 | 
					 | 
				
			||||||
                
 | 
					 | 
				
			||||||
                // services
 | 
					 | 
				
			||||||
                .AddClasses(classes => classes.AssignableTo<INService>())
 | 
					 | 
				
			||||||
                .AsImplementedInterfaces()
 | 
					 | 
				
			||||||
                .AsSelf()
 | 
					 | 
				
			||||||
                .WithSingletonLifetime()
 | 
					                .WithSingletonLifetime()
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // svcs.AddSingleton<IReadyExecutor>(x => x.GetService<SelfService>());
 | 
					 | 
				
			||||||
            // svcs.AddSingleton<IReadyExecutor>(x => x.GetService<CustomReactionsService>());
 | 
					 | 
				
			||||||
            // svcs.AddSingleton<IReadyExecutor>(x => x.GetService<RepeaterService>());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            //initialize Services
 | 
					            //initialize Services
 | 
				
			||||||
            Services = svcs.BuildServiceProvider();
 | 
					            Services = svcs.BuildServiceProvider();
 | 
				
			||||||
            var exec = Services.GetRequiredService<IBehaviourExecutor>();
 | 
					            var exec = Services.GetRequiredService<IBehaviourExecutor>();
 | 
				
			||||||
@@ -320,15 +304,14 @@ namespace NadekoBot
 | 
				
			|||||||
            sw.Stop();
 | 
					            sw.Stop();
 | 
				
			||||||
            Log.Information("Shard {ShardId} connected in {Elapsed:F2}s", Client.ShardId, sw.Elapsed.TotalSeconds);
 | 
					            Log.Information("Shard {ShardId} connected in {Elapsed:F2}s", Client.ShardId, sw.Elapsed.TotalSeconds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var stats = Services.GetService<IStatsService>();
 | 
					            var stats = Services.GetRequiredService<IStatsService>();
 | 
				
			||||||
            stats.Initialize();
 | 
					            stats.Initialize();
 | 
				
			||||||
            var commandHandler = Services.GetService<CommandHandler>();
 | 
					            var commandHandler = Services.GetRequiredService<CommandHandler>();
 | 
				
			||||||
            var CommandService = Services.GetService<CommandService>();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // start handling messages received in commandhandler
 | 
					            // start handling messages received in commandhandler
 | 
				
			||||||
            await commandHandler.StartHandling().ConfigureAwait(false);
 | 
					            await commandHandler.StartHandling().ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _ = await CommandService.AddModulesAsync(this.GetType().GetTypeInfo().Assembly, Services)
 | 
					            _ = await _commandService.AddModulesAsync(this.GetType().GetTypeInfo().Assembly, Services)
 | 
				
			||||||
                .ConfigureAwait(false);
 | 
					                .ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            HandleStatusChanges();
 | 
					            HandleStatusChanges();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
using Discord;
 | 
					using System;
 | 
				
			||||||
 | 
					using Discord;
 | 
				
			||||||
using Discord.Commands;
 | 
					using Discord.Commands;
 | 
				
			||||||
using Discord.WebSocket;
 | 
					using Discord.WebSocket;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore;
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ using Serilog;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Modules.Administration.Services
 | 
					namespace NadekoBot.Modules.Administration.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public sealed class SelfService : ILateExecutor, IReadyExecutor
 | 
					    public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly ConnectionMultiplexer _redis;
 | 
					        private readonly ConnectionMultiplexer _redis;
 | 
				
			||||||
        private readonly CommandHandler _cmdHandler;
 | 
					        private readonly CommandHandler _cmdHandler;
 | 
				
			||||||
@@ -54,7 +54,6 @@ namespace NadekoBot.Modules.Administration.Services
 | 
				
			|||||||
            _httpFactory = factory;
 | 
					            _httpFactory = factory;
 | 
				
			||||||
            _bss = bss;
 | 
					            _bss = bss;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Log.Information("Self service created");
 | 
					 | 
				
			||||||
            var sub = _redis.GetSubscriber();
 | 
					            var sub = _redis.GetSubscriber();
 | 
				
			||||||
            if (_client.ShardId == 0)
 | 
					            if (_client.ShardId == 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,7 +77,6 @@ namespace NadekoBot.Modules.CustomReactions.Services
 | 
				
			|||||||
            _pubSub = pubSub;
 | 
					            _pubSub = pubSub;
 | 
				
			||||||
            _rng = new NadekoRandom();
 | 
					            _rng = new NadekoRandom();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Log.Information("Custom reaction service created");
 | 
					 | 
				
			||||||
            _pubSub.Sub(_crsReloadedKey, OnCrsShouldReload);
 | 
					            _pubSub.Sub(_crsReloadedKey, OnCrsShouldReload);
 | 
				
			||||||
            pubSub.Sub(_gcrAddedKey, OnGcrAdded);
 | 
					            pubSub.Sub(_gcrAddedKey, OnGcrAdded);
 | 
				
			||||||
            pubSub.Sub(_gcrDeletedkey, OnGcrDeleted);
 | 
					            pubSub.Sub(_gcrDeletedkey, OnGcrDeleted);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@ using NadekoBot.Modules.Administration;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Modules.Gambling.Services
 | 
					namespace NadekoBot.Modules.Gambling.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class ShopService : IShopService
 | 
					    public class ShopService : IShopService, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly DbService _db;
 | 
					        private readonly DbService _db;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ using Serilog;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Modules.Utility.Services
 | 
					namespace NadekoBot.Modules.Utility.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public sealed class RepeaterService : IReadyExecutor
 | 
					    public sealed class RepeaterService : IReadyExecutor, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public const int MAX_REPEATERS = 5;
 | 
					        public const int MAX_REPEATERS = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public interface ICurrencyService : INService
 | 
					    public interface ICurrencyService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Task AddAsync(ulong userId, string reason, long amount, bool gamble = false);
 | 
					        Task AddAsync(ulong userId, string reason, long amount, bool gamble = false);
 | 
				
			||||||
        Task AddAsync(IUser user, string reason, long amount, bool sendMessage = false, bool gamble = false);
 | 
					        Task AddAsync(IUser user, string reason, long amount, bool sendMessage = false, bool gamble = false);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ using Discord;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public interface ILocalization : INService
 | 
					    public interface ILocalization
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        CultureInfo DefaultCultureInfo { get; }
 | 
					        CultureInfo DefaultCultureInfo { get; }
 | 
				
			||||||
        ConcurrentDictionary<ulong, CultureInfo> GuildCultureInfos { get; }
 | 
					        ConcurrentDictionary<ulong, CultureInfo> GuildCultureInfos { get; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public interface IStatsService : INService
 | 
					    public interface IStatsService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        string Author { get; }
 | 
					        string Author { get; }
 | 
				
			||||||
        long CommandsRan { get; }
 | 
					        long CommandsRan { get; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@ using Microsoft.Extensions.DependencyInjection;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public sealed class BehaviorExecutor : IBehaviourExecutor
 | 
					    public sealed class BehaviorExecutor : IBehaviourExecutor, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly IServiceProvider _services;
 | 
					        private readonly IServiceProvider _services;
 | 
				
			||||||
        private IEnumerable<ILateExecutor> _lateExecutors;
 | 
					        private IEnumerable<ILateExecutor> _lateExecutors;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ using NadekoBot.Modules.Gambling.Services;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class CurrencyService : ICurrencyService
 | 
					    public class CurrencyService : ICurrencyService, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly DbService _db;
 | 
					        private readonly DbService _db;
 | 
				
			||||||
        private readonly GamblingConfigService _gss;
 | 
					        private readonly GamblingConfigService _gss;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@ using Serilog;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class GoogleApiService : IGoogleApiService
 | 
					    public class GoogleApiService : IGoogleApiService, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private const string SearchEngineId = "018084019232060951019:hs5piey28-e";
 | 
					        private const string SearchEngineId = "018084019232060951019:hs5piey28-e";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@ using NadekoBot.Modules.Administration;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class Localization : ILocalization
 | 
					    public class Localization : ILocalization, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly BotConfigService _bss;
 | 
					        private readonly BotConfigService _bss;
 | 
				
			||||||
        private readonly DbService _db;
 | 
					        private readonly DbService _db;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ using Serilog;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Services
 | 
					namespace NadekoBot.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class StatsService : IStatsService
 | 
					    public class StatsService : IStatsService, INService
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly DiscordSocketClient _client;
 | 
					        private readonly DiscordSocketClient _client;
 | 
				
			||||||
        private readonly IBotCredentials _creds;
 | 
					        private readonly IBotCredentials _creds;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user