mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-09 21:47:07 +00:00
cmdroute: Fix Autocompleter handling (#423)
* handle group with cmdroute/autocompleter * handle autocompleter: find all options
This commit is contained in:
parent
5089b62bb2
commit
529272a9a9
|
@ -316,18 +316,42 @@ type autocompleterData struct {
|
|||
data discord.AutocompleteOption
|
||||
}
|
||||
|
||||
// findAutocompleter finds the autocomplete handler for the given option name.
|
||||
// It checks the current router and its groups.
|
||||
func (r *Router) findAutocompleter(ev *discord.InteractionEvent, data discord.AutocompleteOption) (autocompleterData, bool) {
|
||||
found, ok := r.findAutocompleterOnce(ev, data)
|
||||
if ok {
|
||||
return found, true
|
||||
}
|
||||
|
||||
for _, sub := range r.groups {
|
||||
found, ok = sub.findAutocompleterOnce(ev, data)
|
||||
if ok {
|
||||
return found, true
|
||||
}
|
||||
}
|
||||
|
||||
return autocompleterData{}, false
|
||||
}
|
||||
|
||||
// findAutocompleter finds the autocomplete handler for the given option name.
|
||||
// It only checks the current router and not its groups.
|
||||
func (r *Router) findAutocompleterOnce(ev *discord.InteractionEvent, data discord.AutocompleteOption) (autocompleterData, bool) {
|
||||
node, ok := r.nodes[data.Name]
|
||||
if !ok {
|
||||
return autocompleterData{}, false
|
||||
}
|
||||
|
||||
switch node := node.(type) {
|
||||
case routeNodeSub:
|
||||
if len(data.Options) != 1 || data.Type != discord.SubcommandGroupOptionType {
|
||||
break
|
||||
}
|
||||
return node.findAutocompleter(ev, data.Options[0])
|
||||
for _, option := range data.Options {
|
||||
found, ok := node.findAutocompleter(ev, option)
|
||||
if ok {
|
||||
return found, true
|
||||
}
|
||||
}
|
||||
case routeNodeCommand:
|
||||
if node.autocomplete == nil {
|
||||
break
|
||||
|
@ -341,7 +365,6 @@ func (r *Router) findAutocompleter(ev *discord.InteractionEvent, data discord.Au
|
|||
data: data,
|
||||
}, true
|
||||
}
|
||||
|
||||
return autocompleterData{}, false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue