Add autocomplete callback support#54
Open
Sim-hu wants to merge 1 commit intojchristgit:masterfrom
Open
Conversation
Add an optional `autocomplete/1` callback to ApplicationCommand behaviour so that command modules can handle autocomplete interactions separately from regular command invocations. When an autocomplete interaction (type 4) is received, the dispatcher checks if the command module implements `autocomplete/1` and calls it instead of `command/1`. If not implemented, falls back to `command/1` for backwards compatibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an optional
autocomplete/1callback to theNosedrum.ApplicationCommandbehaviour, enabling command modules to handle autocomplete interactions separately from regular command invocations.Motivation
Discord sends autocomplete interactions (type 4) when a user is typing in an option with
autocomplete: true. Currently, nosedrum routes these to the samecommand/1callback as regular command invocations, forcing command modules to manually inspect the interaction type and branch accordingly.This is a pain point for anyone using autocomplete — the command logic and autocomplete logic serve different purposes and should be separate callbacks.
Changes
lib/nosedrum/application_command.ex— addautocomplete/1as an optional callback with documentation and examplelib/nosedrum/storage/dispatcher.ex— splithandle_interactionto detect autocomplete interactions (type 4) and route toautocomplete/1if implemented, falling back tocommand/1for backwards compatibilityUsage
Backwards Compatibility
Fully backwards compatible —
autocomplete/1is an optional callback. If not implemented, autocomplete interactions fall back tocommand/1as before.Testing
mix compile --warnings-as-errorspassesmix test --no-start— 79 tests, 0 failures