Skip to content

Latest commit

 

History

History
1132 lines (806 loc) · 39.8 KB

modules.md

File metadata and controls

1132 lines (806 loc) · 39.8 KB

Classes

Api

Api module connects to the backend api and provides low level methods for service modules to send and receive data.

ActionCreateChar

ActionCreateChar adds the action to create a character if the limit is not reached.

ActionGo

ActionGo adds the action to go around using exits.

ActionIdle

ActionIdle adds the action to idle with awake characters.

ActionLurk

ActionLurk adds the action to lurk for a while, without having any awake characters.

ActionPose

ActionPose adds the action to pose in a room with other characters.

ActionSay

ActionSay adds the action to speak in a room with other characters.

ActionSleep

ActionSleep adds the action to put a character to sleep.

ActionTeleport

ActionTeleport adds the action to teleport.

ActionWakeup

ActionWakeup adds the action to wake up an existing character.

ActionWhisper

ActionWhisper adds the action to speak in a room with other characters.

BotController

BotController is the central module for creating an autonomous, self acting bot. Other modules may register actions that the bot controller may tell the bot-characters to perform.

Personality

Personality holds common personality traits that an action can use to determine behavior.

ReactionArriveWelcome

ReactionArriveWelcome greets when traveling to a room with other characters.

ReactionRead

ReactionRead intercepts with idle time to read whenever someone else speaks in the room.

ReactionTravelGreet

ReactionTravelGreet greets when traveling to a room with other characters.

ReactionPrivateReply

ReactionPrivateReply reacts to whispers and enqueues a whisper reply.

CharEvents

CharEvents listens to outgoing log events for any controlled character.

The purpose is to simplify listening and reacting to events for other modules.

CharPing

CharPing periodically sends a ping for all controlled characters to ensure they are kept awake.

If the botController module is available, it will only ping characters validated by botController.validChar

Login

Login logs in the bot after registering it.

Player

Player fetches the player object and keeps it suscribed once logged in.

Api

Api module connects to the backend api and provides low level methods for service modules to send and receive data.

Kind: global class

api.connect() ⇒ Promise

Connects the instance to the server. Can be called even if a connection is already established.

Kind: instance method of Api
Returns: Promise - A promise to the established connection.

api.disconnect()

Disconnects any current connection and stops attempts of reconnecting.

Kind: instance method of Api

api.get(rid, [collectionFactory]) ⇒ Promise.<(ResModel|ResCollection)>

Get a resource from the API

Kind: instance method of Api
Returns: Promise.<(ResModel|ResCollection)> - Promise of the resource.

Param Type Description
rid string Resource ID
[collectionFactory] function Collection factory function.

api.call(rid, method, params) ⇒ Promise.<object>

Calls a method on a resource.

Kind: instance method of Api
Returns: Promise.<object> - Promise of the call result.

Param Type Description
rid string Resource ID.
method string Method name
params * Method parameters

api.authenticate(rid, method, params) ⇒ Promise.<object>

Invokes a authentication method on a resource.

Kind: instance method of Api
Returns: Promise.<object> - Promise of the authentication result.

Param Type Description
rid string Resource ID.
method string Method name
params * Method parameters

api.setOnConnect(onConnect) ⇒ this

Sets the onConnect callback.

Kind: instance method of Api

Param Type Description
onConnect ResClient~onConnectCallback On connect callback called prior resolving the connect promise and subscribing to stale resources. May return a promise.

ActionCreateChar

ActionCreateChar adds the action to create a character if the limit is not reached.

Kind: global class

new ActionCreateChar(app, params)

Creates a new ActionCreateChar instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ActionCreateChar~Params : Object

ActionCreateChar parameters.

Kind: inner typedef of ActionCreateChar
Properties

Name Type Description
[charLimit] number Limit on how many characters are totally created.
[probability] number Probability of the action to occur.
[delay] number Delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.

ActionGo

ActionGo adds the action to go around using exits.

Kind: global class

new ActionGo(app, params)

Creates a new ActionGo instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ActionGo~Params : Object

ActionGo parameters.

Kind: inner typedef of ActionGo
Properties

Name Type Description
[populationProbability] object Probabilities of the action to occur based on room population.
[delay] number Delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.

ActionIdle

ActionIdle adds the action to idle with awake characters.

Kind: global class

new ActionIdle(app, params)

Creates a new ActionIdle instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ActionIdle~Params : Object

ActionIdle parameters.

Kind: inner typedef of ActionIdle
Properties

