Comments (2)
There's currently no way to make Use
only work for certain commands of the same level. Middlewares will always run before the command handler regardless of when they're added.
To do something like this, there should be a Group()
function like go-chi:
res.AddFunc("search", res.Search)
res.Group(func(res *cmdroute.Router) {
res.Use(res.CheckAccess)
res.AddFunc("set", res.Set)
})
from arikawa.
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)
}
}
from arikawa.
Related Issues (20)
- SelectComponent should be StringSelectComponent? HOT 1
- Description for StringSelectComponent is incorrect
- Could not find Message Content Intent HOT 1
- v3: Fix regression from c07f574
- Discord doesn't display command results SOLVED HOT 1
- Default avatar is calculated incorrectly for migrated accounts
- v4: Generate API and Gateway structures
- v4: Automatically emit Gateway commands for State wrappers
- v4: Return api.InteractionResponse for CommandHandler
- v4: ComponentHandler should allow type-constructing handlers
- Unable to instrument API call HOT 10
- Support for api/v9/guilds/<guildid>/members/supplemental
- feat: Spacebar support
- v3: Inconsistent channel permission values for large guilds between sessions HOT 9
- v3: Add cmdroute.Router.Group
- v3: CommandInteraction Doesn't Support Attachment Options
- Groups do not use autocompleter
- Responding interaction with no CommandHandler return value HOT 4
- Dynamic routing for cmdroute.Router HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arikawa.