Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
116c8efe
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,发现更多精彩内容 >>
提交
116c8efe
编写于
6月 09, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support to change user self avatar (#1298)
上级
cbe44c62
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
146 addition
and
36 deletion
+146
-36
src/contact.ts
src/contact.ts
+27
-14
src/puppet-mock/puppet-mock.ts
src/puppet-mock/puppet-mock.ts
+23
-1
src/puppet-padchat/puppet-padchat.ts
src/puppet-padchat/puppet-padchat.ts
+30
-4
src/puppet-puppeteer/puppet-puppeteer.ts
src/puppet-puppeteer/puppet-puppeteer.ts
+18
-1
src/puppet-wechat4u/puppet-wechat4u.ts
src/puppet-wechat4u/puppet-wechat4u.ts
+17
-1
src/puppet/puppet.spec.ts
src/puppet/puppet.spec.ts
+7
-2
src/puppet/puppet.ts
src/puppet/puppet.ts
+7
-2
src/wechaty.ts
src/wechaty.ts
+17
-11
未找到文件。
src/contact.ts
浏览文件 @
116c8efe
...
@@ -604,29 +604,42 @@ export class Contact extends Accessory implements Sayable {
...
@@ -604,29 +604,42 @@ export class Contact extends Accessory implements Sayable {
public
weixin
():
null
|
string
{
public
weixin
():
null
|
string
{
return
this
.
payload
&&
this
.
payload
.
weixin
||
null
return
this
.
payload
&&
this
.
payload
.
weixin
||
null
}
}
}
export
class
ContactSelf
extends
Contact
{
constructor
(
id
:
string
,
)
{
super
(
id
)
}
public
async
avatar
()
:
Promise
<
FileBox
>
public
async
avatar
(
file
:
FileBox
)
:
Promise
<
void
>
public
async
avatar
(
file
?:
FileBox
):
Promise
<
void
|
FileBox
>
{
log
.
verbose
(
'
Contact
'
,
'
avatar(%s)
'
,
file
?
file
.
name
:
''
)
if
(
!
file
)
{
return
await
super
.
avatar
()
}
if
(
this
.
id
!==
this
.
puppet
.
selfId
())
{
throw
new
Error
(
'
set avatar only available for user self
'
)
}
await
this
.
puppet
.
contactAvatar
(
this
.
id
,
file
)
}
/**
*
* Need a new class for manage user profile
*
*/
// TODO:
public
async
qrcode
():
Promise
<
string
>
{
public
async
qrcode
():
Promise
<
string
>
{
log
.
verbose
(
'
Contact
'
,
'
qrcode()
'
)
log
.
verbose
(
'
Contact
'
,
'
qrcode()
'
)
if
(
!
this
.
self
())
{
if
(
this
.
id
!==
this
.
puppet
.
selfId
())
{
throw
new
Error
(
'
only can get qrcode for the login userself
'
)
throw
new
Error
(
'
only can get qrcode for the login userself
'
)
}
}
return
'
url of qrcode data for this contact(self only)
'
return
await
this
.
puppet
.
contactQrCode
(
this
.
id
)
}
}
public
async
setAvatar
(
file
:
FileBox
):
Promise
<
void
>
{
log
.
verbose
(
'
Contact
'
,
'
setAvatar(%s)
'
,
file
.
name
)
// should not in contact class ?
// too many methods that can only use on the login-ed userself.
}
}
}
export
default
Contact
export
default
Contact
src/puppet-mock/puppet-mock.ts
浏览文件 @
116c8efe
...
@@ -153,9 +153,31 @@ export class PuppetMock extends Puppet {
...
@@ -153,9 +153,31 @@ export class PuppetMock extends Puppet {
return
[]
return
[]
}
}
public
async
contactAvatar
(
contactId
:
string
):
Promise
<
FileBox
>
{
public
async
contactQrCode
(
contactId
:
string
):
Promise
<
string
>
{
if
(
contactId
!==
this
.
selfId
())
{
throw
new
Error
(
'
can not set avatar for others
'
)
}
throw
new
Error
(
'
not supported
'
)
// return await this.bridge.WXqr
}
public
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
async
contactAvatar
(
contactId
:
string
,
file
?:
FileBox
):
Promise
<
void
|
FileBox
>
{
log
.
verbose
(
'
PuppetMock
'
,
'
contactAvatar(%s)
'
,
contactId
)
log
.
verbose
(
'
PuppetMock
'
,
'
contactAvatar(%s)
'
,
contactId
)
/**
* 1. set
*/
if
(
file
)
{
return
}
/**
* 2. get
*/
const
WECHATY_ICON_PNG
=
path
.
resolve
(
'
../../docs/images/wechaty-icon.png
'
)
const
WECHATY_ICON_PNG
=
path
.
resolve
(
'
../../docs/images/wechaty-icon.png
'
)
return
FileBox
.
fromFile
(
WECHATY_ICON_PNG
)
return
FileBox
.
fromFile
(
WECHATY_ICON_PNG
)
}
}
...
...
src/puppet-padchat/puppet-padchat.ts
浏览文件 @
116c8efe
...
@@ -315,17 +315,43 @@ export class PuppetPadchat extends Puppet {
...
@@ -315,17 +315,43 @@ export class PuppetPadchat extends Puppet {
return
contactIdList
return
contactIdList
}
}
public
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
{
public
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
log
.
verbose
(
'
PuppetPadchat
'
,
'
contactAvatar(%s)
'
,
contactId
)
public
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
async
contactAvatar
(
contactId
:
string
,
file
?:
FileBox
):
Promise
<
void
|
FileBox
>
{
log
.
verbose
(
'
PuppetPadchat
'
,
'
contactAvatar(%s, %s)
'
,
contactId
,
file
?
file
.
name
:
''
)
/**
* 1. set avatar for user self
*/
if
(
file
)
{
if
(
contactId
!==
this
.
selfId
())
{
throw
new
Error
(
'
can not set avatar for others
'
)
}
await
this
.
bridge
.
WXSetHeadImage
(
await
file
.
toBase64
())
return
}
/**
* 2. get avatar
*/
const
payload
=
await
this
.
contactPayload
(
contactId
)
const
payload
=
await
this
.
contactPayload
(
contactId
)
if
(
!
payload
.
avatar
)
{
if
(
!
payload
.
avatar
)
{
throw
new
Error
(
'
no avatar
'
)
throw
new
Error
(
'
no avatar
'
)
}
}
const
file
=
FileBox
.
fromUrl
(
payload
.
avatar
)
const
fileBox
=
FileBox
.
fromUrl
(
payload
.
avatar
)
return
file
return
fileBox
}
public
async
contactQrCode
(
contactId
:
string
):
Promise
<
string
>
{
if
(
contactId
!==
this
.
selfId
())
{
throw
new
Error
(
'
can not set avatar for others
'
)
}
throw
new
Error
(
'
not supported
'
)
// return await this.bridge.WXqr
}
}
public
async
contactRawPayload
(
contactId
:
string
):
Promise
<
PadchatContactPayload
>
{
public
async
contactRawPayload
(
contactId
:
string
):
Promise
<
PadchatContactPayload
>
{
...
...
src/puppet-puppeteer/puppet-puppeteer.ts
浏览文件 @
116c8efe
...
@@ -729,8 +729,16 @@ export class PuppetPuppeteer extends Puppet {
...
@@ -729,8 +729,16 @@ export class PuppetPuppeteer extends Puppet {
}
}
}
}
public
async
contactAvatar
(
contactId
:
string
):
Promise
<
FileBox
>
{
public
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
async
contactAvatar
(
contactId
:
string
,
file
?:
FileBox
):
Promise
<
void
|
FileBox
>
{
log
.
verbose
(
'
PuppetPuppeteer
'
,
'
contactAvatar(%s)
'
,
contactId
)
log
.
verbose
(
'
PuppetPuppeteer
'
,
'
contactAvatar(%s)
'
,
contactId
)
if
(
file
)
{
throw
new
Error
(
'
not support
'
)
}
const
payload
=
await
this
.
contactPayload
(
contactId
)
const
payload
=
await
this
.
contactPayload
(
contactId
)
if
(
!
payload
.
avatar
)
{
if
(
!
payload
.
avatar
)
{
throw
new
Error
(
'
Can not get avatar: no payload.avatar!
'
)
throw
new
Error
(
'
Can not get avatar: no payload.avatar!
'
)
...
@@ -767,6 +775,15 @@ export class PuppetPuppeteer extends Puppet {
...
@@ -767,6 +775,15 @@ export class PuppetPuppeteer extends Puppet {
}
}
}
}
public
async
contactQrCode
(
contactId
:
string
):
Promise
<
string
>
{
if
(
contactId
!==
this
.
selfId
())
{
throw
new
Error
(
'
can not set avatar for others
'
)
}
throw
new
Error
(
'
not supported
'
)
// return await this.bridge.WXqr
}
public
contactAlias
(
contactId
:
string
)
:
Promise
<
string
>
public
contactAlias
(
contactId
:
string
)
:
Promise
<
string
>
public
contactAlias
(
contactId
:
string
,
alias
:
string
|
null
):
Promise
<
void
>
public
contactAlias
(
contactId
:
string
,
alias
:
string
|
null
):
Promise
<
void
>
...
...
src/puppet-wechat4u/puppet-wechat4u.ts
浏览文件 @
116c8efe
...
@@ -316,9 +316,25 @@ export class PuppetWechat4u extends Puppet {
...
@@ -316,9 +316,25 @@ export class PuppetWechat4u extends Puppet {
return
idList
return
idList
}
}
public
async
contactAvatar
(
contactId
:
string
):
Promise
<
FileBox
>
{
public
async
contactQrCode
(
contactId
:
string
):
Promise
<
string
>
{
if
(
contactId
!==
this
.
selfId
())
{
throw
new
Error
(
'
can not set avatar for others
'
)
}
throw
new
Error
(
'
not supported
'
)
// return await this.bridge.WXqr
}
public
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
async
contactAvatar
(
contactId
:
string
,
file
?:
FileBox
):
Promise
<
void
|
FileBox
>
{
log
.
verbose
(
'
PuppetWechat4u
'
,
'
contactAvatar(%s)
'
,
contactId
)
log
.
verbose
(
'
PuppetWechat4u
'
,
'
contactAvatar(%s)
'
,
contactId
)
if
(
file
)
{
throw
new
Error
(
'
not supported
'
)
}
const
rawPayload
=
await
this
.
contactRawPayload
(
contactId
)
const
rawPayload
=
await
this
.
contactRawPayload
(
contactId
)
const
res
=
await
this
.
wechat4u
.
getHeadImg
(
rawPayload
.
HeadImgUrl
)
const
res
=
await
this
.
wechat4u
.
getHeadImg
(
rawPayload
.
HeadImgUrl
)
...
...
src/puppet/puppet.spec.ts
浏览文件 @
116c8efe
...
@@ -52,8 +52,13 @@ class PuppetTest extends Puppet {
...
@@ -52,8 +52,13 @@ class PuppetTest extends Puppet {
public
async
contactAlias
(
contactId
:
string
)
:
Promise
<
string
>
public
async
contactAlias
(
contactId
:
string
)
:
Promise
<
string
>
public
async
contactAlias
(
contactId
:
string
,
alias
:
string
|
null
)
:
Promise
<
void
>
public
async
contactAlias
(
contactId
:
string
,
alias
:
string
|
null
)
:
Promise
<
void
>
public
async
contactAlias
(
contactId
:
string
,
alias
?:
string
|
null
)
:
Promise
<
string
|
void
>
{
return
{
contactId
,
alias
}
as
any
}
public
async
contactAlias
(
contactId
:
string
,
alias
?:
string
|
null
)
:
Promise
<
string
|
void
>
{
return
{
contactId
,
alias
}
as
any
}
public
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
{
return
{
contactId
}
as
any
}
public
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
async
contactAvatar
(
contactId
:
string
,
file
?:
FileBox
)
:
Promise
<
void
|
FileBox
>
{
return
{
contactId
,
file
}
as
any
}
public
async
contactList
()
:
Promise
<
string
[]
>
{
return
{}
as
any
}
public
async
contactList
()
:
Promise
<
string
[]
>
{
return
{}
as
any
}
public
async
contactQrCode
(
contactId
:
string
)
:
Promise
<
string
>
{
return
{
contactId
}
as
any
}
public
async
contactRawPayload
(
id
:
string
)
:
Promise
<
any
>
{
return
{
id
}
as
any
}
public
async
contactRawPayload
(
id
:
string
)
:
Promise
<
any
>
{
return
{
id
}
as
any
}
public
async
contactRawPayloadParser
(
rawPayload
:
any
)
:
Promise
<
ContactPayload
>
{
return
{
rawPayload
}
as
any
}
public
async
contactRawPayloadParser
(
rawPayload
:
any
)
:
Promise
<
ContactPayload
>
{
return
{
rawPayload
}
as
any
}
...
...
src/puppet/puppet.ts
浏览文件 @
116c8efe
...
@@ -355,9 +355,14 @@ export abstract class Puppet extends EventEmitter implements Sayable {
...
@@ -355,9 +355,14 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
abstract
async
contactAlias
(
contactId
:
string
)
:
Promise
<
string
>
public
abstract
async
contactAlias
(
contactId
:
string
)
:
Promise
<
string
>
public
abstract
async
contactAlias
(
contactId
:
string
,
alias
:
string
|
null
)
:
Promise
<
void
>
public
abstract
async
contactAlias
(
contactId
:
string
,
alias
:
string
|
null
)
:
Promise
<
void
>
// public abstract async contactAlias(contactId: string, alias?: string|null) : Promise<string | void>
// public abstract async contactAlias(contactId: string, alias?: string|null) : Promise<string | void>
public
abstract
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
abstract
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
abstract
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
public
abstract
async
contactList
()
:
Promise
<
string
[]
>
public
abstract
async
contactList
()
:
Promise
<
string
[]
>
public
abstract
async
contactQrCode
(
contactId
:
string
)
:
Promise
<
string
>
public
abstract
async
contactRawPayload
(
contactId
:
string
)
:
Promise
<
any
>
public
abstract
async
contactRawPayload
(
contactId
:
string
)
:
Promise
<
any
>
public
abstract
async
contactRawPayloadParser
(
rawPayload
:
any
)
:
Promise
<
ContactPayload
>
public
abstract
async
contactRawPayloadParser
(
rawPayload
:
any
)
:
Promise
<
ContactPayload
>
...
...
src/wechaty.ts
浏览文件 @
116c8efe
...
@@ -59,6 +59,7 @@ import {
...
@@ -59,6 +59,7 @@ import {
import
{
import
{
Contact
,
Contact
,
ContactSelf
,
}
from
'
./contact
'
}
from
'
./contact
'
import
{
import
{
FriendRequest
,
FriendRequest
,
...
@@ -137,6 +138,8 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -137,6 +138,8 @@ export class Wechaty extends Accessory implements Sayable {
// tslint:disable-next-line:variable-name
// tslint:disable-next-line:variable-name
public
readonly
Contact
:
typeof
Contact
public
readonly
Contact
:
typeof
Contact
// tslint:disable-next-line:variable-name
// tslint:disable-next-line:variable-name
public
readonly
ContactSelf
:
typeof
ContactSelf
// tslint:disable-next-line:variable-name
public
readonly
FriendRequest
:
typeof
FriendRequest
public
readonly
FriendRequest
:
typeof
FriendRequest
// tslint:disable-next-line:variable-name
// tslint:disable-next-line:variable-name
public
readonly
Message
:
typeof
Message
public
readonly
Message
:
typeof
Message
...
@@ -193,6 +196,7 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -193,6 +196,7 @@ export class Wechaty extends Accessory implements Sayable {
*/
*/
// TODO: make Message & Room constructor private???
// TODO: make Message & Room constructor private???
this
.
Contact
=
cloneClass
(
Contact
)
this
.
Contact
=
cloneClass
(
Contact
)
this
.
ContactSelf
=
cloneClass
(
ContactSelf
)
this
.
FriendRequest
=
cloneClass
(
FriendRequest
)
this
.
FriendRequest
=
cloneClass
(
FriendRequest
)
this
.
Message
=
cloneClass
(
Message
)
this
.
Message
=
cloneClass
(
Message
)
this
.
Room
=
cloneClass
(
Room
)
this
.
Room
=
cloneClass
(
Room
)
...
@@ -244,8 +248,8 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -244,8 +248,8 @@ export class Wechaty extends Accessory implements Sayable {
public
emit
(
event
:
'
error
'
,
error
:
Error
)
:
boolean
public
emit
(
event
:
'
error
'
,
error
:
Error
)
:
boolean
public
emit
(
event
:
'
friend
'
,
request
:
FriendRequest
)
:
boolean
public
emit
(
event
:
'
friend
'
,
request
:
FriendRequest
)
:
boolean
public
emit
(
event
:
'
heartbeat
'
,
data
:
any
)
:
boolean
public
emit
(
event
:
'
heartbeat
'
,
data
:
any
)
:
boolean
public
emit
(
event
:
'
logout
'
,
user
:
Contact
)
:
boolean
public
emit
(
event
:
'
logout
'
,
user
:
Contact
Self
)
:
boolean
public
emit
(
event
:
'
login
'
,
user
:
Contact
)
:
boolean
public
emit
(
event
:
'
login
'
,
user
:
Contact
Self
)
:
boolean
public
emit
(
event
:
'
message
'
,
message
:
Message
)
:
boolean
public
emit
(
event
:
'
message
'
,
message
:
Message
)
:
boolean
public
emit
(
event
:
'
room-join
'
,
room
:
Room
,
inviteeList
:
Contact
[],
inviter
:
Contact
)
:
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-leave
'
,
room
:
Room
,
leaverList
:
Contact
[],
remover
?
:
Contact
)
:
boolean
...
@@ -267,8 +271,8 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -267,8 +271,8 @@ export class Wechaty extends Accessory implements Sayable {
public
on
(
event
:
'
error
'
,
listener
:
string
|
((
this
:
Wechaty
,
error
:
Error
)
=>
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
:
'
friend
'
,
listener
:
string
|
((
this
:
Wechaty
,
request
:
FriendRequest
)
=>
void
))
:
this
public
on
(
event
:
'
heartbeat
'
,
listener
:
string
|
((
this
:
Wechaty
,
data
:
any
)
=>
void
))
:
this
public
on
(
event
:
'
heartbeat
'
,
listener
:
string
|
((
this
:
Wechaty
,
data
:
any
)
=>
void
))
:
this
public
on
(
event
:
'
logout
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
logout
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
Contact
Self
)
=>
void
))
:
this
public
on
(
event
:
'
login
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
Contact
)
=>
void
))
:
this
public
on
(
event
:
'
login
'
,
listener
:
string
|
((
this
:
Wechaty
,
user
:
Contact
Self
)
=>
void
))
:
this
public
on
(
event
:
'
message
'
,
listener
:
string
|
((
this
:
Wechaty
,
message
:
Message
)
=>
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-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-leave
'
,
listener
:
string
|
((
this
:
Wechaty
,
room
:
Room
,
leaverList
:
Contact
[],
remover
?:
Contact
)
=>
void
))
:
this
...
@@ -300,8 +304,8 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -300,8 +304,8 @@ export class Wechaty extends Accessory implements Sayable {
* @desc Wechaty Class Event Function
* @desc Wechaty Class Event Function
* @typedef WechatyEventFunction
* @typedef WechatyEventFunction
* @property {Function} error -(this: Wechaty, error: Error) => void callback function
* @property {Function} error -(this: Wechaty, error: Error) => void callback function
* @property {Function} login -(this: Wechaty, user: Contact)=> void
* @property {Function} login -(this: Wechaty, user: Contact
Self
)=> void
* @property {Function} logout -(this: Wechaty, user: Contact) => void
* @property {Function} logout -(this: Wechaty, user: Contact
Self
) => void
* @property {Function} scan -(this: Wechaty, url: string, code: number) => void <br>
* @property {Function} scan -(this: Wechaty, url: string, code: number) => void <br>
* <ol>
* <ol>
* <li>URL: {String} the QR code image URL</li>
* <li>URL: {String} the QR code image URL</li>
...
@@ -335,12 +339,12 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -335,12 +339,12 @@ export class Wechaty extends Accessory implements Sayable {
* })
* })
*
*
* @example <caption>Event:login </caption>
* @example <caption>Event:login </caption>
* bot.on('login', (user: Contact) => {
* bot.on('login', (user: Contact
Self
) => {
* console.log(`user ${user} login`)
* console.log(`user ${user} login`)
* })
* })
*
*
* @example <caption>Event:logout </caption>
* @example <caption>Event:logout </caption>
* bot.on('logout', (user: Contact) => {
* bot.on('logout', (user: Contact
Self
) => {
* console.log(`user ${user} logout`)
* console.log(`user ${user} logout`)
* })
* })
*
*
...
@@ -562,7 +566,7 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -562,7 +566,7 @@ export class Wechaty extends Accessory implements Sayable {
case
'
login
'
:
case
'
login
'
:
puppet
.
removeAllListeners
(
'
login
'
)
puppet
.
removeAllListeners
(
'
login
'
)
puppet
.
on
(
'
login
'
,
async
contactId
=>
{
puppet
.
on
(
'
login
'
,
async
contactId
=>
{
const
contact
=
this
.
Contact
.
load
(
contactId
)
const
contact
=
this
.
Contact
Self
.
load
(
contactId
)
await
contact
.
ready
()
await
contact
.
ready
()
this
.
emit
(
'
login
'
,
contact
)
this
.
emit
(
'
login
'
,
contact
)
})
})
...
@@ -571,7 +575,7 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -571,7 +575,7 @@ export class Wechaty extends Accessory implements Sayable {
case
'
logout
'
:
case
'
logout
'
:
puppet
.
removeAllListeners
(
'
logout
'
)
puppet
.
removeAllListeners
(
'
logout
'
)
puppet
.
on
(
'
logout
'
,
async
contactId
=>
{
puppet
.
on
(
'
logout
'
,
async
contactId
=>
{
const
contact
=
this
.
Contact
.
load
(
contactId
)
const
contact
=
this
.
Contact
Self
.
load
(
contactId
)
await
contact
.
ready
()
await
contact
.
ready
()
this
.
emit
(
'
logout
'
,
contact
)
this
.
emit
(
'
logout
'
,
contact
)
})
})
...
@@ -661,6 +665,7 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -661,6 +665,7 @@ export class Wechaty extends Accessory implements Sayable {
* 1. Set Wechaty
* 1. Set Wechaty
*/
*/
this
.
Contact
.
wechaty
=
this
this
.
Contact
.
wechaty
=
this
this
.
ContactSelf
.
wechaty
=
this
this
.
FriendRequest
.
wechaty
=
this
this
.
FriendRequest
.
wechaty
=
this
this
.
Message
.
wechaty
=
this
this
.
Message
.
wechaty
=
this
this
.
Room
.
wechaty
=
this
this
.
Room
.
wechaty
=
this
...
@@ -669,6 +674,7 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -669,6 +674,7 @@ export class Wechaty extends Accessory implements Sayable {
* 2. Set Puppet
* 2. Set Puppet
*/
*/
this
.
Contact
.
puppet
=
puppet
this
.
Contact
.
puppet
=
puppet
this
.
ContactSelf
.
puppet
=
puppet
this
.
FriendRequest
.
puppet
=
puppet
this
.
FriendRequest
.
puppet
=
puppet
this
.
Message
.
puppet
=
puppet
this
.
Message
.
puppet
=
puppet
this
.
Room
.
puppet
=
puppet
this
.
Room
.
puppet
=
puppet
...
@@ -811,7 +817,7 @@ export class Wechaty extends Accessory implements Sayable {
...
@@ -811,7 +817,7 @@ export class Wechaty extends Accessory implements Sayable {
*/
*/
public
userSelf
():
Contact
{
public
userSelf
():
Contact
{
const
userId
=
this
.
puppet
.
selfId
()
const
userId
=
this
.
puppet
.
selfId
()
const
user
=
this
.
Contact
.
load
(
userId
)
const
user
=
this
.
Contact
Self
.
load
(
userId
)
return
user
return
user
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录