UNPKG

twitch-toolkit

Version:

A set of tools to integrate with Twitch API, Twitch Chat and Twitch WebHooks.

1,308 lines (429 loc) 24.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>TwitchChatEmitter - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchApi.html">TwitchApi</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getAccessToken">getAccessToken</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getGames">getGames</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreams">getStreams</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getStreamsMetadata">getStreamsMetadata</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsers">getUsers</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getUsersFollows">getUsersFollows</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#getVideos">getVideos</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#isLive">isLive</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#updateUser">updateUser</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchApi.html#validateAccessToken">validateAccessToken</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchChatEmitter.html">TwitchChatEmitter</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#connect">connect</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchPubSub.html">TwitchPubSub</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#connect">connect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#disconnect">disconnect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#reconnect">reconnect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchPubSub.html#subscribe">subscribe</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="TwitchWebhook.html">TwitchWebhook</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#destroy">destroy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#handleRequest">handleRequest</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#subscribe">subscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#topicStreamUpDownSubscribe">topicStreamUpDownSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#topicUserFollowsSubscribe">topicUserFollowsSubscribe</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="TwitchWebhook.html#unsubscribe">unsubscribe</a></span></li><li class="nav-heading">Events</li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchChatEmitter.html#event:Chat:chat_parsed">Chat:chat_parsed</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebhook.html#event:Webhook:stream_up_down">Webhook:stream_up_down</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="TwitchWebhook.html#event:Webhook:user_follows">Webhook:user_follows</a></span></li> </nav> <div id="main"> <h1 class="page-title">TwitchChatEmitter</h1> <section> <header> <h2> TwitchChatEmitter </h2> <div class="class-description"><p>TwitchChatEmitter The Twitch chat implementation, based on the already existing module tmi.js (tmijs.org), adding more features and handlers to chat interation.</p></div> </header> <article> <div class="container-overview"> <div class="section-method"> <h2>Constructor</h2> <h4 class="name" id="TwitchChatEmitter"><span class="type-signature"></span>new TwitchChatEmitter<span class="signature">(config)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchChatEmitter.js.html">twitchChatEmitter.js</a>, <a href="twitchChatEmitter.js.html#line44">line 44</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>config</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The config object</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>debug</code></td> <td class="type"> <span class="param-type"><code>boolean</code></span> </td> <td class="description last"> <p>Debug mode. If true, will show the debug messages.</p> </td> </tr> <tr> <td class="name"><code>logger</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The logger instance. If empty, the default logger will be used.</p> </td> </tr> <tr> <td class="name"><code>channels</code></td> <td class="type"> <span class="param-type"><code>Array.&lt;string></code></span> </td> <td class="description last"> <p>The twitch channels that will be used. This is required.</p> </td> </tr> <tr> <td class="name"><code>username</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The chat bot username. This is required.</p> </td> </tr> <tr> <td class="name"><code>password</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The chat bot OAUTH token password. You can get it at http://twitchapps.com/tmi/ . This is required.</p> </td> </tr> <tr> <td class="name"><code>reconnect</code></td> <td class="type"> <span class="param-type"><code>boolean</code></span> </td> <td class="description last"> <p>Reconnect to Twitch when disconnected from server. Default: false</p> </td> </tr> <tr> <td class="name"><code>maxReconnectAttempts</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>Max number of reconnection attempts (Default: Infinity)</p> </td> </tr> <tr> <td class="name"><code>maxReconnectInterval</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>Max number of ms to delay a reconnection (Default: 30000)</p> </td> </tr> <tr> <td class="name"><code>reconnectDecay</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>The rate of increase of the reconnect delay (Default: 1.5)</p> </td> </tr> <tr> <td class="name"><code>reconnectInterval</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>Number of ms before attempting to reconnect (Default: 1000)</p> </td> </tr> <tr> <td class="name"><code>secure</code></td> <td class="type"> <span class="param-type"><code>boolean</code></span> </td> <td class="description last"> <p>Use secure connection (SSL / HTTPS) (Overrides port to 443)</p> </td> </tr> <tr> <td class="name"><code>timeout</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>Number of ms to disconnect if no responses from server (Default: 9999)</p> </td> </tr> <tr> <td class="name"><code>commandPrefix</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The prefix caracter for chat command. Default is &quot;!&quot;.</p> </td> </tr> <tr> <td class="name"><code>triggers</code></td> <td class="type"> <span class="param-type"><code>Array.&lt;object></code></span> </td> <td class="description last"> <p>The triggers object array.</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The name of the trigger. This is required.</p> </td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The type of the trigger. Can be one 'word' or 'command'. This is required</p> </td> </tr> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The channel in which the trigger will be used. This is required.</p> </td> </tr> <tr> <td class="name"><code>chatTrigger</code></td> <td class="type"> <span class="param-type"><code>boolean</code></span> </td> <td class="description last"> <p>Define if its a chat trigger. (Default: true)</p> </td> </tr> <tr> <td class="name"><code>whisperTrigger</code></td> <td class="type"> <span class="param-type"><code>boolean</code></span> </td> <td class="description last"> <p>Define if its a whisper trigger. (Default: false)</p> </td> </tr> <tr> <td class="name"><code>minDelay</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>The delay before the action is triggered again. (Default: 0)</p> </td> </tr> <tr> <td class="name"><code>eventName</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The name of the event that will be triggered. If this is empty, no event will be emitted.</p> </td> </tr> <tr> <td class="name"><code>responseText</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The text that will be sent to chat/whisper if the action is triggered. If this is empty, nothing will be sent.</p> </td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name"><code>timedMessages</code></td> <td class="type"> <span class="param-type"><code>Array.&lt;object></code></span> </td> <td class="description last"> <p>The timed messages array.</p> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>message</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The message to be sent.</p> </td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The channel in which the timed message will be sent. This is required.</p> </td> </tr> <tr> <td class="name"><code>timedMessages[].minDelay</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>The minimum delay, in seconds, between this kind of message. This is required.</p> </td> </tr> <tr> <td class="name"><code>timedMessages[].minChatMessages</code></td> <td class="type"> <span class="param-type"><code>number</code></span> </td> <td class="description last"> <p>The minimum ammount of messages in chat to send this message.</p> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> </div> <h3 class="subsection-title">Methods</h3> <div class="section-method"> <h4 class="name" id="connect"><span class="type-signature"></span>connect<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> <p>Connect to the chat.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchChatEmitter.js.html">twitchChatEmitter.js</a>, <a href="twitchChatEmitter.js.html#line118">line 118</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Events</h3> <div class="section-method"> <h4 class="name" id="event:Chat:chat_parsed">Chat:chat_parsed</h4> <div class="description"> <p>The chat message parsed to html, with twitch emotes.</p> </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="twitchChatEmitter.js.html">twitchChatEmitter.js</a>, <a href="twitchChatEmitter.js.html#line245">line 245</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>channel</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The channel in which the command was sent.</p> </td> </tr> <tr> <td class="name"><code>userstate</code></td> <td class="type"> <span class="param-type"><code>object</code></span> </td> <td class="description last"> <p>The userstate object.</p> </td> </tr> <tr> <td class="name"><code>message</code></td> <td class="type"> <span class="param-type"><code>string</code></span> </td> <td class="description last"> <p>The parsed message.</p> </td> </tr> <tr> <td class="name"><code>self</code></td> <td class="type"> <span class="param-type"><code>bool</code></span> </td> <td class="description last"> <p>Whether the command was sent to the user bot or not.</p> </td> </tr> </tbody> </table> </div> </article> </section> </div> <br class="clear"> <footer> Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Oct 30 2018 21:48:20 GMT-0300 (E. South America Standard Time) using the Minami theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>