Skip to content

Commit 28445f9

Browse files
committed
split CommandProcessor into interface and implementation
1 parent caf1b40 commit 28445f9

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

TPP.Core/Commands/CommandProcessor.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010

1111
namespace TPP.Core.Commands
1212
{
13+
public interface ICommandProcessor
14+
{
15+
public Task<CommandResult?> Process(string commandName, IImmutableList<string> args, Message message);
16+
public Command? FindCommand(string commandName);
17+
public void InstallCommand(Command command);
18+
public void UninstallCommand(params string[] commandOrAlias);
19+
}
20+
1321
/// <summary>
1422
/// The command processor can be configured using <see cref="Command"/> instances to have commands,
1523
/// which then get executed using the <see cref="CommandProcessor.Process"/> method.
1624
/// </summary>
17-
public class CommandProcessor
25+
public class CommandProcessor : ICommandProcessor
1826
{
1927
/// <summary>
2028
/// maximum execution time for a command before a warning is logged.

TPP.Core/Commands/Definitions/HelpCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class HelpCommand
1111
Description = "Get general help, or info on a specific command like: \"!help balance\""
1212
};
1313

14-
private readonly CommandProcessor _commandProcessor;
15-
public HelpCommand(CommandProcessor commandProcessor) => _commandProcessor = commandProcessor;
14+
private readonly ICommandProcessor _commandProcessor;
15+
public HelpCommand(ICommandProcessor commandProcessor) => _commandProcessor = commandProcessor;
1616

1717
private CommandResult Execute(CommandContext context)
1818
{

TPP.Core/Modes/ModeBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed class ModeBase : IDisposable
2525
private readonly ILogger<ModeBase> _logger;
2626
private readonly IImmutableDictionary<string, IChat> _chats;
2727
private readonly IImmutableDictionary<string, ICommandResponder> _commandResponders;
28-
private readonly IImmutableDictionary<string, CommandProcessor> _commandProcessors;
28+
private readonly IImmutableDictionary<string, ICommandProcessor> _commandProcessors;
2929
private readonly IImmutableDictionary<string, IModerator> _moderators;
3030
private readonly IImmutableDictionary<string, AdvertisePollsWorker> _advertisePollsWorkers;
3131
private readonly IMessagequeueRepo _messagequeueRepo;
@@ -105,7 +105,7 @@ public ModeBase(
105105

106106
public void InstallAdditionalCommand(Command command)
107107
{
108-
foreach (CommandProcessor commandProcessor in _commandProcessors.Values)
108+
foreach (ICommandProcessor commandProcessor in _commandProcessors.Values)
109109
commandProcessor.InstallCommand(command);
110110
}
111111

TPP.Core/Setups.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static ArgsParser SetUpArgsParser(IUserRepo userRepo, PokedexData pokedex
5959
return argsParser;
6060
}
6161

62-
public static CommandProcessor SetUpCommandProcessor(
62+
public static ICommandProcessor SetUpCommandProcessor(
6363
ILoggerFactory loggerFactory,
6464
ArgsParser argsParser,
6565
Databases databases,
@@ -68,7 +68,7 @@ public static CommandProcessor SetUpCommandProcessor(
6868
IChatModeChanger chatModeChanger,
6969
IImmutableSet<Common.PkmnSpecies> knownSpecies)
7070
{
71-
var commandProcessor = new CommandProcessor(
71+
ICommandProcessor commandProcessor = new CommandProcessor(
7272
loggerFactory.CreateLogger<CommandProcessor>(),
7373
databases.CommandLogger, argsParser);
7474

@@ -180,7 +180,7 @@ public static (WebsocketBroadcastServer, OverlayConnection) SetUpOverlayServer(
180180
}
181181

182182
private static void SetUpDynamicCommands(
183-
ILogger logger, CommandProcessor commandProcessor, IResponseCommandRepo responseCommandRepo)
183+
ILogger logger, ICommandProcessor commandProcessor, IResponseCommandRepo responseCommandRepo)
184184
{
185185
IImmutableList<ResponseCommand> commands = responseCommandRepo.GetCommands().Result;
186186

0 commit comments

Comments
 (0)