mixer-bot
Version:
Simplified chat bot for the mixer live streaming platform
547 lines (265 loc) • 14.1 kB
HTML
<html>
<head>
<meta charset='utf-8' />
<title>mixer-bot 0.1.2 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
<link href='assets/github.css' type='text/css' rel='stylesheet' />
<link href='assets/split.css' type='text/css' rel='stylesheet' />
</head>
<body class='documentation m0'>
<div class='flex'>
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>mixer-bot</h3>
<div class='mb1'><code>0.1.2</code></div>
<input
placeholder='Filter'
id='filter-input'
class='col12 block input'
type='text' />
<div id='toc'>
<ul class='list-reset h5 py1-ul'>
<li><a
href='#mixer-bot'
class="">
mixer-bot
</a>
</li>
<li><a
href='#assign_default_options'
class="">
assign_default_options
</a>
</li>
<li><a
href='#get_connection_info'
class="">
get_connection_info
</a>
</li>
<li><a
href='#get_user_info'
class="">
get_user_info
</a>
</li>
<li><a
href='#join_chat'
class="">
join_chat
</a>
</li>
</ul>
</div>
<div class='mt1 h6 quiet'>
<a href='http://documentation.js.org/reading-documentation.html'>Need help reading this?</a>
</div>
</div>
</div>
<div id='split-right' class='relative overflow-auto height-viewport-100'>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='mixer-bot'>
mixer-bot
</h3>
</div>
<p>Creates a mixer bot client and runs it based on a set of options.</p>
<div class='pre p1 fill-light mt0'>mixer-bot</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>options</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>
= <code>{}</code>)</code>
options for the mixer-bot.
</div>
<table class='mt1 mb2 fixed-table h5 col-12'>
<colgroup>
<col width='30%' />
<col width='70%' />
</colgroup>
<thead>
<tr class='bold fill-light'>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody class='mt1'>
<tr>
<td class='break-word'><span class='code bold'>options.env</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code>
</td>
<td class='break-word'><span>path to the .env file.
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.channel_id</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code>
</td>
<td class='break-word'><span>channel id to join for the bot, which can be found here for a user:
<a href="https://mixer.com/api/v1/channels/">https://mixer.com/api/v1/channels/</a>
<username>
?fields=id
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.greeting</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code>
</td>
<td class='break-word'><span>the greeting message to display when the bot joins a channel (If you use "@me" here it will be replaced with your username)
</span></td>
</tr>
<tr>
<td class='break-word'><span class='code bold'>options.on</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function">Function</a></code>
</td>
<td class='break-word'><span>a list of functions that define the mixer bot's response on channel actions (ChatMessage, UserJoin). Data is passed with reference to the mixer client (data.client), ws socket (data.socket), API user information (data.user_info), and these options (data.options).
</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code>:
returns a mixerbot client.
<div class='py1 quiet mt1 prose-big'>Example</div>
<pre class='p1 overflow-auto round fill-light'><span class="hljs-keyword">const</span> mixerbot = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mixer-bot'</span>);
<span class="hljs-comment">// Create a .env file in the same location and set</span>
<span class="hljs-comment">// MIXER_ACCESS_TOKEN=***</span>
<span class="hljs-comment">// MIXER_CHANNEL_ID=***</span>
<span class="hljs-comment">// Setup options</span>
<span class="hljs-keyword">var</span> options = {};
options.on = {};
options.greeting = <span class="hljs-string">'Hello!'</span>;
<span class="hljs-comment">// Setup channel ID</span>
<span class="hljs-comment">// If left unset, this will be the id to your channel</span>
<span class="hljs-comment">// Get your channel id here: https://mixer.com/api/v1/channels/<username>?fields=id</span>
<span class="hljs-comment">// options.channel_id = '<CHANNEL_ID>';</span>
<span class="hljs-comment">// Assign bot to greet user when they enter</span>
options.on.UserJoin = <span class="hljs-function"><span class="hljs-params">data</span> =></span> {
socket = data.socket;
<span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-params">response</span> =></span> {
socket.call(<span class="hljs-string">'msg'</span>,[
<span class="hljs-string">`Hi <span class="hljs-subst">${response.username}</span>! I'm pingbot! Write !ping and I will pong back!`</span>,
]);
}
};
<span class="hljs-comment">// Assign bot to pong user if they message !ping</span>
options.on.ChatMessage = <span class="hljs-function"><span class="hljs-params">data</span> =></span> {
socket = data.socket;
<span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-params">response</span> =></span> {
<span class="hljs-keyword">if</span> (response.message.message[<span class="hljs-number">0</span>].data.toLowerCase().startsWith(<span class="hljs-string">'!ping'</span>)) {
socket.call(<span class="hljs-string">'msg'</span>, [<span class="hljs-string">`@<span class="hljs-subst">${response.user_name}</span> PONG!`</span>]);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Ponged <span class="hljs-subst">${response.user_name}</span>`</span>);
}
}
};
<span class="hljs-comment">// Handle errors</span>
options.on.error = <span class="hljs-function"><span class="hljs-params">data</span> =></span> {
<span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-params">error</span> =></span> {
<span class="hljs-built_in">console</span>.error(<span class="hljs-string">'Socket error'</span>);
<span class="hljs-built_in">console</span>.error(error);
}
};
<span class="hljs-comment">// Run mixer bot</span>
mixerbot(options);</pre>
</section>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='assign_default_options'>
assign_default_options
</h3>
</div>
<p>Assigns the default options for mixerbot.</p>
<div class='pre p1 fill-light mt0'>assign_default_options(options: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>options</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code>
an options object to assign defaults.
</div>
</div>
</div>
<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code>:
the default options.
</section>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='get_connection_info'>
get_connection_info
</h3>
</div>
<p>Gets connection information from Mixer's chat servers</p>
<div class='pre p1 fill-light mt0'>get_connection_info(client: any, channel_id: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>client</span> <code class='quiet'>(any)</code>
</div>
</div>
<div class='space-bottom0'>
<div>
<span class='code bold'>channel_id</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a>)</code>
the channel_id of the channel you'd like to get connection information for.
</div>
</div>
</div>
</section>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='get_user_info'>
get_user_info
</h3>
</div>
<p>Gets our Currently Authenticated Mixer user's information.
This returns an object full of useful information about the user whose OAuth Token we provided above.</p>
<div class='pre p1 fill-light mt0'>get_user_info(client: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>client</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a>)</code>
the mixer client to use for requesting information.
</div>
</div>
</div>
</section>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='join_chat'>
join_chat
</h3>
</div>
<p>Creates a Mixer chat socket and authenticates</p>
<div class='pre p1 fill-light mt0'>join_chat(client: any, user_id: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, channel_id: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</div>
<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>
<div class='space-bottom0'>
<div>
<span class='code bold'>client</span> <code class='quiet'>(any)</code>
</div>
</div>
<div class='space-bottom0'>
<div>
<span class='code bold'>user_id</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code>
The user to authenticate as
</div>
</div>
<div class='space-bottom0'>
<div>
<span class='code bold'>channel_id</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code>
The channel id of the channel you want to join
</div>
</div>
</div>
</section>
</div>
</div>
<script src='assets/anchor.js'></script>
<script src='assets/split.js'></script>
<script src='assets/site.js'></script>
</body>
</html>