Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
8cf61158
W
wechaty
项目概览
.www.
/
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,发现更多精彩内容 >>
提交
8cf61158
编写于
6月 20, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
ab37155a
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
38 addition
and
16 deletion
+38
-16
src/config.ts
src/config.ts
+4
-0
src/puppet-padchat/pure-function-helpers/message-raw-payload-parser.ts
...dchat/pure-function-helpers/message-raw-payload-parser.ts
+15
-3
src/puppet-wechat4u/puppet-wechat4u.ts
src/puppet-wechat4u/puppet-wechat4u.ts
+10
-9
src/puppet/schemas/message.ts
src/puppet/schemas/message.ts
+1
-1
src/user/message.ts
src/user/message.ts
+4
-2
src/user/room.ts
src/user/room.ts
+4
-1
未找到文件。
src/config.ts
浏览文件 @
8cf61158
...
...
@@ -214,6 +214,10 @@ export interface Sayable {
say
(
text
:
string
,
replyTo
?:
any
|
any
[]):
Promise
<
void
>
}
// http://jkorpela.fi/chars/spaces.html
// String.fromCharCode(8197)
export
const
FOUR_PER_EM_SPACE
=
String
.
fromCharCode
(
0x2005
)
export
{
log
,
Raven
,
...
...
src/puppet-padchat/pure-function-helpers/message-raw-payload-parser.ts
浏览文件 @
8cf61158
...
...
@@ -2,7 +2,7 @@
import
{
MessagePayload
,
//
MessageType,
MessageType
,
}
from
'
../../puppet/
'
import
{
...
...
@@ -37,7 +37,19 @@ export function messageRawPayloadParser(
id
:
rawPayload
.
msg_id
,
timestamp
:
rawPayload
.
timestamp
,
// Padchat message timestamp is seconds
type
:
type
,
filename
:
messageFileName
(
rawPayload
)
||
undefined
,
}
as
{
id
:
string
,
timestamp
:
number
,
type
:
MessageType
,
filename
?
:
string
,
}
if
(
type
===
MessageType
.
Image
||
type
===
MessageType
.
Audio
||
type
===
MessageType
.
Video
||
type
===
MessageType
.
Attachment
)
{
payloadBase
.
filename
=
messageFileName
(
rawPayload
)
||
undefined
}
let
fromId
:
undefined
|
string
=
undefined
...
...
src/puppet-wechat4u/puppet-wechat4u.ts
浏览文件 @
8cf61158
...
...
@@ -22,7 +22,6 @@ import {
FileBox
,
}
from
'
file-box
'
// tslint:disable-next-line
import
Wechat4u
from
'
wechat4u
'
import
{
Misc
}
from
'
../misc
'
...
...
@@ -96,7 +95,7 @@ export type ScanFoodType = 'scan' | 'login' | 'logout'
// }
// MemoryCard Slot Name
const
SYNC_DATA_SLOT
=
'
wechat4u-sync-data
'
const
MEMORY_SLOT_NAME
=
'
puppet-wechat4u
'
export
class
PuppetWechat4u
extends
Puppet
{
...
...
@@ -111,7 +110,7 @@ export class PuppetWechat4u extends Puppet {
private
scanQrCode
?:
string
public
readonly
cacheMessageRawPayload
:
LRU
.
Cache
<
string
,
WebMessageRawPayload
>
public
readonly
cacheMessageRawPayload
:
LRU
.
Cache
<
string
,
WebMessageRawPayload
>
constructor
(
public
options
:
PuppetOptions
,
...
...
@@ -135,7 +134,7 @@ export class PuppetWechat4u extends Puppet {
this
.
state
.
on
(
'
pending
'
)
const
syncData
=
await
this
.
options
.
memory
.
get
(
SYNC_DATA_SLOT
)
const
syncData
=
await
this
.
options
.
memory
.
get
(
MEMORY_SLOT_NAME
)
if
(
syncData
)
{
this
.
wechat4u
=
new
Wechat4u
(
syncData
)
}
else
{
...
...
@@ -183,7 +182,7 @@ export class PuppetWechat4u extends Puppet {
}
await
this
.
login
(
userId
)
// 保存数据,将数据序列化之后保存到任意位置
await
this
.
options
.
memory
.
set
(
SYNC_DATA_SLOT
,
wechat4u
.
botData
)
await
this
.
options
.
memory
.
set
(
MEMORY_SLOT_NAME
,
wechat4u
.
botData
)
await
this
.
options
.
memory
.
save
()
})
/**
...
...
@@ -194,7 +193,7 @@ export class PuppetWechat4u extends Puppet {
await
this
.
logout
()
}
// 清除数据
await
this
.
options
.
memory
.
delete
(
SYNC_DATA_SLOT
)
await
this
.
options
.
memory
.
delete
(
MEMORY_SLOT_NAME
)
await
this
.
options
.
memory
.
save
()
})
/**
...
...
@@ -524,7 +523,8 @@ export class PuppetWechat4u extends Puppet {
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWechat4u
'
,
'
messageSend(%s, %s)
'
,
receiver
,
text
)
const
id
=
receiver
.
contactId
||
receiver
.
roomId
// room first
const
id
=
receiver
.
roomId
||
receiver
.
contactId
if
(
!
id
)
{
throw
new
Error
(
'
no id
'
)
...
...
@@ -547,6 +547,7 @@ export class PuppetWechat4u extends Puppet {
):
Promise
<
void
>
{
log
.
verbose
(
'
PuppetWechat4u
'
,
'
messageSend(%s, %s)
'
,
receiver
,
file
)
// room first
const
id
=
receiver
.
roomId
||
receiver
.
contactId
if
(
!
id
)
{
...
...
@@ -597,7 +598,7 @@ export class PuppetWechat4u extends Puppet {
throw
new
Error
(
'
no rawPayload
'
)
}
const
id
=
receiver
.
contactId
||
receiver
.
room
Id
const
id
=
receiver
.
roomId
||
receiver
.
contact
Id
if
(
!
id
)
{
throw
new
Error
(
'
no id
'
)
...
...
src/puppet/schemas/message.ts
浏览文件 @
8cf61158
...
...
@@ -20,7 +20,7 @@ export interface MessagePayloadBase {
export
interface
MessagePayloadRoom
{
fromId
?
:
string
,
mentionIdList
?
:
string
[],
// Mentioned Contacts' Ids
//
mentionIdList? : string[], // Mentioned Contacts' Ids
roomId
:
string
,
toId
?
:
string
,
// if to is not set, then room must be set
}
...
...
src/user/message.ts
浏览文件 @
8cf61158
...
...
@@ -29,6 +29,7 @@ import {
import
{
log
,
Sayable
,
FOUR_PER_EM_SPACE
,
}
from
'
../config
'
import
{
Accessory
,
...
...
@@ -460,7 +461,8 @@ export class Message extends Accessory implements Sayable {
}
// define magic code `8197` to identify @xxx
const
AT_SEPRATOR
=
String
.
fromCharCode
(
8197
)
// const AT_SEPRATOR = String.fromCharCode(8197)
const
AT_SEPRATOR
=
FOUR_PER_EM_SPACE
const
atList
=
this
.
text
().
split
(
AT_SEPRATOR
)
// console.log('atList: ', atList)
...
...
src/user/room.ts
浏览文件 @
8cf61158
...
...
@@ -29,6 +29,7 @@ import {
Raven
,
Sayable
,
log
,
FOUR_PER_EM_SPACE
,
}
from
'
../config
'
import
{
Accessory
,
...
...
@@ -341,7 +342,9 @@ export class Room extends Accessory implements Sayable {
if
(
typeof
textOrContactOrFile
===
'
string
'
)
{
if
(
replyToList
.
length
>
0
)
{
const
AT_SEPRATOR
=
String
.
fromCharCode
(
8197
)
// const AT_SEPRATOR = String.fromCharCode(8197)
const
AT_SEPRATOR
=
FOUR_PER_EM_SPACE
const
mentionList
=
replyToList
.
map
(
c
=>
'
@
'
+
c
.
name
()).
join
(
AT_SEPRATOR
)
text
=
mentionList
+
'
'
+
textOrContactOrFile
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录