This commit is contained in:
Jay
2018-02-12 23:08:42 +08:00
commit c65d29e81a
14 changed files with 3021 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
const WebSocket = require('ws')
const config = require('../config')
const ws = new WebSocket(`wss://${config.twitch.chat_host}:443`, 'irc')
ws.on('open', () => {
})
ws.on('message', (data) => {
if (typeof data !== 'string') data = data.toString()
})
ws.on('error', (err) => {
console.error(err)
})
ws.on('close', (code, reason) => {
console.log('exit', code, reason)
})
module.exports = ws
+2
View File
@@ -0,0 +1,2 @@
const pg = require('pg')
const config = require('../config')
+9
View File
@@ -0,0 +1,9 @@
class MessageQueue {
constructor() {
this.queue = {}
}
}
module.exports = new MessageQueue()
+50
View File
@@ -0,0 +1,50 @@
/**
* @param {string} msg
*/
const msgSplit = function (msg) {
if (!msg || typeof msg !== 'string') return null
let txtarr = msg.split(' ')
if (txtarr.length > 2) {
if (/^ping$/i.test(txtarr[0])) {
return {
type: 'ack',
msg: `PONG ${txtarr[1]}`
}
}
// chat message
if (/^privmsg$/i.test(txtarr[1])) {
let user = txtarr[0].split('!')[0].substr(1)
let channel = txtarr[2]
txtarr = txtarr.slice(3, txtarr.length)
let m = txtarr.join(' ').substr(1)
if (m.startsWith('!刺蝟')) {
return {
type: 'msg',
channel,
user,
msg: '女裝呢!!!?'
}
}else if (m.startsWith('!zoe')) {
return {
type: 'msg',
channel,
user,
msg: '跟KKBOX犯沖'
}
}else if(m.startsWith('!紫色')) {
return {
type: 'msg',
channel,
user,
msg: '肛刺蝟'
}
}
}
}
}
module.exports = {
msgSplit
}