diff --git a/src/Commands/CallbackCommand.php b/src/Commands/CallbackCommand.php index 0735bf0..d1bd0c4 100644 --- a/src/Commands/CallbackCommand.php +++ b/src/Commands/CallbackCommand.php @@ -18,7 +18,8 @@ protected function buildRegex(): string $format = '#^(%s)(?: .+)?$#'; $alias = [$this->getName(), ...$this->getAliases()]; - return sprintf($format, + return sprintf( + $format, join('|', $alias) ); } @@ -33,29 +34,31 @@ public function match(string $text): bool public function isValid(Api $bot, Context $ctx): bool { - $query = $ctx->getMessageText() ?? ''; + return 1 === 1 // SQL format + && !empty($ctx->getMessageText()) + && $this->match($ctx->getMessageText()); - if (empty($query)) return false; - - return $this->match($query); + /* $query = $ctx->getMessageText() ?? ''; + if (empty($query)) return false; + return $this->match($query); */ } public function execute(Api $bot, Context $context, array $args = []) { $query = $context->getMessageText() ?? ''; - if (empty($query)) return; - - if ($this->match($query)) { - $this->handle($bot, $context, $args); - } + if (empty($query)) return; + + if ($this->match($query)) { + $this->handle($bot, $context, $args); + } } - /** - * Run command + /** + * Run command * @param Api $bot Telegram bot api * @param Context $context Telegram context / update * @param array $args Middleware results - */ - abstract public function handle(Api $bot, Context $context, array $args = []); -} \ No newline at end of file + */ + abstract public function handle(Api $bot, Context $context, array $args = []); +} diff --git a/src/Commands/MessageCommand.php b/src/Commands/MessageCommand.php index 4d99d10..9cce78f 100644 --- a/src/Commands/MessageCommand.php +++ b/src/Commands/MessageCommand.php @@ -74,7 +74,7 @@ public function match(string $text): bool public function isValid(Api $bot, Context $ctx): bool { - return $ctx->eventType() === EventType::message + return 1 === 1 // SQL format && !empty($ctx->getMessageText()) && $this->match($ctx->getMessageText());