mtfosbot/libs/twitch-bot/parser.js

38 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2018-07-15 16:51:36 +00:00
const DB = require('@libs/database') // eslint-disable-line
const config = require('@config/index')
/**
* @param {WebSocket} ws
* @param {string} msg
*/
const msgSplit = async function (ws, msg) {
if (!msg || typeof msg !== 'string') return null
2018-07-25 14:20:59 +00:00
let txtarr = msg.trim().split(' ')
2018-07-15 16:51:36 +00:00
2018-07-25 14:20:59 +00:00
if (txtarr.length >= 2) {
2018-07-15 16:51:36 +00:00
// server heartbeat message
if (/^ping$/i.test(txtarr[0])) {
// reply server heartbeat
2018-07-25 14:20:59 +00:00
console.log(`IRC::: < ${`PONG ${txtarr[1]}`}`)
2018-07-15 16:51:36 +00:00
ws.send(`PONG ${txtarr[1]}`)
return
}
// chat message
if (/^privmsg$/i.test(txtarr[1])) {
// message format
// :user!user@user.tmi.twitch.tv PRIVMSG #channel :message
let user = txtarr[0].split('!')[0].substr(1)
if (user === config.twitch.bot_account) return
let channel = txtarr[2] // eslint-disable-line
// get message
txtarr = txtarr.slice(3, txtarr.length)
// remove message first :
let m = txtarr.join(' ').substr(1) // eslint-disable-line
}
}
}
module.exports = {
2018-07-16 08:51:31 +00:00
msgSplit
2018-07-15 16:51:36 +00:00
}