Class: HG

HG

Hunger Games simulator subModule.

new HG()

Source:
Listens to Events:
  • Discord~Client#event:guildDelete
  • Discord~Client#event:channelDelete
  • Command#event:hg

Extends

Members


<nullable> bot :SpikeyBot

The parent SpikeyBot instance. Defaults to required cache value for autocompletion, updates to current reference at init.
Type:
Inherited From:
Source:

client :external:Discord~Client

The current bot client. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
  • external:Discord~Client
Inherited From:
Source:

command :Command

The command object for registering command listeners. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
Inherited From:
Source:

<constant> commit :string

The commit at HEAD at the time this module was loaded. Essentially the version of this submodule.
Type:
  • string
Inherited From:
Source:

common :Common

The common object. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
Inherited From:
Source:

<constant> defaultOptions :object.<{value: (string|number|boolean), values: (null|Array.<string>), comment: string}>

Default options for a game.
Type:
  • object.<{value: (string|number|boolean), values: (null|Array.<string>), comment: string}>
Source:

Discord :external:Discord

The current Discord object instance of the bot. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
Inherited From:
Source:

formatUsername

Source:

helpMessage :undefined|string|external:Discord~MessageEmbed

The help message to show the user in the main help message.
Type:
  • undefined | string | external:Discord~MessageEmbed
Inherited From:
Overrides:
Source:

<protected, readonly> initialized :boolean

Has this subModule been initialized yet (Has begin() been called).
Type:
  • boolean
Inherited From:
Source:

<constant> loadTime :number

The time at which this module was loaded for use in checking if the module needs to be reloaded because the file has been modified since loading.
Type:
  • number
Inherited From:
Source:

<constant> maxBytes :number

The maximum number of bytes allowed to be received from a client in an image upload.
Type:
  • number
Default Value:
  • 8000000 (8MB)
Source:

<abstract, protected> myName :string

The name of this submodule. Used for differentiating in the log. Should be defined before begin().
Type:
  • string
Inherited From:
Overrides:
Source:

NPC

Source:

<abstract> postPrefix :string

The postfix for the global prefix for this subModule. Must be defined before begin(), otherwise it is ignored.
Type:
  • string
Inherited From:
Overrides:
Source:

<private, inner, constant> alph :string

The alphabet twice, first lowercase, then uppercase.
Type:
  • string
Default Value:
  • abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
Source:

<private, inner, constant> battleFile :string

The file path to read battle events.
Type:
  • string
Default Value:
  • ./save/hgBattles.json
Source:
See:
  • HungryGames~battles

<private, inner, constant> battleMessage :object.<Discord~Message>

Storage of battle messages to edit the content of on the next update.
Type:
  • object.<Discord~Message>
Default Value:
  • {}
Source:

<private, inner> battles :Object

All attacks and outcomes for battles.
Type:
  • Object
Source:
See:
  • HungryGames~battleFile

<private, inner, constant> blockedmessage :string

Reply if unable to send message via DM.
Type:
  • string
Default Value:
  • I couldn't send you a message, you probably blocked me :(
Source:

<private, inner> defaultArenaEvents :Array.<HungryGames~ArenaEvent>

Default parsed arena events.
Type:
Source:
See:
  • HungryGames~eventFile

<private, inner> defaultBloodbathEvents :Array.<HungryGames~Event>

Default parsed bloodbath events.
Type:
Source:
See:
  • HungryGames~eventFile

<private, inner, constant> defaultColor :Discord~ColorResolveable

Default color to choose for embedded messages.
Type:
  • Discord~ColorResolveable
Default Value:
  • [200,125,0]
Source:

<private, inner, constant> defaultOptions :HungryGames~DefaultOptions

Default options for a game.
Type:
Source:

<private, inner> defaultPlayerEvents :Array.<HungryGames~Event>

Default parsed player events.
Type:
Source:
See:
  • HungryGames~eventFile

<private, inner, constant> emoji :object.<string>

Helper object of emoji characters mapped to names.
Type:
  • object.<string>
Source:

<private, inner, constant> eventFile :string

The file path to read default events.
Type:
  • string
Default Value:
  • ./save/hgEvents.json
Source:
See:
  • HungryGames~defaultPlayerEvents
  • HungryGames~defaultArenaEvents
  • HungryGames~defaultBloodbathEvents

