Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
a6943178
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,体验更适合开发者的 AI 搜索 >>
提交
a6943178
编写于
2月 12, 2020
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
83c94888
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
31 addition
and
78 deletion
+31
-78
bin/io-client.ts
bin/io-client.ts
+2
-8
src/config.spec.ts
src/config.spec.ts
+0
-1
src/config.ts
src/config.ts
+19
-59
src/io.ts
src/io.ts
+1
-0
src/user/message.ts
src/user/message.ts
+1
-3
src/wechaty.ts
src/wechaty.ts
+8
-7
未找到文件。
bin/io-client.ts
浏览文件 @
a6943178
...
...
@@ -46,10 +46,7 @@ __________________________________________________
let
token
=
config
.
token
if
(
!
token
)
{
log
.
error
(
'
Client
'
,
'
token not found: please set WECHATY_TOKEN in environment before run io-client
'
)
// process.exit(-1)
token
=
config
.
default
.
DEFAULT_TOKEN
log
.
warn
(
'
Client
'
,
`set token to "
${
token
}
" for demo purpose`
)
throw
new
Error
(
'
token not found: please set WECHATY_TOKEN in environment before run io-client
'
)
}
console
.
info
(
welcome
)
...
...
@@ -63,14 +60,11 @@ const client = new IoClient({
client
.
start
()
.
catch
(
onError
.
bind
(
client
))
// client.initWeb()
// .catch(onError.bind(client))
async
function
onError
(
this
:
IoClient
,
e
:
Error
,
)
{
log
.
error
(
'
Client
'
,
'
initWeb
() fail: %s
'
,
e
)
log
.
error
(
'
Client
'
,
'
start
() fail: %s
'
,
e
)
await
this
.
quit
()
process
.
exit
(
-
1
)
}
src/config.spec.ts
浏览文件 @
a6943178
...
...
@@ -26,7 +26,6 @@ import { config } from './config'
test
(
'
important variables
'
,
async
t
=>
{
// t.true('puppet' in config, 'should exist `puppet` in Config')
t
.
true
(
'
apihost
'
in
config
,
'
should exist `apihost` in Config
'
)
t
.
true
(
'
profile
'
in
config
,
'
should exist `profile` in Config
'
)
t
.
true
(
'
token
'
in
config
,
'
should exist `token` in Config
'
)
// t.ok(config.default.DEFAULT_PUPPET , 'should export DEFAULT_PUPPET')
...
...
src/config.ts
浏览文件 @
a6943178
...
...
@@ -19,11 +19,8 @@
// tslint:disable-next-line:no-reference
/// <reference path="./typings.d.ts" />
import
fs
from
'
fs
'
import
os
from
'
os
'
import
path
from
'
path
'
import
qrImage
from
'
qr-image
'
import
Raven
from
'
raven
'
import
readPkgUp
from
'
read-pkg-up
'
...
...
@@ -34,7 +31,10 @@ import {
PuppetModuleName
,
PUPPET_NAME_DEFAULT
,
}
from
'
./puppet-config
'
import
{
VERSION
}
from
'
./version
'
import
{
VERSION
,
GIT_COMMIT_HASH
,
}
from
'
./version
'
const
pkg
=
readPkgUp
.
sync
({
cwd
:
__dirname
})
!
.
packageJson
...
...
@@ -50,7 +50,7 @@ Raven
{
release
:
VERSION
,
tags
:
{
git_commit
:
''
,
git_commit
:
GIT_COMMIT_HASH
,
platform
:
process
.
env
.
WECHATY_DOCKER
?
'
docker
'
:
os
.
platform
(),
...
...
@@ -82,6 +82,7 @@ if (logLevel) {
*/
if
(
log
.
level
()
===
'
verbose
'
||
log
.
level
()
===
'
silly
'
)
{
log
.
info
(
'
Config
'
,
'
registering process.on("unhandledRejection") for development/debug
'
)
process
.
on
(
'
unhandledRejection
'
,
(
reason
,
promise
)
=>
{
log
.
error
(
'
Config
'
,
'
###########################
'
)
log
.
error
(
'
Config
'
,
'
unhandledRejection: %s %s
'
,
reason
,
promise
)
...
...
@@ -91,15 +92,19 @@ if (log.level() === 'verbose' || log.level() === 'silly') {
console
.
error
(
'
Config
'
,
err
)
// I don't know if log.error has similar full trace print support like console.error
})
})
process
.
on
(
'
uncaughtException
'
,
function
(
error
)
{
const
origin
=
arguments
[
1
]
// to compatible with node 12 or below version typings
log
.
error
(
'
Config
'
,
'
###########################
'
)
log
.
error
(
'
Config
'
,
'
uncaughtException: %s %s
'
,
error
,
origin
)
log
.
error
(
'
Config
'
,
'
###########################
'
)
})
}
export
interface
DefaultSetting
{
DEFAULT_HEAD
:
number
,
DEFAULT_PORT
:
number
,
// DEFAULT_PUPPET : PuppetName,
DEFAULT_APIHOST
:
string
,
// DEFAULT_PROFILE : string,
DEFAULT_TOKEN
:
string
,
DEFAULT_PROTOCOL
:
string
,
}
...
...
@@ -109,8 +114,7 @@ export class Config {
public
default
=
DEFAULT_SETTING
public
apihost
=
process
.
env
.
WECHATY_APIHOST
||
DEFAULT_SETTING
.
DEFAULT_APIHOST
public
head
=
(
'
WECHATY_HEAD
'
in
process
.
env
)
?
(
!!
process
.
env
.
WECHATY_HEAD
)
:
(
!!
(
DEFAULT_SETTING
.
DEFAULT_HEAD
))
public
apihost
=
process
.
env
.
WECHATY_APIHOST
||
DEFAULT_SETTING
.
DEFAULT_APIHOST
public
systemPuppetName
():
PuppetModuleName
{
return
(
...
...
@@ -118,59 +122,19 @@ export class Config {
).
toLowerCase
()
as
PuppetModuleName
}
// DEPRECATED: Use WECHATY_NAME instead
public
profile
=
process
.
env
.
WECHATY_PROFILE
public
name
=
process
.
env
.
WECHATY_NAME
public
name
=
process
.
env
.
WECHATY_NAME
||
process
.
env
.
WECHATY_PROFILE
// replace WECHATY_PROFILE
// DO NOT set DEFAULT, because sometimes user do not want to connect to io cloud service
public
token
=
process
.
env
.
WECHATY_TOKEN
public
token
=
process
.
env
.
WECHATY_TOKEN
// DO NOT set DEFAULT, because sometimes user do not want to connect to io cloud service
public
debug
=
!!
(
process
.
env
.
WECHATY_DEBUG
)
public
httpPort
=
process
.
env
.
PORT
||
process
.
env
.
WECHATY_PORT
||
DEFAULT_SETTING
.
DEFAULT_PORT
public
docker
=
!!
(
process
.
env
.
WECHATY_DOCKER
)
// private _puppetInstance: Puppet | null = null
constructor
()
{
log
.
verbose
(
'
Config
'
,
'
constructor()
'
)
this
.
validApiHost
(
this
.
apihost
)
if
(
this
.
profile
)
{
log
.
warn
(
'
Config
'
,
'
constructor() WECHATY_PROFILE is DEPRECATED, use WECHATY_NAME instead.
'
)
}
}
public
gitRevision
():
string
|
null
{
const
dotGitPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
.git
'
)
// only for ts-node, not for dist
// const gitLogArgs = ['log', '--oneline', '-1']
// TODO: use git rev-parse HEAD ?
const
gitArgs
=
[
'
rev-parse
'
,
'
HEAD
'
]
try
{
// Make sure this is a Wechaty repository
fs
.
statSync
(
dotGitPath
).
isDirectory
()
const
ss
=
require
(
'
child_process
'
)
.
spawnSync
(
'
git
'
,
gitArgs
,
{
cwd
:
__dirname
})
if
(
ss
.
status
!==
0
)
{
throw
new
Error
(
ss
.
error
)
}
const
revision
=
ss
.
stdout
.
toString
()
.
trim
()
.
slice
(
0
,
7
)
return
revision
}
catch
(
e
)
{
/* fall safe */
/**
* 1. .git not exist
* 2. git log fail
*/
log
.
silly
(
'
Wechaty
'
,
'
version() form development environment is not availble: %s
'
,
e
.
message
)
return
null
}
}
public
validApiHost
(
apihost
:
string
):
boolean
{
...
...
@@ -186,11 +150,7 @@ export const CHATIE_OFFICIAL_ACCOUNT_ID = 'gh_051c89260e5d'
export
function
qrCodeForChatie
():
FileBox
{
const
CHATIE_OFFICIAL_ACCOUNT_QRCODE
=
'
http://weixin.qq.com/r/qymXj7DEO_1ErfTs93y5
'
const
name
=
'
qrcode-for-chatie.png
'
const
type
=
'
png
'
const
qrStream
=
qrImage
.
image
(
CHATIE_OFFICIAL_ACCOUNT_QRCODE
,
{
type
})
return
FileBox
.
fromStream
(
qrStream
,
name
)
return
FileBox
.
fromQRCode
(
CHATIE_OFFICIAL_ACCOUNT_QRCODE
)
}
// http://jkorpela.fi/chars/spaces.html
...
...
src/io.ts
浏览文件 @
a6943178
...
...
@@ -150,6 +150,7 @@ export class Io {
this
.
state
.
on
(
true
)
return
}
catch
(
e
)
{
log
.
warn
(
'
Io
'
,
'
start() exception: %s
'
,
e
.
message
)
this
.
state
.
off
(
true
)
...
...
src/user/message.ts
浏览文件 @
a6943178
...
...
@@ -692,9 +692,7 @@ export class Message extends Accessory implements Sayable {
* define magic code `8197` to identify @xxx
* const AT_SEPRATOR = String.fromCharCode(8197)
*/
const
AT_SEPRATOR
=
AT_SEPRATOR_REGEX
const
atList
=
this
.
text
().
split
(
AT_SEPRATOR
)
const
atList
=
this
.
text
().
split
(
AT_SEPRATOR_REGEX
)
// console.log('atList: ', atList)
if
(
atList
.
length
===
0
)
return
[]
...
...
src/wechaty.ts
浏览文件 @
a6943178
...
...
@@ -57,9 +57,13 @@ import {
isProduction
,
log
,
Raven
,
VERSION
,
}
from
'
./config
'
import
{
VERSION
,
GIT_COMMIT_HASH
,
}
from
'
./version
'
import
{
AnyFunction
,
Sayable
,
...
...
@@ -1067,12 +1071,9 @@ export class Wechaty extends Accessory implements Sayable {
/**
* @ignore
*/
public
static
version
(
forceNpm
=
false
):
string
{
if
(
!
forceNpm
)
{
const
revision
=
config
.
gitRevision
()
if
(
revision
)
{
return
`#git[
${
revision
}
]`
}
public
static
version
(
gitHash
=
false
):
string
{
if
(
gitHash
&&
GIT_COMMIT_HASH
)
{
return
`#git[
${
GIT_COMMIT_HASH
}
]`
}
return
VERSION
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录