Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
4a9c467e
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,发现更多精彩内容 >>
提交
4a9c467e
编写于
5月 15, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
naming style: enum name style from UNKNOWN to Unknown
上级
ab389001
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
38 addition
and
260 deletion
+38
-260
examples/friend-bot.ts
examples/friend-bot.ts
+2
-2
examples/gist-bot/on-friend.ts
examples/gist-bot/on-friend.ts
+1
-1
src/puppet-mock/puppet-mock.ts
src/puppet-mock/puppet-mock.ts
+3
-3
src/puppet-puppeteer/puppet-puppeteer.ts
src/puppet-puppeteer/puppet-puppeteer.ts
+10
-10
src/puppet-puppeteer/puppeteer-friend-request.spec.ts
src/puppet-puppeteer/puppeteer-friend-request.spec.ts
+2
-2
src/puppet-puppeteer/puppeteer-message.ts
src/puppet-puppeteer/puppeteer-message.ts
+7
-229
src/puppet/friend-request.ts
src/puppet/friend-request.ts
+9
-9
src/puppet/schemas/web.ts
src/puppet/schemas/web.ts
+4
-4
未找到文件。
examples/friend-bot.ts
浏览文件 @
4a9c467e
...
...
@@ -93,7 +93,7 @@ bot
* when request is set, we can get verify message from `request.hello`,
* and accept this request by `request.accept()`
*/
case
FriendRequest
.
Type
.
R
ECEIVE
:
case
FriendRequest
.
Type
.
R
eceive
:
if
(
request
.
hello
()
===
'
ding
'
)
{
logMsg
=
'
accepted because verify messsage is "ding"
'
request
.
accept
()
...
...
@@ -108,7 +108,7 @@ bot
* 2. Friend Ship Confirmed
*
*/
case
FriendRequest
.
Type
.
C
ONFIRM
:
case
FriendRequest
.
Type
.
C
onfirm
:
logMsg
=
'
friend ship confirmed with
'
+
request
.
contact
().
name
()
break
}
...
...
examples/gist-bot/on-friend.ts
浏览文件 @
4a9c467e
...
...
@@ -35,7 +35,7 @@ export async function onFriend(
try
{
const
contact
=
request
.
contact
()
if
(
request
.
type
()
===
FriendRequest
.
Type
.
C
ONFIRM
)
{
if
(
request
.
type
()
===
FriendRequest
.
Type
.
C
onfirm
)
{
console
.
log
(
'
New friend
'
+
contact
.
name
()
+
'
relationship confirmed!
'
)
return
}
...
...
src/puppet-mock/puppet-mock.ts
浏览文件 @
4a9c467e
...
...
@@ -132,7 +132,7 @@ export class PuppetMock extends Puppet {
return
this
.
user
}
public
async
f
orward
(
message
:
MockMessage
,
sendTo
:
Contact
|
Room
):
Promise
<
void
>
{
public
async
messageF
orward
(
message
:
MockMessage
,
sendTo
:
Contact
|
Room
):
Promise
<
void
>
{
log
.
silly
(
'
PuppetMock
'
,
'
forward() to: %s, message: %s)
'
,
sendTo
,
message
.
filename
(),
// patchData.ToUserName,
...
...
@@ -192,8 +192,8 @@ export class PuppetMock extends Puppet {
public
async
contactPayload
(
contact
:
Contact
):
Promise
<
ContactPayload
>
{
return
{
gender
:
Gender
.
U
NKNOWN
,
type
:
ContactType
.
U
NKNOWN
,
gender
:
Gender
.
U
nknown
,
type
:
ContactType
.
U
nknown
,
}
}
...
...
src/puppet-puppeteer/puppet-puppeteer.ts
浏览文件 @
4a9c467e
...
...
@@ -364,13 +364,13 @@ export class PuppetPuppeteer extends Puppet {
case
'
.jpg
'
:
case
'
.png
'
:
case
'
.gif
'
:
mediatype
=
WebMediaType
.
I
MAGE
mediatype
=
WebMediaType
.
I
mage
break
case
'
.mp4
'
:
mediatype
=
WebMediaType
.
V
IDEO
mediatype
=
WebMediaType
.
V
ideo
break
default
:
mediatype
=
WebMediaType
.
A
TTACHMENT
mediatype
=
WebMediaType
.
A
ttachment
}
const
readStream
=
await
message
.
readyStream
()
...
...
@@ -387,7 +387,7 @@ export class PuppetPuppeteer extends Puppet {
const
LARGE_FILE_SIZE
=
25
*
1024
*
1024
const
MAX_VIDEO_SIZE
=
20
*
1024
*
1024
if
(
mediatype
===
WebMediaType
.
V
IDEO
&&
buffer
.
length
>
MAX_VIDEO_SIZE
)
if
(
mediatype
===
WebMediaType
.
V
ideo
&&
buffer
.
length
>
MAX_VIDEO_SIZE
)
throw
new
Error
(
`Sending video files is not allowed to exceed
${
MAX_VIDEO_SIZE
/
1024
/
1024
}
MB`
)
if
(
buffer
.
length
>
MAX_FILE_SIZE
)
{
throw
new
Error
(
`Sending files is not allowed to exceed
${
MAX_FILE_SIZE
/
1024
/
1024
}
MB`
)
...
...
@@ -423,7 +423,7 @@ export class PuppetPuppeteer extends Puppet {
ToUserName
:
toUserName
,
UploadType
:
2
,
ClientMediaId
:
+
new
Date
,
MediaType
:
WebMediaType
.
A
TTACHMENT
,
MediaType
:
WebMediaType
.
A
ttachment
,
StartPos
:
0
,
DataLen
:
size
,
TotalLen
:
size
,
...
...
@@ -629,7 +629,7 @@ export class PuppetPuppeteer extends Puppet {
* TODO: Test this function if it could work...
*/
// public async forward(baseData: MsgRawObj, patchData: MsgRawObj): Promise<boolean> {
public
async
f
orward
(
public
async
messageF
orward
(
message
:
PuppeteerMessage
,
sendTo
:
PuppeteerContact
|
PuppeteerRoom
,
):
Promise
<
void
>
{
...
...
@@ -807,8 +807,8 @@ export class PuppetPuppeteer extends Puppet {
if
(
!
Object
.
keys
(
rawPayload
).
length
)
{
log
.
error
(
'
PuppetPuppeteer
'
,
'
contactParseRawPayload() got empty rawPayload!
'
)
return
{
gender
:
Gender
.
U
NKNOWN
,
type
:
PuppeteerContact
.
Type
.
U
NKNOWN
,
gender
:
Gender
.
U
nknown
,
type
:
PuppeteerContact
.
Type
.
U
nknown
,
}
}
...
...
@@ -838,8 +838,8 @@ export class PuppetPuppeteer extends Puppet {
*/
// tslint:disable-next-line
type
:
(
!!
rawPayload
.
UserName
&&
!
rawPayload
.
UserName
.
startsWith
(
'
@@
'
)
&&
!!
(
rawPayload
.
VerifyFlag
&
8
))
?
PuppeteerContact
.
Type
.
O
FFICIAL
:
PuppeteerContact
.
Type
.
P
ERSONAL
,
?
PuppeteerContact
.
Type
.
O
fficial
:
PuppeteerContact
.
Type
.
P
ersonal
,
/**
* @see 1. https://github.com/Chatie/webwx-app-tracker/blob/7c59d35c6ea0cff38426a4c5c912a086c4c512b2/formatted/webwxApp.js#L3246
* @ignore
...
...
src/puppet-puppeteer/puppeteer-friend-request.spec.ts
浏览文件 @
4a9c467e
...
...
@@ -74,7 +74,7 @@ test('PuppetPuppeteerFriendRequest.receive smoke testing', async t => {
t
.
is
(
fr
.
hello
(),
'
我是群聊"Wechaty"的李卓桓.PreAngel
'
,
'
should has right request message
'
)
t
.
true
(
fr
.
contact
()
instanceof
PuppeteerContact
,
'
should have a Contact instance
'
)
t
.
is
(
fr
.
type
(),
MyFriendRequest
.
Type
.
R
ECEIVE
,
'
should be receive type
'
)
t
.
is
(
fr
.
type
(),
MyFriendRequest
.
Type
.
R
eceive
,
'
should be receive type
'
)
})
test
(
'
PuppetPuppeteerFriendRequest.confirm smoke testing
'
,
async
t
=>
{
...
...
@@ -106,5 +106,5 @@ test('PuppetPuppeteerFriendRequest.confirm smoke testing', async t => {
const
fr
=
MyFriendRequest
.
createConfirm
(
contact
||
new
MyContact
(
'
xx
'
))
t
.
true
(
fr
.
contact
()
instanceof
PuppeteerContact
,
'
should have a Contact instance
'
)
t
.
is
(
fr
.
type
(),
MyFriendRequest
.
Type
.
C
ONFIRM
,
'
should be confirm type
'
)
t
.
is
(
fr
.
type
(),
MyFriendRequest
.
Type
.
C
onfirm
,
'
should be confirm type
'
)
})
src/puppet-puppeteer/puppeteer-message.ts
浏览文件 @
4a9c467e
/**
* Wechaty - https://github.com/chatie/wechaty
*
* @copyright 2016-2018 Huan LI <zixia@zixia.net>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* @ignore
*/
import
*
as
fs
from
'
fs
'
import
*
as
path
from
'
path
'
import
*
as
mime
from
'
mime
'
...
...
@@ -58,12 +40,12 @@ export interface WebMsgPayload {
}
export
enum
MessageType
{
U
NKNOWN
=
0
,
A
TTACHMENT
,
A
UDIO
,
I
MAGE
,
T
EXT
,
V
IDEO
,
U
nknown
=
0
,
A
ttachment
,
A
udio
,
I
mage
,
T
ext
,
V
ideo
,
}
export
interface
MessagePayloadBase
{
...
...
@@ -289,13 +271,6 @@ export class PuppeteerMessage extends Message {
await
this
.
puppet
.
send
(
m
)
}
/**
* Get the type from the message.
*
* If type is equal to `MsgType.RECALLED`, {@link Message#id} is the msgId of the recalled message.
* @see {@link MsgType}
* @returns {WebMsgType}
*/
public
type
():
WebMsgType
{
log
.
silly
(
'
PuppeteerMessage
'
,
'
type() = %s
'
,
WebMsgType
[
this
.
payload
.
type
])
...
...
@@ -337,14 +312,6 @@ export class PuppeteerMessage extends Message {
throw
new
Error
(
'
unknown type:
'
+
ext
)
}
/**
* Get the typeSub from the message.
*
* If message is a location message: `m.type() === MsgType.TEXT && m.typeSub() === MsgType.LOCATION`
*
* @see {@link MsgType}
* @returns {WebMsgType}
*/
public
typeSub
():
WebMsgType
{
if
(
!
this
.
rawObj
)
{
throw
new
Error
(
'
no rawObj
'
)
...
...
@@ -352,12 +319,6 @@ export class PuppeteerMessage extends Message {
return
this
.
rawObj
.
SubMsgType
}
/**
* Get the typeApp from the message.
*
* @returns {AppMsgType}
* @see {@link AppMsgType}
*/
public
typeApp
():
WebAppMsgType
{
if
(
!
this
.
rawObj
)
{
throw
new
Error
(
'
no rawObj
'
)
...
...
@@ -365,22 +326,6 @@ export class PuppeteerMessage extends Message {
return
this
.
rawObj
.
AppMsgType
}
// /**
// * Get the typeEx from the message.
// *
// * @returns {MsgType}
// */
// public typeEx() { return MsgType[this.obj.type] }
/**
* Check if a message is sent by self.
*
* @returns {boolean} - Return `true` for send from self, `false` for send from others.
* @example
* if (message.self()) {
* console.log('this message is sent by myself!')
* }
*/
public
self
():
boolean
{
const
user
=
this
.
puppet
.
userSelf
()
...
...
@@ -393,25 +338,6 @@ export class PuppeteerMessage extends Message {
return
selfId
===
fromId
}
/**
*
* Get message mentioned contactList.
*
* Message event table as follows
*
* | | Web | Mac PC Client | iOS Mobile | android Mobile |
* | :--- | :--: | :----: | :---: | :---: |
* | [You were mentioned] tip ([有人@我]的提示) | ✘ | √ | √ | √ |
* | Identify magic code (8197) by copy & paste in mobile | ✘ | √ | √ | ✘ |
* | Identify magic code (8197) by programming | ✘ | ✘ | ✘ | ✘ |
* | Identify two contacts with the same roomAlias by [You were mentioned] tip | ✘ | ✘ | √ | √ |
*
* @returns {PuppeteerContact[]} - Return message mentioned contactList
*
* @example
* const contactList = message.mentioned()
* console.log(contactList)
*/
public
mentioned
():
PuppeteerContact
[]
{
log
.
verbose
(
'
PuppeteerMessage
'
,
'
mentioned()
'
)
...
...
@@ -558,7 +484,6 @@ export class PuppeteerMessage extends Message {
default
:
const
e
=
new
Error
(
'
ready() unsupported typeApp():
'
+
this
.
typeApp
())
log
.
warn
(
'
PuppeteerMessage
'
,
e
.
message
)
this
.
dumpRaw
()
throw
e
}
break
...
...
@@ -597,82 +522,6 @@ export class PuppeteerMessage extends Message {
return
this
}
// /**
// * @private
// */
// public get(prop: string): string {
// log.warn('PuppeteerMessage', 'DEPRECATED get() at %s', new Error('stack').stack)
// if (!prop || !(prop in this.obj)) {
// const s = '[' + Object.keys(this.obj).join(',') + ']'
// throw new Error(`Message.get(${prop}) must be in: ${s}`)
// }
// return this.obj[prop]
// }
// /**
// * @private
// */
// public set(prop: string, value: string): this {
// log.warn('PuppeteerMessage', 'DEPRECATED set() at %s', new Error('stack').stack)
// if (typeof value !== 'string') {
// throw new Error('value must be string, we got: ' + typeof value)
// }
// this.obj[prop] = value
// return this
// }
/**
* @private
*/
public
dump
()
{
console
.
error
(
'
======= dump message =======
'
)
Object
.
keys
(
this
.
payload
!
).
forEach
((
k
:
keyof
WebMsgPayload
)
=>
console
.
error
(
`
${
k
}
:
${
this
.
payload
!
[
k
]}
`
))
}
/**
* @private
*/
public
dumpRaw
()
{
console
.
error
(
'
======= dump raw message =======
'
)
if
(
!
this
.
rawObj
)
{
throw
new
Error
(
'
no this.rawObj
'
)
}
Object
.
keys
(
this
.
rawObj
).
forEach
((
k
:
keyof
WebMessageRawPayload
)
=>
console
.
error
(
`
${
k
}
:
${
this
.
rawObj
&&
this
.
rawObj
[
k
]}
`
))
}
// /**
// * @todo add function
// */
// public static async find(query: any) {
// return Promise.resolve(new PuppeteerMessage(<MsgRawPayload>{MsgId: '-1'}))
// }
/**
* @todo add function
*/
// public static async findAll(query: any) {
// return Promise.resolve([
// new PuppeteerMessage (<MsgRawPayload>{MsgId: '-2'}),
// new PuppeteerMessage (<MsgRawPayload>{MsgId: '-3'}),
// ])
// }
// public to(room: Room): void
// public to(): Contact|Room
// public to(contact?: Contact|Room|string): Contact|Room|void {
/**
* Please notice that when we are running Wechaty,
* if you use the browser that controlled by Wechaty to send attachment files,
* you will get a zero sized file, because it is not an attachment from the network,
* but a local data, which is not supported by Wechaty yet.
*
* Get the read stream for attachment file
*
* @returns {Promise<Readable>}
*/
public
async
readyStream
():
Promise
<
Readable
>
{
log
.
verbose
(
'
PuppeteerMessage
'
,
'
readyStream()
'
)
...
...
@@ -707,17 +556,6 @@ export class PuppeteerMessage extends Message {
}
}
/**
* Get the MediaMessage filename, etc: `how to build a chatbot.pdf`..
*
* @returns {string}
* @example
* bot.on('message', async function (m) {
* if (m instanceof MediaMessage) {
* console.log('media message file name is: ' + m.filename())
* }
* })
*/
public
filename
():
string
|
null
{
log
.
verbose
(
'
PuppeteerMessage
'
,
'
filename()
'
)
...
...
@@ -748,17 +586,6 @@ export class PuppeteerMessage extends Message {
}
/**
* Get the MediaMessage file extension(including the dot `.`), etc: `.jpg`, `.gif`, `.pdf`, `.word` ..
*
* @returns {string}
* @example
* bot.on('message', async function (m) {
* if (m instanceof MediaMessage) {
* console.log('media message file name extention is: ' + m.ext())
* }
* })
*/
public
ext
():
string
{
const
fileExt
=
this
.
extFromFile
()
if
(
fileExt
)
{
...
...
@@ -873,55 +700,6 @@ export class PuppeteerMessage extends Message {
})
}
/**
* Forward the received message.
*
* The types of messages that can be forwarded are as follows:
*
* The return value of {@link Message#type} matches one of the following types:
* ```
* MsgType {
* TEXT = 1,
* IMAGE = 3,
* VIDEO = 43,
* EMOTICON = 47,
* LOCATION = 48,
* APP = 49,
* MICROVIDEO = 62,
* }
* ```
*
* When the return value of {@link Message#type} is `MsgType.APP`, the return value of {@link Message#typeApp} matches one of the following types:
* ```
* AppMsgType {
* TEXT = 1,
* IMG = 2,
* VIDEO = 4,
* ATTACH = 6,
* EMOJI = 8,
* }
* ```
* It should be noted that when forwarding ATTACH type message, if the file size is greater than 25Mb, the forwarding will fail.
* The reason is that the server shields the web wx to download more than 25Mb files with a file size of 0.
*
* But if the file is uploaded by you using wechaty, you can forward it.
* You need to detect the following conditions in the message event, which can be forwarded if it is met.
*
* ```javasrcipt
* .on('message', async m => {
* if (m.self() && m.rawObj && m.rawObj.Signature) {
* // Filter the contacts you have forwarded
* const msg = <MediaMessage> m
* await msg.forward()
* }
* })
* ```
*
* @param {(Sayable | Sayable[])} to Room or Contact
* The recipient of the message, the room, or the contact
* @returns {Promise<boolean>}
* @memberof MediaMessage
*/
public
async
forward
(
to
:
PuppeteerRoom
|
PuppeteerContact
):
Promise
<
void
>
{
/**
* 1. Text message
...
...
@@ -935,7 +713,7 @@ export class PuppeteerMessage extends Message {
* 2. Media message
*/
try
{
await
this
.
puppet
.
f
orward
(
this
,
to
)
await
this
.
puppet
.
messageF
orward
(
this
,
to
)
}
catch
(
e
)
{
log
.
error
(
'
PuppeteerMessage
'
,
'
forward(%s) exception: %s
'
,
to
,
e
)
throw
e
...
...
src/puppet/friend-request.ts
浏览文件 @
4a9c467e
...
...
@@ -30,10 +30,10 @@ import {
}
from
'
../config
'
export
enum
FriendRequestType
{
U
NKNOWN
=
0
,
S
END
,
R
ECEIVE
,
C
ONFIRM
,
U
nknown
=
0
,
S
end
,
R
eceive
,
C
onfirm
,
}
export
interface
FriendRequestPayload
{
...
...
@@ -67,7 +67,7 @@ export class FriendRequest extends PuppetAccessory {
)
const
sentRequest
=
new
this
({
type
:
FriendRequestType
.
S
END
,
type
:
FriendRequestType
.
S
end
,
contact
,
hello
,
})
...
...
@@ -83,7 +83,7 @@ export class FriendRequest extends PuppetAccessory {
)
const
confirmedRequest
=
new
this
({
type
:
FriendRequestType
.
C
ONFIRM
,
type
:
FriendRequestType
.
C
onfirm
,
contact
,
})
...
...
@@ -102,7 +102,7 @@ export class FriendRequest extends PuppetAccessory {
)
const
receivedRequest
=
new
this
({
type
:
FriendRequestType
.
R
ECEIVE
,
type
:
FriendRequestType
.
R
eceive
,
contact
,
hello
,
ticket
,
...
...
@@ -128,7 +128,7 @@ export class FriendRequest extends PuppetAccessory {
throw
new
Error
(
'
no payload
'
)
}
else
if
(
!
this
.
payload
.
contact
)
{
throw
new
Error
(
'
no contact
'
)
}
else
if
(
this
.
payload
.
type
!==
FriendRequest
.
Type
.
S
END
)
{
}
else
if
(
this
.
payload
.
type
!==
FriendRequest
.
Type
.
S
end
)
{
throw
new
Error
(
'
not a send request
'
)
}
log
.
verbose
(
'
PuppeteerFriendRequest
'
,
'
send() to %s
'
,
this
.
payload
.
contact
)
...
...
@@ -146,7 +146,7 @@ export class FriendRequest extends PuppetAccessory {
throw
new
Error
(
'
no contact
'
)
}
else
if
(
!
this
.
payload
.
ticket
)
{
throw
new
Error
(
'
no ticket
'
)
}
else
if
(
this
.
payload
.
type
!==
FriendRequest
.
Type
.
R
ECEIVE
)
{
}
else
if
(
this
.
payload
.
type
!==
FriendRequest
.
Type
.
R
eceive
)
{
throw
new
Error
(
'
not a receive request, its a
'
+
FriendRequest
.
Type
[
this
.
payload
.
type
!
])
}
log
.
verbose
(
'
FriendRequest
'
,
'
accept() to %s
'
,
this
.
payload
.
contact
)
...
...
src/puppet/schemas/web.ts
浏览文件 @
4a9c467e
...
...
@@ -275,8 +275,8 @@ export interface WebRecomendInfo {
}
export
const
enum
WebMediaType
{
I
MAGE
=
1
,
V
IDEO
=
2
,
A
UDIO
=
3
,
A
TTACHMENT
=
4
,
I
mage
=
1
,
V
ideo
=
2
,
A
udio
=
3
,
A
ttachment
=
4
,
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录