Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Storage

The storage class used by the MessageBot class and all MessageBotExtension instances.

Hierarchy

  • Storage

Index

Methods

Abstract clear

  • clear(prefix?: undefined | string): void
  • Clears all keys using the current prefix, or the current prefix and the additional prefix if supplied.

    Parameters

    • Optional prefix: undefined | string

      the prefix to limit clearing to

    Returns void

Abstract get

  • get<T>(key: string, fallback: T): T
  • Gets the specified key from the storage, if the key has not been set, returns the fallback. Note that though this is typed as the type of the fallback being returned, a deep comparison will not be used. You must validate your own objects.

    Type parameters

    • T

    Parameters

    • key: string

      the key to get

    • fallback: T

      if the key was not set, this will be returned.

    Returns T

    the stored value for the key.

Abstract keys

  • keys(prefix?: undefined | string): string[]
  • Gets all storage keys available in the current storage object

    Parameters

    • Optional prefix: undefined | string

    Returns string[]

Abstract prefix

  • Creates a new instance of this class with the current prefix and the additional prefix supplied.

    Parameters

    • prefix: string

    Returns Storage

Abstract set

  • set(key: string, value: any): void
  • Sets the specified key in the storage, overwriting any current data.

    Parameters

    • key: string

      the key to set

    • value: any

      the value to set in the storage.

    Returns void

with

  • with<T>(key: string, fallback: T, callback: function): void
  • Utility method to use and automatically save a key

    Type parameters

    • T

    Parameters

    • key: string

      the key use when getting and setting the value

    • fallback: T

      the fallback if the key doesn't exist

    • callback: function

      the function to be called with the data, if the callback returns null or undefined, it is assumed that the value has been mutated and will be saved.

        • (value: T): T | void
        • Parameters

          • value: T

          Returns T | void

    Returns void

Generated using TypeDoc