State of the current update.

Possible scene names

Type Parameters

  • State extends object

    Type that represents the state

Constructors

  • Type Parameters

    • State extends object

    Parameters

    • storage: StateService
    • key: string
    • scene: null | string
    • Optionalscoped: boolean
    • OptionalcustomStorage: StateService
    • OptionalcustomKey: string

    Returns UpdateState<State>

Accessors

  • get scene(): null | string
  • Name of the current scene

    Returns null | string

Methods

  • Delete the state from the storage

    Returns Promise<void>

  • Enter some scene

    Type Parameters

    Parameters

    • scene: Scene
    • Optionalparams: { reset?: boolean; ttl?: number; with?: SceneState }
      • Optionalreset?: boolean

        If currently in a scoped scene, whether to reset the state

        true
        
      • Optionalttl?: number

        TTL for the scene (in seconds)

      • Optionalwith?: SceneState

        Initial state for the scene

        Note that this will only work if the scene uses the same key delegate as this state.

    Returns Promise<void>

  • Exit from current scene to the root

    Parameters

    • reset: boolean = true

      Whether to reset scene state (only applicable in case this is a scoped scene)

    Returns Promise<void>

  • Retrieve the state from the storage, falling back to default if not found

    Parameters

    • fallback: State | () => State

      Default state value

    • Optionalforce: boolean

      Whether to ignore cached state (def. false)

    Returns Promise<State>

  • Retrieve the state from the storage, falling back to default if not found

    Parameters

    • Optionalfallback: State | () => State

      Default state value

    • Optionalforce: boolean

      Whether to ignore cached state (def. false)

    Returns Promise<null | State>

  • Retrieve the state from the storage

    Parameters

    • Optionalforce: boolean

      Whether to ignore cached state (def. false)

    Returns Promise<null | State>

  • Merge the given object to the current state.

    Note: If the storage currently has no state, then fallback must be provided.

    Basically a shorthand to calling .get(), modifying and then calling .set()

    Parameters

    • state: Partial<State>

      State to be merged

    • params: { fallback?: State | () => State; forceLoad?: boolean; ttl?: number } = {}

    Returns Promise<State>

  • Rate limit some handler.

    When the rate limit exceeds, RateLimitError is thrown.

    This is a simple rate-limiting solution that uses the same key as the state. If you need something more sophisticated and/or customizable, you'll have to implement your own rate-limiter.

    Note: key is used to prefix the local key derived using the given key delegate.

    Parameters

    • key: string

      Key of the rate limit

    • limit: number

      Maximum number of requests in window

    • window: number

      Window size in seconds

    Returns Promise<[number, number]>

    Tuple containing the number of remaining and unix time in ms when the user can try again

  • Reset the rate limit

    Parameters

    • key: string

      Key of the rate limit

    Returns Promise<void>

  • Set new state to the storage

    Parameters

    • state: State

      New state

    • Optionalttl: number

      TTL for the new state (in seconds)

    Returns Promise<void>

  • Throttle some handler.

    When the rate limit exceeds, this function waits for it to reset.

    This is a simple wrapper over rateLimit, and follows the same logic.

    Note: key is used to prefix the local key derived using the given key delegate.

    Parameters

    • key: string

      Key of the rate limit

    • limit: number

      Maximum number of requests in window

    • window: number

      Window size in seconds

    Returns Promise<[number, number]>

    Tuple containing the number of remaining and unix time in ms when the user can try again