Skip to content

Commit 9628d54

Browse files
committed
update changelog
1 parent 8d4b48d commit 9628d54

File tree

1 file changed

+25
-44
lines changed

1 file changed

+25
-44
lines changed

CHANGELOG.md

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,51 @@
11
[VERSION]
22

3-
> **Warning**
4-
> This update contains breaking changes!
3+
## Sub Command Support [#14]
54

6-
In order to make the code of ken more type-safe, I am now using [safepool](https://github.com/zekrotja/safepool)
7-
instead of `sync.Pool` which uses generic type parameters for ensuring type safety. Therefore, the minimum
8-
required module version has been bumped to `go1.18`. You might need to upgrade your project accordingly to
9-
be able to use ken.
5+
Finally, you can now register and use sub command groups!
106

11-
## Autocomplete Support [#18]
12-
13-
[Command option autocomplete](https://discord.com/developers/docs/interactions/application-commands#autocomplete)
14-
support has now been added to ken.
15-
16-
Simply enable autocomplete on your command option by setting the `Autocomplete` property to `true`.
7+
Simply add a sub command option to your command in the `Options` implementation of your command.
178

189
*Example:*
1910
```go
20-
func (c *TestCommand) Options() []*discordgo.ApplicationCommandOption {
11+
func (c *SubsCommand) Options() []*discordgo.ApplicationCommandOption {
2112
return []*discordgo.ApplicationCommandOption{
2213
{
23-
Type: discordgo.ApplicationCommandOptionString,
24-
Name: "language",
25-
Required: true,
26-
Description: "Choose a programming language.",
27-
Autocomplete: true,
14+
Type: discordgo.ApplicationCommandOptionSubCommandGroup,
15+
Name: "group",
16+
Description: "Some sub command gorup",
17+
Options: []*discordgo.ApplicationCommandOption{
18+
// ...
19+
},
2820
},
2921
}
3022
}
3123
```
3224

33-
Now, you simply need to implement the [`AutocompleteCommand`](https://pkg.go.dev/github.com/zekrotja/ken#Command)
34-
on your command.
25+
Now, you can add a [`SubCommandGroup`](https://pkg.go.dev/github.com/zekrotja/ken#SubCommandGroup) handler to your `HandleSubCommands` method to register sub commands in the group.
3526

3627
*Example:*
3728
```go
38-
func (c *TestCommand) Autocomplete(ctx *ken.AutocompleteContext) ([]*discordgo.ApplicationCommandOptionChoice, error) {
39-
input, ok := ctx.GetInput("language")
40-
41-
if !ok {
42-
return nil, nil
43-
}
44-
45-
choises := make([]*discordgo.ApplicationCommandOptionChoice, 0, len(programmingLanguages))
46-
input = strings.ToLower(input)
47-
48-
for _, lang := range programmingLanguages {
49-
if strings.HasPrefix(lang[1], input) {
50-
choises = append(choises, &discordgo.ApplicationCommandOptionChoice{
51-
Name: lang[0],
52-
Value: lang[0],
53-
})
54-
}
55-
}
56-
57-
return choises, nil
29+
func (c *SubsCommand) Run(ctx ken.Context) (err error) {
30+
err = ctx.HandleSubCommands(
31+
ken.SubCommandGroup{"group", []ken.CommandHandler{
32+
ken.SubCommandHandler{"one", c.one},
33+
ken.SubCommandHandler{"two", c.two},
34+
}},
35+
)
36+
return
5837
}
5938
```
6039

61-
> The full example can be found in [examples/autocomplete](https://github.com/zekroTJA/ken/tree/master/examples/autocomplete).
40+
> The full example can be found in [examples/subcommandgroups](https://github.com/zekroTJA/ken/tree/master/examples/subcommandgroups).
41+
42+
## Minor Changes
6243

63-
To properly handle errors occuring during autocomplete handling, a new command handler hook `OnEventError` has been added to the [`Options`](https://pkg.go.dev/github.com/zekrotja/ken#Options). It will be called every time a non-command related user event error occurs.
44+
- The [`AutocompleteContext`](https://pkg.go.dev/github.com/zekrotja/ken#AutocompleteContext) now implements [`ObjectMap`](https://pkg.go.dev/github.com/zekrotja/ken#ObjectMap) so you can pass dependencies down the line just like with command contexts.
6445

65-
## `RespondMessage`
46+
- [`AutocompleteContext`](https://pkg.go.dev/github.com/zekrotja/ken#AutocompleteContext) now has a new helper function [`GetInputAny`](https://pkg.go.dev/github.com/zekrotja/ken#AutocompleteContext.GetInputAny) which takes multiple option names and returns the first match found in the event data.
6647

67-
A new respond method has been added to the `ContentResponder` called [`RespondMessage`](https://pkg.go.dev/github.com/zekrotja/ken#Ctx.RespondMessage). It simply takes a message as parameter and responds with a simple message content containing the passed message.
48+
- [`FoolowUpMessage`](https://pkg.go.dev/github.com/zekrotja/ken#FollowUpMessage) has now been added accordingly to [`RespondMessage`](https://pkg.go.dev/github.com/zekrotja/ken@master#Ctx.RespondMessage), which was added in `v0.19.0`.
6849

6950
## Update
7051

0 commit comments

Comments
 (0)