-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v3: cmdroute: Add Router.Group() #383
Labels
enhancement
New feature or request
Comments
There's currently no way to make To do something like this, there should be a res.AddFunc("search", res.Search)
res.Group(func(res *cmdroute.Router) {
res.Use(res.CheckAccess)
res.AddFunc("set", res.Set)
}) |
diamondburned
changed the title
How does the middleware work in this framework?
v3: cmdroute: Add Router.Group()
Mar 15, 2023
simple trick Wrap cmdroute.CommandHandlerFunc in another cmdroute.CommandHandlerFunc res.AddFunc("set", res.CheckAccessMiddleware(res.Set)) func (r *resource) CheckAccessMiddleware(fn cmdroute.CommandHandlerFunc) cmdroute.CommandHandlerFunc {
return func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData {
interaction := data.Event.Data.(*discord.CommandInteraction)
userID, err := ParseUserID(interaction.Options)
if err != nil {
return r.send(err.Error())
}
if !checkAccess(r.supportRoleID, data.Event.Member, userID) {
return r.send(ErrNoAccess.Error())
}
return fn(ctx, data)
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I expect middleware to run for
set
anddelete
commands, but in fact I get this behavior for all commands. How can I concretize the execution of the middleware layer?The text was updated successfully, but these errors were encountered: