Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
80c5dad3
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,发现更多精彩内容 >>
提交
80c5dad3
编写于
5月 15, 2017
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(say): add return boolean to identify success/failure
上级
dbe0c174
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
61 addition
and
50 deletion
+61
-50
src/config.ts
src/config.ts
+1
-1
src/contact.ts
src/contact.ts
+2
-3
src/puppet-web/bridge.ts
src/puppet-web/bridge.ts
+2
-2
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+13
-11
src/puppet-web/wechaty-bro.js
src/puppet-web/wechaty-bro.js
+28
-16
src/puppet.ts
src/puppet.ts
+2
-2
src/room.ts
src/room.ts
+5
-5
src/wechaty.ts
src/wechaty.ts
+8
-10
未找到文件。
src/config.ts
浏览文件 @
80c5dad3
...
...
@@ -188,7 +188,7 @@ export interface RecommendInfo {
}
export
interface
Sayable
{
say
(
content
:
string
,
replyTo
?:
any
|
any
[]):
Promise
<
void
>
say
(
content
:
string
,
replyTo
?:
any
|
any
[]):
Promise
<
boolean
>
}
export
interface
Sleepable
{
...
...
src/contact.ts
浏览文件 @
80c5dad3
...
...
@@ -703,7 +703,7 @@ export class Contact implements Sayable {
public
async
say
(
text
:
string
)
public
async
say
(
mediaMessage
:
MediaMessage
)
public
async
say
(
textOrMedia
:
string
|
MediaMessage
):
Promise
<
void
>
{
public
async
say
(
textOrMedia
:
string
|
MediaMessage
):
Promise
<
boolean
>
{
const
content
=
textOrMedia
instanceof
MediaMessage
?
textOrMedia
.
filename
()
:
textOrMedia
log
.
verbose
(
'
Contact
'
,
'
say(%s)
'
,
content
)
...
...
@@ -726,8 +726,7 @@ export class Contact implements Sayable {
m
.
to
(
this
)
log
.
silly
(
'
Contact
'
,
'
say() from: %s to: %s content: %s
'
,
user
.
name
(),
this
.
name
(),
content
)
await
wechaty
.
send
(
m
)
return
return
await
wechaty
.
send
(
m
)
}
}
...
...
src/puppet-web/bridge.ts
浏览文件 @
80c5dad3
...
...
@@ -248,7 +248,7 @@ export class Bridge {
})
}
public
send
(
toUserName
:
string
,
content
:
string
):
Promise
<
void
>
{
public
send
(
toUserName
:
string
,
content
:
string
):
Promise
<
boolean
>
{
if
(
!
toUserName
)
{
throw
new
Error
(
'
UserName not found
'
)
}
...
...
@@ -387,7 +387,7 @@ export class Bridge {
}
}
public
sendMedia
(
toUserName
:
string
,
mediaId
:
string
,
type
:
number
):
Promise
<
void
>
{
public
sendMedia
(
toUserName
:
string
,
mediaId
:
string
,
type
:
number
):
Promise
<
boolean
>
{
if
(
!
toUserName
)
{
throw
new
Error
(
'
UserName not found
'
)
}
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
80c5dad3
...
...
@@ -425,7 +425,7 @@ export class PuppetWeb extends Puppet {
return
mediaId
as
string
}
public
async
sendMedia
(
message
:
MediaMessage
):
Promise
<
void
>
{
public
async
sendMedia
(
message
:
MediaMessage
):
Promise
<
boolean
>
{
const
to
=
message
.
to
()
const
room
=
message
.
room
()
...
...
@@ -448,16 +448,17 @@ export class PuppetWeb extends Puppet {
mediaId
,
)
let
ret
=
false
try
{
await
this
.
bridge
.
sendMedia
(
destinationId
,
mediaId
,
msgType
)
ret
=
await
this
.
bridge
.
sendMedia
(
destinationId
,
mediaId
,
msgType
)
}
catch
(
e
)
{
log
.
error
(
'
PuppetWeb
'
,
'
send() exception: %s
'
,
e
.
message
)
throw
e
return
fals
e
}
return
return
ret
}
public
async
send
(
message
:
Message
|
MediaMessage
):
Promise
<
void
>
{
public
async
send
(
message
:
Message
|
MediaMessage
):
Promise
<
boolean
>
{
const
to
=
message
.
to
()
const
room
=
message
.
room
()
...
...
@@ -472,8 +473,10 @@ export class PuppetWeb extends Puppet {
destinationId
=
to
.
id
}
let
ret
=
false
if
(
message
instanceof
MediaMessage
)
{
await
this
.
sendMedia
(
message
)
ret
=
await
this
.
sendMedia
(
message
)
}
else
{
const
content
=
message
.
content
()
...
...
@@ -483,20 +486,20 @@ export class PuppetWeb extends Puppet {
)
try
{
await
this
.
bridge
.
send
(
destinationId
,
content
)
ret
=
await
this
.
bridge
.
send
(
destinationId
,
content
)
}
catch
(
e
)
{
log
.
error
(
'
PuppetWeb
'
,
'
send() exception: %s
'
,
e
.
message
)
throw
e
}
}
return
return
ret
}
/**
* Bot say...
* send to `filehelper` for notice / log
*/
public
async
say
(
content
:
string
):
Promise
<
void
>
{
public
async
say
(
content
:
string
):
Promise
<
boolean
>
{
if
(
!
this
.
logined
())
{
throw
new
Error
(
'
can not say before login
'
)
}
...
...
@@ -505,8 +508,7 @@ export class PuppetWeb extends Puppet {
m
.
to
(
'
filehelper
'
)
m
.
content
(
content
)
await
this
.
send
(
m
)
return
return
await
this
.
send
(
m
)
}
/**
...
...
src/puppet-web/wechaty-bro.js
浏览文件 @
80c5dad3
...
...
@@ -444,7 +444,7 @@
function
getBaseRequest
()
{
var
accountFactory
=
WechatyBro
.
glue
.
accountFactory
var
BaseRequest
=
accountFactory
.
getBaseRequest
()
return
JSON
.
stringify
(
BaseRequest
)
}
...
...
@@ -463,17 +463,23 @@
var
confFactory
=
WechatyBro
.
glue
.
confFactory
if
(
!
chatFactory
||
!
confFactory
)
{
log
(
'
send() chatFactory or confFactory not exist.
'
)
log
(
'
send
Media
() chatFactory or confFactory not exist.
'
)
return
false
}
var
m
=
chatFactory
.
createMessage
({
ToUserName
:
ToUserName
,
MediaId
:
MediaId
,
MsgType
:
Type
})
chatFactory
.
appendMessage
(
m
)
return
chatFactory
.
sendMessage
(
m
)
try
{
var
m
=
chatFactory
.
createMessage
({
ToUserName
:
ToUserName
,
MediaId
:
MediaId
,
MsgType
:
Type
})
chatFactory
.
appendMessage
(
m
)
chatFactory
.
sendMessage
(
m
)
}
catch
(
e
)
{
log
(
'
sendMedia() exception:
'
+
e
.
message
)
return
false
}
return
true
}
function
send
(
ToUserName
,
Content
)
{
...
...
@@ -484,13 +490,19 @@
log
(
'
send() chatFactory or confFactory not exist.
'
)
return
false
}
var
m
=
chatFactory
.
createMessage
({
ToUserName
:
ToUserName
,
Content
:
Content
,
MsgType
:
confFactory
.
MSGTYPE_TEXT
})
chatFactory
.
appendMessage
(
m
)
return
chatFactory
.
sendMessage
(
m
)
try
{
var
m
=
chatFactory
.
createMessage
({
ToUserName
:
ToUserName
,
Content
:
Content
,
MsgType
:
confFactory
.
MSGTYPE_TEXT
})
chatFactory
.
appendMessage
(
m
)
chatFactory
.
sendMessage
(
m
)
}
catch
(
e
)
{
log
(
'
send() exception:
'
+
e
.
message
)
return
false
}
return
true
}
function
getContact
(
id
)
{
var
contactFactory
=
WechatyBro
.
glue
.
contactFactory
...
...
src/puppet.ts
浏览文件 @
80c5dad3
...
...
@@ -35,8 +35,8 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public
abstract
self
():
Contact
public
abstract
send
(
message
:
Message
|
MediaMessage
):
Promise
<
void
>
public
abstract
say
(
content
:
string
):
Promise
<
void
>
public
abstract
send
(
message
:
Message
|
MediaMessage
):
Promise
<
boolean
>
public
abstract
say
(
content
:
string
):
Promise
<
boolean
>
public
abstract
reset
(
reason
?:
string
):
void
public
abstract
logout
():
Promise
<
void
>
...
...
src/room.ts
浏览文件 @
80c5dad3
...
...
@@ -163,12 +163,12 @@ export class Room extends EventEmitter implements Sayable {
return
this
}
public
say
(
mediaMessage
:
MediaMessage
)
:
Promise
<
any
>
public
say
(
content
:
string
)
:
Promise
<
any
>
public
say
(
content
:
string
,
replyTo
:
Contact
)
:
Promise
<
void
>
public
say
(
content
:
string
,
replyTo
:
Contact
[])
:
Promise
<
void
>
public
say
(
mediaMessage
:
MediaMessage
)
public
say
(
content
:
string
)
public
say
(
content
:
string
,
replyTo
:
Contact
)
public
say
(
content
:
string
,
replyTo
:
Contact
[])
public
say
(
textOrMedia
:
string
|
MediaMessage
,
replyTo
?:
Contact
|
Contact
[]):
Promise
<
void
>
{
public
say
(
textOrMedia
:
string
|
MediaMessage
,
replyTo
?:
Contact
|
Contact
[]):
Promise
<
boolean
>
{
const
content
=
textOrMedia
instanceof
MediaMessage
?
textOrMedia
.
filename
()
:
textOrMedia
log
.
verbose
(
'
Room
'
,
'
say(%s, %s)
'
,
content
,
...
...
src/wechaty.ts
浏览文件 @
80c5dad3
...
...
@@ -424,29 +424,27 @@ export class Wechaty extends EventEmitter implements Sayable {
/**
* @todo document me
*/
public
async
send
(
message
:
Message
|
MediaMessage
):
Promise
<
void
>
{
public
async
send
(
message
:
Message
|
MediaMessage
):
Promise
<
boolean
>
{
if
(
!
this
.
puppet
)
{
throw
new
Error
(
'
no puppet
'
)
}
await
this
.
puppet
.
send
(
message
)
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
send() exception: %s
'
,
e
.
message
)
throw
e
})
return
return
await
this
.
puppet
.
send
(
message
)
.
catch
(
e
=>
{
log
.
error
(
'
Wechaty
'
,
'
send() exception: %s
'
,
e
.
message
)
throw
e
})
}
/**
* @todo document me
*/
public
async
say
(
content
:
string
):
Promise
<
void
>
{
public
async
say
(
content
:
string
):
Promise
<
boolean
>
{
log
.
verbose
(
'
Wechaty
'
,
'
say(%s)
'
,
content
)
if
(
!
this
.
puppet
)
{
throw
new
Error
(
'
no puppet
'
)
}
this
.
puppet
.
say
(
content
)
return
return
await
this
.
puppet
.
say
(
content
)
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录