Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
93ee541d
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
304
Star
10499
Fork
6
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
152
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
152
Issue
152
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
93ee541d
编写于
6月 16, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
dc1f6792
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
74 addition
and
51 deletion
+74
-51
src/contact.ts
src/contact.ts
+5
-4
src/puppet-mock/puppet-mock.ts
src/puppet-mock/puppet-mock.ts
+2
-2
src/puppet-padchat/puppet-padchat.ts
src/puppet-padchat/puppet-padchat.ts
+2
-2
src/puppet-puppeteer/puppet-puppeteer.ts
src/puppet-puppeteer/puppet-puppeteer.ts
+4
-3
src/puppet-wechat4u/puppet-wechat4u.ts
src/puppet-wechat4u/puppet-wechat4u.ts
+2
-2
src/puppet/puppet.spec.ts
src/puppet/puppet.spec.ts
+2
-2
src/puppet/puppet.ts
src/puppet/puppet.ts
+32
-27
src/room.ts
src/room.ts
+5
-2
src/wechaty.ts
src/wechaty.ts
+20
-7
未找到文件。
src/contact.ts
浏览文件 @
93ee541d
...
...
@@ -290,28 +290,29 @@ export class Contact extends Accessory implements Sayable {
* console.error(e)
* }
*/
public
async
say
(
file
:
FileBox
):
Promise
<
void
>
public
async
say
(
file
:
FileBox
)
:
Promise
<
void
>
public
async
say
(
contact
:
Contact
)
:
Promise
<
void
>
public
async
say
(
textOrContactOrFile
:
string
|
Contact
|
FileBox
):
Promise
<
void
>
{
log
.
verbose
(
'
Contact
'
,
'
say(%s)
'
,
textOrContactOrFile
)
if
(
typeof
textOrContactOrFile
===
'
string
'
)
{
/**
* Text
*
1.
Text
*/
await
this
.
puppet
.
messageSendText
({
contactId
:
this
.
id
,
},
textOrContactOrFile
)
}
else
if
(
textOrContactOrFile
instanceof
Contact
)
{
/**
* Contact
*
2.
Contact
*/
await
this
.
puppet
.
messageSendContact
({
contactId
:
this
.
id
,
},
textOrContactOrFile
.
id
)
}
else
if
(
textOrContactOrFile
instanceof
FileBox
)
{
/**
* File
*
3.
File
*/
await
this
.
puppet
.
messageSendFile
({
contactId
:
this
.
id
,
...
...
src/puppet-mock/puppet-mock.ts
浏览文件 @
93ee541d
...
...
@@ -415,8 +415,8 @@ export class PuppetMock extends Puppet {
log
.
verbose
(
'
PuppetMock
'
,
'
friendshipAccept(%s)
'
,
friendshipId
)
}
public
ding
(
data
?:
any
):
Promise
<
string
>
{
return
data
public
async
ding
():
Promise
<
false
|
'
dong
'
>
{
return
'
dong
'
}
}
...
...
src/puppet-padchat/puppet-padchat.ts
浏览文件 @
93ee541d
...
...
@@ -132,8 +132,8 @@ export class PuppetPadchat extends Puppet {
return
`PuppetPadchat<
${
this
.
options
.
memory
.
name
}
>`
}
public
ding
(
data
?:
any
):
Promise
<
string
>
{
return
data
public
async
ding
():
Promise
<
false
|
'
dong
'
>
{
return
'
dong
'
}
public
startWatchdog
():
void
{
...
...
src/puppet-puppeteer/puppet-puppeteer.ts
浏览文件 @
93ee541d
...
...
@@ -719,13 +719,14 @@ export class PuppetPuppeteer extends Puppet {
}
}
public
async
ding
(
data
?:
any
):
Promise
<
string
>
{
public
async
ding
(
data
?:
any
):
Promise
<
false
|
'
dong
'
>
{
try
{
return
await
this
.
bridge
.
ding
(
data
)
await
this
.
bridge
.
ding
(
data
)
return
'
dong
'
}
catch
(
e
)
{
log
.
warn
(
'
PuppetPuppeteer
'
,
'
ding(%s) rejected: %s
'
,
data
,
e
.
message
)
Raven
.
captureException
(
e
)
throw
e
return
fals
e
}
}
...
...
src/puppet-wechat4u/puppet-wechat4u.ts
浏览文件 @
93ee541d
...
...
@@ -946,8 +946,8 @@ export class PuppetWechat4u extends Puppet {
}
}
public
ding
(
data
?:
any
):
Promise
<
string
>
{
return
data
public
async
ding
():
Promise
<
false
|
'
dong
'
>
{
return
'
dong
'
}
private
filename
(
...
...
src/puppet/puppet.spec.ts
浏览文件 @
93ee541d
...
...
@@ -41,8 +41,8 @@ class PuppetTest extends Puppet {
public
async
start
()
:
Promise
<
void
>
{
return
{}
as
any
}
public
async
stop
()
:
Promise
<
void
>
{
return
{}
as
any
}
public
async
ding
(
data
?:
any
)
:
Promise
<
string
>
{
return
{
data
}
as
any
}
public
async
logout
():
Promise
<
void
>
{
return
{}
as
any
}
public
async
ding
(
)
:
Promise
<
false
|
'
dong
'
>
{
return
'
dong
'
}
public
async
logout
()
:
Promise
<
void
>
{
return
{}
as
any
}
/**
*
...
...
src/puppet/puppet.ts
浏览文件 @
93ee541d
...
...
@@ -36,11 +36,7 @@ import {
WatchdogFood
,
}
from
'
watchdog
'
// import {
// PUPPET_EVENT_DICT,
// } from './schemas/puppet'
import
{
Sayable
,
log
,
}
from
'
../config
'
...
...
@@ -81,7 +77,7 @@ let PUPPET_COUNTER = 0
* See: https://github.com/Chatie/wechaty/wiki/Puppet
*
*/
export
abstract
class
Puppet
extends
EventEmitter
implements
Sayable
{
export
abstract
class
Puppet
extends
EventEmitter
{
public
readonly
cacheContactPayload
:
LRU
.
Cache
<
string
,
ContactPayload
>
public
readonly
cacheFriendshipPayload
:
LRU
.
Cache
<
string
,
FriendshipPayload
>
...
...
@@ -294,11 +290,18 @@ export abstract class Puppet extends EventEmitter implements Sayable {
}
/**
*
*
* Misc
*
*
*/
/**
* Check whether the puppet is work property.
* @returns `false` if something went wrong
* 'dong' if everything is OK
*/
public
abstract
async
ding
(
data
?:
any
)
:
Promise
<
string
>
public
abstract
async
ding
(
)
:
Promise
<
false
|
'
dong
'
>
public
version
():
string
{
if
(
this
.
childPkg
)
{
...
...
@@ -335,23 +338,23 @@ export abstract class Puppet extends EventEmitter implements Sayable {
// return this.pkg.engines.wechaty
}
public
async
say
(
textOrFile
:
string
|
FileBox
)
:
Promise
<
void
>
{
if
(
!
this
.
logonoff
())
{
throw
new
Error
(
'
can not say before login
'
)
}
if
(
typeof
textOrFile
===
'
string
'
)
{
await
this
.
messageSendText
({
contactId
:
this
.
selfId
(),
},
textOrFile
)
}
else
if
(
textOrFile
instanceof
FileBox
)
{
await
this
.
messageSendFile
({
contactId
:
this
.
selfId
(),
},
textOrFile
)
}
else
{
throw
new
Error
(
'
say() arg unknown
'
)
}
}
//
public async say(textOrFile: string | FileBox) : Promise<void> {
//
if (!this.logonoff()) {
//
throw new Error('can not say before login')
//
}
//
if (typeof textOrFile === 'string') {
//
await this.messageSendText({
//
contactId: this.selfId(),
//
}, textOrFile)
//
} else if (textOrFile instanceof FileBox) {
//
await this.messageSendFile({
//
contactId: this.selfId(),
//
}, textOrFile)
//
} else {
//
throw new Error('say() arg unknown')
//
}
//
}
/**
*
...
...
@@ -360,7 +363,6 @@ export abstract class Puppet extends EventEmitter implements Sayable {
*/
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<string | void>
public
abstract
async
contactAvatar
(
contactId
:
string
)
:
Promise
<
FileBox
>
public
abstract
async
contactAvatar
(
contactId
:
string
,
file
:
FileBox
)
:
Promise
<
void
>
...
...
@@ -852,6 +854,9 @@ export abstract class Puppet extends EventEmitter implements Sayable {
return
payload
}
/**
* Concat roomId & contactId to one string
*/
private
cacheKeyRoomMember
(
roomId
:
string
,
contactId
:
string
,
...
...
@@ -887,8 +892,8 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/**
* 1. Try to get from cache
*/
const
cacheKey
=
this
.
cacheKeyRoomMember
(
roomId
,
contactId
)
const
cachedPayload
=
this
.
cacheRoomMemberPayload
.
get
(
cacheKey
)
const
CACHE_KEY
=
this
.
cacheKeyRoomMember
(
roomId
,
contactId
)
const
cachedPayload
=
this
.
cacheRoomMemberPayload
.
get
(
CACHE_KEY
)
if
(
cachedPayload
)
{
return
cachedPayload
...
...
@@ -900,7 +905,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
const
rawPayload
=
await
this
.
roomMemberRawPayload
(
roomId
,
contactId
)
const
payload
=
await
this
.
roomMemberRawPayloadParser
(
rawPayload
)
this
.
cacheRoomMemberPayload
.
set
(
cacheKey
,
payload
)
this
.
cacheRoomMemberPayload
.
set
(
CACHE_KEY
,
payload
)
log
.
silly
(
'
Puppet
'
,
'
roomMemberPayload(%s) cache SET
'
,
roomId
)
return
payload
...
...
src/room.ts
浏览文件 @
93ee541d
...
...
@@ -585,10 +585,13 @@ export class Room extends Accessory implements Sayable {
}
}
// TODO
/**
* Room QR Code
*/
public
async
qrcode
():
Promise
<
string
>
{
log
.
verbose
(
'
Room
'
,
'
qrcode()
'
)
return
'
qrcode url for entry room
'
const
qrcode
=
await
this
.
puppet
.
roomQrcode
(
this
.
id
)
return
qrcode
}
/**
...
...
src/wechaty.ts
浏览文件 @
93ee541d
...
...
@@ -26,6 +26,9 @@ import {
cloneClass
,
// instanceToClass,
}
from
'
clone-class
'
import
{
FileBox
,
}
from
'
file-box
'
import
{
callerResolve
,
hotImport
,
...
...
@@ -826,14 +829,24 @@ export class Wechaty extends Accessory implements Sayable {
}
/**
* Send message to
filehelper
* Send message to
userSelf
*
* @param {string} text
* @param {string} text
OrContactOrFile
* @returns {Promise<boolean>}
*/
public
async
say
(
text
:
string
):
Promise
<
void
>
{
log
.
verbose
(
'
Wechaty
'
,
'
say(%s)
'
,
text
)
await
this
.
puppet
.
say
(
text
)
public
async
say
(
textOrContactOrFile
:
string
|
Contact
|
FileBox
):
Promise
<
void
>
{
log
.
verbose
(
'
Wechaty
'
,
'
say(%s)
'
,
textOrContactOrFile
)
// Make Typescript Happy:
if
(
typeof
textOrContactOrFile
===
'
string
'
)
{
await
this
.
userSelf
().
say
(
textOrContactOrFile
)
}
else
if
(
textOrContactOrFile
instanceof
Contact
)
{
await
this
.
userSelf
().
say
(
textOrContactOrFile
)
}
else
if
(
textOrContactOrFile
instanceof
FileBox
)
{
await
this
.
userSelf
().
say
(
textOrContactOrFile
)
}
else
{
throw
new
Error
(
'
unsupported
'
)
}
}
/**
...
...
@@ -848,13 +861,13 @@ export class Wechaty extends Accessory implements Sayable {
/**
* @private
*/
public
async
ding
():
Promise
<
string
>
{
public
async
ding
():
Promise
<
false
|
'
dong
'
>
{
try
{
return
await
this
.
puppet
.
ding
()
// should return 'dong'
}
catch
(
e
)
{
log
.
error
(
'
Wechaty
'
,
'
ding() exception: %s
'
,
e
.
message
)
Raven
.
captureException
(
e
)
throw
e
return
fals
e
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录