<private, inner, constant> eventHandlers :object.<Array.<function()>>

All registered event handlers.
Type:
  • object.<Array.<function()>>
Source:

<private, inner, constant> helpmessagereply :string

Reply to help on a server.
Type:
  • string
Default Value:
  • I sent you a DM with commands!
Source:

<private, inner, constant> helpObject

The object that stores all data to be formatted into the help message.
Source:

<private, inner> listenersEndTime :number

The last time the currently scheduled reaction event listeners are expected to end. Used for checking of submoduleis unloadable.
Type:
  • number
Source:

<private, inner, constant> maxReactAwaitTime :number

Maximum amount of time to wait for reactions to a message.
Type:
  • number
Default Value:
  • 5 Minutes
Source:

<private, inner, constant> newEventMessages :object.<Discord~Message>

Messages that the user sent with a new event to add, for storage while getting the rest of the information about the event.
Type:
  • object.<Discord~Message>
Default Value:
  • {}
Source:

<private, inner, constant> numEventsPerPage :number

Number of events to show on a single page of events.
Type:
  • number
Default Value:
  • 10
Source:

<private, inner, constant> optionMessages :object.<Discord~Message>

Messages I have sent showing current options.
Type:
  • object.<Discord~Message>
Default Value:
  • {}
Source:

<private, inner, constant> patreonColor :number

Color to put above patrons avatars. RGBA Hex (0xRRGGBBAA).
Type:
  • number
Default Value:
  • 4184364287
Source:

<private, inner, constant> patreonSettingKeys :Array.<string>

The permission tags for all settings related to the Hungry Games.
Type:
  • Array.<string>
Default Value:
  • ["hg:fun_translators","hg:bar_color","hg:customize_stats","hg:personal_weapon"]
Source:

<private, inner, constant> urlRegex :RegExp

Regex to match all URLs in a string.
Type:
  • RegExp
Source:

<private, inner> weapons :object.<HungryGames~WeaponEvent>

All weapons and their respective actions. Parsed from file.
Type:
Default Value:
  • {}
Source:
See:
  • HungryGames~weaponsFile

<private, inner, constant> weaponsFile :string

The file path to read weapon events.
Type:
  • string
Default Value:
  • ./save/hgWeapons.json
Source:
See:
  • HungryGames~weapons

<private, inner, constant> webSM :string

Name of the HG Web submodule for lookup.
Type:
  • string
Default Value:
  • ./web/hg.js
Source:

Methods


<private> _fire(evt, args)

Fire an event on all listeners.
Parameters:
Name Type Argument Description
evt string The event to fire.
args * <repeatable>
Arguments for the event.
Source:

addEvent(id, type, event)

Adds a given event to the given guild's custom events.
Parameters:
Name Type Description
id string The id of the guild to add the event to.
type string The type of event this is.
event HungryGames~Event The event to add.
Source:
Returns:
Error message or null if no error.
Type
string

addMajorEvent(id, type, data [, name])

Creates an event and adds it to the custom events for the given guild. Or edits an existing event by appending new events to the major event.
Parameters:
Name Type Argument Description
id string The guild id to add the event to.
type string The type of event this is. Either 'arena' or 'weapon'.
data HungryGames~ArenaEvent | HungryGames~WeaponEvent The event data.
name string <optional>
The internal name of the weapon being added.
Source:
Returns:
Error message or null if no error.
Type
string

begin(Discord, client, command, common, bot)

Initialize this submodule.
Parameters:
Name Type Description
Discord Discord The Discord object for the API library.
client Discord~Client The client that represents this bot.
command Command The command instance in which to register command listeners.
common Common Class storing common functions.
bot SpikeyBot The parent SpikeyBot instance.
Inherited From:
Source:

createGame(id [, cb])

Create a Hungry Games for a guild.
Parameters:
Name Type Argument Description
id string The id of the guild to create the game in.
cb function <optional>
Callback that fires once loading is complete. Only parameter is created HungryGames~GuildGame or null if failed.
Source:

createNPC(gId, username, avatar, id)

