Class: Connect4

Connect4

Manages a Connect 4 game.

new Connect4()

Source:
Listens to Events:
  • Command#event:connect4

Extends

Classes

Game

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 :Discord~Client

The current bot client. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
  • 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:

Discord :Discord

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

<abstract> helpMessage :undefined|string|Discord~EmbedBuilder

The help message to show the user in the main help message.
Type:
  • undefined | string | Discord~EmbedBuilder
Inherited From:
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:

<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:

<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:
Source:

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

Helper object of emoji characters mapped to names.
Type:
  • object.<string>
Default Value:
  • {"undefined":"9⃣","X":"❌","O":"⭕"}
Source:

<private, inner, constant> maxReactAwaitTime :number

Maximum amount of time to wait for reactions to a message. Also becomes maximum amount of time a game will run with no input, because controls will be disabled after this timeout.
Type:
  • number
Default Value:
  • 5 Minutes
Source:

<private, inner, constant> numCols :number

The number of columns in the board.
Type:
  • number
Default Value:
  • 7
Source:

<private, inner> numGames :number

The number of currently active games. Used to determine of submodule is unloadable.
Type:
  • number
Source:

<private, inner, constant> numRows :number

The number of rows in the board.
Type:
  • number
Default Value:
  • 6
Source:

Methods


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(players, channel)

Create a game with the given players in a given text channel.
Parameters:
Name Type Description
players Object The players in the game.
channel Discord~TextChannel The text channel to send messages.
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:

end()

Trigger subModule to shutdown and get ready for process terminating.
Inherited From:
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:

<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:

<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

<abstract> save( [opt])

Saves all data to files necessary for saving current state.
Parameters:
Name Type Argument Default Description
opt string <optional>
'sync' Can be 'async', otherwise defaults to synchronous.
Inherited From:
Source:

<protected> shutdown()

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

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> addListener(msg, game)

Add the listener for reactions to the game.
Parameters:
Name Type Description
msg Discord~Message The message to add the reactions to.
game Connect4~Game The game to update when changes are made.
Source:

<private, inner> addReactions(msg, index)

Add the reactions to a message for controls of the game. Recursive.
Parameters:
Name Type Default Description
msg Discord~Message The message to add the reactions to.
index number 0 The number of reactions we have added so far.
Source:

<inner> checkWin(board, latestR, latestC)

Checks if the given board has a winner, or if the game is over.
Parameters:
Name Type Description
board Array.<number> Array of 9 numbers defining a board. 0 is nobody, 1 is player 1, 2 is player 2.
latestR number The row index where the latest move occurred.
latestC number The column index where the latest move occurred.
Source:
Returns:
Returns 0 if game is not over, 1 if player 1 won, 2 if player 2 won, 3 if draw.
Type
number

<private, inner> commandConnect4(msg)

Starts a connect 4 game. If someone is mentioned it will start a game between the message author and the mentioned person. Otherwise, waits for someone to play.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:connect4