Created
May 19, 2019 22:04
-
-
Save mariotacke/44c30bf2df737ff2e780cf27da2a324c to your computer and use it in GitHub Desktop.
blog-real-time-word-cloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tmi = require('tmi.js'); | |
const redis = require('redis'); | |
const bluebird = require('bluebird'); | |
bluebird.promisifyAll(redis); | |
const options = { | |
identity: { | |
username: process.env.BOT_USERNAME, | |
password: process.env.OAUTH_TOKEN, | |
}, | |
channels: [ | |
process.env.CHANNEL_NAME, | |
], | |
}; | |
const tmiClient = new tmi.client(options); | |
const redisClient = redis.createClient(process.env.REDIS_URL); | |
tmiClient.on('connected', onConnectedHandler); | |
tmiClient.on('message', onMessageHandler); | |
tmiClient.connect(); | |
async function onConnectedHandler (address, port) { | |
console.log(`* Connected to ${address}:${port}`); | |
} | |
async function onMessageHandler (target, context, message, self) { | |
const words = message.replace(/,/g, '').split(' '); | |
for (let i = 0; i < words.length; i++) { | |
await redisClient.zincrbyAsync(target, 1, words[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment