Skip to content

Commit

Permalink
split CommandProcessor into interface and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Felk committed Sep 20, 2021
1 parent caf1b40 commit 28445f9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 9 additions & 1 deletion TPP.Core/Commands/CommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@

namespace TPP.Core.Commands
{
public interface ICommandProcessor
{
public Task<CommandResult?> Process(string commandName, IImmutableList<string> args, Message message);
public Command? FindCommand(string commandName);
public void InstallCommand(Command command);
public void UninstallCommand(params string[] commandOrAlias);
}

/// <summary>
/// The command processor can be configured using <see cref="Command"/> instances to have commands,
/// which then get executed using the <see cref="CommandProcessor.Process"/> method.
/// </summary>
public class CommandProcessor
public class CommandProcessor : ICommandProcessor
{
/// <summary>
/// maximum execution time for a command before a warning is logged.
Expand Down
4 changes: 2 additions & 2 deletions TPP.Core/Commands/Definitions/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions TPP.Core/Modes/ModeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class ModeBase : IDisposable
private readonly ILogger<ModeBase> _logger;
private readonly IImmutableDictionary<string, IChat> _chats;
private readonly IImmutableDictionary<string, ICommandResponder> _commandResponders;
private readonly IImmutableDictionary<string, CommandProcessor> _commandProcessors;
private readonly IImmutableDictionary<string, ICommandProcessor> _commandProcessors;
private readonly IImmutableDictionary<string, IModerator> _moderators;
private readonly IImmutableDictionary<string, AdvertisePollsWorker> _advertisePollsWorkers;
private readonly IMessagequeueRepo _messagequeueRepo;
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions TPP.Core/Setups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -68,7 +68,7 @@ public static CommandProcessor SetUpCommandProcessor(
IChatModeChanger chatModeChanger,
IImmutableSet<Common.PkmnSpecies> knownSpecies)
{
var commandProcessor = new CommandProcessor(
ICommandProcessor commandProcessor = new CommandProcessor(
loggerFactory.CreateLogger<CommandProcessor>(),
databases.CommandLogger, argsParser);

Expand Down Expand Up @@ -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<ResponseCommand> commands = responseCommandRepo.GetCommands().Result;

Expand Down

0 comments on commit 28445f9

Please sign in to comment.