Contains static command middleware methods
Methods
(static) .expect(argTypes: object) → MiddlewareFunction
Takes an object mapping argument names to Resolver
type names
and checks the types of passed arguments, ensuring required
arguments are present and valid. An argument list string
can also be used -- See Util.parseArgTypes
for an example of how the list string should be formatted
Should be added to the command AFTER any and all middleware functions
that modify args in any way are added (resolve
,
for example), an exception being localize
,
which should always come last.
See BaseResolverType
for a list of base Resolver type names.
Examples:
{ '<mem>': 'Member', '<age>': 'Number', '<desc>': 'String' }
// or: 'mem: Member, age: Number, desc: String'
// An array literal for expecting specific strings can also be used
{ '<height>': ['short', 'medium', 'tall'] }
// or: `height: ['short', 'medium', 'tall']`
This middleware does not modify args in any way.
Parameters:
Name | Type | Description |
---|---|---|
argTypes |
|
An object of argument names mapped to Resolver type names
or a TypeScript-style argument list string |
(static) .localize() → MiddlewareFunction
Middleware function that inserts a ResourceProxy
object for the
language that will be used for the command call as the first arg for that
command call.
Note: The original
localize
middleware that insertedResourceLoader
functions into the command args has been moved tomodule:Middleware.localizeLoader
temporarily, butResourceLoader
functions themselves are deprecated in favor ofResourceProxy
.ResourceLoader
and associated functionality will be removed in a future release, only being left in despite the major version bump of 4.0.0 to ease the transition
Note: This middleware should be used after any other middleware like
expect
orresolve
because those are based around user input whereas this should be handled after user input related things as to not interfere with the other middleware and their inputs
(static) .localizeLoader() → MiddlewareFunction
Middleware function that inserts a ResourceLoader
function for the
language that will be used for the command call as the first arg for that
command call.
Note: This middleware should be used after any other middleware like
expect
orresolve
because those are based around user input whereas this should be handled after user input related things as to not interfere with the other middleware and their inputs
- Deprecated:
- Use
localize
instead.
- Use
- Source:
(static) .resolve(argTypes: object) → MiddlewareFunction
Takes an object mapping argument names to Resolver
type names
and resolves args to their specified type. An argument list string
can also be used -- See Util.parseArgTypes
for an example of how the list should be formatted
See BaseResolverType
for a list of base Resolver type names.
Example:
{ '<mem>': 'Member', '<age>': 'Number', '<desc>': 'String' }
// or: 'mem: Member, age: Number, desc: String'
// An array literal for expecting specific strings can also be used
{ '<height>': ['short', 'medium', 'tall'] }
// or: `height: ['short', 'medium', 'tall']`
Supports '...'
in the argument name as the final argument to gather
all remaining input into one string and attempt to resolve them to
the provided argument type
Parameters:
Name | Type | Description |
---|---|---|
argTypes |
|
An object of argument names mapped to Resolver type names
or a TypeScript-style argument list string |