提交 ef1fd124 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix io-bot code

上级 3c701447
......@@ -42,26 +42,16 @@ const ioBot = new IoBot({
})
ioBot.init()
.catch(e => {
log.error('Bot', 'init() fail: %s', e)
bot.quit()
process.exit(-1)
})
/**
*
* To make heroku happy
*
*/
if (process.env.DYNO) {
const app = require('express')()
.catch(e => {
log.error('Bot', 'init() fail: %s', e)
bot.quit()
process.exit(-1)
})
ioBot.initWeb()
.catch(e => {
log.error('Bot', 'initWeb() fail: %s', e)
bot.quit()
process.exit(-1)
})
app.get('/', function (req, res) {
res.send('Wechaty IO Bot Alive!')
})
app.listen(process.env.PORT || 8080, function () {
console.log('Wechaty IO Bot listening on port ' + process.env.PORT + '!')
})
}
......@@ -62,6 +62,27 @@ class IoBot {
})
}
initWeb(port) {
port = port || process.env.PORT || 8080
// if (process.env.DYNO) {
// }
const app = require('express')()
app.get('/', function (req, res) {
res.send('Wechaty IO Bot Alive!')
})
return new Promise((resolve, reject) => {
app.listen(port, () => {
this.log.verbose('IoBot', 'initWeb() Wechaty IO Bot listening on port ' + port + '!')
return resolve(this)
})
})
}
onMessage(m) {
const from = m.from()
const to = m.to()
......
......@@ -239,14 +239,15 @@ const Room = require('./room')
// const Puppet = require('./puppet')
const PuppetWeb = require('./puppet-web')
const IoBot = require('./io-bot')
Object.assign(Wechaty, {
Message
, Contact
, Room
, IoBot
// Do not include IoBot here, because it will be a circle dependence
// const IoBot = require('./io-bot')
//, IoBot
, log // for convenionce use npmlog with environment variable LEVEL
// Puppet
......@@ -257,3 +258,4 @@ Wechaty.version = require('../package.json').version
* Expose `Wechaty`.
*/
module.exports = Wechaty.default = Wechaty.Wechaty = Wechaty
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册