From e12fd0e6e95383bad6ce812eaefd90ec37ab8aad Mon Sep 17 00:00:00 2001 From: Brett Hewitson Date: Tue, 21 Jun 2022 23:44:14 +1000 Subject: [PATCH] Nuget package updates - discord - changes InteractiveBase to ModuleBase --- .../Modules/ServerCommandModule.cs | 3 +-- .../Modules/ServerQueryModule.cs | 3 +-- .../ServerManager.Discord.csproj | 3 +-- src/ServerManager.Discord/ServerManagerBot.cs | 19 +++++++++++++------ .../Services/StartupService.cs | 6 +++--- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ServerManager.Discord/Modules/ServerCommandModule.cs b/src/ServerManager.Discord/Modules/ServerCommandModule.cs index 574fb3ef..c5c31cd6 100644 --- a/src/ServerManager.Discord/Modules/ServerCommandModule.cs +++ b/src/ServerManager.Discord/Modules/ServerCommandModule.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Discord; -using Discord.Addons.Interactive; using Discord.Commands; using ServerManagerTool.DiscordBot.Delegates; using ServerManagerTool.DiscordBot.Enums; @@ -10,7 +9,7 @@ using ServerManagerTool.DiscordBot.Interfaces; namespace ServerManagerTool.DiscordBot.Modules { [Name("Server Commands")] - public sealed class ServerCommandModule : InteractiveBase + public sealed class ServerCommandModule : ModuleBase { private const int COMMAND_RESPONSE_DELAY = 500; diff --git a/src/ServerManager.Discord/Modules/ServerQueryModule.cs b/src/ServerManager.Discord/Modules/ServerQueryModule.cs index c82e4a52..3eaf8935 100644 --- a/src/ServerManager.Discord/Modules/ServerQueryModule.cs +++ b/src/ServerManager.Discord/Modules/ServerQueryModule.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using Discord; -using Discord.Addons.Interactive; using Discord.Commands; using ServerManagerTool.DiscordBot.Delegates; using ServerManagerTool.DiscordBot.Enums; @@ -10,7 +9,7 @@ using ServerManagerTool.DiscordBot.Interfaces; namespace ServerManagerTool.DiscordBot.Modules { [Name("Server Query")] - public sealed class ServerQueryModule : InteractiveBase + public sealed class ServerQueryModule : ModuleBase { private const int COMMAND_RESPONSE_DELAY = 500; diff --git a/src/ServerManager.Discord/ServerManager.Discord.csproj b/src/ServerManager.Discord/ServerManager.Discord.csproj index a14b3429..5620f117 100644 --- a/src/ServerManager.Discord/ServerManager.Discord.csproj +++ b/src/ServerManager.Discord/ServerManager.Discord.csproj @@ -12,8 +12,7 @@ false - - + diff --git a/src/ServerManager.Discord/ServerManagerBot.cs b/src/ServerManager.Discord/ServerManagerBot.cs index fe75e0f1..6d6fd8fa 100644 --- a/src/ServerManager.Discord/ServerManagerBot.cs +++ b/src/ServerManager.Discord/ServerManagerBot.cs @@ -1,5 +1,5 @@ -using Discord.Addons.Interactive; -using Discord.Commands; +using Discord.Commands; +using Discord.Interactions; using Discord.Net.Providers.WS4Net; using Discord.WebSocket; using Microsoft.Extensions.Configuration; @@ -69,26 +69,33 @@ namespace ServerManagerTool.DiscordBot var commandConfig = new CommandServiceConfig { // Force all commands to run async - DefaultRunMode = RunMode.Async, + DefaultRunMode = Discord.Commands.RunMode.Async, LogLevel = LogLevelHelper.GetLogSeverity(discordBotConfig.LogLevel), CaseSensitiveCommands = false, }; + var interactionConfig = new InteractionServiceConfig + { + // Force all interactions to run async + DefaultRunMode = Discord.Interactions.RunMode.Async, + LogLevel = LogLevelHelper.GetLogSeverity(discordBotConfig.LogLevel), + }; + // Build the service provider var services = new ServiceCollection() + .AddSingleton(config) + .AddSingleton(discordBotConfig) // Add the discord client to the service provider .AddSingleton(new DiscordSocketClient(socketConfig)) // Add the command service to the service provider .AddSingleton(new CommandService(commandConfig)) + .AddSingleton(x => new InteractionService(x.GetRequiredService(), interactionConfig)) // Add remaining services to the provider .AddSingleton() - .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(config) - .AddSingleton(discordBotConfig) .AddSingleton(handleCommandCallback) .AddSingleton(handleTranslationCallback) .AddSingleton(this); diff --git a/src/ServerManager.Discord/Services/StartupService.cs b/src/ServerManager.Discord/Services/StartupService.cs index 6ca86e86..b86f7b0b 100644 --- a/src/ServerManager.Discord/Services/StartupService.cs +++ b/src/ServerManager.Discord/Services/StartupService.cs @@ -33,13 +33,13 @@ namespace ServerManagerTool.DiscordBot.Services throw new Exception("#DiscordBot_MissingTokenError"); } + // Load commands and modules into the command service + await _commands.AddModulesAsync(Assembly.GetExecutingAssembly(), _services); + // Login to discord await _client.LoginAsync(TokenType.Bot, discordToken); // Connect to the websocket await _client.StartAsync(); - - // Load commands and modules into the command service - await _commands.AddModulesAsync(Assembly.GetExecutingAssembly(), _services); } } } \ No newline at end of file