Skip to content

Commit

Permalink
update changelog
Browse files Browse the repository at this point in the history
zekroTJA committed Jul 21, 2023
1 parent 90c71b0 commit b621ecf
Showing 1 changed file with 58 additions and 27 deletions.
85 changes: 58 additions & 27 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,70 @@
[VERSION]

> **Warning**
> This update contains breaking changes!
> This update contains breaking changes!
In order to support the attachment of message components to a flollow-up message on creation [see #13],
the methods `ContextResponder#FollowUp`, `ContextResponder#FollowUpEmbed` and `ContextResponder#FollowUpError`
now return a `*FollowUpMessageBuilder`, which can be used to attach components and handlers before the
follow-up message is sent.
In order to make the code of ken more type-safe, I am now using [safepool](https://github.com/zekrotja/safepool)
instead of `sync.Pool` which uses generic type parameters for ensuring type safety. Therefore, the minimum
required module version has been bumped to `go1.18`. You might need to upgrade your project accordingly to
be able to use ken.

**Example**
## Autocomplete Support [#18]

[Command option autocomplete](https://discord.com/developers/docs/interactions/application-commands#autocomplete)
support has now been added to ken.

Simply enable autocomplete on your command option by setting the `Autocomplete` property to `true`.

*Example:*
```go
b := ctx.FollowUpEmbed(&discordgo.MessageEmbed{
Description: "Hello",
})

b.AddComponents(func(cb *ken.ComponentBuilder) {
cb.Add(
discordgo.Button{
CustomID: "button-1",
Label: "Absolutely fantastic!",
},
func(ctx ken.ComponentContext) bool {
ctx.RespondEmbed(&discordgo.MessageEmbed{
Description: fmt.Sprintf("Responded to %s", ctx.GetData().CustomID),
})
return true
}, true,
)
})

fum := b.Send()
func (c *TestCommand) Options() []*discordgo.ApplicationCommandOption {
return []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "language",
Required: true,
Description: "Choose a programming language.",
Autocomplete: true,
},
}
}
```

A full example can be found in [examples/components/commands/test.go](examples/components/commands/test.go).
Now, you simply need to implement the [`AutocompleteCommand`](https://pkg.go.dev/github.com/zekrotja/ken#Command)
on your command.

*Example:*
```go
func (c *TestCommand) Autocomplete(ctx *ken.AutocompleteContext) ([]*discordgo.ApplicationCommandOptionChoice, error) {
input, ok := ctx.GetInput("language")

if !ok {
return nil, nil
}

choises := make([]*discordgo.ApplicationCommandOptionChoice, 0, len(programmingLanguages))
input = strings.ToLower(input)

for _, lang := range programmingLanguages {
if strings.HasPrefix(lang[1], input) {
choises = append(choises, &discordgo.ApplicationCommandOptionChoice{
Name: lang[0],
Value: lang[0],
})
}
}

return choises, nil
}
```

> The full example can be found in [examples/autocomplete](https://github.com/zekroTJA/ken/tree/master/examples/autocomplete).
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.

## `RespondMessage`

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.

## Update

0 comments on commit b621ecf

Please sign in to comment.