Skip to content

Commit

Permalink
implementations of isValid has been simplefied
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateodioev committed Jun 8, 2023
1 parent 19b33bd commit c7b678a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions src/Commands/CallbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ protected function buildRegex(): string
$format = '#^(%s)(?: .+)?$#';
$alias = [$this->getName(), ...$this->getAliases()];

return sprintf($format,
return sprintf(
$format,
join('|', $alias)
);
}
Expand All @@ -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 = []);
}
*/
abstract public function handle(Api $bot, Context $context, array $args = []);
}
2 changes: 1 addition & 1 deletion src/Commands/MessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit c7b678a

Please sign in to comment.