mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 02:08:27 -04: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<ICoordinator, IReadyExecutor>().To<RemoteGrpcCoordinator>().InSingletonScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel.Bind(scan =>
|
kernel.AddLifetimeServices();
|
||||||
{
|
|
||||||
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.Bind<IServiceProvider>().ToConstant(kernel).InSingletonScope();
|
kernel.Bind<IServiceProvider>().ToConstant(kernel).InSingletonScope();
|
||||||
|
|
||||||
var services = kernel.GetServices(typeof(INService));
|
|
||||||
foreach (var s in services)
|
|
||||||
{
|
|
||||||
Console.WriteLine(s.GetType().FullName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//initialize Services
|
//initialize Services
|
||||||
Services = kernel;
|
Services = kernel;
|
||||||
Services.GetRequiredService<IBehaviorHandler>().Initialize();
|
Services.GetRequiredService<IBehaviorHandler>().Initialize();
|
||||||
@@ -348,6 +321,7 @@ public sealed class Bot
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(toExec.GetType().FullName);
|
||||||
await toExec.OnReadyAsync();
|
await toExec.OnReadyAsync();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@@ -18,6 +18,7 @@ public sealed record MedusaStats(string Name,
|
|||||||
IReadOnlyCollection<SnekStats> Sneks);
|
IReadOnlyCollection<SnekStats> Sneks);
|
||||||
|
|
||||||
public sealed record SnekStats(string Name,
|
public sealed record SnekStats(string Name,
|
||||||
|
string? Prefix,
|
||||||
IReadOnlyCollection<SnekCommandStats> Commands);
|
IReadOnlyCollection<SnekCommandStats> Commands);
|
||||||
|
|
||||||
public sealed record SnekCommandStats(string Name);
|
public sealed record SnekCommandStats(string Name);
|
@@ -79,7 +79,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor,
|
|||||||
commands.Add(new SnekCommandStats(command.Aliases.First()));
|
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));
|
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 cmdCount = found.Sneks.Sum(x => x.Commands.Count);
|
||||||
var cmdNames = found.Sneks
|
var cmdNames = found.Sneks
|
||||||
.SelectMany(x => x.Commands)
|
.SelectMany(x => Format.Code(string.IsNullOrWhiteSpace(x.Prefix)
|
||||||
.Select(x => Format.Code(x.Name))
|
? x.Name
|
||||||
.Join(" | ");
|
: $"{x.Prefix} {x.Name}"))
|
||||||
|
.Join("\n");
|
||||||
|
|
||||||
var eb = _eb.Create(ctx)
|
var eb = _eb.Create(ctx)
|
||||||
.WithOkColor()
|
.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
|
- `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("""
|
[Comment("""
|
||||||
Set the searx instance urls in case you want to use 'searx' for either img or web search.
|
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)
|
_prefixes = bot.AllGuildConfigs.Where(x => x.Prefix is not null)
|
||||||
.ToDictionary(x => x.GuildId, x => x.Prefix)
|
.ToDictionary(x => x.GuildId, x => x.Prefix)
|
||||||
.ToConcurrent();
|
.ToConcurrent();
|
||||||
|
|
||||||
|
Console.WriteLine("Command handler created");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnReadyAsync()
|
public async Task OnReadyAsync()
|
||||||
{
|
{
|
||||||
|
Log.Information("Command handler runnning on ready");
|
||||||
// clear users on short cooldown every GLOBAL_COMMANDS_COOLDOWN miliseconds
|
// clear users on short cooldown every GLOBAL_COMMANDS_COOLDOWN miliseconds
|
||||||
using var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(GLOBAL_COMMANDS_COOLDOWN));
|
using var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(GLOBAL_COMMANDS_COOLDOWN));
|
||||||
while (await timer.WaitForNextTickAsync())
|
while (await timer.WaitForNextTickAsync())
|
||||||
|
@@ -8,6 +8,8 @@ using Ninject.Extensions.Conventions;
|
|||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
|
using Ninject.Infrastructure.Language;
|
||||||
|
|
||||||
namespace NadekoBot.Extensions;
|
namespace NadekoBot.Extensions;
|
||||||
|
|
||||||
@@ -125,4 +127,31 @@ public static class ServiceCollectionExtensions
|
|||||||
|
|
||||||
return kernel;
|
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