Skip to content

Commit

Permalink
chore: update release-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
MKRhere committed Sep 2, 2023
1 parent e4c0383 commit e5c6f78
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions release-notes/4.13.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,33 @@ Thanks to @Evertt for making the case for this feature.

### Command parser

It's an often requested feature to be able to parse command arguments. As of this release, `ctx.command` and `ctx.args` are available for this usecase. It's only available in `bot.command` handlers.
It's an often requested feature to be able to parse command arguments.

`ctx.command` is the matched command (even if you used RegExp), and it does not include the botname if it was included in the user's command. `ctx.args` is a parsed list of arguments passed to it. Have a look at the example:
As of this release, `ctx.command`, `ctx.payload`, and `ctx.args` are available for this usecase. It's only available in `bot.command` handlers.

`ctx.command` is the matched command (even if you used RegExp), and it does not include the botname if it was included in the user's command. `ctx.payload` is the unparsed text part excluding the command. `ctx.args` is a parsed list of arguments passed to it. Have a look at the example:

```TS
// User sends /warn --delete "Offtopic chat"

bot.command("warn", async ctx => {
ctx.command; // [ "warn" ]
ctx.args; // [ "--delete", "Offtopic chat" ]

ctx.command; // [ "warn" ]
ctx.payload; // "--delete \"Offtopic chat\""
});
```

`ctx.args` is considered unstable, and the parser is subject to fine-tuning and improvements based on user feedback.
⚠️ `ctx.args` is still considered unstable, and the parser is subject to fine-tuning and improvements based on user feedback.

The more generic `ctx.payload` for all commands causes `ctx.startPayload` in `bot.start` to be redundant, and hence the latter is now deprecated.

```diff
bot.start(ctx => {
- console.log(ctx.startPayload);
+ console.log(ctx.payload);
});
```

You can also play with this feature by importing the parser directly:

Expand Down

0 comments on commit e5c6f78

Please sign in to comment.