update bot code

This commit is contained in:
Jay 2018-02-13 13:41:32 +08:00
parent 725791dd4e
commit 79eed290d4

View File

@ -3,21 +3,39 @@ const config = require('../config')
const dbPool = require('./database')
const request = require('request')
const log = require('debug')('BOT:IRC')
const { msgSplit } = require('./twitchParser')
const {
msgSplit
} = require('./twitchParser')
const ws = new WebSocket(`wss://${config.twitch.chat_host}:443`, 'irc')
/** @type {WebSocket} */
var ws = null
runBot()
function runBot() {
ws = new WebSocket(`wss://${config.twitch.chat_host}:443`, 'irc')
ws.on('open', handleOpen)
ws.on('message', handleMessage)
ws.on('error', (err) => {
console.error(err)
})
ws.on('error', handleError)
ws.on('close', (code, reason) => {
console.log('exit', code, reason)
})
ws.on('close', handleExit)
}
function handleError(err) {
console.error(err)
ws = null
runBot()
// do reconnect
}
function handleExit(code) {
// do reconnect
ws = null
runBot()
}
function handleMessage(data) {
let d = data.toString()