Skip to content

Commit 6fb7c80

Browse files
authored
Merge pull request #42 from nutgram/sync
Add other where methods
2 parents d7aec3f + 88a02e2 commit 6fb7c80

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

docs/usage/handlers.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,52 @@ $bot->onCommand('hello {name} {age}', HelloCommand::class)
423423
->where(['name' => '[A-Za-z]+', 'age' => '[0-9]+']);
424424
```
425425

426+
:::info
426427
By default, parameters are constrained by the default regular expression `.*`.
428+
:::
429+
430+
Here is the list of the other available constraints:
431+
432+
- `whereIn(string $parameter, array $values)`<br/>
433+
The parameter must be contained in the given array.
434+
435+
```php
436+
$bot->onCommand('confirm {answer}', ConfirmCommand::class)
437+
->whereIn('answer', ['y','n']);
438+
```
439+
440+
- `whereAlpha(string $parameter)`<br/>
441+
The parameter must be entirely alphabetic characters.
442+
443+
```php
444+
$bot->onCommand('hello {name}', HelloCommand::class)
445+
->whereAlpha('name');
446+
```
447+
448+
- `whereNumber(string $parameter)`<br/>
449+
The parameter must be entirely numeric characters.
450+
451+
```php
452+
$bot->onCommand('age {age}', AgeCommand::class)
453+
->whereNumber('age');
454+
```
455+
456+
- `whereAlphaNumeric(string $parameter)`<br/>
457+
The parameter must be entirely alpha-numeric characters.
458+
459+
```php
460+
$bot->onCommand('hello {name}', HelloCommand::class)
461+
->whereAlphaNumeric('name');
462+
```
463+
464+
You can also use the `where` methods in group method:
465+
466+
```php
467+
$bot->group(function () use (Nutgram $bot) {
468+
$bot->onCommand('create {name}', CreateCommand::class);
469+
$bot->onCommand('delete {name}', DeleteCommand::class);
470+
})->whereAlpha('name');
471+
```
427472

428473
### `registerCommand`
429474

0 commit comments

Comments
 (0)