GuildStorage
Stores data entries associated with guilds
Constructor Summary
Public Constructor | ||
public |
constructor(key: string, localStorage: LocalStorage, logger: Logger, objectBased: boolean) |
Member Summary
Public Members | ||
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
|
Method Summary
Public Methods | ||
public |
Clears all entries associated with a guild |
|
public |
clearAll() Clears all entries |
|
public |
Deletes an entry associated with a guild |
|
public |
Checks if an entry associated with a guild exists |
|
public |
find(guild: Guild | string, searchString: string, searchOptions: SearchOptions): *[] Finds all entries in a storage that optionally match a search string |
|
public |
Checks if there are no entries associated with a guild |
|
public |
Loads the data from LocalStorage |
|
public |
Saves an entry associated with a guild |
|
public |
Saves the data to LocalStorage |
Public Constructors
public constructor(key: string, localStorage: LocalStorage, logger: Logger, objectBased: boolean) source
Params:
Name | Type | Attribute | Description |
key | string | The key of the storage in the LocalStorage |
|
localStorage | LocalStorage | The LocalStorage instance to use |
|
logger | Logger |
|
The logger to use |
objectBased | boolean |
|
If true, the storage will be object based. If false, it will be array-based. |
Public Members
public localStorage: LocalStorage source
Public Methods
public delete(guild: Guild | string, entry: * | Object | string, searchFunction: function): boolean source
Deletes an entry associated with a guild
Params:
Name | Type | Attribute | Description |
guild | Guild | string | The guild or guild ID the entry is associated with |
|
entry | * | Object | string | If the storage is array-based, this can be any value to find and delete. If it is object-based, this must be an object with a "key" property, or a string that is the key. |
|
searchFunction | function |
|
The function to find existing entries (See GuildStorage#exists) |
public exists(guild: Guild | string, entry: * | Object | string, searchFunction: function): boolean source
Checks if an entry associated with a guild exists
Params:
Name | Type | Attribute | Description |
guild | Guild | string | The guild or guild ID the entry is associated with |
|
entry | * | Object | string | If the storage is array-based, this can be any value to check existence of. If it is object-based, this must be an object with a "key" property, or a string that is the key. |
|
searchFunction | function |
|
The function to find existing entries. If the storage is array-based, it will be passed the value of each entry. If it is object-based, it will be passed the key and value of each entry. |
public find(guild: Guild | string, searchString: string, searchOptions: SearchOptions): *[] source
Finds all entries in a storage that optionally match a search string
Params:
Name | Type | Attribute | Description |
guild | Guild | string | The guild or guild ID to find the entries of |
|
searchString | string |
|
The string to match entries against |
searchOptions | SearchOptions |
|
Options for the search |
Return:
*[] | All found entries |
public isEmpty(guild: Guild | string): boolean source
Checks if there are no entries associated with a guild
public save(guild: Guild | string, entry: * | Object, searchFunction: function): boolean source
Saves an entry associated with a guild
Params:
Name | Type | Attribute | Description |
guild | Guild | string | The guild or guild ID the entry should be associated with |
|
entry | * | Object | If the storage is array-based, this can be any value to store. If it is object-based, this must be an object with "key" and "value" properties to store. |
|
searchFunction | function |
|
The function to find existing entries (See GuildStorage#exists) |
Return:
boolean | Whether or not the entry was saved (will be false only if the storage is array-based and the entry already exists) |