Middleware

Contains static command middleware methods

Source:

Methods

(static) .expect(argTypes: object)MiddlewareFunction

Takes an object mapping argument names to argument types that checks the types of passed arguments and ensures required arguments are present and valid. An argument list string can also be used -- See Util.parseArgTypes for an example of how the list 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), the only exception being localize, which should always come last.

See ExpectArgType for information on valid types.

Examples:

{ '<mem>': 'Member', '<age>': 'Number', '<desc>': 'String' }
{ '<height>': ['short', 'medium', 'tall'] }

Note: If verifying a BannedUser returned from resolve, use the User type. If verifying a Duration type, use Number.

This middleware does not modify args in any way.

Parameters:
Name Type Description
argTypes
object
|
string

An object of argument names mapped to argument types or a TypeScript-style argument list string
See: ExpectArgType
See: Util.parseArgTypes

Source:
Returns:
MiddlewareFunction

(static) .localize()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. This middleware should be used after any other middleware like expect or resolve 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

Source:
Returns:
MiddlewareFunction

(static) .resolve(argTypes: object)MiddlewareFunction

Takes an object mapping argument names to argument types that resolves args to their specified type or throws errors for any invalid input. An argument list string can also be used -- See Util.parseArgTypes for an example of how the list should be formatted

See ResolveArgType for information on valid types.

Example:

{ '<mem>': 'Member', '<age>': 'Number', '<...desc>': 'String' }

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

Note: If you are using a string literal array type with expect alongside this, the corresponding type you should resolve for that arg before using expect is String

Parameters:
Name Type Description
argTypes
object
|
string

An object of argument names mapped to argument types or a TypeScript-style argument list string
See: ResolveArgType
See: Util.parseArgTypes

Source:
Returns:
MiddlewareFunction