// // Startup.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NosSmooth.ChatCommands; using NosSmooth.Core.Client; using NosSmooth.Core.Extensions; using NosSmooth.LocalBinding; using NosSmooth.LocalClient; using NosSmooth.LocalClient.Extensions; using Remora.Commands.Extensions; using WalkCommands.Commands; namespace WalkCommands; /// /// Startup class of WalkCommands. /// public class Startup { private IServiceProvider BuildServices() { var collection = new ServiceCollection() .AddLocalClient() .AddScoped() .AddScoped() .AddSingleton() .Configure(o => o.AllowIntercept = true) .AddNostaleChatCommands() .AddLogging ( b => { b.ClearProviders(); b.AddConsole(); b.SetMinimumLevel(LogLevel.Debug); } ); collection.AddCommandTree() .WithCommandGroup() .WithCommandGroup() .WithCommandGroup(); return collection.BuildServiceProvider(); } /// /// Run the MoveToMiniland. /// /// A task that may or may not have succeeded. public async Task RunAsync() { var provider = BuildServices(); var bindingManager = provider.GetRequiredService(); var logger = provider.GetRequiredService>(); var initializeResult = bindingManager.Initialize(); if (!initializeResult.IsSuccess) { logger.LogError($"Could not initialize NosBindingManager."); logger.LogResultError(initializeResult); } var mainCancellation = provider.GetRequiredService(); var client = provider.GetRequiredService(); await client.RunAsync(mainCancellation.Token); } }