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

v0.0.9

上级 d58f67b7
......@@ -2,8 +2,8 @@
*
* Wechaty bot use a ApiAi.com brain
*
* Apply your own tuling123.com API_KEY
* at: http://www.tuling123.com/html/doc/api.html
* Apply Your Own ApiAi Developer API_KEY at:
* http://www.api.ai
*
* Enjoy!
*
......@@ -20,9 +20,6 @@ const Wechaty = require('../src/wechaty')
// log.level = 'silly'
/**
*
* Apply Your Own ApiAi Developer API_KEY at:
* http://www.api.ai
*
* `7217d7bce18c4bcfbe04ba7bdfaf9c08` for Wechaty demo
*
......@@ -33,7 +30,7 @@ const brainApiAi = ApiAi(APIAI_API_KEY)
const bot = new Wechaty({head: false})
console.log(`
Welcome to Tuling Wechaty Bot.
Welcome to api.AI Wechaty Bot.
Api.AI Doc: https://docs.api.ai/v16/docs/get-started
Notice: This bot will only active in the group which name contains 'wechaty'.
......
......@@ -28,7 +28,7 @@ Please wait... I'm trying to login in...
`
console.log(welcome)
const bot = new Wechaty({head: true})
const bot = new Wechaty({head: false})
bot
.on('login' , () => log.info('Bot', 'logined'))
......
/*
To be writen
https://wit.ai/
*/
{
"name": "wechaty",
"version": "0.0.8",
"version": "0.0.9",
"description": "Wechat for Bot. (Personal Account, NOT Official Account)",
"main": "index.js",
"scripts": {
......
......@@ -166,16 +166,21 @@ class PuppetWeb extends Puppet {
*/
log.verbose('PuppetWeb', 'server received unload event')
this.emit('logout', data) // XXX: should emit event[logout] from browser
this.bridge.inject()
.then(r => log.verbose('PuppetWeb', 're-injected:' + r))
.catch(e => log.error('PuppetWeb', 'inject err: ' + e))
if (this.bridge) {
this.bridge.inject()
.then(r => log.verbose('PuppetWeb', 're-injected:' + r))
.catch(e => log.error('PuppetWeb', 'inject err: ' + e))
} else {
log.verbose('PuppetWeb', 'bridge gone, should be quiting now')
}
}
send(message) {
const userName = message.to().id
const content = message.content()
log.silly('PuppetWeb', `say(${userName}, ${content})`)
log.silly('PuppetWeb', `send(${userName}, ${content})`)
return this.bridge.send(userName, content)
}
reply(recvMsg, replyMsg) {
......@@ -204,14 +209,26 @@ class PuppetWeb extends Puppet {
log.verbose('PuppetWeb', 'quit()')
let p = Promise.resolve(true)
if (this.server) { p.then(this.server.quit.bind(this)) }
else { log.warn('PuppetWeb', 'quit() without server') }
if (this.bridge) { p.then(this.bridge.quit.bind(this)) }
else { log.warn('PuppetWeb', 'quit() without bridge') }
if (this.browser) { p.then(this.browser.quit.bind(this)) }
else { log.warn('PuppetWeb', 'quit() without browser') }
if (this.bridge) {
p.then(this.bridge.quit.bind(this.bridge))
this.bridge = null
} else {
log.warn('PuppetWeb', 'quit() without bridge')
}
if (this.browser) {
p.then(this.browser.quit.bind(this.browser))
this.browser = null
} else {
log.warn('PuppetWeb', 'quit() without browser')
}
if (this.server) {
p.then(this.server.quit.bind(this.server))
this.server = null
} else {
log.warn('PuppetWeb', 'quit() without server')
}
return p // return Promise
}
......
......@@ -66,7 +66,8 @@ class Wechaty extends EventEmitter {
currentUser() { return this.puppet.currentUser() }
quit() { return this.puppet.quit() }
send(message) { return this.puppet.say(message) }
send(message) { return this.puppet.send(message) }
reply(message, reply) { return this.puppet.reply(message, reply) }
ding() {
......
......@@ -2,7 +2,7 @@ const co = require('co')
const test = require('tap').test
const log = require('npmlog')
log.level = 'verbose'
// log.level = 'silly'
log.level = 'silly'
const PuppetWeb = require('../src/puppet-web')
const PORT = 58788
......
......@@ -18,24 +18,24 @@ const PORT = 58788
function driverProcessNum() {
return new Promise((resolve, reject) => {
// require('ps-tree')(process.pid, (err, data) => {
// if (err) { return reject(err) }
// data.forEach(c => console.log(c))
// const num = data.filter(obj => /phantomjs/i.test(obj.COMMAND)).length
// return resolve(num)
// })
require('ps-tree')(process.pid, (err, children) => {
if (err) { return reject(err) }
children.forEach(child => log.silly('TestingWebDriver', 'ps-tree: %s %s', child.PID, child.COMMAND))
const num = children.filter(child => /phantomjs/i.test(child.COMMAND)).length
return resolve(num)
})
const exec = require('child_process').exec
exec('ps axf >> /tmp/ps.log', r=>r)
exec('ps axf | grep phantomjs | grep -v grep | wc -l >> /tmp/ps.log', r=>r)
// const exec = require('child_process').exec
// exec('ps axf >> /tmp/ps.log', r=>r)
// exec('ps axf | grep phantomjs | grep -v grep | wc -l >> /tmp/ps.log', r=>r)
exec('ps axf | grep phantomjs | grep -v grep | wc -l', function(err, stdout, stderr) {
if (err) {
return reject(err)
}
return resolve(parseInt(stdout[0]))
})
// exec('ps axf | grep phantomjs | grep -v grep | wc -l', function(err, stdout, stderr) {
// if (err) {
// return reject(err)
// }
// return resolve(parseInt(stdout[0]))
// })
})
}
......@@ -88,7 +88,7 @@ test('WebDriver smoke testing', function(t) {
// XXX: if get rid of this dummy,
// driver.get() will fail due to cant start phantomjs process
// yield Promise.resolve()
yield Promise.resolve()
yield driver.get('https://wx.qq.com/')
t.pass('driver url opened')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册