mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	Some reorganization, still completely broken
This commit is contained in:
		@@ -132,37 +132,10 @@ public sealed class Bot
 | 
			
		||||
            kernel.Bind<ICoordinator, IReadyExecutor>().To<RemoteGrpcCoordinator>().InSingletonScope();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        kernel.Bind(scan =>
 | 
			
		||||
        {
 | 
			
		||||
            var classes = scan.FromThisAssembly()
 | 
			
		||||
                              .SelectAllClasses()
 | 
			
		||||
                              .Where(c => (c.IsAssignableTo(typeof(INService))
 | 
			
		||||
                                           || c.IsAssignableTo(typeof(IExecOnMessage))
 | 
			
		||||
                                           || c.IsAssignableTo(typeof(IInputTransformer))
 | 
			
		||||
                                           || c.IsAssignableTo(typeof(IExecPreCommand))
 | 
			
		||||
                                           || c.IsAssignableTo(typeof(IExecPostCommand))
 | 
			
		||||
                                           || c.IsAssignableTo(typeof(IExecNoCommand)))
 | 
			
		||||
                                          && !c.HasAttribute<DontAddToIocContainerAttribute>()
 | 
			
		||||
#if GLOBAL_NADEKO
 | 
			
		||||
                                                && !c.HasAttribute<NoPublicBotAttribute>()
 | 
			
		||||
#endif
 | 
			
		||||
                              );
 | 
			
		||||
            classes
 | 
			
		||||
                .BindAllInterfaces()
 | 
			
		||||
                .Configure(c => c.InSingletonScope());
 | 
			
		||||
 | 
			
		||||
            classes.BindToSelf()
 | 
			
		||||
                   .Configure(c => c.InSingletonScope());
 | 
			
		||||
        });
 | 
			
		||||
        kernel.AddLifetimeServices(); 
 | 
			
		||||
 | 
			
		||||
        kernel.Bind<IServiceProvider>().ToConstant(kernel).InSingletonScope();
 | 
			
		||||
 | 
			
		||||
        var services = kernel.GetServices(typeof(INService));
 | 
			
		||||
        foreach (var s in services)
 | 
			
		||||
        {
 | 
			
		||||
            Console.WriteLine(s.GetType().FullName);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //initialize Services
 | 
			
		||||
        Services = kernel;
 | 
			
		||||
        Services.GetRequiredService<IBehaviorHandler>().Initialize();
 | 
			
		||||
@@ -348,6 +321,7 @@ public sealed class Bot
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine(toExec.GetType().FullName);
 | 
			
		||||
                await toExec.OnReadyAsync();
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,8 @@ public sealed record MedusaStats(string Name,
 | 
			
		||||
    string? Description,
 | 
			
		||||
    IReadOnlyCollection<SnekStats> Sneks);
 | 
			
		||||
    
 | 
			
		||||
public sealed record SnekStats(string Name, 
 | 
			
		||||
public sealed record SnekStats(string Name,
 | 
			
		||||
    string? Prefix,
 | 
			
		||||
    IReadOnlyCollection<SnekCommandStats> Commands);
 | 
			
		||||
 | 
			
		||||
public sealed record SnekCommandStats(string Name);
 | 
			
		||||
@@ -79,7 +79,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
 | 
			
		||||
                    commands.Add(new SnekCommandStats(command.Aliases.First()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                sneks.Add(new SnekStats(snekInfos.Name, commands));
 | 
			
		||||
                sneks.Add(new SnekStats(snekInfos.Name, snekInfos.Instance.Prefix, commands));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            toReturn.Add(new MedusaStats(name, resolvedData.Strings.GetDescription(culture), sneks));
 | 
			
		||||
 
 | 
			
		||||
@@ -150,9 +150,10 @@ public partial class Medusa : NadekoModule<IMedusaLoaderService>
 | 
			
		||||
 | 
			
		||||
            var cmdCount = found.Sneks.Sum(x => x.Commands.Count);
 | 
			
		||||
            var cmdNames = found.Sneks
 | 
			
		||||
                                .SelectMany(x => x.Commands)
 | 
			
		||||
                                   .Select(x => Format.Code(x.Name))
 | 
			
		||||
                                   .Join(" | ");
 | 
			
		||||
                                   .SelectMany(x => Format.Code(string.IsNullOrWhiteSpace(x.Prefix)
 | 
			
		||||
                                       ? x.Name
 | 
			
		||||
                                       : $"{x.Prefix} {x.Name}"))
 | 
			
		||||
                                   .Join("\n");
 | 
			
		||||
 | 
			
		||||
            var eb = _eb.Create(ctx)
 | 
			
		||||
                        .WithOkColor()
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,7 @@ public partial class SearchesConfig : ICloneable<SearchesConfig>
 | 
			
		||||
        
 | 
			
		||||
        - `invidious` - recommended advanced, uses invidious api. Requires at least one invidious instance specified in the `invidiousInstances` property
 | 
			
		||||
        """)]
 | 
			
		||||
    public YoutubeSearcher YtProvider { get; set; } = YoutubeSearcher.Ytdl;
 | 
			
		||||
    public YoutubeSearcher YtProvider { get; set; } = YoutubeSearcher.Ytdlp;
 | 
			
		||||
 | 
			
		||||
    [Comment("""
 | 
			
		||||
        Set the searx instance urls in case you want to use 'searx' for either img or web search.
 | 
			
		||||
 
 | 
			
		||||
@@ -55,10 +55,13 @@ public class CommandHandler : INService, IReadyExecutor
 | 
			
		||||
        _prefixes = bot.AllGuildConfigs.Where(x => x.Prefix is not null)
 | 
			
		||||
                       .ToDictionary(x => x.GuildId, x => x.Prefix)
 | 
			
		||||
                       .ToConcurrent();
 | 
			
		||||
 | 
			
		||||
        Console.WriteLine("Command handler created");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async Task OnReadyAsync()
 | 
			
		||||
    {
 | 
			
		||||
        Log.Information("Command handler runnning on ready");
 | 
			
		||||
        // clear users on short cooldown every GLOBAL_COMMANDS_COOLDOWN miliseconds
 | 
			
		||||
        using var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(GLOBAL_COMMANDS_COOLDOWN));
 | 
			
		||||
        while (await timer.WaitForNextTickAsync())
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,8 @@ using Ninject.Extensions.Conventions;
 | 
			
		||||
using StackExchange.Redis;
 | 
			
		||||
using System.Net;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using NadekoBot.Common.ModuleBehaviors;
 | 
			
		||||
using Ninject.Infrastructure.Language;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Extensions;
 | 
			
		||||
 | 
			
		||||
@@ -125,4 +127,31 @@ public static class ServiceCollectionExtensions
 | 
			
		||||
 | 
			
		||||
        return kernel;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static IKernel AddLifetimeServices(this IKernel kernel)
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
        Assembly.GetExecutingAssembly()
 | 
			
		||||
            .ExportedTypes
 | 
			
		||||
            .Where(x => x.IsPublic && x.IsClass && !x.IsAbstract)
 | 
			
		||||
            .Where(c => (c.IsAssignableTo(typeof(INService))
 | 
			
		||||
                             || c.IsAssignableTo(typeof(IExecOnMessage))
 | 
			
		||||
                             || c.IsAssignableTo(typeof(IInputTransformer))
 | 
			
		||||
                             || c.IsAssignableTo(typeof(IExecPreCommand))
 | 
			
		||||
                             || c.IsAssignableTo(typeof(IExecPostCommand))
 | 
			
		||||
                             || c.IsAssignableTo(typeof(IExecNoCommand)))
 | 
			
		||||
                            && !c.HasAttribute<DontAddToIocContainerAttribute>()
 | 
			
		||||
#if GLOBAL_NADEKO
 | 
			
		||||
                                                && !c.HasAttribute<NoPublicBotAttribute>()
 | 
			
		||||
#endif
 | 
			
		||||
                );
 | 
			
		||||
        
 | 
			
		||||
            /*
 | 
			
		||||
            classes.BindToSelf()
 | 
			
		||||
                .Configure(c => c.InSingletonScope());
 | 
			
		||||
                */
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        return kernel;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user