diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 4e1d07a15..499216b4a 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -132,37 +132,10 @@ public sealed class Bot kernel.Bind().To().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() -#if GLOBAL_NADEKO - && !c.HasAttribute() -#endif - ); - classes - .BindAllInterfaces() - .Configure(c => c.InSingletonScope()); - - classes.BindToSelf() - .Configure(c => c.InSingletonScope()); - }); + kernel.AddLifetimeServices(); kernel.Bind().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().Initialize(); @@ -348,6 +321,7 @@ public sealed class Bot { try { + Console.WriteLine(toExec.GetType().FullName); await toExec.OnReadyAsync(); } catch (Exception ex) diff --git a/src/NadekoBot/Common/Medusa/IMedusaLoaderService.cs b/src/NadekoBot/Common/Medusa/IMedusaLoaderService.cs index 9b60c418b..06812a8e1 100644 --- a/src/NadekoBot/Common/Medusa/IMedusaLoaderService.cs +++ b/src/NadekoBot/Common/Medusa/IMedusaLoaderService.cs @@ -17,7 +17,8 @@ public sealed record MedusaStats(string Name, string? Description, IReadOnlyCollection Sneks); -public sealed record SnekStats(string Name, +public sealed record SnekStats(string Name, + string? Prefix, IReadOnlyCollection Commands); public sealed record SnekCommandStats(string Name); \ No newline at end of file diff --git a/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs b/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs index 2e25622ad..8f6c30f2f 100644 --- a/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs +++ b/src/NadekoBot/Common/Medusa/MedusaLoaderService.cs @@ -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)); diff --git a/src/NadekoBot/Modules/Medusae/Medusa.cs b/src/NadekoBot/Modules/Medusae/Medusa.cs index 3d28c028a..13ba3d2f1 100644 --- a/src/NadekoBot/Modules/Medusae/Medusa.cs +++ b/src/NadekoBot/Modules/Medusae/Medusa.cs @@ -150,9 +150,10 @@ public partial class Medusa : NadekoModule 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() diff --git a/src/NadekoBot/Modules/Searches/_Common/Config/SearchesConfig.cs b/src/NadekoBot/Modules/Searches/_Common/Config/SearchesConfig.cs index a9b7165ff..b584276b3 100644 --- a/src/NadekoBot/Modules/Searches/_Common/Config/SearchesConfig.cs +++ b/src/NadekoBot/Modules/Searches/_Common/Config/SearchesConfig.cs @@ -36,7 +36,7 @@ public partial class SearchesConfig : ICloneable - `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. diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index f7ac2a3d0..02efb0914 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -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()) diff --git a/src/NadekoBot/_Extensions/ServiceCollectionExtensions.cs b/src/NadekoBot/_Extensions/ServiceCollectionExtensions.cs index 034911e71..3b3a00377 100644 --- a/src/NadekoBot/_Extensions/ServiceCollectionExtensions.cs +++ b/src/NadekoBot/_Extensions/ServiceCollectionExtensions.cs @@ -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() +#if GLOBAL_NADEKO + && !c.HasAttribute() +#endif + ); + + /* + classes.BindToSelf() + .Configure(c => c.InSingletonScope()); + */ + }); + + return kernel; + } } \ No newline at end of file