yuuko
yuuko copied to clipboard
Argument parsing
Fixes #25 (or at least it will).
This should be ready for at least basic testing, though it doesn't come with much at the moment. The available argument types out of the box are integer, number, and member. Options for each argument type are documented in the source, but aren't exposed super well in intellisense without Typescript's generics being attached to the method. Not sure if there's much I can do about that, but I'll make sure the built-in ones are outlined well on the site and stuff at least.
To use with JS:
const [member, num] = await parseArgs(args, [
{
type: 'member',
me: msg.member,
guild: msg.channel.guild,
},
{
type: 'integer',
lowerBound: 1,
},
]);
To register a custom argument type:
registerArgumentType('foo', (args, options) => {
// do something with args to get your type
// options is one of the objects passed to parseArgs, you can pull custom options from there
// remember to modify the args array so other argument resolvers don't try to parse the same text
return args.shift().length > options.customThing;
// (async resolvers are also supported)
});
const [val] = await parseArgs(['somethingVeryLong'], [
{
type: 'foo',
customThing: 3,
}
]);
val //> true (since "somethingVeryLong" has more than 3 characters)