Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const _ = require('lodash'), // Just to handle a couple of things more easily
- tmi = require('tmi.js'),
- channel = ''; // Your channel
- let mainConfig = {
- options: {
- debug: true // Debug to console
- },
- connection: {
- reconnect: true, // Make sure to reconnect on connection error
- secure: true // Secure servers are cooler
- },
- channels: [channel] // Yooouurrr channel
- },
- identities = {
- A: {
- username: '', // botA's username and password
- password: ''
- },
- B: {
- username: '', // botB's username and password
- password: ''
- },
- },
- botAConfig = _.defaults({ identity: identities.A }, mainConfig),
- botBConfig = _.defaults({ identity: identities.B }, mainConfig),
- botA = new tmi.client(botAConfig),
- botB = new tmi.client(botBConfig);
- function reply(channel) {
- return message => this.say(channel, message);
- }
- function handleCommand(chan, user, message) {
- let parameters = message.split(' ').filter(n => n),
- command = parameters.shift().toLowerCase().replace(/^!+/, ''),
- replyA = reply.call(botA, chan), // Reply as botA
- replyB = reply.call(botB, chan); // Reply as botB
- if(command == 'time') { // botA will respond to this
- let d = new Date();
- replyA(user.displayName + ', the time is ' + [
- (d.getHours()%12 || 12),
- d.getMinutes(),
- d.getSeconds()
- ]
- .map(n => n.toString().length == 1 ? '0' + n : n)
- .join(':'));
- }
- else if(command == 'date') { // botB will respond to this
- let d = new Date();
- replyB(user.displayName + ', the date is ' + [
- d.getMonth() + 1,
- d.getDate(),
- d.getFullYear()
- ]
- .join('/'));
- }
- }
- function handleMessage(channel, _user, message, fromSelf) {
- if(fromSelf) { // Don't respond to self
- return false;
- }
- let chan = channel.replace('#', ''), // #channel -> channel
- user = _.mapKeys(_user, _.rearg(_.camelCase, 1)); // user.['user-type'] -> user.userType
- if(message.startsWith('!')) { // Possible commands
- handleCommand(chan, user, message); // Send to command handler
- }
- }
- botA.on('message', handleMessage); // Only 1 bot needs to listen to the chat
- [botA, botB].forEach(n => n.connect()); // Connect multiple bots
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement