1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 01:02:58 +00:00

cmdroute: Further deprecate Handle{Command,Autocompletion}

These functions now call HandleInteraction directly, which then calls
internal functions. For incorrect uses, this change is breaking.
This commit is contained in:
diamondburned 2024-07-06 11:19:53 +07:00
parent 4d2f793418
commit bc3439b8ff
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -128,9 +128,9 @@ func (r *Router) With(mws ...Middleware) *Router {
func (r *Router) HandleInteraction(ev *discord.InteractionEvent) *api.InteractionResponse {
switch data := ev.Data.(type) {
case *discord.CommandInteraction:
return r.HandleCommand(ev, data)
return r.handleCommand(ev, data)
case *discord.AutocompleteInteraction:
return r.HandleAutocompletion(ev, data)
return r.handleAutocompletion(ev, data)
case discord.ComponentInteraction:
return r.handleComponent(ev, data)
default:
@ -138,6 +138,23 @@ func (r *Router) HandleInteraction(ev *discord.InteractionEvent) *api.Interactio
}
}
// HandleCommand implements CommandHandler. It applies middlewares onto the
// handler to be executed.
//
// Deprecated: This function should not be used directly. Use [HandleInteraction]
// instead. This function now calls HandleInteraction internally.
func (r *Router) HandleCommand(ev *discord.InteractionEvent, data *discord.CommandInteraction) *api.InteractionResponse {
return r.HandleInteraction(ev)
}
// HandleAutocompletion handles an autocompletion event.
//
// Deprecated: This function should not be used directly. Use [HandleInteraction]
// instead. This function now calls HandleInteraction internally.
func (r *Router) HandleAutocompletion(ev *discord.InteractionEvent, data *discord.AutocompleteInteraction) *api.InteractionResponse {
return r.HandleInteraction(ev)
}
func (r *Router) callHandler(ev *discord.InteractionEvent, fn InteractionHandlerFunc) *api.InteractionResponse {
h := InteractionHandler(fn)
@ -154,12 +171,7 @@ func (r *Router) callHandler(ev *discord.InteractionEvent, fn InteractionHandler
return h.HandleInteraction(context.Background(), ev)
}
// HandleCommand implements CommandHandler. It applies middlewares onto the
// handler to be executed.
//
// Deprecated: This function should not be used directly. Use HandleInteraction
// instead.
func (r *Router) HandleCommand(ev *discord.InteractionEvent, data *discord.CommandInteraction) *api.InteractionResponse {
func (r *Router) handleCommand(ev *discord.InteractionEvent, data *discord.CommandInteraction) *api.InteractionResponse {
cmdType := discord.SubcommandOptionType
if cmdIsGroup(data) {
cmdType = discord.SubcommandGroupOptionType
@ -278,11 +290,7 @@ func (r *Router) AddAutocompleterFunc(name string, f AutocompleterFunc) {
r.AddAutocompleter(name, f)
}
// HandleAutocompletion handles an autocompletion event.
//
// Deprecated: This function should not be used directly. Use HandleInteraction
// instead.
func (r *Router) HandleAutocompletion(ev *discord.InteractionEvent, data *discord.AutocompleteInteraction) *api.InteractionResponse {
func (r *Router) handleAutocompletion(ev *discord.InteractionEvent, data *discord.AutocompleteInteraction) *api.InteractionResponse {
cmdType := discord.SubcommandOptionType
if autocompIsGroup(data) {
cmdType = discord.SubcommandGroupOptionType