-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitch_chatter.js
34 lines (25 loc) · 1.08 KB
/
twitch_chatter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
//----------------------------------------------------------------
const redis = require('redis')
const log = require('fancy-log')
//----------------------------------------------------------------
class TwitchChatter {
constructor(twitchClient, twitchChannel, redisHost, redisPort, channelPrefix) {
this.redisClient = redis.createClient(redisPort, redisHost);
// e.g. "laddspencer.chatter.say"
let chatterChannelPrefix = `${channelPrefix}.chatter`;
let subChannel = `${chatterChannelPrefix}.say`;
console.log(`TwitchChatter will be listening on ${subChannel}`);
this.redisClient.on("message", (channel, message) => {
log(`${channel}: "${message}"`);
if (twitchClient.readyState() == "OPEN") {
twitchClient.say(twitchChannel, message);
return;
}
log(`Twitch client not connected to ${channel}; unable to say "${message}"`);
});
this.redisClient.subscribe(subChannel);
}
}
module.exports = TwitchChatter;
//----------------------------------------------------------------