Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const tmi = require('tmi.js');
- const client = new tmi.Client({
- options: {debug: true},
- connection: {
- secure: true,
- reconnect: true
- },
- identity: {
- username: 'metamarktea',
- password: process.env.TWITCH_OAUTH_TOKEN
- },
- channels: ['eroaxee']
- });
- // Register our event handlers (defined below)
- client.on('message', onMessageHandler);
- client.on('connected', onConnectedHandler);
- // Connect to Twitch:
- client.connect();
- // Called every time a message comes in
- function onMessageHandler(target, context, msg, self)
- {
- if (self) {return;} // Ignore messages from the bot
- // Remove whitespace from chat message
- const commandName = msg.trim();
- var parts = commandName.split(" ");
- var command = parts[0];
- if (command === '!char')
- {
- client.say(client.channels[0], 'Char\'s stream is at: https://www.twitch.tv/ch4rrq');
- }
- if (command === '!game')
- {
- client.say(client.channels[0], 'Our game is at: https://ldjam.com/events/ludum-dare/48/aye-aye-captain');
- }
- if (command === '!bet' )
- {
- client.say(target, Date.now() + `${context["display-name"]} bet ${parts[1]}`);
- console.log(`* Executed ${commandName} command`);
- }
- // If the command is known, let's execute it
- if (command === '!dice' || command === '!roll')
- {
- var sides = 64;
- if (parts[1]){
- sides = parseInt(parts[1]);
- }
- const num = rollDice(sides);
- client.say(target, Date.now() + `You rolled a ${num}`);
- console.log(`* Executed ${commandName} command`);
- } else
- {
- console.log(`* Unknown command ${commandName}`);
- }
- }
- // Function called when the "dice" command is issued
- function rollDice(sides)
- {
- return Math.floor(Math.random() * sides) + 1;
- }
- // Called every time the bot connects to Twitch chat
- function onConnectedHandler(addr, port)
- {
- console.log(`* Connected to ${addr}:${port}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment