Skip to content

Commit

Permalink
Merge pull request #42 from nutgram/sync
Browse files Browse the repository at this point in the history
Add other where methods
  • Loading branch information
sergix44 authored Jan 5, 2024
2 parents d7aec3f + 88a02e2 commit 6fb7c80
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/usage/handlers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,52 @@ $bot->onCommand('hello {name} {age}', HelloCommand::class)
->where(['name' => '[A-Za-z]+', 'age' => '[0-9]+']);
```

:::info
By default, parameters are constrained by the default regular expression `.*`.
:::

Here is the list of the other available constraints:

- `whereIn(string $parameter, array $values)`<br/>
The parameter must be contained in the given array.

```php
$bot->onCommand('confirm {answer}', ConfirmCommand::class)
->whereIn('answer', ['y','n']);
```

- `whereAlpha(string $parameter)`<br/>
The parameter must be entirely alphabetic characters.

```php
$bot->onCommand('hello {name}', HelloCommand::class)
->whereAlpha('name');
```

- `whereNumber(string $parameter)`<br/>
The parameter must be entirely numeric characters.

```php
$bot->onCommand('age {age}', AgeCommand::class)
->whereNumber('age');
```

- `whereAlphaNumeric(string $parameter)`<br/>
The parameter must be entirely alpha-numeric characters.

```php
$bot->onCommand('hello {name}', HelloCommand::class)
->whereAlphaNumeric('name');
```

You can also use the `where` methods in group method:

```php
$bot->group(function () use (Nutgram $bot) {
$bot->onCommand('create {name}', CreateCommand::class);
$bot->onCommand('delete {name}', DeleteCommand::class);
})->whereAlpha('name');
```

### `registerCommand`

Expand Down

0 comments on commit 6fb7c80

Please sign in to comment.