Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
3ba33137
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,发现更多精彩内容 >>
提交
3ba33137
编写于
10月 19, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#52
support `room-*` event for chinese wechat
上级
1d7d89be
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
38 deletion
+76
-38
package.json
package.json
+1
-1
src/puppet-web/firer.spec.ts
src/puppet-web/firer.spec.ts
+43
-21
src/puppet-web/firer.ts
src/puppet-web/firer.ts
+32
-16
未找到文件。
package.json
浏览文件 @
3ba33137
...
...
@@ -84,7 +84,7 @@
"dependencies"
:
{
"
arrify
"
:
"
^1.0.1
"
,
"
body-parser
"
:
"
^1.15.2
"
,
"
brolog
"
:
"
^0.3.
7
"
,
"
brolog
"
:
"
^0.3.
10
"
,
"
chromedriver
"
:
"
^2.23.1
"
,
"
express
"
:
"
^4.13.4
"
,
"
is-ci
"
:
"
^1.0.9
"
,
...
...
src/puppet-web/firer.spec.ts
浏览文件 @
3ba33137
...
...
@@ -12,11 +12,7 @@
*/
import
{
test
}
from
'
ava
'
// import Contact from '../contact'
// import Message from '../message'
// import FriendRequest from './friend-request'
import
Firer
from
'
./firer
'
import
Firer
from
'
./firer
'
test
(
'
Firer smoking test
'
,
t
=>
{
...
...
@@ -56,6 +52,11 @@ test('Firer.checkRoomJoin', t => {
,
`凌`
,
[
'
庆次
'
,
'
小桔妹
'
]
]
,
[
`你邀请"李佳芮"加入了群聊`
,
'
你
'
,
[
'
李佳芮
'
]
]
]
let
result
...
...
@@ -72,15 +73,23 @@ test('Firer.checkRoomJoin', t => {
})
test
(
'
Firer.checkRoomLeave
'
,
t
=>
{
const
data
=
[
`You removed "Bruce LEE" from the group chat`
,
`Bruce LEE`
const
contentList
=
[
[
`You removed "Bruce LEE" from the group chat`
,
`Bruce LEE`
]
,
[
'
你将"李佳芮"移出了群聊
'
,
'
李佳芮
'
]
]
let
leaver
leaver
=
Firer
.
checkRoomLeave
(
data
[
0
])
t
.
truthy
(
leaver
,
'
should get leaver for leave message
'
)
t
.
is
(
leaver
,
data
[
1
],
'
should get leaver name right
'
)
let
result
contentList
.
forEach
(([
content
,
leaver
])
=>
{
result
=
Firer
.
checkRoomLeave
(
content
)
t
.
truthy
(
result
,
'
should get leaver for leave message:
'
+
content
)
t
.
is
(
result
,
leaver
,
'
should get leaver name right
'
)
})
t
.
throws
(()
=>
{
Firer
.
checkRoomLeave
(
'
fafdsfsdfafa
'
)
...
...
@@ -88,16 +97,29 @@ test('Firer.checkRoomLeave', t => {
})
test
(
'
Firer.checkRoomTopic
'
,
t
=>
{
const
data
=
[
`"李卓桓.PreAngel" changed the group name to "ding"`
,
`李卓桓.PreAngel`
,
`ding`
const
contentList
=
[
[
`"李卓桓.PreAngel" changed the group name to "ding"`
,
`李卓桓.PreAngel`
,
`ding`
]
,
[
'
"李佳芮"修改群名为“dong”
'
,
'
李佳芮
'
,
'
dong
'
]
]
const
result
=
Firer
.
checkRoomTopic
(
data
[
0
])
t
.
truthy
(
result
,
'
should check topic right
'
)
let
result
contentList
.
forEach
(([
content
,
changer
,
topic
])
=>
{
result
=
Firer
.
checkRoomTopic
(
content
)
t
.
truthy
(
result
,
'
should check topic right for content:
'
+
content
)
t
.
is
(
topic
,
result
[
2
],
'
should get right topic
'
)
t
.
is
(
changer
,
result
[
1
],
'
should get right changer
'
)
})
t
.
throws
(()
=>
{
Firer
.
checkRoomTopic
(
'
fafdsfsdfafa
'
)
},
'
should throw if message is not expected
'
)
const
[
topic
,
changer
]
=
result
as
[
string
,
string
]
t
.
is
(
topic
,
data
[
2
],
'
should get right topic
'
)
t
.
is
(
changer
,
data
[
1
],
'
should get right changer
'
)
})
src/puppet-web/firer.ts
浏览文件 @
3ba33137
...
...
@@ -50,11 +50,22 @@ const PuppetWebFirer = {
}
const
regexConfig
=
{
friendConfirm
:
/^You have added
(
.+
)
as your WeChat contact. Start chatting!$/
,
roomJoin
:
/^"
?(
.+
?)
"
?
invited "
(
.+
)
" to the group chat$/
,
roomLeave
:
/^You removed "
(
.+
)
" from the group chat$/
,
roomTopic
:
/^"
?(
.+
?)
"
?
changed the group name to "
(
.+
)
"$/
friendConfirm
:
[
/^You have added
(
.+
)
as your WeChat contact. Start chatting!$/
]
,
roomJoin
:
[
/^"
?(
.+
?)
"
?
invited "
(
.+
)
" to the group chat$/
,
/^"
?(
.+
?)
"
?
邀请"
(
.+
)
"加入了群聊$/
]
,
roomLeave
:
[
/^You removed "
(
.+
)
" from the group chat$/
,
/^你将"
(
.+
)
"移出了群聊$/
]
,
roomTopic
:
[
/^"
?(
.+
?)
"
?
changed the group name to "
(
.+
)
"$/
,
/^"
?(
.+
?)
"
?
修改群名为“
(
.+
)
”$/
]
}
async
function
fireFriendRequest
(
m
:
Message
)
{
...
...
@@ -82,8 +93,10 @@ async function fireFriendRequest(m: Message) {
* try to find FriendRequest Confirmation Message
*/
function
checkFriendConfirm
(
content
)
{
const
re
=
regexConfig
.
friendConfirm
if
(
re
.
test
(
content
))
{
const
reList
=
regexConfig
.
friendConfirm
let
found
=
false
reList
.
some
(
re
=>
!!
(
found
=
re
.
test
(
content
)))
if
(
found
)
{
return
true
}
else
{
return
false
...
...
@@ -121,10 +134,11 @@ async function fireFriendConfirm(m: Message) {
function
checkRoomJoin
(
content
:
string
):
[
string
[],
string
]
{
log
.
verbose
(
'
PuppetWebFirer
'
,
'
checkRoomJoin()
'
)
const
re
=
regexConfig
.
roomJoin
const
re
List
=
regexConfig
.
roomJoin
const
found
=
content
.
match
(
re
)
if
(
!
found
)
{
let
found
:
string
[]
|
null
=
[]
reList
.
some
(
re
=>
!!
(
found
=
content
.
match
(
re
)))
if
(
!
found
||
!
found
.
length
)
{
throw
new
Error
(
'
checkRoomJoin() not found
'
)
}
...
...
@@ -249,10 +263,11 @@ async function fireRoomJoin(m: Message): Promise<void> {
}
function
checkRoomLeave
(
content
:
string
):
string
|
null
{
const
re
=
regexConfig
.
roomLeave
const
re
List
=
regexConfig
.
roomLeave
const
found
=
content
.
match
(
re
)
if
(
!
found
)
{
let
found
:
string
[]
|
null
=
[]
reList
.
some
(
re
=>
!!
(
found
=
content
.
match
(
re
)))
if
(
!
found
||
!
found
.
length
)
{
return
null
}
return
found
[
1
]
// leaver
...
...
@@ -290,10 +305,11 @@ async function fireRoomLeave(m: Message) {
}
function
checkRoomTopic
(
content
:
string
):
[
string
,
string
]
{
const
re
=
regexConfig
.
roomTopic
const
re
List
=
regexConfig
.
roomTopic
const
found
=
content
.
match
(
re
)
if
(
!
found
)
{
let
found
:
string
[]
|
null
=
[]
reList
.
some
(
re
=>
!!
(
found
=
content
.
match
(
re
)))
if
(
!
found
||
!
found
.
length
)
{
throw
new
Error
(
'
checkRoomTopic() not found
'
)
}
const
[,
changer
,
topic
]
=
found
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录