Create an npc in a guild.
Parameters:
Name Type Description
gId string | number The guild id to add the npc to.
username string The name of the npc.
avatar string The url path to the avatar. Must be valid url to this server. (ex: https://www.spikeybot.com/avatars/NPCBBBADEF031F83638/avatar1.png).
id string The npc id of this npc. Must match the id in the avatar url.
Source:
Returns:
Error message or null if no error.
Type
string

createReactJoinMessage(channel)

Send a message with a reaction for users to click on. Records message id and channel id in game data.
Parameters:
Name Type Description
channel Discord~TextChannel | string The channel in the guild to send the message, or the ID of the channel.
Source:

<protected> debug(msg)

Log using common.logDebug, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

editMajorEvent(id, type, search, data [, name] [, newName])

Searches custom events for the given one, then edits it with the given data. If the data is null besides required data for finding the major event, the major event gets deleted. (Arena or Weapon events).
Parameters:
Name Type Argument Description
id string The id of the guild to remove the event from.
type string The type of event this is.
search HungryGames~ArenaEvent | HungryGames~WeaponEvent The event data to use to search for.
data HungryGames~ArenaEvent | HungryGames~WeaponEvent The event data to set the matched search to. If this is null, the event is deleted.
name string <optional>
The name of the weapon to look for or the message of the arena event to edit.
newName string <optional>
The new name of the weapon that was found with `name`.
Source:
Returns:
Error message or null if no error.
Type
string

editTeam(uId, gId, cmd, one, two)

Allows editing teams. Entry for all team actions.
Parameters:
Name Type Description
uId string The id of the user is running the action.
gId string The id of the guild to run this in.
cmd string The command to run on the teams.
one string The id of the user to swap, or the new name of the team if we're renaming a team.
two string The id of the user to swap, or the team id if we're moving a player to a team.
Source:
Returns:
Error message or null if no error.
Type
string

end()

Trigger subModule to shutdown and get ready for process terminating.
Inherited From:
Source:

endGame(uId, gId)

End the games in the given guild as the given user.
Parameters:
Name Type Description
uId string | Discord~Message The id of the user who trigged the games to end, or a Discord message sent by the user who triggered this.
gId string The id of the guild to end the games in.
Source:

endReactJoinMessage(id [, cb])

End the reaction join and update the included users to only include those who reacted to the message.
Parameters:
Name Type Argument Description
id string The guild id of which to end the react join.
cb function <optional>
Callback once this is complete. First parameter is a string if error, null otherwise, the second is a string with info if success or null otherwise.
Source:

<protected> error(msg)

Log using common.error, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

excludeUsers(users, id, cb)

Removes users from a games of a given guild.
Parameters:
Name Type Description
users string | Array.<string> | Array.<Discord~User> | Array.<HungryGames~NPC> The users to exclude, or 'everyone' to exclude everyone.
id string The guild id to remove the users from.
cb function Callback for when long running operations complete. Single argument with a string with the outcomes of each user. May have multiple lines for a single user.
Source:
Fires:
  • HG#event:refresh

getDefaultBattles()

Returns the object storing all default HungryGames~Battles parsed from file.
Source:
Returns:
Array of all default battle events.
Type
Array.<HungryGames~Battle>

getDefaultEvents()

Returns an object storing all of the default events for the games.
Source:
Returns:
Object storing default events.
Type
Object

getDefaultWeapons()

Returns the object storing all default HungryGames~Weapons parsed from file.
Source:
Returns:
Array of all default weapons.
Type
Array.<HungryGames~Weapon>

getHG()

Fetch a reference to the current HungryGames instance.
Source:
Returns:
Current instance.
Type
HungryGames

getNumSimulating()

Returns the number of games that are currently being shown to users.
Source:
Returns:
Number of games simulating.
Type
number

includeUsers(users, id, cb)

Adds a user back into the next game.
Parameters:
Name Type Description
users string | Array.<string> | Array.<Discord~User> | Array.<HungryGames~NPC> The users to include, 'everyone' to include all users, 'online' to include online users, 'offline', 'idle', or 'dnd' for respective users.
id string The guild id to add the users to.
cb function Callback for when long running operations complete. Single argument with a string with the outcomes of each user. May have multiple lines for a single user.
Source:
Fires:
  • HG#event:refresh

<protected> initialize()

The function called at the end of begin() for further initialization specific to the subModule. Must be defined before begin() is called.
Inherited From:
Overrides:
Source:

<protected> log(msg)

Log using common.log, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

makeAndAddEvent(id, type, message, numVictim, numAttacker, victimOutcome, attackerOutcome, victimKiller, attackerKiller, vWeapon, aWeapon)

Creates an event and adds it to the custom events for the given guild.
Parameters:
Name Type Description
id string The guild id to add the event to.
type string The type of event this is. Either 'player' or 'bloodbath'.
message string The event message.
numVictim number The number of victims in the event.
numAttacker number The number of attackers in the event.
victimOutcome string The outcome of the victims due to this event.
attackerOutcome string The outcome of the attackers due to this event.
victimKiller boolean Do the victims kill anyone.
attackerKiller boolean Do the attackers kill anyone.
vWeapon Object The weapon information to give the victim.
aWeapon Object The weapon information to give the attacker.
Source:
Returns:
Error message or null if no error.
Type
string

nextDay(uId, gId, cId)

Start the next day of the game in the given channel and guild by the given user.
Parameters:
Name Type Description
uId string The id of the user who trigged autoplay to start.
gId string The id of the guild to run autoplay in.
cId string The id of the channel to run autoplay in.
Source:

on(evt, handler)

Register an event listener. Handlers are called in order they are registered. Earlier events can modify event data.
Parameters:
Name Type Description
evt string The name of the event to listen for.
handler function The function to call when the event is fired.
Source:

pauseAutoplay(uId, gId)

Pause autoplay in the given guild as the given user.
Parameters:
Name Type Description
uId string The id of the user who trigged autoplay to end.
gId string The id of the guild to end autoplay.
Source:

pauseGame(id)

Pause the game in by clearing the current interval.
Parameters:
Name Type Description
id string The id of the guild to pause in.
Source:
Returns:
User information of the outcome of this command.
Type
string

<abstract> reloadable()

Check if this module is in a state that is ready to be reloaded. If false is returned, this module should not be unloaded and doing such may risk putting the module into an uncontrollable state. This is different from unloadable, which checks if this module can be stopped completely, this checks if the module can be stopped and restarted.
Inherited From:
Source:
See:
  • SubModule~unloadable
Returns:
True if can be reloaded, false if cannot.
Type
boolean

removeEvent(id, type, event)

Searches custom events for the given one, then removes it from the custom events. (Bloodbath or Player events).
Parameters:
Name Type Description
id string The id of the guild to remove the event from.
type string The type of event this is.
event HungryGames~Event The event to search for.
Source:
Returns:
Error message or null if no error.
Type
string

removeListener(evt, handler)

Remove an event listener;.
Parameters:
Name Type Description
evt string The name of the event that was being listened for.
handler function The currently registered handler.
Source:

removeNPC(gId, npc)

Delete an NPC from a guild.
Parameters:
Name Type Description
gId string Guild id of which to remove npc.
npc string ID of npc to delete.
Source:
Returns:
String if error, MessageEmbed to send if success.
Type
string | Discord~MessageEmbed

renameGame(id, name)

Rename the guild's game to the given custom name.
Parameters:
Name Type Description
id string | number The guild id of which to change the game's name.
name string The custom name to change to. Must be 100 characters or fewer.
Source:
Returns:
True if successful, false if failed. Failure is probably due to a game not existing or the name being longer than 100 characters.
Type
boolean

save( [opt] [, wait])

Save all game data to file.
Parameters:
Name Type Argument Default Description
opt string <optional>
'sync' Can be 'async', otherwise defaults to synchronous.
wait boolean <optional>
false If requested before subModule is initialized, keep trying until it is initialized.
Inherited From:
Overrides:
Source:

setOption(id, option, value [, text])

Change an option to a value for the given guild.
Parameters:
Name Type Argument Default Description
id string The guild id to change the option in.
option string <nullable>
The option key to change.
value string | boolean | number The value to change the option to.
text string <optional>
'' The original message sent without the command prefix in the case we are changing the value of an object and require all user inputted data.
Source:
Returns:
A message saying what happened, or null if we should show the user the list of options instead.
Type
string

<protected> shutdown()

Shutdown and disable this submodule. Removes all event listeners.
Inherited From:
Overrides:
Source:

startAutoplay(uId, gId, cId)

Start autoplay in the given channel and guild by the given user.
Parameters:
Name Type Description
uId string The id of the user who trigged autoplay to start.
gId string The id of the guild to run autoplay in.
cId string The id of the channel to run autoplay in.
Source:

startGame(uId, gId, cId)

Start the games in the given channel and guild by the given user.
Parameters:
Name Type Description
uId string The id of the user who trigged the games to start.
gId string The id of the guild to run the games in.
cId string The id of the channel to run the games in.
Source:

toggleEvent(id, type, subCat, event [, value])

Enable or disable an event without deleting it completely.
Parameters:
Name Type Argument Description
id number | string The guild id that the event shall be toggled in.
type string The type of event. 'bloodbath', 'player', 'weapon', or 'arena'.
subCat string <nullable>
The sub-category name of the event if there is one (Such as the weapon name, or arena event message).
event HungryGames~Event | HungryGames~ArenaEvent | HungryGames~WeaponEvent The event to toggle.
value boolean <optional>
Set enabled to a value instead of toggling.
Source:
Returns:
Error message or null if no error.
Type
string

unloadable()

Check if this module is in a state that is ready to be unloaded. If false is returned, this module should not be unloaded and doing such may risk putting the module into an uncontrollable state.
Inherited From:
Overrides:
Source:
See:
  • SubModule~reloadable
Returns:
True if can be unloaded, false if cannot.
Type
boolean

<protected> warn(msg)

Log using common.logWarning, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

<private, inner> calcColNum(numCols, statusList)

Calculates the number of columns for the given player list. Assumes maximum character count of 1024 per section. The number of columns also becomes limited to 5, because we will run into the embed total character limit of 6000 if we add any more. [Discord API Docs]( https://discordapp.com/developers/docs/resources/channel#embed-limits).
Parameters:
Name Type Description
numCols number Minimum number of columns.
statusList Array.<string> List of text to check.
Source:
Returns:
Number of columns the data shall be formatted as.
Type
number

<private, inner> changeObjectValue(obj, defaultObj, option, value, values, id [, range] [, keys])

Recurse through an object to change a certain child value based off a given array of words.
Parameters:
Name Type Argument Default Description
obj HungryGames~GuildGame.options The object with the values to change.
defaultObj HungryGames~defaultOptions The default template object to base changes off of.
option string The first value to check.
value number | boolean | string The value to change to, or the next option key to check if we have not found an end to a branch yet.
values Array.<(string|boolean|number)> All keys leading to the final value, as well as the final value.
id string The id of the guild this was triggered for.
range Object <optional>
Allowable range for values that are numbers.
keys Array.<string> <optional>
[] List of previous option keys.
Source:
Fires:
  • HG#event:toggleOption
Returns:
Message saying what happened. Can be an error message.
Type
string

<private, inner> commandDeleteGroup(msg, id)

Deletes an existing stat group.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string Guild ID this command was called from.
Source:

<private, inner> commandGiveWeapon(msg, id)

Give a certain amount of a weapon to a player.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:
See:
Listens to Events:
  • Command#event:hg give

<private, inner> commandGroups(msg, id)

Responds with list of all stat group names and IDs.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string Guild ID this command was called from.
Source:

<private, inner> commandHeal(msg, id [, game])

Allows the game creator to heal or revive a player in the game.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> commandKill(msg, id [, game])

Allows the game creator to kill a player in the game.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> commandLeaderboard(msg, id)

Ranks players by stat.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string Guild ID this command was called from.
Source:

<private, inner> commandMakeMeLose(msg)

Tell a user their chances of losing have not increased.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:hg makemelose

<private, inner> commandMakeMeWin(msg)

Tell a user their chances of winning have not increased.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:hg makemelose

<private, inner> commandModifyWeapon(msg, id [, flip])

Actually does the parsing for HG~commandGiveWeapon and HG~commandTakeWeapon.
Parameters:
Name Type Argument Default Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
flip boolean <optional>
false Should the parsed number value be multiplied by -1.
Source:

<private, inner> commandNewGroup(msg, id)

Creates a new stat group.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string Guild ID this command was called from.
Source:

<private, inner> commandNums(msg)

Replies to the user with stats about all the currently loaded games in this shard.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
Source:

<private, inner> commandReactJoin(msg, id [, game])

Start or stop allowing users to enter in to a game by clicking on a reaction to a message.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> commandRename(msg, id [, game])

Rename a guild's game to a custom name.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> commandRenameGroup(msg, id)

Renames an existing stat group.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string Guild ID this command was called from.
Source:

<private, inner> commandRig(msg)

Replies to the user with an image saying "rigged". That is all.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
Source:

<private, inner> commandSelectGroup(msg, id)

Selects an existing stat group.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string Guild ID this command was called from.
Source:

<private, inner> commandStats(msg, id)

Responds with stats about a player in the games.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string Guild ID this command was called from.
Source:

<private, inner> commandTakeWeapon(msg, id)

Take a certain amount of a weapon from a player.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:
See:
Listens to Events:
  • Command#event:hg take

<inner> commandToggleEvent(msg)

Toggle events in the games.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
Source:
To Do:
  • Write this. This is not implemented yet.

<private, inner> commandWound(msg, id [, game])

Allows the game creator to wound a player in the game.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> createEvent(msg, id [, game])

Create a custom event for a guild.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> createEventAttacker(msg, id, show, cb)

Let the user choose whether the event attackers and victims kill anyone.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
show string The message to show explaining the options.
cb HungryGames~createEventBooleanCallback The callback after the user has chosen an outcome.
Source:

<private, inner> createEventNums(msg, id, show, cb)

Let the user choose how many of something will be in this event being created.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
show string The message to show explaining the number.
cb HungryGames~createEventNumCallback The callback after the user has chosen a number.
Source:

<private, inner> createEventOutcome(msg, id, show, cb)

Let the user choose what the outcome of an event will be.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
show string The message to show explaining the options.
cb HungryGames~createEventOutcomeCallback The callback after the user has chosen an outcome.
Source:

<private, inner> createGame(msg, id [, silent] [, cb])

Create a Hungry Games for a guild.
Parameters:
Name Type Argument Default Description
msg Discord~Message <nullable>
The message that lead to this being called.
id string The id of the guild this was triggered from.
silent boolean <optional>
false Should we suppress replies to message.
cb function <optional>
Callback that fires once loading is complete. Only parameter is created HungryGames~GuildGame or null if failed.
Source:

<private, inner> createNPC(msg, id)

Create a new NPC.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> editTeam(msg, id [, silent])

Entry for all team commands.
Parameters:
Name Type Argument Default Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
silent boolean <optional>
false Should we disable replying to the given message?
Source:
Returns:
Error message or null if no error.
Type
string

<private, inner> endGame(msg, id [, silent])

End a game early.
Parameters:
Name Type Argument Default Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
silent boolean <optional>
false Prevent sending messages.
Source:

<private, inner> excludeIterate(game, obj [, onlyError] [, large])

Exclude a single user from the game as a single iteration step of the exclude command.
Parameters:
Name Type Argument Default Description
game HungryGames~GuildGame The game to manipulate.
obj string | HungryGames~Player | HungryGames~NPC Player for this iteration.
onlyError boolean <optional>
false Only add error messages to response.
large boolean <optional>
false Is this a large game where excluded users are not tracked.
Source:
Returns:
Response text for the user performing the operation.
Type
string

<private, inner> excludeNPC(msg, id)

Exclude an NPC from the game.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> excludeUser(msg, id [, game])

Remove a user from users to be in next game.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
Game object to exclude user from.
Source:

<private, inner> exit( [code])

Catch process exiting so we can save if necessary, and remove other handlers to allow for another module to take our place.
Parameters:
Name Type Argument Description
code number <optional>
The exit code.
Source:
Listens to Events:
  • Process#event:exit

<private, inner> fetchPatreonSettings(players, cId, gId [, cb])

Given an array of players, lookup the settings for each and update their data. This is asynchronous.
Parameters:
Name Type Argument Description
players Array.<HungryGames~Player> The players to lookup and update.
cId string | number The channel ID to fetch the settings for.
gId string | number The guild ID to fetch the settings for.
cb function <optional>
Calls this callback on completion. No parameters.
Source:

<private, inner> fetchStats(events)

Put information about an array of events into the array.
Parameters:
Name Type Description
events Array.<HungryGames~Event> Array of events to process and modify.
Source:

<private, inner> formatEventString(arenaEvent [, newline])

Format an event to show its settings to the user.
Parameters:
Name Type Argument Default Description
arenaEvent HungryGames~Event | string The event to format.
newline boolean <optional>
false If a new line should be inserted for better formatting.
Source:
Returns:
The formatted message with emojis.
Type
string

<private, inner> formatUsername(u [, remove])

Remove url from username, and format to rules similar to Discord.
Parameters:
Name Type Argument Description
u string The username.
remove string | RegExp <optional>
A substring or RegExp to remove.
Source:
Returns:
Formatted username.
Type
string

<private, inner> getName(guild, user)

Get the username of a user id if available, or their id if they couldn't be found.
Parameters:
Name Type Description
guild Discord~Guild The guild to look for the user in.
user string The id of the user to find the name of.
Source:
Returns:
The user's name or id if name was unable to be found.
Type
string

<private, inner> getOutcomeEmoji(outcome)

Get the emoji for a specific outcome of an event.
Parameters:
Name Type Description
outcome string The outcome to get the emoji of.
Source:
Returns:
The emoji.
Type
string

<private, inner> getStatsString( [short])

Get this shard's stats and format it into a human readable string.
Parameters:
Name Type Argument Default Description
short boolean <optional>
false Provide a short version.
Source:
Returns:
The formatted string.
Type
string

<private, inner> handleMessageEdit(oldMsg, newMsg)

Handler for when the create event message is edited and we should update our message with the updated event.
Parameters:
Name Type Description
oldMsg Discord~Message The message before being edited.
newMsg Discord~Message The message after being edited.
Source:
Listens to Events:
  • Discord~Client#event:messageUpdate

<private, inner> help(msg)

Send help message to DM and reply to server.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
Source:

<private, inner> includeIterate(game, obj [, onlyError])

Include a single user from the game as a single iteration step of the include command.
Parameters:
Name Type Argument Default Description
game HungryGames~GuildGame The game to manipulate.
obj string | HungryGames~Player | HungryGames~NPC Player for this iteration.
onlyError boolean <optional>
false Only add error messages to response.
Source:
Returns:
Response text for the user performing the operation.
Type
string

<private, inner> includeNPC(msg, id)

Include an NPC in the game.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> includeUser(msg, id [, game])

Add a user back into the next game.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> listEvents(msg, id [, page] [, eventType] [, editMsg])

Allow user to view all events available on their server and summary of each type of event.
Parameters:
Name Type Argument Default Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
page number <optional>
0 The page number to show.
eventType string <optional>
'player' The type of event to show.
editMsg Discord~Message <optional>
The message to edit instead of sending a new message.
Source:

<private, inner> listNPCs(msg, id)

List all currently created NPCs.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> listPlayers(msg, id)

Show a formatted message of all users and teams in current server.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> makeMessage(uId, gId, cId, msg)

Forms a Discord~Message similar object from given IDs.
Parameters:
Name Type Argument Description
uId string The id of the user who wrote this message.
gId string The id of the guild this message is in.
cId string <nullable>
The id of the channel this message was 'sent' in.
msg string <nullable>
The message content.
Source:
Returns:
The created message-like object.
Type
Object

<private, inner> makePlayerListEmbed(game [, finalMessage])

Create a external:Discord~MessageEmbed that lists all included and excluded players in the game.
Parameters:
Name Type Argument Description
game HungryGames~GuildGame The game to format.
finalMessage external:Discord~MessageEmbed <optional>
Optional existing embed to modify instead of creating a new one.
Source:
Returns:
The created message embed.
Type
external:Discord~MessageEmbed

<private, inner> mkCmd(cb)

Make a subcommand handler with the given callback function. This is a wrapper around existing functions.
Parameters:
Name Type Description
cb HungryGames~hgCommandHandler Command handler when subcommand is triggered.
Source:
Returns:
Subcommand initial handler that will fire when command is fired. Calls the passed callback handler with the mapped parameters.
Type
Command~commandHandler

<private, inner> moveTeamUser(msg, id [, game])

Move a single user to another team.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> newReact(duration)

Update HungryGames~listenersEndTime because a new listener was registered with the given duration.
Parameters:
Name Type Description
duration number The length of time the listener will be active.
Source:

<private, inner> nextDay(msg, id)

Simulate a single day then show events to users.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> nothing()

Get a random word that means "nothing".
Source:
Returns:
A word meaning "nothing".
Type
string

<private, inner> onChannelDelete(channel)

Handle a channel being deleted. Cleans up games that may be in progress in these channels.
Parameters:
Name Type Description
channel Discord~DMChannel | Discord~GuildChannel The channel that was deleted.
Source:
Listens to Events:
  • Discord~Client#event:channelDelete

<private, inner> onGuildDelete(guild)

Handle being removed from a guild.
Parameters:
Name Type Description
guild Discord~Guild The guild that we just left.
Source:
Listens to Events:
  • Discord~Client#event:guildDelete

<private, inner> optChangeListener(msg_, options, index)

The callback for when the user chooses to change page of the options.
Parameters:
Name Type Description
msg_ Discord~Message The message we sent showing the options.
options object The options to show in the message.
index number The page index to show.
Source:

<private, inner> parseGamePlayers(msg, game)

Fetch an array of user IDs that are in the current game and have been referenced in any way due to the given message from the user.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
game HungryGames~GuildGame The game this is for.
Source:
Returns:
Array of user IDs that are in the current game that were mentioned.
Type
Array.<string>

<private, inner> pauseAutoplay(msg, id)

Stop autoplaying.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> pauseGame(msg, id)

Stop the game in the middle of the day until resumed. Just clears the interval for the game.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> printDay(msg, id)

Trigger the end of a day and print summary/outcome at the end of the day.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> printEvent(msg, id)

Print an event string to the channel and add images, or if no events remain, trigger end of day.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> randomizeTeams(msg, id [, silent])

Swap random users between teams.
Parameters:
Name Type Argument Default Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
silent boolean <optional>
false If true, this will not attempt to send messages to the channel where the msg was sent..
Source:

<private, inner> readImage(url)

Attempt to fetch an image from a URL. Checks if the file has been cached to the filesystem first.
Parameters:
Name Type Description
url string | Jimp | Buffer The url to fetch the image from, or anything Jimp supports.
Source:
Returns:
Promise from JIMP with image data.
Type
Promise

<private, inner> removeEvent(msg, id)

Delete a custom event from a guild.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> removeNPC(msg, id)

Delete an NPC.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> renameTeam(msg, id [, silent])

Rename a team.
Parameters:
Name Type Argument Default Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
silent boolean <optional>
false Disable replying to message.
Source:

<private, inner> resetGame(msg, id)

Reset data that the user specifies.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> sendAtTime(channel, one, two, time)

Delay a message to send at the given time in milliseconds since epoch.
Parameters:
Name Type Description
channel Discord~TextChannel The channel to send the message in.
one Discord~StringResolvable | Discord~MessageOptions | Discord~MessageEmbed | Discord~MessageAttachment | Array.<Discord~MessageAttachment> The message to send.
two Discord~StringResolvable | Discord~MessageOptions | Discord~MessageEmbed | Discord~MessageAttachment | Array.<Discord~MessageAttachment> The message to send.
time number The time to send the message in milliseconds since epoch.
Source:

<private, inner> setupHelp()

Set all help messages once we know what prefix to use.
Source:

<private, inner> showGameEvents(msg, id)

Send all event data about the default events to the chat.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> showGameInfo(msg, id)

Send all of the game data about the current server to the chat.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> showOpts(msg, options)

Format the options for the games and show them to the user.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
options object The options to format.
Source:

<private, inner> sigint()

Same as exit(), but triggered via SIGINT, SIGHUP or SIGTERM.
Source:
Listens to Events:
  • Process#event:SIGINT
  • Process#event:SIGHUP
  • Process#event:SIGTERM

<private, inner> sortTeams(game)

Sort the includedUsers and teams for the given game.
Parameters:
Name Type Description
game HungryGames~GuildGame The game to sort.
Source:

<private, inner> startAutoplay(msg, id [, game])

Start autoplaying.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to start autoplay on.
Source:

<private, inner> startGame(msg, id)

Start the games in the channel this was called from.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> swapTeamUsers(msg, id [, game])

Swap two users from one team to the other.
Parameters:
Name Type Argument Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
game HungryGames~GuildGame <optional>
The game object to modify.
Source:

<private, inner> toggleOpt(msg, id)

Change an option to a value that the user specifies.
Parameters:
Name Type Description
msg Discord~Message The message that lead to this being called.
id string The id of the guild this was triggered from.
Source:

<private, inner> updateBattles()

Parse all battles from file.
Source:

<private, inner> updateEventPreview(msg)

When a user is creating a custom event and edits their message, we need to edit the preview.
Parameters:
Name Type Description
msg Discord~Message Our message previewing the new event.
Source:

<private, inner> updateEvents()

Parse all default events from file.
Source:

<private, inner> updateWeapons()

Parse all weapons events from file.
Source: