Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
8d062fed
W
wechaty
项目概览
.www.
/
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,发现更多精彩内容 >>
提交
8d062fed
编写于
10月 06, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
async code fix, and return Error as object
上级
1462b19a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
66 addition
and
18 deletion
+66
-18
example/room-bot.js
example/room-bot.js
+14
-4
src/puppet-web/bridge.js
src/puppet-web/bridge.js
+2
-2
src/puppet-web/wechaty-bro.js
src/puppet-web/wechaty-bro.js
+43
-12
src/room.js
src/room.js
+7
-0
未找到文件。
example/room-bot.js
浏览文件 @
8d062fed
...
...
@@ -171,12 +171,22 @@ bot
log
.
verbose
(
'
Bot
'
,
'
contactList: %s
'
,
contactList
.
join
(
'
,
'
))
Room
.
create
(
contactList
,
'
ding
'
)
.
then
(
r
=>
{
log
.
info
(
'
Bot
'
,
'
new ding room created: %s
'
,
r
)
console
.
log
(
r
)
.
then
(
roomId
=>
{
log
.
info
(
'
Bot
'
,
'
new ding room created, id: %s
'
,
roomId
)
Room
.
load
(
roomId
)
.
ready
()
.
then
(
room
=>
{
room
.
topic
(
'
ding - created
'
)
const
m
=
new
Message
()
m
.
set
(
'
to
'
,
roomId
)
m
.
set
(
'
room
'
,
roomId
)
m
.
set
(
'
content
'
,
'
ding - created
'
)
bot
.
send
(
m
)
})
})
.
catch
(
e
=>
{
log
.
error
(
'
Bot
'
,
'
new ding room create fail: %s
'
,
e
.
stack
)
log
.
error
(
'
Bot
'
,
'
new ding room create fail: %s
'
,
e
.
message
)
})
})
...
...
src/puppet-web/bridge.js
浏览文件 @
8d062fed
...
...
@@ -144,9 +144,9 @@ class Bridge {
}
contactFind
(
filterFunction
)
{
return
this
.
proxyWechaty
(
'
contactFind
'
,
filterFunction
)
return
this
.
proxyWechaty
(
'
contactFind
Async
'
,
filterFunction
)
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebBridge
'
,
'
contactFind() exception: %s
'
,
e
.
message
)
log
.
error
(
'
PuppetWebBridge
'
,
'
contactFind
Async
() exception: %s
'
,
e
.
message
)
throw
e
})
}
...
...
src/puppet-web/wechaty-bro.js
浏览文件 @
8d062fed
...
...
@@ -451,7 +451,13 @@
:
null
}
function
contactFind
(
filterFunction
)
{
function
contactFindAsync
(
filterFunction
)
{
const
callback
=
arguments
[
arguments
.
length
-
1
]
if
(
typeof
callback
!==
'
function
'
)
{
// here we should in sync mode, because there's no callback
throw
new
Error
(
'
async method need to be called via webdriver.executeAsyncScript
'
)
}
var
contactFactory
=
WechatyBro
.
glue
.
contactFactory
var
match
...
...
@@ -460,10 +466,26 @@
}
else
{
match
=
eval
(
filterFunction
)
}
// log(match.toString())
return
contactFactory
.
getAllFriendContact
()
.
filter
(
r
=>
match
(
r
.
NickName
))
.
map
(
r
=>
r
.
UserName
)
return
retryFind
(
0
)
// retry 3 times, sleep 300ms between each time
function
retryFind
(
attempt
=
0
)
{
const
contactList
=
contactFactory
.
getAllFriendContact
()
.
filter
(
c
=>
match
(
c
.
NickName
))
.
map
(
c
=>
c
.
UserName
)
if
(
contactList
&&
contactList
.
length
)
{
callback
(
contactList
)
}
else
if
(
attempt
>
3
)
{
callback
([])
}
else
{
attempt
++
setTimeout
(
_
=>
retryFind
(
attempt
),
300
)
}
}
}
function
roomFind
(
filterFunction
)
{
...
...
@@ -510,15 +532,17 @@
const
chatroomFactory
=
WechatyBro
.
glue
.
chatroomFactory
const
state
=
WechatyBro
.
glue
.
state
chatroomFactory
.
create
(
UserNameListArg
)
.
then
(
r
=>
{
if
(
r
.
BaseResponse
&&
0
==
r
.
BaseResponse
.
Ret
||
-
2013
==
e
.
BaseResponse
.
Ret
)
{
if
(
r
.
BaseResponse
&&
0
==
r
.
BaseResponse
.
Ret
||
-
2013
==
r
.
BaseResponse
.
Ret
)
{
state
.
go
(
'
chat
'
,
{
userName
:
r
.
ChatRoomName
})
// BE CAREFUL: key name is userName, not UserName! 20161001
if
(
topic
)
{
roomModTopic
(
r
.
ChatRoomName
,
topic
)
// if (topic) {
// setTimeout(_ => roomModTopic(r.ChatRoomName, topic), 3000)
// }
if
(
!
r
.
ChatRoomName
)
{
throw
new
Error
(
'
chatroomFactory.create() got empty r.ChatRoomName
'
)
}
callback
(
r
.
ChatRoomName
,
topic
)
callback
(
r
.
ChatRoomName
)
}
else
{
throw
new
Error
(
'
chatroomFactory.create() error with Ret:
'
+
r
&&
r
.
BaseResponse
.
Ret
...
...
@@ -529,7 +553,14 @@
})
.
catch
(
e
=>
{
// Async can only return by call callback
callback
(
e
)
callback
(
JSON
.
parse
(
JSON
.
stringify
(
e
,
Object
.
getOwnPropertyNames
(
e
)
)
)
)
})
}
...
...
@@ -639,7 +670,7 @@
,
getMsgImg
:
getMsgImg
// for Wechaty Contact Class
,
contactFind
,
contactFind
Async
// for Wechaty Room Class
,
roomCreateAsync
...
...
src/room.js
浏览文件 @
8d062fed
...
...
@@ -246,6 +246,13 @@ class Room extends EventEmitter{
return
Config
.
puppetInstance
()
.
roomCreate
(
contactList
,
topic
)
.
then
(
roomId
=>
{
if
(
typeof
roomId
===
'
object
'
)
{
// It is a Error Object send back by callback in browser(WechatyBro)
throw
roomId
}
return
roomId
})
}
// private
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录