Pipeline
Utility functions for the command dispatch pipeline - error responses, guards, permissionission checks, option transforms, middleware, and post-execute hooks.
Summary
Functions
Pipeline.sendErrorResponse(interaction: classes.TypesCommand | classes.Component | classes.Modal, errorMessage: string, override: ((classes.TypesCommand | classes.Component | classes.Modal, string) -> ())?)Pipeline.runGuards(guardEntries: { command.GuardEntry }, interaction: classes.TypesCommand, log: logger.Logger, name: string, onGuardFailed: ((classes.TypesCommand) -> ())?, onError: ((classes.TypesCommand | classes.Component | classes.Modal, string) -> ())?) → booleanPipeline.getMissingPermissions(permissionObject: classes.Permission, required: { apiTypes.Permissions }) → { apiTypes.Permissions }Pipeline.runTransforms(transforms: { [string]: command.TransformFunction }, interaction: classes.TypesCommand, log: logger.Logger, name: string, onError: ((classes.TypesCommand | classes.Component | classes.Modal, string) -> ())?) → { [string]: any }?Pipeline.injectGetTransformed(interaction: classes.TypesCommand, transformed: { [string]: any })Pipeline.runAfterHooks(afterHooks: { (classes.TypesCommand) -> () }, perCommand: ((classes.TypesCommand) -> ())?, interaction: classes.TypesCommand, log: logger.Logger)Pipeline.runMiddleware(middlewares: { (any, () -> ()) -> () }, index: number, interaction: any, final: () -> (), log: logger.Logger)Functions
Section titled “Functions”sendErrorResponse
Section titled “sendErrorResponse”Pipeline . sendErrorResponse ( interaction , errorMessage , override ) -> ()
Sends a generic error reply to the interaction, or delegates to override if provided.
runGuards
Section titled “runGuards”Pipeline . runGuards ( guardEntries , interaction , log , name , onGuardFailed , onError ) -> boolean
Evaluates all guard entries against the interaction. AND guards must all pass; within an OR group at least one must pass. Returns false and fires the guard-failed handler on first failure.
Parameters
| guardEntries: GuardEntry } | |
| interaction: TypesCommand | |
| log: Logger | |
| name: string | |
| onGuardFailed: TypesCommand) -> ())? | |
| onError: Modal, string) -> ())? |
Returns
| boolean |
getMissingPermissions
Section titled “getMissingPermissions”Pipeline . getMissingPermissions ( permissionObject , required ) -> { Permissions }
Returns permissionissions from required that are absent from permissionObject.
Parameters
| permissionObject: Permission | |
| required: Permissions } |
Returns
| Permissions } |
runTransforms
Section titled “runTransforms”Pipeline . runTransforms ( transforms , interaction , log , name , onError ) -> { [string]: any }?
Runs each named transform over its option value. Returns nil and fires the error handler if any transform throws; otherwise returns the full map of transformed values.
Parameters
| transforms: { { [string]: command.TransformFunction } } | |
| interaction: TypesCommand | |
| log: Logger | |
| name: string | |
| onError: Modal, string) -> ())? |
Returns
| { { [string]: any } } |
injectGetTransformed
Section titled “injectGetTransformed”Pipeline . injectGetTransformed ( interaction , transformed ) -> ()
Injects a getTransformed(name) method onto the interaction for retrieving transformed option values.
Parameters
| interaction: TypesCommand | |
| transformed: { { [string]: any } } |
runAfterHooks
Section titled “runAfterHooks”Pipeline . runAfterHooks ( afterHooks , perCommand , interaction , log ) -> ()
Runs the per-command afterExecute hook followed by all global after-hooks.
Errors in individual hooks are logged but do not propagate.
Parameters
| afterHooks: TypesCommand) -> () } | |
| perCommand: TypesCommand) -> ())? | |
| interaction: TypesCommand | |
| log: Logger |
runMiddleware
Section titled “runMiddleware”Pipeline . runMiddleware ( middlewares , index , interaction , final , log ) -> ()
Recursively runs each middleware in order, calling final when the chain is exhausted.