@@ -38,8 +38,8 @@ abstract class Command implements CommandInterface
3838 /** @var string Command Argument Pattern */
3939 protected string $ pattern = '' ;
4040
41- /** @var array|null Details of the current entity this command is responding to - offset, length, type etc */
42- protected ? array $ entity ;
41+ /** @var array Details of the current entity this command is responding to - offset, length, type etc */
42+ protected array $ entity = [] ;
4343
4444 /**
4545 * Get the Command Name.
@@ -168,12 +168,12 @@ protected function parseCommandArguments(): array
168168 // Generate the regex needed to search for this pattern
169169 $ regex = $ this ->makeRegexPattern ();
170170
171- preg_match ("% {$ regex }%ixmu " , $ this ->relevantMessageSubString (), $ matches , PREG_UNMATCHED_AS_NULL );
171+ preg_match ("% {$ regex[ 0 ] }%ixmu " , $ this ->relevantMessageSubString (), $ matches , PREG_UNMATCHED_AS_NULL );
172172
173- return $ this ->formatMatches ($ matches );
173+ return $ this ->formatMatches ($ matches, $ regex [ 1 ] );
174174 }
175175
176- private function makeRegexPattern (): string
176+ private function makeRegexPattern (): array
177177 {
178178 preg_match_all (
179179 pattern: '#\{\s*(?<name>\w+)\s*(?::\s*(?<pattern>\S+)\s*)?}#ixmu ' ,
@@ -198,7 +198,10 @@ private function makeRegexPattern(): string
198198
199199 $ commandName = ($ this ->aliases === []) ? $ this ->name : implode ('| ' , [$ this ->name , ...$ this ->aliases ]);
200200
201- return sprintf ('(?:\/)%s%s%s ' , "(?: {$ commandName }) " , self ::OPTIONAL_BOT_NAME , $ patterns ->implode ('\s* ' ));
201+ return [
202+ sprintf ('(?:\/)%s%s%s ' , "(?: {$ commandName }) " , self ::OPTIONAL_BOT_NAME , $ patterns ->implode ('\s* ' )),
203+ $ patterns ->keys ()->all (),
204+ ];
202205 }
203206
204207 private function relevantMessageSubString (): string
@@ -249,9 +252,11 @@ private function cutTextFrom(Collection $splice): string
249252 );
250253 }
251254
252- private function formatMatches (array $ matches ): array
255+ private function formatMatches (array $ matches, array $ arguments ): array
253256 {
254- return array_filter ($ matches , 'is_string ' , ARRAY_FILTER_USE_KEY );
257+ $ matches = array_filter ($ matches , 'is_string ' , ARRAY_FILTER_USE_KEY );
258+
259+ return array_merge (array_fill_keys ($ arguments , null ), $ matches );
255260 }
256261
257262 /**
0 commit comments