Name Type Description
[probability] number Probability of the action to occur.
[delayMin] number Minimum time in milliseconds to idle.
[delayMax] number Maximum time in milliseconds to idle.
[spread] string How the random values are spread. May be 'linear', 'cube' (less high values), or 'square' (even less high values).

ActionLurk

ActionLurk adds the action to lurk for a while, without having any awake characters.

Kind: global class

new ActionLurk(app, params)

Creates a new ActionLurk instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ActionLurk~Params : Object

ActionLurk parameters.

Kind: inner typedef of ActionLurk
Properties

Name Type Description
[probability] number Probability of the action to occur.
[delayMin] number Minimum time in milliseconds to lurk.
[delayMax] number Maximum time in milliseconds to lurk.

ActionPose

ActionPose adds the action to pose in a room with other characters.

Kind: global class

new ActionPose(app, params)

Creates a new ActionPose instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

actionPose.enqueue(charId, msg, priority)

Enqueues a pose action to the botController.

Kind: instance method of ActionPose

Param Type Description
charId string Character ID.
msg string Message to pose.
priority number Priority of the action.

ActionPose~Params : Object

ActionPose parameters.

Kind: inner typedef of ActionPose
Properties

Name Type Description
[populationProbability] object Probabilities of the action to occur based on room population.
[delay] number Additional delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.
[wordLengthMin] number Minimum number of words in a message. Ignored if phrases is set.
[wordLengthMax] number Maximum number of words in a message. Ignored if phrases is set.
[phrases] Array.<string> An array of phrases to use as message. Null means random lorem ipsum.

ActionSay

ActionSay adds the action to speak in a room with other characters.

Kind: global class

new ActionSay(app, params)

Creates a new ActionSay instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

actionSay.enqueue(charId, msg, priority)

Enqueues a say action to the botController.

Kind: instance method of ActionSay

Param Type Description
charId string Character ID.
msg string Message to say.
priority number Priority of the action.

ActionSay~Params : Object

ActionSay parameters.

Kind: inner typedef of ActionSay
Properties

Name Type Description
[populationProbability] object Probabilities of the action to occur based on room population.
[delay] number Additional delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.
[wordLengthMin] number Minimum number of words in a message. Ignored if phrases is set.
[wordLengthMax] number Maximum number of words in a message. Ignored if phrases is set.
[phrases] Array.<string> An array of phrases to use as message. Null means random lorem ipsum.

ActionSleep

ActionSleep adds the action to put a character to sleep.

Kind: global class

new ActionSleep(app, params)

Creates a new ActionSleep instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ActionSleep~Params : Object

ActionSleep parameters.

Kind: inner typedef of ActionSleep
Properties

Name Type Description
[probability] number Probability of the action to occur.
[delay] number Delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.

ActionTeleport

ActionTeleport adds the action to teleport.

Kind: global class

new ActionTeleport(app, params)

Creates a new ActionTeleport instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ActionTeleport~Params : Object

ActionTeleport parameters.

Kind: inner typedef of ActionTeleport
Properties

Name Type Description
[populationProbability] object Probabilities of the action to occur based on room population.
[delay] number Delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.

ActionWakeup

ActionWakeup adds the action to wake up an existing character.

Kind: global class

new ActionWakeup(app, params)

Creates a new ActionWakeup instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ActionWakeup~Params : Object

ActionWakeup parameters.

Kind: inner typedef of ActionWakeup
Properties

Name Type Description
[charLimit] number Limit on how many characters to have awake at any single time.
[probability] number Probability of the action to occur.
[delay] number Delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.

ActionWhisper

ActionWhisper adds the action to speak in a room with other characters.

Kind: global class

new ActionWhisper(app, params)

Creates a new ActionWhisper instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

actionWhisper.enqueue(charId, targetId, msg, pose, priority)

Enqueues a whisper action to the botController.

Kind: instance method of ActionWhisper

Param Type Description
charId string Character ID.
targetId string Target character ID.
msg string Message to whisper.
pose boolean Flag if message is posed.
priority number Priority of the action.

ActionWhisper~Params : Object

ActionWhisper parameters.

Kind: inner typedef of ActionWhisper
Properties

Name Type Description
[populationProbability] object Probabilities of the action to occur based on room population.
[delay] number Additional delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.
[phrases] Array.<string> An array of phrases to use as message. Null means random lorem ipsum.
[chars] Array.<string> An array of chars eligible to be whispered to. Null means any.

BotController

BotController is the central module for creating an autonomous, self acting bot. Other modules may register actions that the bot controller may tell the bot-characters to perform.

Kind: global class

new BotController(app, params)

Creates a new BotController instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

botController.addAction(action) ⇒ this

Register an action that may be performed by the controller.

Kind: instance method of BotController

Param Type Description
action object Action definition object.
action.id string Action ID.
action.outcomes outcomesCallback Callback that returns an array of possible outcomes.
action.exec executeCallback Callback that executes one of the action outcomes.

botController.removeAction(actionId) ⇒ this

Unregisters a previously registered action.

Kind: instance method of BotController

Param Type Description
actionId string Action ID.

botController.enqueue(outcome)

Queues an outcome for an action.

Kind: instance method of BotController

Param Type Description
action.id string Action ID.
outcome ActionOutcome Action outcome to queue.

botController.validChar(charId, [opt])

Validates in a char is under bot control

Kind: instance method of BotController

Param Type Description
charId string ID of character.
[opt] object Optional parameters.
[opt.includeChars] Array.<string> Array of characters to include. If provided, it overrides the includesChars of botController.
[opt.excludeChars] Array.<string> Array of characters to exclude. If provided, it overrides the excludeChars of botController.

BotController~Params : Object

BotController parameters.

Kind: inner typedef of BotController
Properties

Name Type Description
[includeChars] Array.<string> Char IDs of chars handled by the bot controller. Null means all characters are included.
[excludeChars] Array.<string> Char IDs of chars not handled by the bot controller. Null means no character is excluded.
[queue] Array Initial queue of actions when starting controller. Mainly for debug purpose.

BotController~ActionOutcome : Object

BotController action outcome. The object may contain any additional properties used by the action to perform the outcome.

Kind: inner typedef of BotController
Properties

Name Type Description
[probability] number Proportional chance that the outcome will be selected by the bot controller as the next action outsome.
[delay] number Delay in milliseconds before the action outcome is executed. Defaults to 0.
[postdelay] number Delay in milliseconds after the action outcome has been executed. Defaults to 0.
[priority] number Priority of the action outcome when queued. A higher priority outcome will be executed before lower priority outcomes. Defaults to 1.

BotController~outcomesCallback ⇒ ActionOutcome | Array.<ActionOutcome>

Outcomes callback This callback is displayed as a global member.

Kind: inner typedef of BotController
Returns: ActionOutcome | Array.<ActionOutcome> - Zero or more possible outcomes for the action.

Param Type Description
player Model Player model.
state object State object.

BotController~executeCallback ⇒ string | Promise.<?string>

Execute callback called to execute an action outcome.

Kind: inner typedef of BotController
Returns: string | Promise.<?string> - Optional string to log, or promise of a string to log. If the promise rejects, it will be logged as an error.

Param Type Description
player Model Player model.
state object State object.
outcome ActionOutcome Outcome to execute.

Personality

Personality holds common personality traits that an action can use to determine behavior.

Kind: global class

new Personality(app, params)

Creates a new Personality instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

personality.calculateTypeDuration(msg) ⇒ number

Calculates the time it takes in milliseconds to type a message.

Kind: instance method of Personality
Returns: number - Duration in milliseconds.

Param Type Description
msg string Message to type.

personality.calculateReadDuration(msg) ⇒ number

Calculates the time it takes in milliseconds to read a message.

Kind: instance method of Personality
Returns: number - Duration in milliseconds.

Param Type Description
msg string Message to read.

Personality~Params : Object

Personality parameters.

Kind: inner typedef of Personality
Properties

Name Type Description
[typeSpeed] number Type speed in characters per minute.
[readSpeed] number Read speed in characters per minute.

ReactionArriveWelcome

ReactionArriveWelcome greets when traveling to a room with other characters.

Kind: global class

new ReactionArriveWelcome(app, params)

Creates a new ReactionArriveWelcome instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ReactionArriveWelcome~Params : Object

ReactionArriveWelcome parameters.

Kind: inner typedef of ReactionArriveWelcome
Properties

Name Type Description
[populationChance] object Chances of welcoming arrivals, between 0 and 1, based on room population.
[priority] number Priority of the reply action.
[delay] number Additional delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.
[wordLengthMin] number Minimum number of words in a message. Ignored if phrases is set.
[wordLengthMax] number Maximum number of words in a message. Ignored if phrases is set.
[phrases] Array.<string> An array of phrases to use as message. Null means random lorem ipsum.

ReactionRead

ReactionRead intercepts with idle time to read whenever someone else speaks in the room.

Kind: global class

new ReactionRead(app, params)

Creates a new ReactionRead instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ReactionRead~Params : Object

ReactionRead parameters.

Kind: inner typedef of ReactionRead
Properties

Name Type Description
[chance] object Chance of reading, between 0 and 1.
[priority] number Priority of the read action.
[eventTypes] Array.<string> List of event types to read. Defaults to [ 'say', 'pose', 'ooc', 'describe' ].

ReactionTravelGreet

ReactionTravelGreet greets when traveling to a room with other characters.

Kind: global class

new ReactionTravelGreet(app, params)

Creates a new ReactionTravelGreet instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ReactionTravelGreet~Params : Object

ReactionTravelGreet parameters.

Kind: inner typedef of ReactionTravelGreet
Properties

Name Type Description
[populationChance] object Chances of greeting on entering room, between 0 and 1, based on room population.
[priority] number Priority of the reply action.
[delay] number Additional delay in milliseconds to wait prior to executing the action.
[postdelay] number Delay in milliseconds to wait after executing the action.
[wordLengthMin] number Minimum number of words in a message. Ignored if phrases is set.
[wordLengthMax] number Maximum number of words in a message. Ignored if phrases is set.
[phrases] Array.<string> An array of phrases to use as message. Null means random lorem ipsum.

ReactionPrivateReply

ReactionPrivateReply reacts to whispers and enqueues a whisper reply.

Kind: global class

new ReactionPrivateReply(app, params)

Creates a new ReactionPrivateReply instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

ReactionPrivateReply~Params : Object

ReactionPrivateReply parameters.

Kind: inner typedef of ReactionPrivateReply
Properties

Name Type Description
[chance] object Chance of replying, between 0 and 1.
[priority] number Priority of the action.
[wordLengthMin] number Minimum number of words in a message. Ignored if phrases is set.
[wordLengthMax] number Maximum number of words in a message. Ignored if phrases is set.
[phrases] Array.<string> An array of phrases to use as message. Null means random lorem ipsum.

CharEvents

CharEvents listens to outgoing log events for any controlled character.

The purpose is to simplify listening and reacting to events for other modules.

Kind: global class

new CharEvents(app, params)

Creates a new CharEvents instance.

Param Type Description
app App Modapp App object.
params CharEvents~Params Module parameters.

charEvents.subscribe(cb) ⇒ function

Subscribes to char log events.

Kind: instance method of CharEvents
Returns: function - Unsubscribe function.

Param Type Description
cb function Callback called on events: function(char, event)

charEvents.unsubscribe(cb) ⇒ boolean

Unsubscribes to char log events.

Kind: instance method of CharEvents
Returns: boolean - Returns true if callback was found, eitherwise false.

Param Type Description
cb function Callback previously passed to the subscribe method.

CharPing

CharPing periodically sends a ping for all controlled characters to ensure they are kept awake.

If the botController module is available, it will only ping characters validated by botController.validChar

Kind: global class

new CharPing(app, params)

Creates a new CharPing instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

CharPing~Params : Object

CharPing parameters.

Kind: inner typedef of CharPing
Properties

Name Type Description
[duration] number Duration in milliseconds between successful pings.
[threshold] number Threshold in milliseconds after which a character is put to sleep.
[retry] number Duration in milliseconds beteween retries on failed pings.

Login

Login logs in the bot after registering it.

Kind: global class

new Login(app, params)

Creates a new Login instance.

Param Type Description
app App Modapp App object.
params Params Module parameters.

login.getUserPromise() ⇒ Promise.<Model>

Returns a promise that resolves with the logged in user.

Kind: instance method of Login
Returns: Promise.<Model> - Promise of the user model.

Login~Params : Object

Login parameters.

Kind: inner typedef of Login
Properties

Name Type Description
[user] string User account name.
[pass] string Password, sha256 hashed and base64 encoded, padded with equal (=). Eg. "ZSx9xofZjJiJME7S5AjHS2EehqQMqlHEtD8d1ZE8XNA="

Player

Player fetches the player object and keeps it suscribed once logged in.

Kind: global class

player.getModel() ⇒ Model

Returns the module model.

Kind: instance method of Player
Returns: Model - Module model.

player.getPlayerPromise() ⇒ Promise.<Model>

Returns a promise that resolves with the player model, containing all characters and their info, of the logged in user.

Kind: instance method of Player
Returns: Promise.<Model> - Promise of the player model.

player.getOwnedChar(charId) ⇒ Model

Returns an owned character with a given ID. If the character is not owned, or if the player isn't loaded, null is returned;

Kind: instance method of Player
Returns: Model - Controlled character model or null.

Param Type Description
charId string Character ID

player.getControlledChar(charId) ⇒ Model

Returns a controlled character with a given ID. If the character is not controlled, or if the player isn't loaded, null is returned;

Kind: instance method of Player
Returns: Model - Controlled character model or null.

Param Type Description
charId string Character ID