Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
3b556453
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,发现更多精彩内容 >>
提交
3b556453
编写于
6月 16, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean & add unit test to wechaty
上级
ef449f08
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
64 addition
and
29 deletion
+64
-29
src/puppet/index.ts
src/puppet/index.ts
+2
-6
src/puppet/schemas/puppet.ts
src/puppet/schemas/puppet.ts
+1
-4
src/wechaty.spec.ts
src/wechaty.spec.ts
+25
-6
src/wechaty.ts
src/wechaty.ts
+36
-13
未找到文件。
src/puppet/index.ts
浏览文件 @
3b556453
...
...
@@ -6,9 +6,5 @@ export * from './schemas/room'
export
*
from
'
./schemas/puppet
'
export
{
Puppet
,
}
from
'
./puppet
'
export
{
YOU
,
}
from
'
./schemas/puppet
'
Puppet
,
}
from
'
./puppet
'
src/puppet/schemas/puppet.ts
浏览文件 @
3b556453
import
{
MemoryCard
,
}
from
'
memory-card
'
import
{
MemoryCard
}
from
'
memory-card
'
/**
* This is used internally to as a placeholder for the bot name.
...
...
@@ -52,7 +50,6 @@ export type ChatEventName = keyof typeof CHAT_EVENT_DICT
export
const
PUPPET_EVENT_DICT
=
{
...
CHAT_EVENT_DICT
,
error
:
'
document can be writen at here
'
,
// heartbeat : 'document can be writen at here',
start
:
'
document can be writen at here
'
,
stop
:
'
document can be writen at here
'
,
watchdog
:
'
document can be writen at here
'
,
...
...
src/wechaty.spec.ts
浏览文件 @
3b556453
...
...
@@ -42,10 +42,16 @@ import {
import
{
Puppet
,
}
from
'
./puppet/
'
}
from
'
./puppet/
'
import
{
PuppetMock
}
from
'
./puppet-mock
'
import
{
MemoryCard
}
from
'
memory-card
'
class
WechatyTest
extends
Wechaty
{
public
initPuppetAccessoryTest
(
puppet
:
Puppet
):
void
{
return
this
.
initPuppetAccessory
(
puppet
)
}
}
test
(
'
Export of the Framework
'
,
async
t
=>
{
t
.
ok
(
Contact
,
'
should export Contact
'
)
t
.
ok
(
Friendship
,
'
should export Friendship
'
)
...
...
@@ -150,11 +156,6 @@ test('on(event, Function)', async t => {
})
test
(
'
initPuppetAccessory()
'
,
async
t
=>
{
class
WechatyTest
extends
Wechaty
{
public
initPuppetAccessoryTest
(
puppet
:
Puppet
):
void
{
return
this
.
initPuppetAccessory
(
puppet
)
}
}
const
wechatyTest
=
new
WechatyTest
()
const
puppet
=
new
PuppetMock
({
memory
:
new
MemoryCard
()
})
...
...
@@ -163,3 +164,21 @@ test('initPuppetAccessory()', async t => {
})
// TODO: add test for event args
test
.
only
(
'
Wechaty restart for many times
'
,
async
t
=>
{
const
wechaty
=
Wechaty
.
instance
({
puppet
:
'
mock
'
,
})
try
{
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
await
wechaty
.
start
()
await
wechaty
.
stop
()
t
.
pass
(
'
start/stop-ed at #
'
+
i
)
}
t
.
pass
(
'
Wechaty start/restart successed.
'
)
}
catch
(
e
)
{
t
.
fail
(
e
)
}
})
src/wechaty.ts
浏览文件 @
3b556453
...
...
@@ -437,10 +437,23 @@ export class Wechaty extends Accessory implements Sayable {
private
initPuppet
():
void
{
log
.
verbose
(
'
Wechaty
'
,
'
initPuppet(%s)
'
,
this
.
options
.
puppet
)
let
inited
=
false
try
{
inited
=
!!
this
.
puppet
}
catch
(
e
)
{
inited
=
false
}
if
(
inited
)
{
log
.
verbose
(
'
Wechaty
'
,
'
initPuppet(%s) had already been inited, no need to init twice
'
,
this
.
options
.
puppet
)
return
}
const
puppet
=
this
.
initPuppetResolver
(
this
.
options
.
puppet
)
this
.
initPuppetVersionSatisfy
(
puppet
)
this
.
initPuppetEventBridge
(
puppet
)
this
.
initPuppetAccessory
(
puppet
)
}
...
...
@@ -668,20 +681,20 @@ export class Wechaty extends Accessory implements Sayable {
/**
* 1. Set Wechaty
*/
this
.
Contact
.
wechaty
=
this
this
.
ContactSelf
.
wechaty
=
this
this
.
Friendship
.
wechaty
=
this
this
.
Message
.
wechaty
=
this
this
.
Room
.
wechaty
=
this
this
.
Contact
.
wechaty
=
this
this
.
ContactSelf
.
wechaty
=
this
this
.
Friendship
.
wechaty
=
this
this
.
Message
.
wechaty
=
this
this
.
Room
.
wechaty
=
this
/**
* 2. Set Puppet
*/
this
.
Contact
.
puppet
=
puppet
this
.
ContactSelf
.
puppet
=
puppet
this
.
Friendship
.
puppet
=
puppet
this
.
Message
.
puppet
=
puppet
this
.
Room
.
puppet
=
puppet
this
.
Contact
.
puppet
=
puppet
this
.
ContactSelf
.
puppet
=
puppet
this
.
Friendship
.
puppet
=
puppet
this
.
Message
.
puppet
=
puppet
this
.
Room
.
puppet
=
puppet
this
.
puppet
=
puppet
}
...
...
@@ -695,7 +708,7 @@ export class Wechaty extends Accessory implements Sayable {
* // do other stuff with bot here
*/
public
async
start
():
Promise
<
void
>
{
log
.
info
(
'
Wechaty
'
,
'
v%
s starting...
'
,
this
.
version
())
log
.
info
(
'
Wechaty
'
,
'
start() v%s i
s starting...
'
,
this
.
version
())
log
.
verbose
(
'
Wechaty
'
,
'
puppet: %s
'
,
this
.
options
.
puppet
)
log
.
verbose
(
'
Wechaty
'
,
'
profile: %s
'
,
this
.
options
.
profile
)
log
.
verbose
(
'
Wechaty
'
,
'
id: %s
'
,
this
.
id
)
...
...
@@ -724,7 +737,17 @@ export class Wechaty extends Accessory implements Sayable {
console
.
error
(
e
)
log
.
error
(
'
Wechaty
'
,
'
start() exception: %s
'
,
e
&&
e
.
message
)
Raven
.
captureException
(
e
)
throw
e
this
.
emit
(
'
error
'
,
e
)
try
{
await
this
.
stop
()
}
catch
(
e
)
{
log
.
error
(
'
Wechaty
'
,
'
start() stop() exception: %s
'
,
e
&&
e
.
message
)
Raven
.
captureException
(
e
)
this
.
emit
(
'
error
'
,
e
)
}
finally
{
return
}
}
this
.
on
(
'
heartbeat
'
,
()
=>
this
.
memoryCheck
())
...
...
@@ -747,7 +770,7 @@ export class Wechaty extends Accessory implements Sayable {
* await bot.stop()
*/
public
async
stop
():
Promise
<
void
>
{
log
.
verbose
(
'
Wechaty
'
,
'
stop()
'
)
log
.
info
(
'
Wechaty
'
,
'
stop() v%s is stoping ...
'
,
this
.
version
()
)
if
(
this
.
state
.
off
())
{
log
.
silly
(
'
Wechaty
'
,
'
stop() on an stopping/stopped instance
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录