change background to fork

This commit is contained in:
Jay 2018-08-25 20:54:35 +08:00
parent f391a6043a
commit 3e3539d503
2 changed files with 21 additions and 5 deletions

View File

@ -308,9 +308,15 @@ const checkDonate = async (loginName = null, opayid = null) => {
values values
}) })
let msg = `/me 感謝 ${i.name} 贊助了 ${i.amount} 元, ${i.msg}` let msg = `/me 感謝 ${i.name} 贊助了 ${i.amount} 元, ${i.msg}`
event.emit('twitchSend', { //event.emit('twitchSend', {
msg, // msg,
channel: loginName // channel: loginName
//})
process.send({
type: 'twitchSend',
data: {
msg, channel: loginName
}
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)

View File

@ -1,12 +1,22 @@
require('module-alias/register') require('module-alias/register')
const fs = require('fs') const fs = require('fs')
const fork = require('child_process').fork
const path = require('path') const path = require('path')
try { try {
fs.accessSync(path.resolve(__dirname, '.env')) fs.accessSync(path.resolve(__dirname, '.env'))
require('dotenv').config() require('dotenv').config()
} catch (err) {} } catch (err) {}
require('./app') require('./app')
require('./background') const event = require('./event')
require('./event') let bgProc = fork('./background.js')
bgProc.on('message', data => {
if ('type' in data && 'data' in data) {
event.emit(data.type, data.data)
}
})
bgProc.on('close', () => {
console.log(`background close`)
})
//require('./background')
const twitchChat = require('./libs/twitch-bot') const twitchChat = require('./libs/twitch-bot')
twitchChat.runBot() twitchChat.runBot()