Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.Veneno.
wechaty
提交
89098db5
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,发现更多精彩内容 >>
提交
89098db5
编写于
5月 26, 2018
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable tsconfig **strict** mode (#1180)
上级
82d50e9f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
81 addition
and
36 deletion
+81
-36
examples/friend-bot.ts
examples/friend-bot.ts
+1
-1
src/contact.ts
src/contact.ts
+1
-1
src/io.ts
src/io.ts
+13
-3
src/profile.ts
src/profile.ts
+17
-14
src/puppet-puppeteer/bridge.ts
src/puppet-puppeteer/bridge.ts
+34
-2
src/puppet-puppeteer/puppet-puppeteer.ts
src/puppet-puppeteer/puppet-puppeteer.ts
+9
-13
src/puppet/puppet.ts
src/puppet/puppet.ts
+5
-2
tsconfig.json
tsconfig.json
+1
-0
未找到文件。
examples/friend-bot.ts
浏览文件 @
89098db5
...
...
@@ -95,7 +95,7 @@ bot
*/
case
FriendRequest
.
Type
.
Receive
:
if
(
request
.
hello
()
===
'
ding
'
)
{
logMsg
=
'
accepted because verify messsage is "ding"
'
logMsg
=
'
accepted
automatically
because verify messsage is "ding"
'
request
.
accept
()
}
else
{
...
...
src/contact.ts
浏览文件 @
89098db5
...
...
@@ -193,7 +193,7 @@ export class Contact extends PuppetAccessory implements Sayable {
// log.verbose('Cotnact', 'findAll({ name: %s })', query.name)
log
.
verbose
(
'
Cotnact
'
,
'
findAll({ %s })
'
,
Object
.
keys
(
query
)
.
map
(
(
k
:
keyof
ContactQueryFilter
)
=>
`
${
k
}
:
${
query
[
k
]}
`
)
.
map
(
k
=>
`
${
k
}
:
${
query
[
k
as
keyof
ContactQueryFilter
]}
`
)
.
join
(
'
,
'
),
)
...
...
src/io.ts
浏览文件 @
89098db5
...
...
@@ -68,14 +68,14 @@ export class Io {
private
readonly
cuid
:
string
private
readonly
protocol
:
string
private
eventBuffer
:
IoEvent
[]
=
[]
private
ws
:
WebSocket
private
ws
:
undefined
|
WebSocket
private
readonly
state
=
new
StateSwitch
(
'
Io
'
,
log
)
private
reconnectTimer
?
:
NodeJS
.
Timer
private
reconnectTimeout
?
:
number
private
onMessage
:
Function
private
onMessage
:
undefined
|
Function
private
scanData
:
ScanData
...
...
@@ -392,6 +392,12 @@ export class Io {
}
private
async
send
(
ioEvent
?:
IoEvent
):
Promise
<
void
>
{
if
(
!
this
.
ws
)
{
throw
new
Error
(
'
no ws
'
)
}
const
ws
=
this
.
ws
if
(
ioEvent
)
{
log
.
silly
(
'
Io
'
,
'
send(%s: %s)
'
,
ioEvent
.
name
,
ioEvent
.
payload
)
this
.
eventBuffer
.
push
(
ioEvent
)
...
...
@@ -404,7 +410,7 @@ export class Io {
const
list
:
Promise
<
any
>
[]
=
[]
while
(
this
.
eventBuffer
.
length
)
{
const
p
=
new
Promise
((
resolve
,
reject
)
=>
this
.
ws
.
send
(
const
p
=
new
Promise
((
resolve
,
reject
)
=>
ws
.
send
(
JSON
.
stringify
(
this
.
eventBuffer
.
shift
(),
),
...
...
@@ -425,6 +431,10 @@ export class Io {
}
public
async
quit
():
Promise
<
void
>
{
if
(
!
this
.
ws
)
{
throw
new
Error
(
'
no ws
'
)
}
this
.
state
.
off
(
'
pending
'
)
// try to send IoEvents in buffer
...
...
src/profile.ts
浏览文件 @
89098db5
...
...
@@ -25,14 +25,15 @@ import {
}
from
'
./config
'
export
interface
ProfileSchema
{
cookies
?:
any
[]
cookies
?
:
any
[]
[
idx
:
string
]
:
any
}
export
type
ProfileSection
=
keyof
ProfileSchema
export
class
Profile
{
private
obj
:
ProfileSchema
private
file
?
:
string
private
payload
:
ProfileSchema
private
file
?
:
string
constructor
(
public
name
=
config
.
profile
,
...
...
@@ -44,7 +45,7 @@ export class Profile {
}
else
{
this
.
file
=
path
.
isAbsolute
(
name
)
?
name
:
path
.
join
(
:
path
.
resolve
(
process
.
cwd
(),
name
,
)
...
...
@@ -52,6 +53,8 @@ export class Profile {
this
.
file
+=
'
.wechaty.json
'
}
}
this
.
payload
=
{}
}
public
toString
()
{
...
...
@@ -60,7 +63,7 @@ export class Profile {
public
async
load
():
Promise
<
void
>
{
log
.
verbose
(
'
Profile
'
,
'
load() file: %s
'
,
this
.
file
)
this
.
obj
=
{}
this
.
payload
=
{}
if
(
!
this
.
file
)
{
log
.
verbose
(
'
Profile
'
,
'
load() no file, NOOP
'
)
...
...
@@ -74,7 +77,7 @@ export class Profile {
const
text
=
fs
.
readFileSync
(
this
.
file
).
toString
()
try
{
this
.
obj
=
JSON
.
parse
(
text
)
this
.
payload
=
JSON
.
parse
(
text
)
}
catch
(
e
)
{
log
.
error
(
'
Profile
'
,
'
load() exception: %s
'
,
e
)
}
...
...
@@ -86,13 +89,13 @@ export class Profile {
log
.
verbose
(
'
Profile
'
,
'
save() no file, NOOP
'
)
return
}
if
(
!
this
.
obj
)
{
if
(
!
this
.
payload
)
{
log
.
verbose
(
'
Profile
'
,
'
save() no obj, NOOP
'
)
return
}
try
{
const
text
=
JSON
.
stringify
(
this
.
obj
)
const
text
=
JSON
.
stringify
(
this
.
payload
)
fs
.
writeFileSync
(
this
.
file
,
text
)
}
catch
(
e
)
{
log
.
error
(
'
Profile
'
,
'
save() exception: %s
'
,
e
)
...
...
@@ -102,23 +105,23 @@ export class Profile {
public
async
get
<
T
=
any
>
(
section
:
ProfileSection
):
Promise
<
null
|
T
>
{
log
.
verbose
(
'
Profile
'
,
'
get(%s)
'
,
section
)
if
(
!
this
.
obj
)
{
if
(
!
this
.
payload
)
{
return
null
}
return
this
.
obj
[
section
]
as
any
as
T
return
this
.
payload
[
section
]
as
any
as
T
}
public
async
set
(
section
:
ProfileSection
,
data
:
any
):
Promise
<
void
>
{
log
.
verbose
(
'
Profile
'
,
'
set(%s, %s)
'
,
section
,
data
)
if
(
!
this
.
obj
)
{
this
.
obj
=
{}
if
(
!
this
.
payload
)
{
this
.
payload
=
{}
}
this
.
obj
[
section
]
=
data
this
.
payload
[
section
]
=
data
}
public
async
destroy
():
Promise
<
void
>
{
log
.
verbose
(
'
Profile
'
,
'
destroy() file: %s
'
,
this
.
file
)
this
.
obj
=
{}
this
.
payload
=
{}
if
(
this
.
file
&&
fs
.
existsSync
(
this
.
file
))
{
fs
.
unlinkSync
(
this
.
file
)
this
.
file
=
undefined
...
...
src/puppet-puppeteer/bridge.ts
浏览文件 @
89098db5
...
...
@@ -57,8 +57,8 @@ export interface BridgeOptions {
}
export
class
Bridge
extends
EventEmitter
{
private
browser
:
Browser
private
page
:
Page
private
browser
:
undefined
|
Browser
private
page
:
undefined
|
Page
private
state
:
StateSwitch
constructor
(
...
...
@@ -276,6 +276,14 @@ export class Bridge extends EventEmitter {
public
async
quit
():
Promise
<
void
>
{
log
.
verbose
(
'
PuppetPuppeteerBridge
'
,
'
quit()
'
)
if
(
!
this
.
page
)
{
throw
new
Error
(
'
no page
'
)
}
if
(
!
this
.
browser
)
{
throw
new
Error
(
'
no browser
'
)
}
this
.
state
.
off
(
'
pending
'
)
try
{
...
...
@@ -644,6 +652,11 @@ export class Bridge extends EventEmitter {
?
''
:
'
,
'
+
args
.
join
(
'
,
'
),
)
if
(
!
this
.
page
)
{
throw
new
Error
(
'
no page
'
)
}
try
{
const
noWechaty
=
await
this
.
page
.
evaluate
(()
=>
{
return
typeof
WechatyBro
===
'
undefined
'
...
...
@@ -832,6 +845,11 @@ export class Bridge extends EventEmitter {
public
async
hostname
():
Promise
<
string
|
null
>
{
log
.
verbose
(
'
PuppetPuppeteerBridge
'
,
'
hostname()
'
)
if
(
!
this
.
page
)
{
throw
new
Error
(
'
no page
'
)
}
try
{
const
hostname
=
await
this
.
page
.
evaluate
(()
=>
location
.
hostname
)
as
string
log
.
silly
(
'
PuppetPuppeteerBridge
'
,
'
hostname() got %s
'
,
hostname
)
...
...
@@ -847,6 +865,10 @@ export class Bridge extends EventEmitter {
public
async
cookies
():
Promise
<
Cookie
[]
>
public
async
cookies
(
cookieList
?:
Cookie
[]):
Promise
<
void
|
Cookie
[]
>
{
if
(
!
this
.
page
)
{
throw
new
Error
(
'
no page
'
)
}
if
(
cookieList
)
{
try
{
await
this
.
page
.
setCookie
(...
cookieList
)
...
...
@@ -905,12 +927,22 @@ export class Bridge extends EventEmitter {
public
async
reload
():
Promise
<
void
>
{
log
.
verbose
(
'
PuppetPuppeteerBridge
'
,
'
reload()
'
)
if
(
!
this
.
page
)
{
throw
new
Error
(
'
no page
'
)
}
await
this
.
page
.
reload
()
return
}
public
async
evaluate
(
fn
:
()
=>
any
,
...
args
:
any
[]):
Promise
<
any
>
{
log
.
silly
(
'
PuppetPuppeteerBridge
'
,
'
evaluate()
'
)
if
(
!
this
.
page
)
{
throw
new
Error
(
'
no page
'
)
}
try
{
return
await
this
.
page
.
evaluate
(
fn
,
...
args
)
}
catch
(
e
)
{
...
...
src/puppet-puppeteer/puppet-puppeteer.ts
浏览文件 @
89098db5
...
...
@@ -47,7 +47,7 @@ import {
log
,
Raven
,
}
from
'
../config
'
import
Profile
from
'
../profile
'
//
import Profile from '../profile'
import
Misc
from
'
../misc
'
import
{
...
...
@@ -104,7 +104,11 @@ export class PuppetPuppeteer extends Puppet {
)
{
super
(
options
)
// this.fileId = 0
this
.
fileId
=
0
this
.
bridge
=
new
Bridge
({
head
:
config
.
head
,
profile
:
this
.
options
.
profile
,
})
const
SCAN_TIMEOUT
=
2
*
60
*
1000
// 2 minutes
this
.
scanWatchdog
=
new
Watchdog
<
ScanFoodType
>
(
SCAN_TIMEOUT
,
'
Scan
'
)
...
...
@@ -119,7 +123,7 @@ export class PuppetPuppeteer extends Puppet {
this
.
initWatchdog
()
this
.
initWatchdogForScan
()
this
.
bridge
=
await
this
.
initBridge
(
this
.
options
.
profile
)
this
.
bridge
=
await
this
.
initBridge
()
log
.
verbose
(
'
PuppetPuppeteer
'
,
'
initBridge() done
'
)
/**
...
...
@@ -275,7 +279,7 @@ export class PuppetPuppeteer extends Puppet {
}
}
public
async
initBridge
(
profile
:
Profile
):
Promise
<
Bridge
>
{
public
async
initBridge
():
Promise
<
Bridge
>
{
log
.
verbose
(
'
PuppetPuppeteer
'
,
'
initBridge()
'
)
if
(
this
.
state
.
off
())
{
...
...
@@ -284,14 +288,6 @@ export class PuppetPuppeteer extends Puppet {
throw
e
}
const
head
=
config
.
head
// we have to set this.bridge right now,
// because the Event.onXXX might arrive while we are initializing.
this
.
bridge
=
new
Bridge
({
head
,
profile
,
})
this
.
bridge
.
on
(
'
ding
'
,
Event
.
onDing
.
bind
(
this
))
this
.
bridge
.
on
(
'
error
'
,
e
=>
this
.
emit
(
'
error
'
,
e
))
this
.
bridge
.
on
(
'
log
'
,
Event
.
onLog
.
bind
(
this
))
...
...
@@ -749,7 +745,7 @@ export class PuppetPuppeteer extends Puppet {
):
string
{
log
.
verbose
(
'
PuppetPuppeteer
'
,
'
contactQueryFilterToFunctionString({ %s })
'
,
Object
.
keys
(
query
)
.
map
(
(
k
:
keyof
ContactQueryFilter
)
=>
`
${
k
}
:
${
query
[
k
]}
`
)
.
map
(
k
=>
`
${
k
}
:
${
query
[
k
as
keyof
ContactQueryFilter
]}
`
)
.
join
(
'
,
'
),
)
...
...
src/puppet/puppet.ts
浏览文件 @
89098db5
...
...
@@ -116,7 +116,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
/**
* childPkg stores the `package.json` that the NPM module who extends the `Puppet`
*/
private
readonly
childPkg
:
normalize
.
Package
private
readonly
childPkg
:
undefined
|
normalize
.
Package
constructor
(
public
options
:
PuppetOptions
,
...
...
@@ -209,7 +209,10 @@ export abstract class Puppet extends EventEmitter implements Sayable {
}
public
version
():
string
{
return
this
.
childPkg
.
version
if
(
this
.
childPkg
)
{
return
this
.
childPkg
.
version
}
return
'
0.0.0
'
}
/**
...
...
tsconfig.json
浏览文件 @
89098db5
...
...
@@ -3,6 +3,7 @@
"target"
:
"es6"
,
"module"
:
"commonjs"
,
"outDir"
:
"dist"
,
"strict"
:
true
,
"experimentalDecorators"
:
true
,
"emitDecoratorMetadata"
:
true
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录