Chat

Extends

  • EventEmitter

Members

connected

Is the irc connection established and the user logged in. You can listen to the connected event in case of false.

irc :TwitchChat

The irc connection

Methods

auth(username, authtoken)

Set the username and auth token and connects to the irc
Parameters:
Name Type Description
username String The username that is being logged in as
authtoken String The twitch api token to login with

disconnect()

Planned disconnect from the twitch irc

getUserObjByTags(user, tags) → {Chat~userObject}

Generate an user object from the username and the tags, that were given with a message
Parameters:
Name Type Description
user String A username
tags Object The twitch irc tags that were given
Returns:
Chat~userObject - Always returns a complete object, but properties might be empty or incomplete because of missing tags

join(channel)

Join a channel
Parameters:
Name Type Description
channel String The channel that should be joined

part(channel, cb)

Leave a channel
Parameters:
Name Type Description
channel String The channel that should be left
cb function A callback that is called when the channel was left

sendmsg(channel, message, emotesopt)

Send a message to a channel
Parameters:
Name Type Attributes Description
channel String Channel the message is being send to
message String The message that is being send. Must not contain CR or LF symbols or everything breaks.
emotes Object <optional>
A twitch api object with the for the user available emoticon sets. This is just for display for the user. The twitch server may decide which emotes the user has and are being displayed.
To Do:
  • Filter CR and LF symbols from channel or message

showmsg(prefix, user, to, msg, tags, type)

Prepares a message and emits the chatmessage event. It replaces emotes, checks for highlights and creates a user object by the tags
Parameters:
Name Type Description
prefix null | Object Might be the prefix object
Properties
Name Type Description
user String Username in the prefix
host String Host in the prefix
user String Username of the user that sent the message. Might be empty
to String Channel that the message was sent to
msg String The messages that was sent
tags Object The message tags
type Number The type of message that was sent. 0 - Default user message 1 - Action message (message font color similar to user name color) 2 - Server message (darker background, no username) 3 - Important user message (darker background) 4 - Whisper message 5 - Highlight message
Fires:

Type Definitions

userObject

A user object that is used to give more information about a user
Properties:
Name Type Attributes Default Description
user String Twitch user name
name String Twitch display name
color String Hex color string prepended by a #
sort Number Number to sort the user in a list by
badges String HTML string with badges the user has
nooverwrite Boolean <optional>
false If set to true it sends the signal that data is definitely not complete. Can be omitted

Events

autohostingyou

Fires when someone is hosting the channel. Only the channel owner will receive these.
Parameters:
Name Type Description
channel String Channel that the message was sent to
user Chat~userObject The user that hosts you
viewers Number How many viewers are being hosted
message String The system message
tags Object Tag object

chatmessage

Parameters:
Name Type Description
channel String The channel the message was sent to
timestamp String The time the message was sent (or received depending on available data)
userobj Chat~userObject The userobject of the sender
message String The HTML message with replaces emoticons and useable links.
org_message String The original message, how it was sent from the server
type Number The type of message that is being displayed; See Chat#showmsg for help on the possible numbers

clearchat

Fires when the entire chat is being cleared
Parameters:
Name Type Description
channel String The channel that is being cleared
tags Object The message tags

clearuser

Fires when messages of a specific user was deleted.
Parameters:
Name Type Description
channel String The channel the messages were deleted in
user Chat~userObject The user the messages were deleted from
tags String The message tags

connected

Fires when the connection is established and a user is logged in

hostingyou

Fires when someone is hosting the channel. Only the channel owner will receive these.
Parameters:
Name Type Description
channel String Channel that the message was sent to
user Chat~userObject The user that hosts you
viewers Number How many viewers are being hosted
message String The system message
tags Object Tag object

join

Fires when someone joines the channel
Parameters:
Name Type Description
channel String
user Chat~userObject The user object of the joining user. Is definitely incomplete since twitch sends no tags with the join action

names

Fires when the logged in user joines a channel. Twitch sends all user in a channel if the number is under 100. So this array might be empty
Parameters:
Name Type Description
channel String The channel this user list belongs to
userobjects Array.<Chat~userObject> An array of userobjects that are in this channel

part

Fires when someone leaves the channel
Parameters:
Name Type Description
channel String
user Chat~userObject The user object of the leaving user. Is definitely incomplete since twitch sends no tags with the part action

usernotice

Fires when a user shares is (re)subscription. There might be up to two chatmessage events emitted before this.
Parameters:
Name Type Description
channel String The channel this usernotice was sent to
user Chat~userObject The userobject of the subscriber
tags Object All tags of the message
message String The message the user added to his sub share. Might be empty.

userstate

Fires when the server sends a userstate and defines the state the logged in user is in for this channel (contains badges, permission and such)
Parameters:
Name Type Description
channel String The channel the userstate was sent to
user Chat~userObject The user object of the logged in user
tags Object The tags of the userstate
See: