mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-20 19:47:12 +00:00
cmdroute: Add ev.Data into {Command,Autocomplete}Data
This mostly helps avoid a type assertion that could potentially be incorrectly done.
This commit is contained in:
parent
5e0d1cfe4a
commit
4bc415f72b
|
@ -38,6 +38,7 @@ type Middleware = func(next InteractionHandler) InteractionHandler
|
|||
type CommandData struct {
|
||||
discord.CommandInteractionOption
|
||||
Event *discord.InteractionEvent
|
||||
Data *discord.CommandInteraction
|
||||
}
|
||||
|
||||
// CommandHandler is a slash command handler.
|
||||
|
@ -71,6 +72,7 @@ func (f CommandHandlerFunc) HandleCommand(ctx context.Context, data CommandData)
|
|||
type AutocompleteData struct {
|
||||
discord.AutocompleteOption
|
||||
Event *discord.InteractionEvent
|
||||
Data *discord.AutocompleteInteraction
|
||||
}
|
||||
|
||||
// Autocompleter is a type for an autocompleter.
|
||||
|
|
|
@ -194,6 +194,7 @@ func (r *Router) callCommandHandler(ev *discord.InteractionEvent, found handlerD
|
|||
data := found.handler.HandleCommand(ctx, CommandData{
|
||||
CommandInteractionOption: found.data,
|
||||
Event: ev,
|
||||
Data: ev.Data.(*discord.CommandInteraction),
|
||||
})
|
||||
if data == nil {
|
||||
return nil
|
||||
|
@ -299,6 +300,7 @@ func (r *Router) callAutocompletion(ev *discord.InteractionEvent, found autocomp
|
|||
choices := found.handler.Autocomplete(ctx, AutocompleteData{
|
||||
AutocompleteOption: found.data,
|
||||
Event: ev,
|
||||
Data: ev.Data.(*discord.AutocompleteInteraction),
|
||||
})
|
||||
if choices == nil {
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue