Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
d4cead2e
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,发现更多精彩内容 >>
提交
d4cead2e
编写于
5月 29, 2018
作者:
ruiruibupt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add roomRawPayload and roomRawPayloadParser
上级
bf81ab74
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
97 addition
and
33 deletion
+97
-33
src/puppet-padchat/bridge.ts
src/puppet-padchat/bridge.ts
+29
-2
src/puppet-padchat/padchat-schemas.ts
src/puppet-padchat/padchat-schemas.ts
+2
-2
src/puppet-padchat/puppet-padchat.ts
src/puppet-padchat/puppet-padchat.ts
+66
-29
未找到文件。
src/puppet-padchat/bridge.ts
浏览文件 @
d4cead2e
...
...
@@ -352,7 +352,7 @@ export class Bridge extends EventEmitter {
* Get contact by contact id
* @param {any} id user_name
*/
p
ublic
async
WXGetContact
(
id
:
string
):
Promise
<
PadchatContact
RawPayload
>
{
p
rivate
async
WXGetContact
(
id
:
string
):
Promise
<
PadchatContactRawPayload
|
PadchatRoom
RawPayload
>
{
const
result
=
await
this
.
sendToWebSocket
(
'
WXGetContact
'
,
[
id
])
if
(
!
result
)
{
throw
Error
(
'
PuppetPadchatBridge, WXGetContact, cannot get result from websocket server!
'
)
...
...
@@ -360,6 +360,33 @@ export class Bridge extends EventEmitter {
if
(
!
result
.
user_name
)
{
log
.
warn
(
'
PuppetPadchatBridge
'
,
'
WXGetContact cannot get user_name, id: %s
'
,
id
)
}
if
(
result
.
member
)
{
result
.
member
=
JSON
.
parse
(
decodeURIComponent
(
result
.
member
))
}
return
result
}
/**
* Get contact by contact id
* @param {any} id user_name
*/
public
async
WXGetContactPayload
(
id
:
string
):
Promise
<
PadchatContactRawPayload
>
{
if
(
/@chatroom$/
.
test
(
id
))
{
throw
Error
(
`should use WXGetRoomPayload because get a room id :
${
id
}
`
)
}
const
result
=
await
this
.
WXGetContact
(
id
)
as
PadchatContactRawPayload
return
result
}
/**
* Get contact by contact id
* @param {any} id user_name
*/
public
async
WXGetRoomPayload
(
id
:
string
):
Promise
<
PadchatRoomRawPayload
>
{
if
(
!
(
/@chatroom$/
.
test
(
id
)))
{
throw
Error
(
`should use WXGetContactPayload because get a contact id :
${
id
}
`
)
}
const
result
=
await
this
.
WXGetContact
(
id
)
as
PadchatRoomRawPayload
return
result
}
...
...
@@ -373,7 +400,7 @@ export class Bridge extends EventEmitter {
throw
Error
(
'
PuppetPadchatBridge, WXGetChatRoomMember, cannot get result from websocket server!
'
)
}
if
(
!
result
.
user_name
||
!
result
.
member
)
{
log
.
warn
(
'
PuppetPadchatBridge
'
,
'
WXGetChatRoomMember cannot get user_name or member
: %s, id
: %s
'
,
id
,
result
.
member
)
log
.
warn
(
'
PuppetPadchatBridge
'
,
'
WXGetChatRoomMember cannot get user_name or member
! user_name: %s, member
: %s
'
,
id
,
result
.
member
)
}
// tslint:disable-next-line:max-line-length
...
...
src/puppet-padchat/padchat-schemas.ts
浏览文件 @
d4cead2e
...
...
@@ -255,7 +255,7 @@ export enum PadchatMessageType {
export
interface
PadchatRoomRawMember
{
big_head
:
string
,
// "http://wx.qlogo.cn/mmhead/ver_1/DpS0ZssJ5s8tEpSr9JuPTRxEUrCK0USrZcR3PjOMfUKDwpnZLxWXlD4Q38bJpcXBtwXWwevsul1lJqwsQzwItQ/0",
chatroom_nick_name
:
string
,
// "
",
chatroom_nick_name
:
string
,
// "
李佳芮-群里设置的备注", roomAlias
invited_by
:
string
,
// "wxid_7708837087612",
nick_name
:
string
,
// "李佳芮",
small_head
:
string
,
// "http://wx.qlogo.cn/mmhead/ver_1/DpS0ZssJ5s8tEpSr9JuPTRxEUrCK0USrZcR3PjOMfUKDwpnZLxWXlD4Q38bJpcXBtwXWwevsul1lJqwsQzwItQ/132",
...
...
@@ -298,7 +298,7 @@ export interface PadchatRoomRawPayload {
chatroom_owner
:
string
,
// "qq512436430",
continue
:
number
,
// 1,
max_member_count
:
number
,
// 500,
member
:
string
[],
// "[\"qq512436430\",\"mengjunjun001\",\"wxid_zj2cahpwzgie12\",\"wxid_7708837087612\"]\n",
member
:
string
[],
//
JSON.parse(decodeURIComponent(member)) |
"[\"qq512436430\",\"mengjunjun001\",\"wxid_zj2cahpwzgie12\",\"wxid_7708837087612\"]\n",
member_count
:
number
,
// 4,
nick_name
:
string
,
// room-topic:"facenet",
py_initial
:
string
,
// 'FACENET',
...
...
src/puppet-padchat/puppet-padchat.ts
浏览文件 @
d4cead2e
...
...
@@ -29,6 +29,8 @@ import {
MessagePayload
,
MessageType
,
}
from
'
../message
'
import
Misc
from
'
../misc
'
import
{
Contact
,
ContactQueryFilter
,
...
...
@@ -41,6 +43,7 @@ import {
// Room,
RoomPayload
,
RoomQueryFilter
,
RoomMemberQueryFilter
,
}
from
'
../room
'
// import {
...
...
@@ -76,6 +79,7 @@ import {
PadchatMessageRawPayload
,
PadchatMessageType
,
PadchatRoomRawPayload
,
PadchatRoomRawMember
,
}
from
'
./padchat-schemas
'
export
type
PuppetFoodType
=
'
scan
'
|
'
ding
'
...
...
@@ -346,6 +350,8 @@ export class PuppetPadchat extends Puppet {
await
user
.
ready
()
this
.
emit
(
'
login
'
,
user
)
this
.
test
()
log
.
verbose
(
'
PuppetPadchatBridge
'
,
'
loginSucceed: Send login to the bot, user_name: %s
'
,
this
.
bridge
.
username
)
await
this
.
bridge
.
WXSendMsg
(
this
.
bridge
.
autoData
.
user_name
,
'
Bot on line!
'
)
...
...
@@ -360,6 +366,11 @@ export class PuppetPadchat extends Puppet {
}
}
public
async
test
()
{
const
ret
=
await
this
.
bridge
.
WXGetChatRoomMember
(
'
5616634434@chatroom
'
)
console
.
log
(
ret
)
}
public
async
stop
():
Promise
<
void
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
quit()
'
)
...
...
@@ -414,12 +425,13 @@ export class PuppetPadchat extends Puppet {
log
.
verbose
(
'
PuppetPadchat
'
,
'
contactAvatar(%s)
'
,
contactId
)
const
WECHATY_ICON_PNG
=
path
.
resolve
(
'
../../docs/images/wechaty-icon.png
'
)
return
FileBox
.
packLocal
(
WECHATY_ICON_PNG
)
// TODO
return
FileBox
.
packBase64
(
''
,
WECHATY_ICON_PNG
)
}
public
async
contactRawPayload
(
id
:
string
):
Promise
<
PadchatContactRawPayload
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
contactRawPayload(%s)
'
,
id
)
const
rawPayload
=
await
this
.
bridge
.
WXGetContact
(
id
)
const
rawPayload
=
await
this
.
bridge
.
WXGetContact
Payload
(
id
)
return
rawPayload
}
...
...
@@ -584,45 +596,70 @@ export class PuppetPadchat extends Puppet {
*/
public
async
roomRawPayload
(
id
:
string
):
Promise
<
PadchatRoomRawPayload
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
roomRawPayload(%s)
'
,
id
)
const
rawPayload
:
PadchatRoomRawPayload
=
{
big_head
:
''
,
bit_mask
:
4294967295
,
bit_value
:
2050
,
chatroom_id
:
700000154
,
chatroom_owner
:
''
,
continue
:
1
,
max_member_count
:
500
,
member
:
[],
member_count
:
4
,
msg_type
:
2
,
nick_name
:
''
,
small_head
:
''
,
status
:
1
,
uin
:
324216852
,
user_name
:
''
,
// owner : 'padchat_room_owner_id',
// topic : 'padchat topic',
// memberList : [],
}
const
rawPayload
=
await
this
.
bridge
.
WXGetRoomPayload
(
id
)
return
rawPayload
}
public
async
roomRawPayloadParser
(
rawPayload
:
PadchatRoomRawPayload
):
Promise
<
RoomPayload
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
roomRawPayloadParser(%s)
'
,
rawPayload
)
const
memberList
=
(
rawPayload
.
member
||
[])
.
map
(
id
=>
this
.
Contact
.
load
(
id
))
await
Promise
.
all
(
memberList
.
map
(
c
=>
c
.
ready
()))
const
padchatRoomRawMemberList
=
await
this
.
bridge
.
WXGetChatRoomMember
(
rawPayload
.
user_name
)
const
nameMap
=
await
this
.
roomParseMap
(
'
name
'
,
padchatRoomRawMemberList
.
member
)
const
roomAliasMap
=
await
this
.
roomParseMap
(
'
roomAlias
'
,
padchatRoomRawMemberList
.
member
)
const
contactAliasMap
=
await
this
.
roomParseMap
(
'
contactAlias
'
,
padchatRoomRawMemberList
.
member
)
const
payload
:
RoomPayload
=
{
topic
:
'
padchat topic
'
,
memberIdList
:
[]
,
nameMap
:
n
ew
Map
<
string
,
string
>
()
,
roomAliasMap
:
new
Map
<
string
,
string
>
()
,
contactAliasMap
:
new
Map
<
string
,
string
>
()
,
topic
:
rawPayload
.
nick_name
,
memberIdList
:
rawPayload
.
member
,
nameMap
:
n
ameMap
,
roomAliasMap
:
roomAliasMap
,
contactAliasMap
:
contactAliasMap
,
}
return
payload
}
private
roomParseMap
(
parseSection
:
keyof
RoomMemberQueryFilter
,
memberList
?:
PadchatRoomRawMember
[],
):
Map
<
string
,
string
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
roomParseMap(%s, memberList.length=%d)
'
,
parseSection
,
memberList
&&
memberList
.
length
,
)
const
dict
:
Map
<
string
,
string
>
=
new
Map
<
string
,
string
>
()
if
(
memberList
&&
Array
.
isArray
(
memberList
))
{
memberList
.
forEach
(
member
=>
{
let
tmpName
:
string
switch
(
parseSection
)
{
case
'
name
'
:
tmpName
=
member
.
nick_name
break
case
'
roomAlias
'
:
tmpName
=
member
.
chatroom_nick_name
break
case
'
contactAlias
'
:
const
contact
=
this
.
Contact
.
load
(
member
.
user_name
)
tmpName
=
contact
.
alias
()
||
''
break
default
:
throw
new
Error
(
'
PuppetPadchat parseMap failed, member not found
'
)
}
dict
.
set
(
member
.
user_name
,
Misc
.
stripEmoji
(
tmpName
))
})
}
return
dict
}
public
async
roomFindAll
(
query
:
RoomQueryFilter
=
{
topic
:
/.*/
},
):
Promise
<
string
[]
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录