Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
40534f54
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,发现更多精彩内容 >>
提交
40534f54
编写于
10月 09, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#40 Typescript transition step 19: fix firer.ts & tslint
上级
e8a5bc51
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
59 deletion
+63
-59
src/puppet-web/firer.spec.ts
src/puppet-web/firer.spec.ts
+3
-3
src/puppet-web/firer.ts
src/puppet-web/firer.ts
+60
-56
未找到文件。
src/puppet-web/firer.spec.ts
浏览文件 @
40534f54
...
...
@@ -12,10 +12,10 @@
*/
import
{
test
}
from
'
ava
'
import
Contact
from
'
../contact
'
import
Message
from
'
../message
'
//
import Contact from '../contact'
//
import Message from '../message'
import
FriendRequest
from
'
./friend-request
'
//
import FriendRequest from './friend-request'
import
Firer
from
'
./firer
'
test
(
'
Firer smoking test
'
,
t
=>
{
...
...
src/puppet-web/firer.ts
浏览文件 @
40534f54
...
...
@@ -8,26 +8,25 @@
*
* Licenst: ISC
* https://github.com/wechaty/wechaty
*
*/
/**************************************
*
* Firer for Class PuppetWeb
*
* here `this` is a PuppetWeb Instance
*
***************************************/
const
util
=
require
(
'
util
'
)
const
fs
=
require
(
'
fs
'
)
// const co = require('co')
*/
// import * as util from 'util'
// import * as fs from 'fs'
/* tslint:disable:no-var-requires */
const
retryPromise
=
require
(
'
retry-promise
'
).
default
import
Contact
from
'
../contact
'
import
FriendRequest
from
'
./friend-request
'
import
Message
from
'
../message
'
// import Message from '../message'
import
log
from
'
../brolog-env
'
import
FriendRequest
from
'
./friend-request
'
/* tslint:disable:variable-name */
const
PuppetWebFirer
=
{
fireFriendConfirm
,
fireFriendRequest
...
...
@@ -89,18 +88,17 @@ function fireFriendConfirm(m) {
this
.
emit
(
'
friend
'
,
contact
)
}
/**
* try to find 'join' event for Room
*
1.
You've invited "李卓桓" to the group chat
You've invited "李卓桓.PreAngel、Bruce LEE" to the group chat
2.
"李卓桓.PreAngel" invited "Bruce LEE" to the group chat
"凌" invited "庆次、小桔妹" to the group chat
*/
function
checkRoomJoin
(
content
)
{
*
1.
*
You've invited "李卓桓" to the group chat
*
You've invited "李卓桓.PreAngel、Bruce LEE" to the group chat
*
2.
*
"李卓桓.PreAngel" invited "Bruce LEE" to the group chat
*
"凌" invited "庆次、小桔妹" to the group chat
*/
function
checkRoomJoin
(
content
)
:
[
string
|
string
[],
string
]
|
boolean
{
log
.
verbose
(
'
PuppetWebFirer
'
,
'
checkRoomJoin()
'
)
const
re
=
regexConfig
.
roomJoin
...
...
@@ -109,7 +107,7 @@ function checkRoomJoin(content) {
if
(
!
found
)
{
return
false
}
const
[
_
,
inviter
,
inviteeStr
]
=
found
const
[,
inviter
,
inviteeStr
]
=
found
// "凌" invited "庆次、小桔妹" to the group chat
const
inviteeList
=
inviteeStr
.
split
(
/、/
)
...
...
@@ -127,7 +125,7 @@ function fireRoomJoin(m) {
if
(
!
result
)
{
return
}
const
[
inviteeList
,
inviter
]
=
result
const
[
inviteeList
,
inviter
]
=
<
[
string
[],
string
]
>
result
let
inviterContact
,
inviteeContactList
=
[]
...
...
@@ -163,7 +161,9 @@ function fireRoomJoin(m) {
}
}
inviterContact
||
(
inviterContact
=
room
.
member
(
inviter
))
if
(
!
inviterContact
)
{
inviterContact
=
room
.
member
(
inviter
)
}
if
(
allDone
&&
inviterContact
)
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomJoin() resolve() inviteeContactList: %s, inviterContact: %s
'
...
...
@@ -176,7 +176,7 @@ function fireRoomJoin(m) {
,
inviteeContactList
.
join
(
'
,
'
)
,
inviterContact
)
return
Promise
.
reject
()
return
Promise
.
reject
(
'
not found(yet)
'
)
}
})
.
catch
(
e
=>
{
...
...
@@ -218,7 +218,7 @@ function checkRoomLeave(content) {
if
(
!
found
)
{
return
false
}
const
[
_
,
leaver
]
=
found
const
[,
leaver
]
=
found
return
leaver
}
...
...
@@ -233,41 +233,44 @@ function fireRoomLeave(m) {
const
room
=
m
.
room
()
let
leaverContact
=
room
.
member
(
leaver
)
leaverContact
||
co
.
call
(
this
,
function
*
()
{
const
max
=
20
const
backoff
=
300
const
timeout
=
max
*
(
backoff
*
max
)
/
2
// 20 / 300 => 63,000
if
(
!
leaverContact
)
{
yield
retryPromise
({
max
:
max
,
backoff
:
backoff
},
attempt
=>
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() retryPromise() attempt %d with timeout %d
'
,
attempt
,
timeout
)
co
.
call
(
this
,
function
*
()
{
const
max
=
20
const
backoff
=
300
const
timeout
=
max
*
(
backoff
*
max
)
/
2
// 20 / 300 => 63,000
return
room
.
refresh
()
.
then
(
_
=>
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
leaver: %s
'
,
leaver
)
yield
retryPromise
({
max
:
max
,
backoff
:
backoff
},
attempt
=>
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() retryPromise() attempt %d with timeout %d
'
,
attempt
,
timeout
)
leaverContact
=
room
.
member
(
leaver
)
return
room
.
refresh
()
.
then
(
_
=>
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
leaver: %s
'
,
leaver
)
if
(
leaverContact
)
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() resolve() leaverContact: %s
'
,
leaverContact
)
return
Promise
.
resolve
()
}
else
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() reject() leaver: %s
'
,
leaver
leaverContact
=
room
.
member
(
leaver
)
if
(
leaverContact
)
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() resolve() leaverContact: %s
'
,
leaverContact
)
return
Promise
.
reject
()
}
})
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() retryPromise() room.refresh() rejected: %s
'
,
e
&&
e
.
stack
||
e
)
throw
e
})
return
Promise
.
resolve
(
leaverContact
)
}
else
{
log
.
silly
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() reject() leaver: %s
'
,
leaver
)
return
Promise
.
reject
(
'
not found(yet)
'
)
}
})
.
catch
(
e
=>
{
log
.
error
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() retryPromise() room.refresh() rejected: %s
'
,
e
&&
e
.
stack
||
e
)
throw
e
})
})
}).
catch
(
e
=>
{
log
.
error
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() co exception: %s
'
,
e
&&
e
.
stack
||
e
)
})
}).
catch
(
e
=>
{
log
.
error
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() co exception: %s
'
,
e
&&
e
.
stack
||
e
)
})
}
if
(
!
leaverContact
)
{
log
.
error
(
'
PuppetWebFirer
'
,
'
fireRoomLeave() leaver not found for %s
'
,
leaver
)
...
...
@@ -282,14 +285,14 @@ function fireRoomLeave(m) {
})
}
function
checkRoomTopic
(
content
)
{
function
checkRoomTopic
(
content
)
:
[
string
,
string
]
|
boolean
{
const
re
=
regexConfig
.
roomTopic
const
found
=
content
.
match
(
re
)
if
(
!
found
)
{
return
false
}
const
[
_
,
changer
,
topic
]
=
found
const
[,
changer
,
topic
]
=
found
return
[
topic
,
changer
]
}
...
...
@@ -299,10 +302,11 @@ function fireRoomTopic(m) {
return
}
const
[
topic
,
changer
]
=
result
const
[
topic
,
changer
]
=
<
[
string
,
string
]
>
result
const
room
=
m
.
room
()
const
oldTopic
=
room
.
topic
()
let
changerContact
:
Contact
if
(
/^You$/
.
test
(
changer
))
{
changerContact
=
Contact
.
load
(
this
.
userId
)
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录