new StatGroup(parent [, metadata])
HG stats for a single timeframe.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
parent |
GuildGame | The parent instance of this group. | |
metadata |
HGStatMetadata | string |
<optional> |
Additional information to store with these stats, or ID if metadata should be read from file since this group already exists. |
- Source:
Members
-
<private, constant> _dir :string
-
The directory where all of this group's information is stored.
Type:
- string
- Source:
-
<private> _fetchQueue :object.<Array.<function()>>
-
Queue of callbacks to fire once an object has been read from file. This is used to ensure that if multiple manipulations are requested on a single object at the same time, all modifications will take place on the same instance instead of overwriting eachother. Mapped by ID being fetched.
Type:
- object.<Array.<function()>>
- Default Value:
-
- {}
- Source:
-
<private> _saveQueue :object.<{data: HungryGames~Stats, timeout: Timeout}>
-
Cache of Stats objects that are to be saved to file, and the timeout until it will be saved. Prevents saving the same file multiple times at once.
Type:
- object.<{data: HungryGames~Stats, timeout: Timeout}>
- Default Value:
-
- {}
- Source:
-
<constant> bot :string
-
The ID of this current bot.
Type:
- string
- Source:
-
<constant> guild :string
-
The guild ID where this stat group resides.
Type:
- string
- Source:
-
id :string
-
The unique ID for this stat group. Unique per-guild.
Type:
- string
- Source:
Methods
-
<static> createID(game)
-
Create an ID for a new group.
Parameters:
Name Type Description game
HungryGames~GuildGame The game to create an ID for to ensure no collisions. - Source:
- To Do:
-
- Limit number of IDs to prevent infinite loop finding new ID.
Returns:
Valid created ID.- Type
- string
-
<static> exists(game, id)
-
Check if a stat group with the given ID exists for the given game.
Parameters:
Name Type Description game
HungryGames~GuildGame The game of which the stats to look up. id
string The group ID to check for. - Source:
Returns:
True if exists, false otherwise.- Type
- boolean
-
<static> fetchList(game, cb)
-
Fetch list of IDs for all created groups.
Parameters:
Name Type Description game
HungryGames~GuildGame The game to get list for. cb
function Callback with optional error argument, otherwise second argument is array of IDs as strings. - Source:
-
<private> _fetchMetadata(cb)
-
Fetch the metadata for this group from file.
Parameters:
Name Type Description cb
function Callback with optional error argument, otherwise second argument is parsed HGStatMetadata. - Source:
-
<private> _fetchUser(uId, cb)
-
Fetch stats for a specific user in this group. Returned stats are modifiable, but changes will not persist unless saved to file.
Parameters:
Name Type Description uId
string The user ID of which to lookup. cb
function Callback with optional error as first argument, otherwise has stats as second argument. - Source:
-
<private> _parseMetadata(data)
-
Parse the given object into a HGStatMetadata object.
Parameters:
Name Type Description data
object The data to parse. - Source:
Returns:
The parsed object.- Type
- HGStatMetadata
-
<private> _saveMetadata(meta [, immediate])
-
Save the current metadata to file.
Parameters:
Name Type Argument Default Description meta
HGStatMetadata The data to save. Overwrites existing data. immediate
boolean <optional>
false Force saving to perform immediately instead of delaying until next event loop. - Source:
-
<private> _saveUser(data [, immediate])
-
Save a stats object to file.
Parameters:
Name Type Argument Default Description data
HungryGames~Stats The stats object to save. immediate
boolean <optional>
false Force saving to happen immediately instead of waiting until next event loop. - Source:
-
<private> fetchMetadata(cb)
-
Fetch the metadata for this group from file. Modified values will not persist. Use functions to modify.
Parameters:
Name Type Description cb
function Callback with optional error argument, otherwise second argument is parsed HGStatMetadata. - Source:
-
fetchUser(uId, cb)
-
Fetch stats for a specific user in this group. Modified values will not persist. Use functions to modify.
Parameters:
Name Type Description uId
string The user ID of which to lookup. cb
function Callback with optional error as first argument, otherwise has stats as second argument. - Source:
- To Do:
-
- Return immutable/frozen copy to enforce no-modify rule.
-
fetchUsers( [opts], cb)
-
Fetch stats for a group of users. If array of IDs is given, data will not be sorted.
Parameters:
Name Type Argument Description opts
HGStatGroupUserSelectOptions | Array.<string> <optional>
Options to specify which users are fetched, or array of user IDs to fetch. cb
function Callback with optional error as first argument, otherwise has stats as second argument as array of HungryGames~Stats objects. - Source:
-
fetchValue(uId, key, cb)
-
Fetch a stat value for a single user. Immutable.
Parameters:
Name Type Description uId
string The user ID of which to fetch. key
string The key of the value to fetch. cb
function Callback with optional error argument, and matched value. - Source:
-
increment(uId, key [, amount] [, cb])
-
Increment a value by an amount.
Parameters:
Name Type Argument Default Description uId
string The user ID of which to modify. key
string The key of the value to modify. amount
number <optional>
1 Amount to increment by. Can be negative to decrement. cb
function <optional>
Callback with single optional error argument. - Source:
-
reset()
-
Delete all data associated with this group.
- Source:
-
setMetaEnd(endTime)
-
Set the metadata end time.
Parameters:
Name Type Description endTime
Date | number | string Date parsable time. - Source:
-
setMetaName(name)
-
Set the metadata name.
Parameters:
Name Type Description name
string The new value. - Source:
-
setMetaStart(startTime)
-
Set the metadata start time.
Parameters:
Name Type Description startTime
Date | number | string Date parsable time. - Source:
-
setValue(uId, key, value, cb)
-
Set a stat value for a single user.
Parameters:
Name Type Description uId
string The user ID of which to change. key
string The key of the value to change. value
* The value to store. cb
function Callback with single optional error argument. - Source: