using MatrixContentFilter; using MatrixContentFilter.Handlers; using LibMatrix.Services; using LibMatrix.Utilities.Bot; using MatrixContentFilter.Abstractions; using MatrixContentFilter.Handlers.Filters; using MatrixContentFilter.Services; using MatrixContentFilter.Services.AsyncActionQueues; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; var builder = Host.CreateDefaultBuilder(args); builder.ConfigureHostOptions(host => { host.ServicesStartConcurrently = true; host.ServicesStopConcurrently = true; host.ShutdownTimeout = TimeSpan.FromSeconds(5); }); if (Environment.GetEnvironmentVariable("MATRIXCONTENTFILTER_APPSETTINGS_PATH") is string path) builder.ConfigureAppConfiguration(x => x.AddJsonFile(path)); var host = builder.ConfigureServices((ctx, services) => { var config = new MatrixContentFilterConfiguration(ctx.Configuration); services.AddSingleton(config); services.AddRoryLibMatrixServices(new() { AppName = "MatrixContentFilter" }); services.AddMatrixBot().AddCommandHandler().DiscoverAllCommands() .WithInviteHandler(InviteHandler.HandleAsync) .WithCommandResultHandler(CommandResultHandler.HandleAsync); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(s => s.GetRequiredService()); services.AddSingleton(); services.AddSingleton(s => s.GetRequiredService()); switch (config.AppMode) { case "bot": services.AddHostedService(); // services.AddHostedService(); break; default: throw new NotSupportedException($"Unknown app mode: {config.AppMode}"); } switch (config.AsyncQueueImplementation) { case "lifo": services.AddSingleton(); services.AddSingleton(s => s.GetRequiredService()); services.AddSingleton(s => s.GetRequiredService()); break; case "fifo": services.AddSingleton(); services.AddSingleton(s => s.GetRequiredService()); services.AddSingleton(s => s.GetRequiredService()); break; default: throw new NotSupportedException($"Unknown async queue implementation: {config.AsyncQueueImplementation}"); } }).UseConsoleLifetime().Build(); await host.RunAsync();