hasPermission() & inhibitor to allow asynchronous code to be run inside #34
Comments
|
That's a good point, I haven't been aware of this method being called somewhere else. However, I am sure you are aware that permission checks are usually more complex requiring various query calls etc. So the only way is to either cache that data somewhere and process it in |
I have use case where I have to asynchronously get data in Inhibitor. More specifically, it's Keyv storage operation: |
OK, I temporarily solve my case by introducing guards module that provides function for returning I import this guard function in each command module tightly restricted to whitelisted channels and check whether to return that warning |
It would be really great if inhibitor function and/or
hasPermission()
function would be able to deal with asynchronous code inside. It seems from the source point of view rewrittinghasPermission()
to deal with async would take a bit of work and might be prone to bugs (hell, if no one wants to do it, I can) so I propose an alternative functionHasPermissionAsync()
or whatever you guys like more. It would require just additional, perhaps, redundantif
check indiscord.js-commando/src/commands/message.js #134
There could also be an additional check, let's say..
This doesn't seem to cause any issues since run() method is
async
itself. It might be redundant, but gives flexibility for users who wantasync
code to be run inhasPermission()
and those who don't. The same goes for inhibitor functions, to be honest, I can't get the sense why they are not async to begin with.Now, pardon my walls of text, the reason I am proposing this is that I am developing myself a commando based bot and my application is quite restrictive in terms of who can do what and when. Meaning there has to be a permission / role check for every command user requests. All that translates to various services calling to database and retrieving relevant information and forming a response whether that user can, at this point of time, use desired command. Back to the point, all those services that connect to database are asynchronous, because database calls by nature are like that in Node and that makes things complicated when
commando
does not handle async code. This issue I am having could've been solved either by inhibitor and/or hasPermission method call if they handled async code.I could, of course, just do redundant and nightmare to maintain checks in every command I develop, but honestly, the thought alone, makes me regret to porting my code to
commando
. My code previously was mostly plain discord.js with npmclapp
package integration. Good parts, it was very flexible, but became a nightmare to maintain in the long run due to lack of solid structure. Commando has that, but lacks flexibility part. I am hoping for a decent middle ground between the two.The text was updated successfully, but these errors were encountered: