From 28445f99b185ada3d98039059d126808d82ebbf3 Mon Sep 17 00:00:00 2001 From: felk Date: Mon, 20 Sep 2021 20:49:36 +0200 Subject: [PATCH] split CommandProcessor into interface and implementation --- TPP.Core/Commands/CommandProcessor.cs | 10 +++++++++- TPP.Core/Commands/Definitions/HelpCommand.cs | 4 ++-- TPP.Core/Modes/ModeBase.cs | 4 ++-- TPP.Core/Setups.cs | 6 +++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/TPP.Core/Commands/CommandProcessor.cs b/TPP.Core/Commands/CommandProcessor.cs index 1b1050f9..644bdea5 100644 --- a/TPP.Core/Commands/CommandProcessor.cs +++ b/TPP.Core/Commands/CommandProcessor.cs @@ -10,11 +10,19 @@ namespace TPP.Core.Commands { + public interface ICommandProcessor + { + public Task Process(string commandName, IImmutableList args, Message message); + public Command? FindCommand(string commandName); + public void InstallCommand(Command command); + public void UninstallCommand(params string[] commandOrAlias); + } + /// /// The command processor can be configured using instances to have commands, /// which then get executed using the method. /// - public class CommandProcessor + public class CommandProcessor : ICommandProcessor { /// /// maximum execution time for a command before a warning is logged. diff --git a/TPP.Core/Commands/Definitions/HelpCommand.cs b/TPP.Core/Commands/Definitions/HelpCommand.cs index beb962f5..128d137f 100644 --- a/TPP.Core/Commands/Definitions/HelpCommand.cs +++ b/TPP.Core/Commands/Definitions/HelpCommand.cs @@ -11,8 +11,8 @@ public class HelpCommand Description = "Get general help, or info on a specific command like: \"!help balance\"" }; - private readonly CommandProcessor _commandProcessor; - public HelpCommand(CommandProcessor commandProcessor) => _commandProcessor = commandProcessor; + private readonly ICommandProcessor _commandProcessor; + public HelpCommand(ICommandProcessor commandProcessor) => _commandProcessor = commandProcessor; private CommandResult Execute(CommandContext context) { diff --git a/TPP.Core/Modes/ModeBase.cs b/TPP.Core/Modes/ModeBase.cs index 4682b6cf..3d680932 100644 --- a/TPP.Core/Modes/ModeBase.cs +++ b/TPP.Core/Modes/ModeBase.cs @@ -25,7 +25,7 @@ public sealed class ModeBase : IDisposable private readonly ILogger _logger; private readonly IImmutableDictionary _chats; private readonly IImmutableDictionary _commandResponders; - private readonly IImmutableDictionary _commandProcessors; + private readonly IImmutableDictionary _commandProcessors; private readonly IImmutableDictionary _moderators; private readonly IImmutableDictionary _advertisePollsWorkers; private readonly IMessagequeueRepo _messagequeueRepo; @@ -105,7 +105,7 @@ public ModeBase( public void InstallAdditionalCommand(Command command) { - foreach (CommandProcessor commandProcessor in _commandProcessors.Values) + foreach (ICommandProcessor commandProcessor in _commandProcessors.Values) commandProcessor.InstallCommand(command); } diff --git a/TPP.Core/Setups.cs b/TPP.Core/Setups.cs index 780d3e62..62e4be7a 100644 --- a/TPP.Core/Setups.cs +++ b/TPP.Core/Setups.cs @@ -59,7 +59,7 @@ public static ArgsParser SetUpArgsParser(IUserRepo userRepo, PokedexData pokedex return argsParser; } - public static CommandProcessor SetUpCommandProcessor( + public static ICommandProcessor SetUpCommandProcessor( ILoggerFactory loggerFactory, ArgsParser argsParser, Databases databases, @@ -68,7 +68,7 @@ public static CommandProcessor SetUpCommandProcessor( IChatModeChanger chatModeChanger, IImmutableSet knownSpecies) { - var commandProcessor = new CommandProcessor( + ICommandProcessor commandProcessor = new CommandProcessor( loggerFactory.CreateLogger(), databases.CommandLogger, argsParser); @@ -180,7 +180,7 @@ public static (WebsocketBroadcastServer, OverlayConnection) SetUpOverlayServer( } private static void SetUpDynamicCommands( - ILogger logger, CommandProcessor commandProcessor, IResponseCommandRepo responseCommandRepo) + ILogger logger, ICommandProcessor commandProcessor, IResponseCommandRepo responseCommandRepo) { IImmutableList commands = responseCommandRepo.GetCommands().Result;