Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
a3ef134f
W
wechaty
项目概览
.Veneno.
/
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,发现更多精彩内容 >>
提交
a3ef134f
编写于
6月 12, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip...
上级
21b0884b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
118 addition
and
60 deletion
+118
-60
src/puppet-mock/puppet-mock.ts
src/puppet-mock/puppet-mock.ts
+2
-1
src/puppet-padchat/bridge.ts
src/puppet-padchat/bridge.ts
+2
-4
src/puppet-padchat/puppet-padchat.ts
src/puppet-padchat/puppet-padchat.ts
+43
-4
src/puppet-padchat/pure-function-helper.ts
src/puppet-padchat/pure-function-helper.ts
+19
-0
src/puppet/puppet.ts
src/puppet/puppet.ts
+24
-23
src/wechaty.ts
src/wechaty.ts
+28
-28
未找到文件。
src/puppet-mock/puppet-mock.ts
浏览文件 @
a3ef134f
...
...
@@ -72,7 +72,8 @@ export interface MockRoomRawPayload {
export
class
PuppetMock
extends
Puppet
{
/**
* Watchdog Timeout in Seconds
* if set this value, the parent Puppet class will use it to init watchdog
* if set this value, the default timeout value will be overwrited,
* and the parent Puppet class will use it to init watchdog
*/
protected
[
WATCHDOG_TIMEOUT
]
=
30
...
...
src/puppet-padchat/bridge.ts
浏览文件 @
a3ef134f
...
...
@@ -795,10 +795,8 @@ export class Bridge extends PadchatRpc {
* add syncRoomMember task to the queue
*/
this
.
delayQueueExecutor
.
execute
(
()
=>
{
this
.
syncRoomMember
(
roomId
)
},
'
syncRoomMember(
'
+
roomId
+
'
)
'
,
()
=>
this
.
syncRoomMember
(
roomId
),
`syncRoomMember(
${
roomId
}
)`
,
)
log
.
silly
(
'
PuppetPadchatBridge
'
,
'
syncContactsAndRooms() added sync room(%s) task to delayQueueExecutor
'
,
roomId
)
...
...
src/puppet-padchat/puppet-padchat.ts
浏览文件 @
a3ef134f
...
...
@@ -233,7 +233,7 @@ export class PuppetPadchat extends Puppet {
}
protected
onPadchatMessage
(
rawPayload
:
PadchatMessagePayload
)
{
protected
async
onPadchatMessage
(
rawPayload
:
PadchatMessagePayload
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
onPadchatMessage({id=%s, type=%s(%s)})
'
,
rawPayload
.
msg_id
,
PadchatMessageType
[
rawPayload
.
sub_type
],
...
...
@@ -252,9 +252,48 @@ export class PuppetPadchat extends Puppet {
case
PadchatMessageType
.
Sys
:
console
.
log
(
'
sys message:
'
,
rawPayload
)
// this.emit('room-join', roomId, inviteeIdList, inviterId)
// this.emit('room-leave', roomId, leaverIdList, remover)
// this.emit('room-topic', roomId, topic, oldTopic, changerId)
const
roomJoin
=
pfHelper
.
roomJoinMessageParser
(
rawPayload
)
if
(
roomJoin
)
{
const
inviteeNameList
=
roomJoin
.
inviteeNameList
const
inviterName
=
roomJoin
.
inviterName
const
roomId
=
roomJoin
.
roomId
const
inviteeIdList
=
await
Promise
.
all
(
inviteeNameList
.
map
(
inviteeName
=>
this
.
roomMemberSearch
(
roomId
,
inviteeName
))
)
const
inviterId
=
await
this
.
roomMemberSearch
(
roomId
,
inviterName
)
this
.
emit
(
'
room-join
'
,
roomId
,
inviteeIdList
,
inviterId
)
}
const
roomLeave
=
pfHelper
.
roomLeaveMessageParser
(
rawPayload
)
if
(
roomLeave
)
{
const
leaverNameList
=
roomLeave
.
leaverNameList
const
removerName
=
roomLeave
.
removerName
const
roomId
=
roomLeave
.
roomId
const
leaverIdList
=
await
Promise
.
all
(
leaverNameList
.
map
(
leaverName
=>
this
.
roomMemberSearch
(
roomId
,
leaverName
))
)
const
removerId
=
await
this
.
roomMemberSearch
(
roomId
,
removerName
)
this
.
emit
(
'
room-leave
'
,
roomId
,
leaverIdList
,
removerId
)
}
const
roomTopic
=
pfHelper
.
roomTopicMessageParser
(
rawPayload
)
if
(
roomTopic
)
{
const
changerName
=
roomTopic
.
changerName
const
newTopic
=
roomTopic
.
topic
const
roomId
=
roomTopic
.
roomId
const
roomPayload
=
await
this
.
roomPayload
(
roomId
)
const
oldTopic
=
roomPayload
.
topic
const
changerId
=
await
this
.
roomMemberSearch
(
roomId
,
changerName
)
this
.
emit
(
'
room-topic
'
,
roomId
,
newTopic
,
oldTopic
,
changerId
)
}
break
...
...
src/puppet-padchat/pure-function-helper.ts
浏览文件 @
a3ef134f
...
...
@@ -404,6 +404,25 @@ export class PadchatPureFunctionHelper {
const
decodedObject
:
T
=
JSON
.
parse
(
decodedText
)
return
decodedObject
}
public
roomJoinMessageParser
(
rawPayload
:
PadchatMessagePayload
):
RoomJoinPayload
{
const
roomJoinPayload
=
roomJoin
.
inviteeNameList
const
inviterName
=
roomJoin
.
inviterName
const
roomId
=
roomJoin
.
roomId
}
public
roomLeaveMessageParser
(
rawPayload
:
PadchatMessagePayload
):
RoomLeavePayload
{
const
roomJoinPayload
roomLeave
.
leaverNameList
const
removerName
=
roomLeave
.
removerName
const
roomId
=
roomLeave
.
roomId
}
public
roomTopicMessageParser
(
rawPayload
:
PadchatMessagePayload
):
RoomTopicPayload
{
const
roomJoinPayload
roomTopic
.
changerName
const
newTopic
=
roomTopic
.
topic
const
roomId
=
roomTopic
.
roomId
}
}
export
default
PadchatPureFunctionHelper
src/puppet/puppet.ts
浏览文件 @
a3ef134f
...
...
@@ -99,7 +99,8 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/**
* Watchdog Timeout in Seconds
* if set this value, the parent Puppet class will use it to init watchdog
* if set this value, the default timeout value will be overwrited,
* and the parent Puppet class will use it to init watchdog
*/
protected
[
WATCHDOG_TIMEOUT
]?:
number
// Watchdog timeout, in seconds
...
...
@@ -186,17 +187,17 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*
*
*/
public
emit
(
event
:
'
error
'
,
error
:
string
)
:
boolean
public
emit
(
event
:
'
friend
'
,
requestId
:
string
)
:
boolean
public
emit
(
event
:
'
login
'
,
contactId
:
string
)
:
boolean
public
emit
(
event
:
'
logout
'
,
contactId
:
string
)
:
boolean
public
emit
(
event
:
'
message
'
,
messageId
:
string
)
:
boolean
public
emit
(
event
:
'
room-join
'
,
roomId
:
string
,
inviteeIdList
:
string
[],
inviterId
:
string
)
:
boolean
public
emit
(
event
:
'
room-leave
'
,
roomId
:
string
,
leaverIdList
:
string
[],
remover
?:
string
)
:
boolean
public
emit
(
event
:
'
room-topic
'
,
roomId
:
string
,
t
opic
:
string
,
oldTopic
:
string
,
changerId
:
string
)
:
boolean
public
emit
(
event
:
'
scan
'
,
qrcode
:
string
,
status
:
number
,
data
?:
string
)
:
boolean
public
emit
(
event
:
'
start
'
)
:
boolean
public
emit
(
event
:
'
stop
'
)
:
boolean
public
emit
(
event
:
'
error
'
,
error
:
string
)
:
boolean
public
emit
(
event
:
'
friend
'
,
requestId
:
string
)
:
boolean
public
emit
(
event
:
'
login
'
,
contactId
:
string
)
:
boolean
public
emit
(
event
:
'
logout
'
,
contactId
:
string
)
:
boolean
public
emit
(
event
:
'
message
'
,
messageId
:
string
)
:
boolean
public
emit
(
event
:
'
room-join
'
,
roomId
:
string
,
inviteeIdList
:
string
[],
inviterId
:
string
)
:
boolean
public
emit
(
event
:
'
room-leave
'
,
roomId
:
string
,
leaverIdList
:
string
[],
remover
?:
string
)
:
boolean
public
emit
(
event
:
'
room-topic
'
,
roomId
:
string
,
newT
opic
:
string
,
oldTopic
:
string
,
changerId
:
string
)
:
boolean
public
emit
(
event
:
'
scan
'
,
qrcode
:
string
,
status
:
number
,
data
?:
string
)
:
boolean
public
emit
(
event
:
'
start
'
)
:
boolean
public
emit
(
event
:
'
stop
'
)
:
boolean
// Internal Usage: watchdog
public
emit
(
event
:
'
watchdog
'
,
food
:
WatchdogFood
)
:
boolean
...
...
@@ -216,17 +217,17 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*
*
*/
public
on
(
event
:
'
error
'
,
listener
:
(
error
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
friend
'
,
listener
:
(
requestId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
login
'
,
listener
:
(
contactId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
logout
'
,
listener
:
(
contactId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
message
'
,
listener
:
(
messageId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
room-join
'
,
listener
:
(
roomId
:
string
,
inviteeIdList
:
string
[],
inviterId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
room-leave
'
,
listener
:
(
roomId
:
string
,
leaverIdList
:
string
[],
removerId
?:
string
)
=>
void
)
:
this
public
on
(
event
:
'
room-topic
'
,
listener
:
(
roomId
:
string
,
t
opic
:
string
,
oldTopic
:
string
,
changerId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
scan
'
,
listener
:
(
qrcode
:
string
,
status
:
number
,
data
?:
string
)
=>
void
)
:
this
public
on
(
event
:
'
start
'
,
listener
:
()
=>
void
)
:
this
public
on
(
event
:
'
stop
'
,
listener
:
()
=>
void
)
:
this
public
on
(
event
:
'
error
'
,
listener
:
(
error
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
friend
'
,
listener
:
(
requestId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
login
'
,
listener
:
(
contactId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
logout
'
,
listener
:
(
contactId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
message
'
,
listener
:
(
messageId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
room-join
'
,
listener
:
(
roomId
:
string
,
inviteeIdList
:
string
[],
inviterId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
room-leave
'
,
listener
:
(
roomId
:
string
,
leaverIdList
:
string
[],
removerId
?:
string
)
=>
void
)
:
this
public
on
(
event
:
'
room-topic
'
,
listener
:
(
roomId
:
string
,
newT
opic
:
string
,
oldTopic
:
string
,
changerId
:
string
)
=>
void
)
:
this
public
on
(
event
:
'
scan
'
,
listener
:
(
qrcode
:
string
,
status
:
number
,
data
?:
string
)
=>
void
)
:
this
public
on
(
event
:
'
start
'
,
listener
:
()
=>
void
)
:
this
public
on
(
event
:
'
stop
'
,
listener
:
()
=>
void
)
:
this
// Internal Usage: watchdog
public
on
(
event
:
'
watchdog
'
,
listener
:
(
data
:
WatchdogFood
)
=>
void
)
:
this
...
...
src/wechaty.ts
浏览文件 @
a3ef134f
...
...
@@ -245,18 +245,18 @@ export class Wechaty extends Accessory implements Sayable {
return
Wechaty
.
version
(
forceNpm
)
}
public
emit
(
event
:
'
error
'
,
error
:
Error
)
:
boolean
public
emit
(
event
:
'
friend
'
,
request
:
FriendRequest
)
:
boolean
public
emit
(
event
:
'
heartbeat
'
,
data
:
any
)
:
boolean
public
emit
(
event
:
'
logout
'
,
user
:
ContactSelf
)
:
boolean
public
emit
(
event
:
'
login
'
,
user
:
ContactSelf
)
:
boolean
public
emit
(
event
:
'
message
'
,
message
:
Message
)
:
boolean
public
emit
(
event
:
'
room-join
'
,
room
:
Room
,
inviteeList
:
Contact
[],
inviter
:
Contact
)
:
boolean
public
emit
(
event
:
'
room-leave
'
,
room
:
Room
,
leaverList
:
Contact
[],
remover
?
:
Contact
)
:
boolean
public
emit
(
event
:
'
room-topic
'
,
room
:
Room
,
t
opic
:
string
,
oldTopic
:
string
,
changer
:
Contact
)
:
boolean
public
emit
(
event
:
'
scan
'
,
qrcode
:
string
,
status
:
number
,
data
?:
string
)
:
boolean
public
emit
(
event
:
'
start
'
)
:
boolean
public
emit
(
event
:
'
stop
'
)
:
boolean
public
emit
(
event
:
'
error
'
,
error
:
Error
)
:
boolean
public
emit
(
event
:
'
friend
'
,
request
:
FriendRequest
)
:
boolean
public
emit
(
event
:
'
heartbeat
'
,
data
:
any
)
:
boolean
public
emit
(
event
:
'
logout
'
,
user
:
ContactSelf
)
:
boolean
public
emit
(
event
:
'
login
'
,
user
:
ContactSelf
)
:
boolean
public
emit
(
event
:
'
message
'
,
message
:
Message
)
:
boolean
public
emit
(
event
:
'
room-join
'
,
room
:
Room
,
inviteeList
:
Contact
[],
inviter
:
Contact
)
:
boolean
public
emit
(
event
:
'
room-leave
'
,
room
:
Room
,
leaverList
:
Contact
[],
remover
?
:
Contact
)
:
boolean
public
emit
(
event
:
'
room-topic
'
,
room
:
Room
,
newT
opic
:
string
,
oldTopic
:
string
,
changer
:
Contact
)
:
boolean
public
emit
(
event
:
'
scan
'
,
qrcode
:
string
,
status
:
number
,
data
?:
string
)
:
boolean
public
emit
(
event
:
'
start
'
)
:
boolean
public
emit
(
event
:
'
stop
'
)
:
boolean
// guard for the above event: make sure it includes all the possible values
public
emit
(
event
:
never
,
listener
:
never
):
never
...
...
@@ -268,18 +268,18 @@ export class Wechaty extends Accessory implements Sayable {
return
super
.
emit
(
event
,
...
args
)
}
public
on
(
event
:
'
error
'
,
listener
:
string
|
((
this
:
Wechaty
,
error
:
Error
)
=>
void
))
:
this
public
on
(
event
:
'
friend
'
,
listener
:
string
|
((
this
:
Wechaty
,
request
:
FriendRequest
)
=>
void
))
:
this
public
on
(
event
:
'
heartbeat
'
,
listener
:
string
|
((
this
:
Wechaty
,
data
:
any
)
=>
void
))
:
this
public
on
(
event
:
'
logout
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
ContactSelf
)
=>
void
))
:
this
public
on
(
event
:
'
login
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
ContactSelf
)
=>
void
))
:
this
public
on
(
event
:
'
message
'
,
listener
:
string
|
((
this
:
Wechaty
,
message
:
Message
)
=>
void
))
:
this
public
on
(
event
:
'
room-join
'
,
listener
:
string
|
((
this
:
Wechaty
,
room
:
Room
,
inviteeList
:
Contact
[],
inviter
:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
room-leave
'
,
listener
:
string
|
((
this
:
Wechaty
,
room
:
Room
,
leaverList
:
Contact
[],
remover
?:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
room-topic
'
,
listener
:
string
|
((
this
:
Wechaty
,
room
:
Room
,
t
opic
:
string
,
oldTopic
:
string
,
changer
:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
scan
'
,
listener
:
string
|
((
this
:
Wechaty
,
qrcode
:
string
,
status
:
number
,
data
?:
string
)
=>
void
))
:
this
public
on
(
event
:
'
start
'
,
listener
:
string
|
((
this
:
Wechaty
)
=>
void
))
:
this
public
on
(
event
:
'
stop
'
,
listener
:
string
|
((
this
:
Wechaty
)
=>
void
))
:
this
public
on
(
event
:
'
error
'
,
listener
:
string
|
((
this
:
Wechaty
,
error
:
Error
)
=>
void
))
:
this
public
on
(
event
:
'
friend
'
,
listener
:
string
|
((
this
:
Wechaty
,
request
:
FriendRequest
)
=>
void
))
:
this
public
on
(
event
:
'
heartbeat
'
,
listener
:
string
|
((
this
:
Wechaty
,
data
:
any
)
=>
void
))
:
this
public
on
(
event
:
'
logout
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
ContactSelf
)
=>
void
))
:
this
public
on
(
event
:
'
login
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
ContactSelf
)
=>
void
))
:
this
public
on
(
event
:
'
message
'
,
listener
:
string
|
((
this
:
Wechaty
,
message
:
Message
)
=>
void
))
:
this
public
on
(
event
:
'
room-join
'
,
listener
:
string
|
((
this
:
Wechaty
,
room
:
Room
,
inviteeList
:
Contact
[],
inviter
:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
room-leave
'
,
listener
:
string
|
((
this
:
Wechaty
,
room
:
Room
,
leaverList
:
Contact
[],
remover
?:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
room-topic
'
,
listener
:
string
|
((
this
:
Wechaty
,
room
:
Room
,
newT
opic
:
string
,
oldTopic
:
string
,
changer
:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
scan
'
,
listener
:
string
|
((
this
:
Wechaty
,
qrcode
:
string
,
status
:
number
,
data
?:
string
)
=>
void
))
:
this
public
on
(
event
:
'
start
'
,
listener
:
string
|
((
this
:
Wechaty
)
=>
void
))
:
this
public
on
(
event
:
'
stop
'
,
listener
:
string
|
((
this
:
Wechaty
)
=>
void
))
:
this
// guard for the above event: make sure it includes all the possible values
public
on
(
event
:
never
,
listener
:
never
):
never
...
...
@@ -321,7 +321,7 @@ export class Wechaty extends Accessory implements Sayable {
* @property {Function} friend -(this: Wechaty, request?: FriendRequest) => void
* @property {Function} message -(this: Wechaty, message: Message) => void
* @property {Function} room-join -(this: Wechaty, room: Room, inviteeList: Contact[], inviter: Contact) => void
* @property {Function} room-topic -(this: Wechaty, room: Room,
t
opic: string, oldTopic: string, changer: Contact) => void
* @property {Function} room-topic -(this: Wechaty, room: Room,
newT
opic: string, oldTopic: string, changer: Contact) => void
* @property {Function} room-leave -(this: Wechaty, room: Room, leaverList: Contact[]) => void
*/
...
...
@@ -629,15 +629,15 @@ export class Wechaty extends Accessory implements Sayable {
case
'
room-topic
'
:
puppet
.
removeAllListeners
(
'
room-topic
'
)
puppet
.
on
(
'
room-topic
'
,
async
(
roomId
,
t
opic
,
oldTopic
,
changerId
)
=>
{
puppet
.
on
(
'
room-topic
'
,
async
(
roomId
,
newT
opic
,
oldTopic
,
changerId
)
=>
{
const
room
=
this
.
Room
.
load
(
roomId
)
await
room
.
ready
()
const
changer
=
this
.
Contact
.
load
(
changerId
)
await
changer
.
ready
()
this
.
emit
(
'
room-topic
'
,
room
,
t
opic
,
oldTopic
,
changer
)
room
.
emit
(
'
topic
'
,
t
opic
,
oldTopic
,
changer
)
this
.
emit
(
'
room-topic
'
,
room
,
newT
opic
,
oldTopic
,
changer
)
room
.
emit
(
'
topic
'
,
newT
opic
,
oldTopic
,
changer
)
})
break
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录