Skip to content
New issue

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

Listening for multiple command variations using a single hears() #38

Open
jonathantittle opened this issue Jul 15, 2018 · 0 comments
Open

Comments

@jonathantittle
Copy link

Version: ^2.1

Is it possible to listen for multiple variations of a command using hears()? For example, I'd like to be able to listen for:

mycommand action (.*)

and

action (.*)

Using | to separate the commands seems to allow execution, though when using regex in both of the commands, the text doesn't seem to come through as expected.

Example Code

$botman->hears('command action (.*)|action (.*)', function ( $botman, $message ) {
    $uid = $botman->getUser()->getId();

    $botman->reply(
        '<@' . $uid . '> You said: ' . $message
    );
});

When the bot hears command action [message], $message comes through without any issues. When the bot hears action [message], $message is empty.

As long as there's not regex, both command variants work, though I need regex in 99% of the commands in use. Perhaps I'm just doing it wrong :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant