0.11.0 • Published 5 years ago

hackmud-chatapi v0.11.0

Weekly downloads
25
License
SEE LICENSE IN LI...
Repository
github
Last release
5 years ago

Hackmud-ChatAPI

Class: Account

new Account(token, tick_rate)

Creates a new account associated with the token specified token. For more information about tick_rate, see account.tick_rate

Account.getToken(pass)

Fetches a new chat token from the specified pass.

Event: 'message'
  • user <string> The user on which received this message
  • message <Message> The message itself

Fired whenever a message is received on this account.

account.destroy()

Destroys this account. This calls destroy on the agent and stops the tick mechanism. You must call this function before exiting. Otherwise, the tick mechanism will always keep the event loop busy, and the node process will never exit.

account.fetchUsers()

Fetch the userdata for this account. The data will be stored in account.userData, the usernames in account.users. The Promise resolves to the new value of account.users.

account.getHistory(usernames)

Get the chat history of this account.

account.getUser(username)

Get a specific user. If the user does not exist on this account, this method returns null. Note: This function performs no update checks and works solely off of the value of account.users. It is thus recommended to call account.fetchUsers() before calling this method.

account.request(endpoint, data)

Send a request on behalf of this account. The account's agent and token will be automatically used/added for/to the request. The Promise returned resolves with the body of the reply.

account.send(sender, channel, message)

Send a message to a channel. Acts like chats.send ingame. The message may be looped back in a message event(#eventmessage).

account.tell(sender, to, message)

Send a tell to a user. Acts like chats.tell ingame. The message may be looped back in a message event.

account.tick()

Perform a tick for this account. User code should rarely, if ever, call this function. The new tick is scheduled after this method completes.

account.agent

The agent this account uses for outgoing requests. This agent is created with {keepAlive: true}.

account.last_tick

The last time a tick completed, but before the respective events are fired.

account.tickTimeout

The timeout of the next tick. May be stale (used up) or null if tick_rate is Infinity.

account.tick_rate

The amount of milliseconds delay between ticks. Should be above 800 and never below 700 (unless you enjoy getting errors about polling too fast). Takes effect on the next tick.

account.token

The token for this account.

account.userData

The user data for this account. Filled by account.fetchUsers.

account.users

The usernames for this account. Filled by account.fetchUsers.

Class: User

Event: 'message'

Fired whenever a message is received for this user.

user.getHistory(before)

Get the chat history of this user.

user.send(channel, message)

Send a message to a channel. Acts like chats.send ingame. The message may be looped back in a message event.

user.tell(to, message)

Send a tell to a user. Acts like chats.tell ingame. The message may be looped back in a message event.

user.account

The account this user is associated with.

user.username

The name of this user.

Class: Message

Represents a message received from the server.

message.channel

If this message was received from a channel, the channel name. Otherwise, null.

message.content

The content of this message.

message.from_me

Whether this message was sent from a user associated with this account. This indicates a possible loopback message or you sending messages ingame.

message.sender

The name of the user who sent this message.

message.to

If this is a tell, the name of the user to which this tell was sent. Otherwise, null.

message.type

The "special type" of this message, if any. Currently, there are only two types: "join" for channel join messages and "leave" for channel leave messages.

cfg

An object used for various configuration. Contains the following properties:

cfg.HACKMUD_ADDRESS

The address of the server this wrapper talks to. Only change if you know what you are doing.

cfg.REQUIRE_TLS_SECURE

Whether to require a secure TLS connection while talking to the server. Only set to false if you know what you are doing.

0.11.0

5 years ago

0.10.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago