/// <summary> /// Handles the commands events and suscribes modules to the <see cref="CommandService"/>. /// </summary> /// <param name="client">The Discord client.</param> /// <param name="commandsService">The <see cref="CommandService"/> object.</param> /// <param name="interactionService">The <see cref="InteractionService"/> object.</param> /// <param name="fergunInteractiveService">The interactive service to handle pagination and selections.</param> /// <param name="services">A collection of services to use throughout the application.</param> /// <returns>A task with the result of the asynchronous operation.</returns> private async Task RegisterEventsAsync(DiscordSocketClient client, ApiCalls api, CommandService commandsService, InteractionService interactionService, FergunInteractiveService fergunInteractiveService, IServiceProvider services) { ClientHandler clientHandler = new(client, api, interactionService, Configuration, logger : logger); CommandHandler commandHandler = new(client, commandsService, services, Configuration, logger); InteractionHandler interactionHandler = new(client, interactionService, fergunInteractiveService, services, logger); client.Log += LogClientEvent; client.Ready += clientHandler.OnReady; client.JoinedGuild += clientHandler.OnGuildCountChanged; client.LeftGuild += clientHandler.OnGuildCountChanged; client.MessageReceived += commandHandler.HandleCommandAsync; client.InteractionCreated += interactionHandler.HandleInteractionAsync; interactionService.SlashCommandExecuted += interactionHandler.HandleSlashCommandAsync; interactionService.ContextCommandExecuted += interactionHandler.HandleContextCommandAsync; interactionService.ComponentCommandExecuted += interactionHandler.HandleComponentCommandAsync; Task addCommandModules = commandsService.AddModulesAsync(Assembly.GetAssembly(typeof(CommandHandler)), services); Task addInteractionCommmandModules = interactionService.AddModulesAsync(Assembly.GetAssembly(typeof(InteractionHandler)), services); await Task.WhenAll(addCommandModules, addInteractionCommmandModules); }
/// <summary> /// Configures all the required services and returns a built service provider. /// </summary> /// <param name="discordClient">The <see cref="DiscordSocketClient"/> instance.</param> /// <param name="commandsService">The <see cref="CommandService"/> instance.</param> /// <param name="interactionService">The <see cref="InteractionService"/> instance.</param> /// <param name="fergunInteractiveService">The interactive service to handle pagination and selections.</param> /// <param name="api">The <see cref="ApiCalls"/> instance.</param> /// <returns>A built service provider.</returns> private ServiceProvider ConfigureServices(DiscordSocketClient discordClient, CommandService commandsService, InteractionService interactionService, FergunInteractiveService fergunInteractiveService, ApiCalls api) { return(new ServiceCollection().AddSingleton(discordClient) .AddSingleton(commandsService) .AddSingleton(interactionService) .AddSingleton(fergunInteractiveService) .AddSingleton(Configuration) .AddSingleton <InteractiveService>() .AddSingleton(api) .AddSingleton(logger) .BuildServiceProvider()); }