fix twitch irc leave bug

This commit is contained in:
Jay 2018-07-25 22:20:59 +08:00
parent a767ef3869
commit ba4dba3429
2 changed files with 9 additions and 6 deletions

View File

@ -65,7 +65,7 @@ class WS {
for (let i in darr) {
// parse message
console.log('IRC:::: ', darr[i])
console.log('IRC::: > ', darr[i])
msgSplit(this.ws, darr[i]).then(() => { /* pass */ })
}
}
@ -87,12 +87,12 @@ class WS {
// release pool connection
await db.release()
this.joinChannel = []
if (result !== null && result.rowCount > 0) {
for (let row of result.rows) {
if ('name' in row) {
this.ws.send('JOIN #' + row.name)
this.join.push(row.name)
this.joinChannel(row.name)
// this.ws.send('JOIN #' + row.name)
// this.join.push(row.name)
}
}
}
@ -142,6 +142,7 @@ class WS {
if (channel === null || typeof channel !== 'string' || channel.trim().length === 0) return null
if (message === null || typeof message !== 'string' || message.trim().length === 0) return null
if (this.join.indexOf(channel) === -1) return null
console.log(`IRC::: < ${`PRIVMSG #${channel} :${message}`}`)
this.ws.send(`PRIVMSG #${channel} :${message}`)
}
@ -149,6 +150,7 @@ class WS {
if (this.ws === null || !('send' in this.ws) || typeof this.ws.send !== 'function') return null
if (channel === null || typeof channel !== 'string' || channel.trim().length === 0) return null
if (this.join.indexOf(channel) !== -1) return null
console.log(`IRC::: < ${`JOIN #${channel.trim()}`}`)
this.ws.send(`JOIN #${channel.trim()}`)
this.join.push(channel.trim())
}

View File

@ -6,12 +6,13 @@ const config = require('@config/index')
*/
const msgSplit = async function (ws, msg) {
if (!msg || typeof msg !== 'string') return null
let txtarr = msg.split(' ')
let txtarr = msg.trim().split(' ')
if (txtarr.length > 2) {
if (txtarr.length >= 2) {
// server heartbeat message
if (/^ping$/i.test(txtarr[0])) {
// reply server heartbeat
console.log(`IRC::: < ${`PONG ${txtarr[1]}`}`)
ws.send(`PONG ${txtarr[1]}`)
return
}