99namespace Botticelli . Framework . Commands . Processors ;
1010
1111public abstract class CommandProcessor < TCommand > : ICommandProcessor
12- where TCommand : class , ICommand
12+ where TCommand : class , ICommand
1313{
1414 private const string SimpleCommandPattern = @"\/([a-zA-Z0-9]*)$" ;
1515 private const string ArgsCommandPattern = @"\/([a-zA-Z0-9]*) (.*)" ;
1616 private readonly string _commandName ;
17- protected readonly ILogger Logger ;
18- protected readonly ICommandValidator < TCommand > Validator ;
19- protected IList < IBot > Bots = new List < IBot > ( 10 ) ;
17+ protected readonly IList < IBot > Bots = new List < IBot > ( 10 ) ;
18+ private readonly ILogger _logger ;
19+ private readonly ICommandValidator < TCommand > _validator ;
2020 protected IServiceProvider Sp ;
2121
2222 protected CommandProcessor ( ILogger logger ,
23- ICommandValidator < TCommand > validator )
23+ ICommandValidator < TCommand > validator )
2424 {
25- Logger = logger ;
26- Validator = validator ;
25+ _logger = logger ;
26+ _validator = validator ;
2727 _commandName = GetCommandName ( typeof ( TCommand ) . Name ) ;
2828 }
2929
@@ -40,7 +40,7 @@ public async Task ProcessAsync(Message message, CancellationToken token)
4040 message . Contact == default &&
4141 message . Poll == default )
4242 {
43- Logger . LogWarning ( "Message {msgId} is empty! Skipping..." , message . Uid ) ;
43+ _logger . LogWarning ( "Message {msgId} is empty! Skipping..." , message . Uid ) ;
4444
4545 return ;
4646 }
@@ -50,7 +50,7 @@ public async Task ProcessAsync(Message message, CancellationToken token)
5050 if ( Regex . IsMatch ( message . Body , SimpleCommandPattern ) )
5151 {
5252 var match = Regex . Matches ( message . Body , SimpleCommandPattern )
53- . FirstOrDefault ( ) ;
53+ . FirstOrDefault ( ) ;
5454
5555 var commandName = GetCommandName ( match . Groups [ 1 ] . Value ) ;
5656
@@ -59,24 +59,24 @@ public async Task ProcessAsync(Message message, CancellationToken token)
5959 if ( match == default ) return ;
6060
6161 await ValidateAndProcess ( message ,
62- string . Empty ,
63- token ,
64- request ) ;
62+ string . Empty ,
63+ token ,
64+ request ) ;
6565 }
6666 else if ( Regex . IsMatch ( message . Body , ArgsCommandPattern ) )
6767 {
6868 var match = Regex . Matches ( message . Body , ArgsCommandPattern )
69- . FirstOrDefault ( ) ;
69+ . FirstOrDefault ( ) ;
7070 var argsString = match . Groups [ 2 ] . Value ;
7171
7272 var commandName = GetCommandName ( match . Groups [ 1 ] . Value ) ;
7373
7474 if ( commandName != _commandName ) return ;
7575
7676 await ValidateAndProcess ( message ,
77- argsString ,
78- token ,
79- request ) ;
77+ argsString ,
78+ token ,
79+ request ) ;
8080 }
8181
8282 if ( message . Location != default ) await InnerProcessLocation ( message , string . Empty , token ) ;
@@ -85,7 +85,7 @@ await ValidateAndProcess(message,
8585 }
8686 catch ( Exception ex )
8787 {
88- Logger . LogError ( ex , $ "Error in { GetType ( ) . Name } : { ex . Message } ") ;
88+ _logger . LogError ( ex , $ "Error in { GetType ( ) . Name } : { ex . Message } ") ;
8989 }
9090 }
9191
@@ -99,17 +99,17 @@ public string GetCommandName(string fullCommand)
9999 => fullCommand . ToLowerInvariant ( ) . Replace ( "command" , "" ) ;
100100
101101 private async Task ValidateAndProcess ( Message message ,
102- string args ,
103- CancellationToken token ,
104- SendMessageRequest request )
102+ string args ,
103+ CancellationToken token ,
104+ SendMessageRequest request )
105105 {
106- if ( await Validator . Validate ( message . ChatIds , message . Body ) )
106+ if ( await _validator . Validate ( message . ChatIds , message . Body ) )
107107 {
108108 await InnerProcess ( message , args , token ) ;
109109 }
110110 else
111111 {
112- request . Message . Body = Validator . Help ( ) ;
112+ request . Message . Body = _validator . Help ( ) ;
113113
114114 foreach ( var bot in Bots ) await bot . SendMessageAsync ( request , token ) ;
115115 }
0 commit comments