Command

implementsMiddlewareChainer<M, C>

Description

An executable command which only executes if its Matcher is satisfied

Example

const command = new Command()
  .match(matchPrefixes("sum"))
  .use(context => {
    const { content } = context

    const numbers = content.split(" ").map(n => Number(n))
    const result = numbers.reduce((a, b) => a + b)

    console.log("The sum is:", result)
  })

// Input: "sum 4 4"
// Output: "The sum is: 8"

Generics

M
Message
C
Client
D
Metadata
S

Properties

metadata:
D
middleware:
Middleware<any, M, C>[]

Methods

match(matcher)Command<M, C, D, T & S>
Parameters
matcher:
Matcher<T & S, M, C>
setMetadata(data)Command<M, C, T, S>
Parameters
data:
T
use(middleware)Command<M, C, D, T & S>

Add Middleware. The order that you call this is the order the middleware will be in

Parameters
middleware:
Middleware<T & S, M, C>