Skip to content

Commit

Permalink
update regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateodioev committed Jun 25, 2023
1 parent 787b24c commit 6496a5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 5 additions & 3 deletions examples/ButtonCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ class ButtonCallback extends CallbackCommand

public function handle(Api $bot, Context $context, array $args = [])
{
$this->getLogger()->info('Button 1 pressed');
$this->logger()->info('Button 1 pressed');
// log telegram context
$this->getLogger()->info('Update: {up}', ['up' => \json_encode($context->get(), JSON_PRETTY_PRINT)]);
$this->logger()->info('Update: {up}', [
'up' => \json_encode($context->getReduced(), JSON_PRETTY_PRINT)
]);

$payload = $context->getPayload();
// send answerCallbackQuery method
Expand All @@ -42,4 +44,4 @@ function echoPayload(Context $ctx, Api $bot): void

$payload = $ctx->getPayload();
echo sprintf($message, $payload) . PHP_EOL;
}
}
8 changes: 2 additions & 6 deletions src/Commands/CallbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function buildRegex(): Matcher
if ($this->pattern instanceof Matcher)
return $this->pattern;

$format = '#^(%s)(?: .+)?$#';
$format = '(%s)(?: .+)?';
$alias = [$this->getName(), ...$this->getAliases()];

$this->pattern = new Matcher(
Expand All @@ -39,18 +39,14 @@ protected function buildRegex(): Matcher
*/
public function match(string $text): bool
{
return $this->buildRegex()->isValid($text);
return $this->buildRegex()->isValid($text, true);
}

public function isValid(Api $bot, Context $ctx): bool
{
return 1 === 1 // SQL format
&& !empty($ctx->getMessageText())
&& $this->match($ctx->getMessageText());

/* $query = $ctx->getMessageText() ?? '';
if (empty($query)) return false;
return $this->match($query); */
}

public function execute(Api $bot, Context $context, array $args = [])
Expand Down

0 comments on commit 6496a5f

Please sign in to comment.