From b621ecf8ef33c2562d56bc935f410515da661372 Mon Sep 17 00:00:00 2001 From: zekroTJA Date: Fri, 21 Jul 2023 10:27:20 +0000 Subject: [PATCH] update changelog --- CHANGELOG.md | 85 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 576c9a0..1515958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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