We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The specs says this:
Commands can use latin letters, numbers and underscores
But it's not possible to define a command that contains underscores.
For example, let's assume that we'd like to define the command /foo_bar.
/foo_bar
If we define it in a file named FooBarCommand.php, at this line we have that $command has a value of Foobar, and $command_name will be foobar.
FooBarCommand.php
$command
Foobar
$command_name
foobar
If we define it in a file named Foo_BarCommand.php, at this line we have that $command has a value of FooBar, and $command_name will still be foobar.
Foo_BarCommand.php
FooBar
It's impossible to define a command containing underscores.
Create a command like this one
<?php class FooBarCommand extends UserCommand { protected $name = 'foo_bar'; }
It won't be executed with /foo_bar.
Invoking /foo_bar should execute a command defined in a file named FooBarCommand.
FooBarCommand
The text was updated successfully, but these errors were encountered:
You can use GenericCommand to create "aliases" or commands with special characters.
GenericCommand
Something like this:
<?php class GenericCommand extends SystemCommand { private static array $aliases = [ 'foo_bar' => 'foobar', ]; public function execute(): ServerResponse { $command = $this->getUpdate()->getMessage()->getCommand(); if (isset(self::$aliases[strtolower($command)])) { $target_command = self::$aliases[strtolower($command)]; if ($this->getTelegram()->getCommandObject($target_command) !== null) { return $this->getTelegram()->executeCommand($target_command); } } return Request::emptyResponse(); } }
Sorry, something went wrong.
@jacklul Thanks! That's a really nice approach!
BTW, I think it should be easier for developers to add commands containing underscores: see #1365
Successfully merging a pull request may close this issue.
🐞 Bug Report
Required Information
Summary
The specs says this:
But it's not possible to define a command that contains underscores.
For example, let's assume that we'd like to define the command
/foo_bar
.If we define it in a file named
FooBarCommand.php
, at this line we have that$command
has a value ofFoobar
, and$command_name
will befoobar
.If we define it in a file named
Foo_BarCommand.php
, at this line we have that$command
has a value ofFooBar
, and$command_name
will still befoobar
.Current behaviour
It's impossible to define a command containing underscores.
How to reproduce
Create a command like this one
It won't be executed with
/foo_bar
.Expected behaviour
Invoking
/foo_bar
should execute a command defined in a file namedFooBarCommand
.The text was updated successfully, but these errors were encountered: