Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UserCache

Cache responsible for caching users

Hierarchy

Index

Methods

addToIndex

  • addToIndex(id: string): Promise<void>
  • Add users to the index

    Parameters

    • id: string

      ids of the users

    Returns Promise<void>

bindGuild

  • Bind a guild id to the cache

    Parameters

    • guildId: string

      id of the guild that should be bound to this cache

    Returns UserCache

bindObject

  • bindObject(boundObject: Partial<UserData>): void
  • Bind an object to the cache instance, you can read more on binding on the landing page of the documentation

    Parameters

    • boundObject: Partial<UserData>

      Object to bind to this cache instance

    Returns void

bindUserId

  • Bind a user id to the cache, used by the member cache

    Parameters

    • userId: string

      id of the user

    Returns UserCache

    Returns a UserCache that has an id bound to it, which serves as the default argument to get, update and delete

buildId

  • buildId(id: string): string
  • Build an id consisting of $namespace.$id

    Parameters

    • id: string

      id to append to namespace

    Returns string

    constructed id

filter

  • filter(fn: (user?: UserData, index?: number, array?: UserData[]) => unknown, ids?: undefined | string[]): Promise<UserCache[]>
  • Filter for users by providing a filter function which returns true upon success and false otherwise

    Parameters

    • fn: (user?: UserData, index?: number, array?: UserData[]) => unknown

      filter function to use for the filtering

        • (user?: UserData, index?: number, array?: UserData[]): unknown
        • Parameters

          • Optional user: UserData
          • Optional index: number
          • Optional array: UserData[]

          Returns unknown

    • ids: undefined | string[] = undefined

      Array of user ids, if omitted the global user index will be used

    Returns Promise<UserCache[]>

find

  • find(fn: (user?: UserData, index?: number, array?: string[]) => unknown, ids?: undefined | string[]): Promise<null | UserCache>
  • Find a user by providing a filter function which returns true upon success and false otherwise

    Parameters

    • fn: (user?: UserData, index?: number, array?: string[]) => unknown

      filter function to use for filtering for a user

        • (user?: UserData, index?: number, array?: string[]): unknown
        • Parameters

          • Optional user: UserData
          • Optional index: number
          • Optional array: string[]

          Returns unknown

    • ids: undefined | string[] = undefined

      List of ids that should be used as the scope of the filter

    Returns Promise<null | UserCache>

    Returns a User Cache with a bound user or null if no user was found

get

  • Loads a user from the cache via id

    Parameters

    • id: undefined | string = ...

      discord id of the user

    Returns Promise<null | UserCache>

    Returns a User Cache with a bound user or null if no user was found

getIndexCount

  • Get the number of users that are currently cached

    Returns Promise<number>

    Number of users currently cached

getIndexMembers

  • getIndexMembers(): Promise<string[]>
  • Get a list of currently indexed users, since users is a global namespace, this will return ALL users that the bot cached currently

    Returns Promise<string[]>

    Array with a list of ids of users that are indexed

isIndexed

  • isIndexed(id: string): Promise<boolean>
  • Check if a user is indexed

    paramid

    id of the user

    Parameters

    • id: string

    Returns Promise<boolean>

    True if the user is indexed, false otherwise

remove

  • remove(id?: undefined | string): Promise<void>
  • Remove a user from the cache

    Parameters

    • id: undefined | string = ...

      discord id of the user

    Returns Promise<void>

removeFromIndex

  • removeFromIndex(id: string): Promise<void>
  • Remove a user from the index

    Parameters

    • id: string

      id of the user

    Returns Promise<void>

removeIndex

  • Delete the user index, you should probably not use this function, but I won't stop you.

    Returns Promise<void>

structurize

  • structurize<D>(data: Partial<D>): Partial<D>
  • Delete keys from data if necessary based on RainCache structureDefs options and return the cleaned data

    Type parameters

    • D

    Parameters

    • data: Partial<D>

      The data to possibly delete object entries from

    Returns Partial<D>

update

  • Update a user entry in the cache

    Parameters

    • id: undefined | string = ...

      discord id of the user

    • data: Partial<UserData>

      updated data of the user, it will be merged with the old data

    Returns Promise<UserCache>

Properties

Optional boundGuild

boundGuild?: string

guild id bound to this cache

boundObject

boundObject: null | Partial<UserData> = null

dataTimestamp

dataTimestamp: null | Date = null

namespace

namespace: "user" = "user"

rain

rain: RainCache<any, any>

storageEngine

storageEngine: BaseStorageEngine<UserData>

Constructors

constructor

  • Create a new UserCache

    This class is automatically instantiated by RainCache

    Parameters

    • storageEngine: BaseStorageEngine<UserData>

      Storage engine to use for this cache

    • rain: RainCache<any, any>
    • Optional boundObject: Partial<UserData>

      Optional, may be used to bind a user object to the cache

    Returns UserCache

Generated using TypeDoc