Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
5c3cd427
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,发现更多精彩内容 >>
提交
5c3cd427
编写于
5月 07, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
better mock design
上级
d398c44d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
19 deletion
+32
-19
src/puppet-mock/mock-message.ts
src/puppet-mock/mock-message.ts
+27
-17
src/puppet/message.ts
src/puppet/message.ts
+5
-2
未找到文件。
src/puppet-mock/mock-message.ts
浏览文件 @
5c3cd427
...
...
@@ -36,8 +36,18 @@ import {
export
type
ParsedPath
=
Partial
<
path
.
ParsedPath
>
export
interface
MockMessagePayload
{
text
:
string
,
from
:
MockContact
,
to
?:
MockContact
,
room
?:
MockRoom
,
type
:
MsgType
,
}
export
class
MockMessage
extends
Message
{
private
payload
:
MockMessagePayload
/**
* Static Methods
*/
...
...
@@ -74,6 +84,8 @@ export class MockMessage extends Message {
)
{
super
()
log
.
silly
(
'
MockMessage
'
,
'
constructor()
'
)
this
.
payload
=
{}
as
MockMessagePayload
}
public
from
(
contact
:
MockContact
)
:
this
...
...
@@ -81,29 +93,23 @@ export class MockMessage extends Message {
public
from
(
contact
?:
MockContact
):
this
|
MockContact
{
if
(
contact
)
{
// set from to contact...
this
.
payload
.
from
=
contact
return
this
}
const
loadedContact
=
MockContact
.
load
(
'
mockid
'
)
loadedContact
.
puppet
=
this
.
puppet
return
loadedContact
return
this
.
payload
.
from
}
public
to
(
contact
:
MockContact
):
this
public
to
(
id
:
string
):
this
public
to
():
MockContact
|
null
// if to is not set, then room must had set
public
to
(
contact
?:
MockContact
|
string
):
MockContact
|
null
|
this
{
public
to
(
contact
?:
MockContact
):
MockContact
|
null
|
this
{
if
(
contact
)
{
this
.
payload
.
to
=
contact
return
this
}
const
to
=
MockContact
.
load
(
'
mockid
'
)
as
MockContact
to
.
puppet
=
this
.
puppet
return
to
return
this
.
payload
.
to
||
null
}
public
room
(
room
:
MockRoom
):
this
...
...
@@ -111,26 +117,30 @@ export class MockMessage extends Message {
public
room
(
room
?:
MockRoom
):
this
|
MockRoom
|
null
{
if
(
room
)
{
// set room to room...
this
.
payload
.
room
=
room
return
this
}
return
null
return
this
.
payload
.
room
||
null
}
public
text
():
string
public
text
(
content
:
string
):
this
public
text
(
text
?:
string
):
string
|
this
{
if
(
text
)
{
this
.
payload
.
text
=
text
return
this
}
return
'
mock text
'
return
this
.
payload
.
text
||
'
'
}
public
async
say
(
text
:
string
,
mention
?:
MockContact
|
MockContact
[]):
Promise
<
void
>
public
async
say
(
message
:
MockMessage
):
Promise
<
void
>
public
async
say
(
textOrMessage
:
string
|
MockMessage
,
replyTo
?:
MockContact
|
MockContact
[],
mention
?:
MockContact
|
MockContact
[],
):
Promise
<
void
>
{
log
.
verbose
(
'
MockMessage
'
,
'
say(%s, %s)
'
,
textOrMessage
,
replyTo
)
log
.
verbose
(
'
MockMessage
'
,
'
say(%s, %s)
'
,
textOrMessage
,
mention
)
const
message
=
new
MockMessage
()
...
...
@@ -142,7 +152,7 @@ export class MockMessage extends Message {
message
.
room
(
room
)
}
// TODO: implement the
replyTo
// TODO: implement the
`mention`
await
this
.
puppet
.
send
(
message
)
}
...
...
src/puppet/message.ts
浏览文件 @
5c3cd427
...
...
@@ -175,12 +175,15 @@ export abstract class Message extends PuppetAccessory implements Sayable {
*/
public
abstract
text
(
text
:
string
):
this
|
string
public
abstract
async
say
(
text
:
string
,
mention
?:
Contact
|
Contact
[]):
Promise
<
void
>
public
abstract
async
say
(
message
:
Message
):
Promise
<
void
>
/**
* Reply a Text or Media File message to the sender.
*
* @see {@link https://github.com/Chatie/wechaty/blob/master/examples/ding-dong-bot.ts|Examples/ding-dong-bot}
* @param {(string | Message)} textOrMessage
* @param {(Contact|Contact[])} [
replyTo
]
* @param {(Contact|Contact[])} [
mention
]
* @returns {Promise<void>}
*
* @example
...
...
@@ -197,7 +200,7 @@ export abstract class Message extends PuppetAccessory implements Sayable {
*/
public
abstract
async
say
(
textOrMessage
:
string
|
Message
,
replyTo
?
:
Contact
|
Contact
[],
mention
?
:
Contact
|
Contact
[],
):
Promise
<
void
>
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录