diff --git a/src/YumeChan.ConsoleRunner/ConsoleRunnerContext.cs b/src/YumeChan.ConsoleRunner/ConsoleRunnerContext.cs index 00edfca..b81285f 100644 --- a/src/YumeChan.ConsoleRunner/ConsoleRunnerContext.cs +++ b/src/YumeChan.ConsoleRunner/ConsoleRunnerContext.cs @@ -2,4 +2,4 @@ namespace YumeChan.ConsoleRunner; -internal record ConsoleRunnerContext(RunnerType RunnerType, string RunnerName, string RunnerVersion) : IRunnerContext; \ No newline at end of file +internal sealed record ConsoleRunnerContext(RunnerType RunnerType, string RunnerName, string RunnerVersion) : IRunnerContext; \ No newline at end of file diff --git a/src/YumeChan.ConsoleRunner/Program.cs b/src/YumeChan.ConsoleRunner/Program.cs index 08e7072..3490c9c 100644 --- a/src/YumeChan.ConsoleRunner/Program.cs +++ b/src/YumeChan.ConsoleRunner/Program.cs @@ -15,7 +15,7 @@ namespace YumeChan.ConsoleRunner; public static class Program { - private static readonly LoggerConfiguration SerilogConfiguration = new LoggerConfiguration() + private static readonly LoggerConfiguration _serilogConfiguration = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .MinimumLevel.Override("DSharpPlus", LogEventLevel.Information) @@ -24,13 +24,13 @@ public static class Program private static readonly string _informationalVersion = Assembly.GetEntryAssembly()?.GetCustomAttribute()?.InformationalVersion; - public static async Task Main(string[] _) + public static async Task Main(string[] args) { - Log.Logger = SerilogConfiguration.CreateLogger(); + Log.Logger = _serilogConfiguration.CreateLogger(); - IHost host = CreateHostBuilder().Build(); + IHost host = CreateHostBuilder(args).Build(); await using AsyncServiceScope scope = host.Services.CreateAsyncScope(); IServiceProvider services = scope.ServiceProvider; @@ -46,7 +46,7 @@ public static async Task Main(string[] _) await host.WaitForShutdownAsync(); } - public static IHostBuilder CreateHostBuilder() => new HostBuilder() + public static IHostBuilder CreateHostBuilder(string[] args) => new HostBuilder() .UseServiceProviderFactory(new DryIocServiceProviderFactory()) .ConfigureLogging(static x => x.ClearProviders()) .UseSerilog() diff --git a/src/YumeChan.Core/CommandHandler.cs b/src/YumeChan.Core/CommandHandler.cs index 01147f8..2337d3f 100644 --- a/src/YumeChan.Core/CommandHandler.cs +++ b/src/YumeChan.Core/CommandHandler.cs @@ -254,7 +254,7 @@ private async Task OnSlashCommandErroredAsync(SlashCommandsExtension _, SlashCom SlashRequireGuildAttribute => "Sorry, not here. Please send this command in a server.", // SlashRequireNsfwAttribute => "Sorry. As much as I'd love to, I've gotta keep the hot stuff to the right channels.", // SlashCooldownAttribute cd => $"Sorry. This command is on Cooldown. You can use it {cd.MaxUses} time(s) every {cd.Reset.TotalSeconds} seconds.", - SlashRequireUserPermissionsAttribute p => $"Sorry. You need to have permission(s) ``{p.Permissions}`` to run this.", + SlashRequireUserPermissionsAttribute p => $"Sorry. You need to have permission(s) {p.Permissions:F} (``0x{p.Permissions:X}``) to run this.", _ => null }).ToArray(); diff --git a/src/YumeChan.Core/Infrastructure/YumeCoreDependencyInjectionExtensions.cs b/src/YumeChan.Core/Infrastructure/YumeCoreDependencyInjectionExtensions.cs index 4b8cfba..ba62f26 100644 --- a/src/YumeChan.Core/Infrastructure/YumeCoreDependencyInjectionExtensions.cs +++ b/src/YumeChan.Core/Infrastructure/YumeCoreDependencyInjectionExtensions.cs @@ -17,6 +17,26 @@ namespace Microsoft.Extensions.DependencyInjection; /// public static class YumeCoreDependencyInjectionExtensions { + /// + /// Extension method for to add custom services necessary for running the YumeCore application. + /// This method configures a comprehensive service pipeline including various singleton services, database providers, configuration providers, and an HTTP client. + /// + /// An instance of . + /// The same service collection passed in, enabling chained configuration calls. + /// + /// + /// Components added to the DI pipeline: + /// + /// - a singleton service instance for the application. + /// - a singleton service with initial settings for intents, token type, token, logger factory, and minimum log level. + /// - a singleton that loads plugins from the path specified in . + /// Singleton instances of , , , , and . + /// Services for MongoDB and Postgres are set up using a class , which implements and . + /// and generic services provide configuration data. + /// and instances are added with configurations loaded from 'coreconfig.json' and 'plugins.json' respectively. + /// An is registered and configured via the HttpClientFactory for making HTTP requests, and the is added to the client. + /// + /// public static IServiceCollection AddYumeCoreServices(this IServiceCollection services) { services.AddSingleton(); diff --git a/src/YumeChan.NetRunner/Infrastructure/Blazor/ComponentActivator.cs b/src/YumeChan.NetRunner/Infrastructure/Blazor/ComponentActivator.cs index 459a262..034ab4e 100644 --- a/src/YumeChan.NetRunner/Infrastructure/Blazor/ComponentActivator.cs +++ b/src/YumeChan.NetRunner/Infrastructure/Blazor/ComponentActivator.cs @@ -9,7 +9,7 @@ public sealed class ComponentActivator : IComponentActivator public ComponentActivator(IContainer container) { - this._container = container; + _container = container; } public IComponent CreateInstance(Type type) diff --git a/src/YumeChan.NetRunner/NetRunnerContext.cs b/src/YumeChan.NetRunner/NetRunnerContext.cs index 7fe0431..a292742 100644 --- a/src/YumeChan.NetRunner/NetRunnerContext.cs +++ b/src/YumeChan.NetRunner/NetRunnerContext.cs @@ -2,4 +2,4 @@ namespace YumeChan.NetRunner; -internal record NetRunnerContext(RunnerType RunnerType, string RunnerName, string RunnerVersion) : IRunnerContext; \ No newline at end of file +internal sealed record NetRunnerContext(RunnerType RunnerType, string RunnerName, string RunnerVersion) : IRunnerContext; \ No newline at end of file diff --git a/src/YumeChan.NetRunner/Program.cs b/src/YumeChan.NetRunner/Program.cs index c81058a..187b868 100644 --- a/src/YumeChan.NetRunner/Program.cs +++ b/src/YumeChan.NetRunner/Program.cs @@ -12,18 +12,16 @@ namespace YumeChan.NetRunner; public static class Program { private static Container _container = new(); + private static readonly LoggerConfiguration _loggerConfiguration = new LoggerConfiguration() + .MinimumLevel.Debug() + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) + .Enrich.FromLogContext() + .WriteTo.Console(); public static async Task Main(string[] args) { - - - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .Enrich.FromLogContext() - .WriteTo.Console() - .CreateLogger(); + Log.Logger = _loggerConfiguration.CreateLogger(); using IHost host = CreateHostBuilder(args).Build(); IServiceProvider services = host.Services; @@ -34,15 +32,13 @@ public static async Task Main(string[] args) yumeCore.StartBotAsync(), host.RunAsync() ); - - await host.WaitForShutdownAsync(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseServiceProviderFactory(new DryIocServiceProviderFactory()) .ConfigureLogging(x => x.ClearProviders()) .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup()) -// .ConfigureContainer((_, container) => container -// .WithDependencyInjectionAdapter() -// ) + .ConfigureContainer((_, container) => container + .WithDependencyInjectionAdapter() + ) ; } diff --git a/src/YumeChan.NetRunner/Services/Authentication/UserRoles.cs b/src/YumeChan.NetRunner/Services/Authentication/UserRoles.cs index 6296c3b..1b79c27 100644 --- a/src/YumeChan.NetRunner/Services/Authentication/UserRoles.cs +++ b/src/YumeChan.NetRunner/Services/Authentication/UserRoles.cs @@ -2,7 +2,5 @@ public static class UserRoles { - public const string - Admin = "Admin" - ; + public const string Admin = "Admin"; } diff --git a/src/YumeChan.NetRunner/Services/Authentication/WebAppClaims.cs b/src/YumeChan.NetRunner/Services/Authentication/WebAppClaims.cs index 9e33dec..76dbb46 100644 --- a/src/YumeChan.NetRunner/Services/Authentication/WebAppClaims.cs +++ b/src/YumeChan.NetRunner/Services/Authentication/WebAppClaims.cs @@ -1,15 +1,14 @@ using DSharpPlus; using Microsoft.AspNetCore.Authentication; using System.Security.Claims; -using Microsoft.Extensions.Configuration; namespace YumeChan.NetRunner.Services.Authentication; -public class WebAppClaims : IClaimsTransformation +public sealed class WebAppClaims : IClaimsTransformation { private readonly DiscordClient _client; - public WebAppClaims(DiscordClient client, IConfiguration config) + public WebAppClaims(DiscordClient client) { _client = client; } diff --git a/src/YumeChan.NetRunner/Startup.cs b/src/YumeChan.NetRunner/Startup.cs index 9da9bb4..70b1302 100644 --- a/src/YumeChan.NetRunner/Startup.cs +++ b/src/YumeChan.NetRunner/Startup.cs @@ -66,8 +66,10 @@ public void ConfigureServices(IServiceCollection services) }) .AddDiscord(options => { - options.ClientId = Configuration["DiscordAuth:ClientId"]; - options.ClientSecret = Configuration["DiscordAuth:ClientSecret"]; + Configuration.GetSection("DiscordAuth").Bind(options); + +// options.ClientId = Configuration["DiscordAuth:ClientId"]; +// options.ClientSecret = Configuration["DiscordAuth:ClientSecret"]; options.CallbackPath = "/signin-oauth2"; options.Scope.Add("identify");