Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
fede82cb
W
wechaty
项目概览
weixin_46011646
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fede82cb
编写于
5月 28, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
v0.0.9
上级
d58f67b7
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
53 addition
and
43 deletion
+53
-43
example/api-ai-bot.js
example/api-ai-bot.js
+3
-6
example/ding-dong-bot.js
example/ding-dong-bot.js
+1
-1
example/wit-ai-bot.js
example/wit-ai-bot.js
+0
-5
package.json
package.json
+1
-1
src/puppet-web.js
src/puppet-web.js
+29
-12
src/wechaty.js
src/wechaty.js
+2
-1
test/puppet-web-spec.js
test/puppet-web-spec.js
+1
-1
test/webdriver-spec.js
test/webdriver-spec.js
+16
-16
未找到文件。
example/api-ai-bot.js
浏览文件 @
fede82cb
...
...
@@ -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'.
...
...
example/ding-dong-bot.js
浏览文件 @
fede82cb
...
...
@@ -28,7 +28,7 @@ Please wait... I'm trying to login in...
`
console
.
log
(
welcome
)
const
bot
=
new
Wechaty
({
head
:
tru
e
})
const
bot
=
new
Wechaty
({
head
:
fals
e
})
bot
.
on
(
'
login
'
,
()
=>
log
.
info
(
'
Bot
'
,
'
logined
'
))
...
...
example/wit-ai-bot.js
已删除
100644 → 0
浏览文件 @
d58f67b7
/*
To be writen
https://wit.ai/
*/
package.json
浏览文件 @
fede82cb
{
"name"
:
"wechaty"
,
"version"
:
"0.0.
8
"
,
"version"
:
"0.0.
9
"
,
"description"
:
"Wechat for Bot. (Personal Account, NOT Official Account)"
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
src/puppet-web.js
浏览文件 @
fede82cb
...
...
@@ -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
'
,
`s
ay
(
${
userName
}
,
${
content
}
)`
)
log
.
silly
(
'
PuppetWeb
'
,
`s
end
(
${
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
}
...
...
src/wechaty.js
浏览文件 @
fede82cb
...
...
@@ -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
()
{
...
...
test/puppet-web-spec.js
浏览文件 @
fede82cb
...
...
@@ -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
...
...
test/webdriver-spec.js
浏览文件 @
fede82cb
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录