-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
feat: add ExtendedPrecondition #320
feat: add ExtendedPrecondition #320
Conversation
While there's a use for this, I don't know if it's worth the trouble, you see, you can define an array of entries to require one step to pass before the former, so if you have
|
That's true, but if you add the Moderator precondition to a lot of commands, it could be quite tiresome. Furthermore, with the syntax of extended argument, it can make it perfectly clear to other readers that it depends on another, and it's not just a coincidence that they are coupled together in commands. If a contributor adds in one precondition but doesn't realize they need the other, insecurities will open up in the bot. Lastly, although a very rare case, if you have a precondition that depends on another that depends on another, it will be very tedious to list them out each time. With extended preconditions, the method to do so will be super easy no matter how long the chain gets. |
That's why you define abstractions in your commands to push those entries, just like Sapphire's Command class does. |
Yeah, that would definitely be my alternative, and I'm fine if that's the direction you guys think we should go in. I just find it a bit hacky, and would always prefer a built-in system. |
@vladfrangu @favna any thoughts? |
I don't see the use for this when you can do something like this // maybe we should export our preconditions...
import { CoreGuildOnlyPrecondition, isErr } from '@sapphire/framework';
export class UserPrecondition extends CoreGuildOnlyPrecondition {
public override async run(...args: VladIsLazyTheseAreTheArgs[]) {
const baseResult = await super.run(...args);
if (isErr(baseResult)) return baseResult;
// My custom checks
return this.ok()
}
} So, I'm with kyra on this one |
Why didn't I think of that lmao that's so simple But then why do we need |
|
It was kept for backwards compatibility and for users who like to use it, but we removed it internally when we switched to resolvers because they could achieve the same anyway. |
Other than that, I'm with @kyranet and @vladfrangu |
@Lioness100 as for your brain dumps:
The
I'm not sure to what part of the docs you're referring to. Anyway, the
Yes, because they show up in IntelliSense. If anything in depth JSDoc descriptions can be copied to guides, but because IntelliSense is provided right in the IDE this will remain to be valueable.
Because that still needs to be written 🤔. PRs for documentation (be that website / guides, or JSDoc) are very, very welcome and appreciated.
That's something for @kyranet to answer.
Can you point to some examples? It might be typos, it might be intentional. I'm not sure.
In light of the responses above, I'll skip this one.
That's actually a good remark. We could add that for the other pieces. Feel free to make a PR for this. |
Let's deprecate it in v2, and remove in v3 please. |
My bad! I wasn't specific. I was referencing that in the examples in the JSDoc for
Again, this was referring to the examples in the JSDoc for Thank you for all the other answers to my brain dump! As for PRs, I'd be happy to make one for namespaces of I'll also try to help with guides sometime in the future, but it's not something I can do right now :(. Lastly, Vlad mentioned in their code that it might be worthwhile to export internal preconditions? Could I also make a PR for this, and if so, is there a certain format you guys would prefer? Thanks! |
This PR adds the
ExtendedPrecondition
class, where you can define a precondition to extend. Wherever the extended precondition is run, the base will be run first, and execution will only continue if the base returnsOk
. This is for performing operations that depend on another precondition passing, and imo is easier and more readable than just adding both preconditions sequentially every time you want to use the second one.I basically just copied
ExtendedArgument
and changedArgument
toPrecondition
but I have a few thoughts after looking through the source code a bit more:O
for the options that is then passed intoStore<O>
, shouldn't the type foroptions
in the constructor also beO
?(at)
no longer needs to replace@
?User*
in the JSDoc?Argument
, you can useexport default
orexport =
too." seems pretty guide like which doesn't fit in API docs. Also, why doesExtendedArgument
get jsdoc guides but notCommand
,Listener
, etc? They feel left out :(PreconditionContext
extend a record instead of fetching context types from thePreconditions
interface which would be much safer?#handle
function, right?Precondition
use a namespace for its affiliated interfaces but none of the other stores do?Sorry for my thought vomit lol
This PR is untested