Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wechaty
wechaty
提交
ec561b19
W
wechaty
项目概览
wechaty
/
wechaty
上一次同步 大约 3 年
通知
305
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,发现更多精彩内容 >>
提交
ec561b19
编写于
4月 27, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
work as expected
上级
4faf933f
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
61 addition
and
51 deletion
+61
-51
src/abstract-puppet/contact.ts
src/abstract-puppet/contact.ts
+2
-0
src/abstract-puppet/message.ts
src/abstract-puppet/message.ts
+0
-5
src/abstract-puppet/puppet-accessory.ts
src/abstract-puppet/puppet-accessory.ts
+5
-7
src/abstract-puppet/room.ts
src/abstract-puppet/room.ts
+2
-2
src/config.ts
src/config.ts
+1
-0
src/puppet-web/bridge.ts
src/puppet-web/bridge.ts
+1
-1
src/puppet-web/puppet-web.ts
src/puppet-web/puppet-web.ts
+29
-24
src/puppet-web/web-message.ts
src/puppet-web/web-message.ts
+3
-2
src/puppet-web/web-room.ts
src/puppet-web/web-room.ts
+5
-5
src/wechaty.ts
src/wechaty.ts
+13
-5
未找到文件。
src/abstract-puppet/contact.ts
浏览文件 @
ec561b19
...
@@ -44,6 +44,8 @@ export interface ContactQueryFilter {
...
@@ -44,6 +44,8 @@ export interface ContactQueryFilter {
alias
?:
string
|
RegExp
,
alias
?:
string
|
RegExp
,
}
}
export
type
ContactQueryName
=
keyof
ContactQueryFilter
/**
/**
* All wechat contacts(friend) will be encapsulated as a Contact.
* All wechat contacts(friend) will be encapsulated as a Contact.
*
*
...
...
src/abstract-puppet/message.ts
浏览文件 @
ec561b19
...
@@ -34,11 +34,6 @@ import Contact from './contact'
...
@@ -34,11 +34,6 @@ import Contact from './contact'
import
Room
from
'
./room
'
import
Room
from
'
./room
'
import
PuppetAccessory
from
'
./puppet-accessory
'
import
PuppetAccessory
from
'
./puppet-accessory
'
// export type TypeName = 'attachment'
// | 'audio'
// | 'image'
// | 'video'
/**
/**
* All wechat messages will be encapsulated as a Message.
* All wechat messages will be encapsulated as a Message.
*
*
...
...
src/abstract-puppet/puppet-accessory.ts
浏览文件 @
ec561b19
...
@@ -12,14 +12,13 @@ export abstract class PuppetAccessory extends EventEmitter {
...
@@ -12,14 +12,13 @@ export abstract class PuppetAccessory extends EventEmitter {
private
static
_puppet
?:
Puppet
private
static
_puppet
?:
Puppet
public
static
set
puppet
(
puppet
:
Puppet
)
{
public
static
set
puppet
(
puppet
:
Puppet
)
{
log
.
silly
(
'
PuppetAssessory
'
,
'
static set puppet(
)
'
)
log
.
silly
(
'
PuppetAssessory
'
,
'
static set puppet(
%s)
'
,
puppet
.
constructor
.
name
)
this
.
_puppet
=
puppet
this
.
_puppet
=
puppet
}
}
public
static
get
puppet
():
Puppet
{
public
static
get
puppet
():
Puppet
{
log
.
silly
(
'
PuppetAssessory
'
,
'
static get puppet()
'
)
log
.
silly
(
'
PuppetAssessory
'
,
'
static get puppet()
'
)
if
(
this
.
_puppet
)
{
if
(
this
.
_puppet
)
{
log
.
silly
(
'
PuppetAssessory
'
,
'
static get puppet() from instance properties
'
)
return
this
.
_puppet
return
this
.
_puppet
}
}
...
@@ -32,20 +31,19 @@ export abstract class PuppetAccessory extends EventEmitter {
...
@@ -32,20 +31,19 @@ export abstract class PuppetAccessory extends EventEmitter {
private
_puppet
?:
Puppet
private
_puppet
?:
Puppet
public
set
puppet
(
puppet
:
Puppet
)
{
public
set
puppet
(
puppet
:
Puppet
)
{
log
.
silly
(
'
PuppetAssessory
'
,
'
set puppet(
)
'
)
log
.
silly
(
'
PuppetAssessory
'
,
'
set puppet(
%s)
'
,
puppet
.
constructor
.
name
)
this
.
_puppet
=
puppet
this
.
_puppet
=
puppet
}
}
public
get
puppet
():
Puppet
{
public
get
puppet
():
Puppet
{
log
.
silly
(
'
PuppetAssessory
'
,
'
get puppet()
'
)
log
.
silly
(
'
PuppetAssessory
'
,
'
get puppet()
from instance
'
)
if
(
this
.
_puppet
)
{
if
(
this
.
_puppet
)
{
log
.
silly
(
'
PuppetAssessory
'
,
'
get puppet() from instance properties
'
)
return
this
.
_puppet
return
this
.
_puppet
}
}
return
(
this
.
constructor
as
any
).
puppet
// use the Class Static puppet
return
(
this
.
constructor
as
any
as
PuppetAccessory
).
puppet
}
}
}
}
export
default
PuppetAccessory
export
default
PuppetAccessory
src/abstract-puppet/room.ts
浏览文件 @
ec561b19
...
@@ -32,14 +32,14 @@ export type RoomEventName = 'join'
...
@@ -32,14 +32,14 @@ export type RoomEventName = 'join'
|
'
leave
'
|
'
leave
'
|
'
topic
'
|
'
topic
'
export
type
RoomMemberQueryName
=
'
name
'
|
'
roomAlias
'
|
'
contactAlias
'
export
interface
RoomMemberQueryFilter
{
export
interface
RoomMemberQueryFilter
{
name
?:
string
,
name
?:
string
,
roomAlias
?:
string
,
roomAlias
?:
string
,
contactAlias
?:
string
,
contactAlias
?:
string
,
}
}
export
type
RoomMemberQueryName
=
keyof
RoomMemberQueryFilter
export
interface
RoomQueryFilter
{
export
interface
RoomQueryFilter
{
topic
:
string
|
RegExp
,
topic
:
string
|
RegExp
,
}
}
...
...
src/config.ts
浏览文件 @
ec561b19
...
@@ -90,6 +90,7 @@ export type PuppetName = 'android-pad'
...
@@ -90,6 +90,7 @@ export type PuppetName = 'android-pad'
|
'
hostie
'
|
'
hostie
'
|
'
ios-app-phone
'
|
'
ios-app-phone
'
|
'
ios-app-pad
'
|
'
ios-app-pad
'
|
'
mock
'
|
'
web
'
|
'
web
'
|
'
win32
'
|
'
win32
'
...
...
src/puppet-web/bridge.ts
浏览文件 @
ec561b19
...
@@ -432,7 +432,7 @@ export class Bridge extends EventEmitter {
...
@@ -432,7 +432,7 @@ export class Bridge extends EventEmitter {
try
{
try
{
const
ret
=
await
this
.
proxyWechaty
(
'
send
'
,
toUserName
,
content
)
const
ret
=
await
this
.
proxyWechaty
(
'
send
'
,
toUserName
,
content
)
if
(
ret
)
{
if
(
!
ret
)
{
throw
new
Error
(
'
send fail
'
)
throw
new
Error
(
'
send fail
'
)
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
src/puppet-web/puppet-web.ts
浏览文件 @
ec561b19
...
@@ -329,18 +329,19 @@ export class PuppetWeb extends Puppet {
...
@@ -329,18 +329,19 @@ export class PuppetWeb extends Puppet {
}
}
}
}
private
async
uploadMedia
(
mediaMessage
:
WebMessage
,
toUserName
:
string
):
Promise
<
MediaData
>
{
private
async
uploadMedia
(
message
:
WebMessage
,
toUserName
:
string
):
Promise
<
MediaData
>
{
if
(
!
mediaMessage
)
if
(
message
.
type
()
===
WebMessage
.
Type
.
TEXT
)
{
throw
new
Error
(
'
require mediaMessage
'
)
throw
new
Error
(
'
require a Media Message
'
)
}
const
filename
=
me
diaMe
ssage
.
filename
()
const
filename
=
message
.
filename
()
const
ext
=
me
diaMe
ssage
.
ext
()
const
ext
=
message
.
ext
()
// const contentType = Misc.mime(ext)
// const contentType = Misc.mime(ext)
// const contentType = mime.getType(ext)
// const contentType = mime.getType(ext)
const
contentType
=
me
diaMe
ssage
.
mimeType
()
const
contentType
=
message
.
mimeType
()
if
(
!
contentType
)
{
if
(
!
contentType
)
{
throw
new
Error
(
'
no MIME Type found on mediaMessage:
'
+
me
diaMe
ssage
.
filename
())
throw
new
Error
(
'
no MIME Type found on mediaMessage:
'
+
message
.
filename
())
}
}
let
mediatype
:
MediaType
let
mediatype
:
MediaType
...
@@ -359,7 +360,7 @@ export class PuppetWeb extends Puppet {
...
@@ -359,7 +360,7 @@ export class PuppetWeb extends Puppet {
mediatype
=
MediaType
.
ATTACHMENT
mediatype
=
MediaType
.
ATTACHMENT
}
}
const
readStream
=
await
me
diaMe
ssage
.
readyStream
()
const
readStream
=
await
message
.
readyStream
()
const
buffer
=
<
Buffer
>
await
new
Promise
((
resolve
,
reject
)
=>
{
const
buffer
=
<
Buffer
>
await
new
Promise
((
resolve
,
reject
)
=>
{
readStream
.
pipe
(
bl
((
err
,
data
)
=>
{
readStream
.
pipe
(
bl
((
err
,
data
)
=>
{
if
(
err
)
reject
(
err
)
if
(
err
)
reject
(
err
)
...
@@ -682,6 +683,8 @@ export class PuppetWeb extends Puppet {
...
@@ -682,6 +683,8 @@ export class PuppetWeb extends Puppet {
}
}
public
async
send
(
message
:
WebMessage
):
Promise
<
void
>
{
public
async
send
(
message
:
WebMessage
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWeb
'
,
'
send(%s)
'
,
message
)
const
to
=
message
.
to
()
const
to
=
message
.
to
()
const
room
=
message
.
room
()
const
room
=
message
.
room
()
...
@@ -689,33 +692,35 @@ export class PuppetWeb extends Puppet {
...
@@ -689,33 +692,35 @@ export class PuppetWeb extends Puppet {
if
(
room
)
{
if
(
room
)
{
destinationId
=
room
.
id
destinationId
=
room
.
id
}
else
{
}
else
if
(
to
)
{
if
(
!
to
)
{
throw
new
Error
(
'
PuppetWeb.send(): message with neither room nor to?
'
)
}
destinationId
=
to
.
id
destinationId
=
to
.
id
}
else
{
throw
new
Error
(
'
PuppetWeb.send(): message with neither room nor to?
'
)
}
}
if
(
message
.
type
()
!==
MsgType
.
TEXT
)
{
if
(
message
.
type
()
===
MsgType
.
TEXT
)
{
const
ret
=
await
this
.
sendMedia
(
message
)
log
.
silly
(
'
PuppetWeb
'
,
'
send() TEXT message.
'
)
if
(
!
ret
)
{
const
text
=
message
.
text
()
throw
new
Error
(
'
sendMedia fail
'
)
}
}
else
{
const
content
=
message
.
text
()
log
.
silly
(
'
PuppetWeb
'
,
'
send() destination: %s,
conten
t: %s)
'
,
log
.
silly
(
'
PuppetWeb
'
,
'
send() destination: %s,
tex
t: %s)
'
,
destinationId
,
destinationId
,
conten
t
,
tex
t
,
)
)
try
{
try
{
await
this
.
bridge
.
send
(
destinationId
,
conten
t
)
await
this
.
bridge
.
send
(
destinationId
,
tex
t
)
}
catch
(
e
)
{
}
catch
(
e
)
{
log
.
error
(
'
PuppetWeb
'
,
'
send() exception: %s
'
,
e
.
message
)
log
.
error
(
'
PuppetWeb
'
,
'
send() exception: %s
'
,
e
.
message
)
Raven
.
captureException
(
e
)
Raven
.
captureException
(
e
)
throw
e
throw
e
}
}
}
else
{
log
.
silly
(
'
PuppetWeb
'
,
'
send() non-TEXT message.
'
)
const
ret
=
await
this
.
sendMedia
(
message
)
if
(
!
ret
)
{
throw
new
Error
(
'
sendMedia fail
'
)
}
}
}
}
}
...
...
src/puppet-web/web-message.ts
浏览文件 @
ec561b19
...
@@ -329,7 +329,8 @@ export class WebMessage extends Message {
...
@@ -329,7 +329,8 @@ export class WebMessage extends Message {
* @returns {MsgType}
* @returns {MsgType}
*/
*/
public
type
():
MsgType
{
public
type
():
MsgType
{
return
this
.
obj
.
type
log
.
silly
(
'
WebMessage
'
,
'
type() = %s
'
,
MsgType
[
this
.
obj
.
type
])
return
this
.
obj
.
type
||
MsgType
.
TEXT
}
}
/**
/**
...
@@ -817,7 +818,7 @@ export class WebMessage extends Message {
...
@@ -817,7 +818,7 @@ export class WebMessage extends Message {
}
}
break
break
}
}
log
.
error
(
'
WebMessage
'
,
`ext() got unknown type:
${
this
.
type
()}
`
)
log
.
silly
(
'
WebMessage
'
,
`ext() got unknown type:
${
this
.
type
()}
`
)
return
String
(
'
.
'
+
this
.
type
())
return
String
(
'
.
'
+
this
.
type
())
}
}
...
...
src/puppet-web/web-room.ts
浏览文件 @
ec561b19
...
@@ -125,7 +125,7 @@ export class WebRoom extends Room {
...
@@ -125,7 +125,7 @@ export class WebRoom extends Room {
const
currNum
=
roomRawObj
.
MemberList
&&
roomRawObj
.
MemberList
.
length
||
0
const
currNum
=
roomRawObj
.
MemberList
&&
roomRawObj
.
MemberList
.
length
||
0
const
prevNum
=
this
.
rawObj
&&
this
.
rawObj
.
MemberList
&&
this
.
rawObj
.
MemberList
.
length
||
0
const
prevNum
=
this
.
rawObj
&&
this
.
rawObj
.
MemberList
&&
this
.
rawObj
.
MemberList
.
length
||
0
log
.
silly
(
'
WebRoom
'
,
`ready()
contactGetter
(%s) MemberList.length:%d at ttl:%d`
,
log
.
silly
(
'
WebRoom
'
,
`ready()
puppet.getContact
(%s) MemberList.length:%d at ttl:%d`
,
this
.
id
,
this
.
id
,
currNum
,
currNum
,
ttl
,
ttl
,
...
@@ -133,27 +133,27 @@ export class WebRoom extends Room {
...
@@ -133,27 +133,27 @@ export class WebRoom extends Room {
if
(
currNum
)
{
if
(
currNum
)
{
if
(
prevNum
===
currNum
)
{
if
(
prevNum
===
currNum
)
{
log
.
verbose
(
'
WebRoom
'
,
`ready() contactGetter
(
${
this
.
id
}
) done at ttl:%d`
,
ttl
)
log
.
silly
(
'
WebRoom
'
,
`ready() puppet.getContact
(
${
this
.
id
}
) done at ttl:%d`
,
ttl
)
break
break
}
}
this
.
rawObj
=
roomRawObj
this
.
rawObj
=
roomRawObj
}
}
log
.
silly
(
'
WebRoom
'
,
`ready()
contactGetter
(
${
this
.
id
}
) retry at ttl:%d`
,
ttl
)
log
.
silly
(
'
WebRoom
'
,
`ready()
puppet.getContact
(
${
this
.
id
}
) retry at ttl:%d`
,
ttl
)
await
new
Promise
(
r
=>
setTimeout
(
r
,
1000
))
// wait for 1 second
await
new
Promise
(
r
=>
setTimeout
(
r
,
1000
))
// wait for 1 second
}
}
await
this
.
readyAllMembers
(
this
.
rawObj
&&
this
.
rawObj
.
MemberList
||
[])
await
this
.
readyAllMembers
(
this
.
rawObj
&&
this
.
rawObj
.
MemberList
||
[])
this
.
obj
=
this
.
parse
(
this
.
rawObj
)
this
.
obj
=
this
.
parse
(
this
.
rawObj
)
if
(
!
this
.
obj
)
{
if
(
!
this
.
obj
)
{
throw
new
Error
(
'
no this.obj set after
contactGetter
'
)
throw
new
Error
(
'
no this.obj set after
puppet.getContact
'
)
}
}
await
Promise
.
all
(
this
.
obj
.
memberList
.
map
(
c
=>
c
.
ready
()))
await
Promise
.
all
(
this
.
obj
.
memberList
.
map
(
c
=>
c
.
ready
()))
return
this
return
this
}
catch
(
e
)
{
}
catch
(
e
)
{
log
.
error
(
'
WebRoom
'
,
'
contactGetter
(%s) exception: %s
'
,
this
.
id
,
e
.
message
)
log
.
error
(
'
WebRoom
'
,
'
puppet.getContact
(%s) exception: %s
'
,
this
.
id
,
e
.
message
)
Raven
.
captureException
(
e
)
Raven
.
captureException
(
e
)
throw
e
throw
e
}
}
...
...
src/wechaty.ts
浏览文件 @
ec561b19
...
@@ -38,10 +38,10 @@ import {
...
@@ -38,10 +38,10 @@ import {
Sayable
,
Sayable
,
VERSION
,
VERSION
,
WechatyEvent
,
WechatyEvent
,
}
from
'
./config
'
}
from
'
./config
'
import
{
import
{
}
from
'
./message
'
}
from
'
./message
'
import
Profile
from
'
./profile
'
import
Profile
from
'
./profile
'
import
{
import
{
Contact
,
Contact
,
...
@@ -50,9 +50,10 @@ import {
...
@@ -50,9 +50,10 @@ import {
Puppet
,
Puppet
,
PuppetAccessory
,
PuppetAccessory
,
Room
,
Room
,
}
from
'
./abstract-puppet/
'
}
from
'
./abstract-puppet/
'
import
PuppetWeb
from
'
./puppet-web/
'
import
PuppetWeb
from
'
./puppet-web/
'
import
PuppetMock
from
'
./puppet-mock/
'
export
interface
WechatyOptions
{
export
interface
WechatyOptions
{
puppet
?:
PuppetName
,
puppet
?:
PuppetName
,
...
@@ -350,6 +351,13 @@ export class Wechaty extends PuppetAccessory implements Sayable {
...
@@ -350,6 +351,13 @@ export class Wechaty extends PuppetAccessory implements Sayable {
})
})
break
break
case
'
mock
'
:
puppet
=
new
PuppetMock
({
profile
:
this
.
profile
,
wechaty
:
this
,
})
break
default
:
default
:
throw
new
Error
(
'
Puppet unsupport(yet?):
'
+
this
.
options
.
puppet
)
throw
new
Error
(
'
Puppet unsupport(yet?):
'
+
this
.
options
.
puppet
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录