Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.www.
wechaty
提交
db422d1d
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,发现更多精彩内容 >>
提交
db422d1d
编写于
3月 09, 2017
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:wechaty/wechaty
上级
47b7194e
df34d75f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
141 addition
and
8 deletion
+141
-8
README.md
README.md
+1
-0
example/hot-reload-bot/index.js
example/hot-reload-bot/index.js
+92
-0
example/hot-reload-bot/listener/friend.js
example/hot-reload-bot/listener/friend.js
+8
-0
example/hot-reload-bot/listener/login.js
example/hot-reload-bot/listener/login.js
+3
-0
example/hot-reload-bot/listener/message.js
example/hot-reload-bot/listener/message.js
+22
-0
example/hot-reload-bot/listener/scan.js
example/hot-reload-bot/listener/scan.js
+5
-0
package.json
package.json
+8
-8
src/config.ts
src/config.ts
+2
-0
未找到文件。
README.md
浏览文件 @
db422d1d
...
...
@@ -216,6 +216,7 @@ You can directly submit pull requests for documentation changes.
*
[
cherry-geqi
](
https://github.com/cherry-geqi
)
*
[
lijiarui
](
https://github.com/lijiarui
)
*
[
xinbenlv
](
https://github.com/xinbenlv
)
*
[
Gcaufy
](
https://github.com/Gcaufy
)
## Join us
...
...
example/hot-reload-bot/index.js
0 → 100644
浏览文件 @
db422d1d
/**
* Wechaty hot load dots demo
*
* DEV: docker run -ti -e --rm --volume="$(pwd)":/bot zixia/wechaty index.js
* PROD: docker run -ti -e NODE_ENV=production --rm --volume="$(pwd)":/bot zixia/wechaty index.js
*
* @author: Gcaufy
*
*/
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
const
Wechaty
=
require
(
'
wechaty
'
).
default
;
const
isProd
=
process
.
env
.
NODE_ENV
===
'
production
'
;
const
bot
=
Wechaty
.
instance
();
const
EVENT_LIST
=
[
'
scan
'
,
'
logout
'
,
'
login
'
,
'
friend
'
,
'
room-join
'
,
'
room-leave
'
,
'
room-topic
'
,
'
message
'
,
'
heartbeat
'
,
'
error
'
];
// Load lisenter
const
loadListener
=
(
evt
)
=>
{
let
fn
;
try
{
fn
=
require
(
`./listener/
${
evt
}
`
);
console
.
log
(
`binded listener:
${
evt
}
`
);
}
catch
(
e
)
{
fn
=
()
=>
void
0
;
if
(
e
.
toString
().
indexOf
(
'
Cannot find module
'
)
>
-
1
)
{
console
.
warn
(
`listener
${
evt
}
is not defined.`
);
}
else
{
console
.
error
(
e
);
}
}
return
fn
;
}
// purge require cache
const
purgeCache
=
(
moduleName
)
=>
{
var
mod
=
require
.
resolve
(
moduleName
);
if
(
mod
&&
((
mod
=
require
.
cache
[
mod
])
!==
undefined
))
{
(
function
traverse
(
mod
)
{
mod
.
children
.
forEach
(
function
(
child
)
{
traverse
(
child
);
});
delete
require
.
cache
[
mod
.
id
];
}(
mod
));
}
Object
.
keys
(
module
.
constructor
.
_pathCache
).
forEach
(
function
(
cacheKey
)
{
if
(
cacheKey
.
indexOf
(
moduleName
)
>
0
)
{
delete
module
.
constructor
.
_pathCache
[
cacheKey
];
}
});
};
let
eventHandler
=
{};
if
(
!
isProd
)
{
// start a watcher only if it's not production environment.
fs
.
watch
(
'
./listener
'
,
(
e
,
filename
)
=>
{
let
evt
=
filename
.
substring
(
0
,
filename
.
length
-
3
);
console
.
log
(
`
${
e
}
:
${
filename
}
`
);
if
(
EVENT_LIST
.
indexOf
(
evt
)
>
-
1
)
{
if
(
e
===
'
change
'
)
{
console
.
log
(
`
${
evt
}
listener reloaded.`
);
purgeCache
(
`./listener/
${
evt
}
`
);
// It may read an empty file, if not use setTimeout
setTimeout
(()
=>
{
bot
.
removeListener
(
evt
,
eventHandler
[
evt
]);
//console.log('filecontent: ' + fs.readFileSync(`./listener/${evt}.js`));
eventHandler
[
evt
]
=
loadListener
(
evt
);
bot
.
on
(
evt
,
eventHandler
[
evt
]);
},
1000
);
}
else
if
(
e
===
'
rename
'
)
{
console
.
log
(
`
${
evt
}
listener removed.`
);
bot
.
removeListener
(
evt
,
eventHandler
[
evt
]);
eventHandler
[
evt
]
=
()
=>
void
0
;
bot
.
on
(
evt
,
eventHandler
[
evt
]);
}
}
});
}
// Bind events
EVENT_LIST
.
forEach
(
evt
=>
{
eventHandler
[
evt
]
=
loadListener
(
evt
);
bot
.
on
(
evt
,
eventHandler
[
evt
]);
});
bot
.
init
();
\ No newline at end of file
example/hot-reload-bot/listener/friend.js
0 → 100644
浏览文件 @
db422d1d
exports
=
module
.
exports
=
async
function
onFriend
(
contact
,
request
)
{
if
(
request
){
let
name
=
contact
.
name
();
await
request
.
accept
();
console
.
log
(
`Contact:
${
name
}
send request
${
request
.
hello
}
`
);
}
}
example/hot-reload-bot/listener/login.js
0 → 100644
浏览文件 @
db422d1d
exports
=
module
.
exports
=
function
onLoging
(
user
)
{
console
.
log
(
`
${
user
}
login`
);
}
example/hot-reload-bot/listener/message.js
0 → 100644
浏览文件 @
db422d1d
exports
=
module
.
exports
=
async
function
onMessage
(
message
)
{
const
room
=
message
.
room
();
const
sender
=
message
.
from
();
const
content
=
message
.
content
();
const
topic
=
room
?
'
[
'
+
room
.
topic
()
+
'
]
'
:
''
;
console
.
log
(
`
${
topic
}
<
${
sender
.
name
()}
> :
${
message
.
toStringDigest
()}
`
);
if
(
message
.
self
()
||
room
)
{
console
.
log
(
'
message is sent from myself, or inside a room.
'
);
return
;
}
if
(
content
===
'
ding
'
)
{
message
.
say
(
'
thanks for ding me...
'
);
}
else
{
sender
.
say
(
'
auto reply.
'
);
return
;
}
}
\ No newline at end of file
example/hot-reload-bot/listener/scan.js
0 → 100644
浏览文件 @
db422d1d
exports
=
module
.
exports
=
function
onScan
(
url
,
code
)
{
let
loginUrl
=
url
.
replace
(
'
qrcode
'
,
'
l
'
);
require
(
'
qrcode-terminal
'
).
generate
(
loginUrl
);
console
.
log
(
url
);
}
\ No newline at end of file
package.json
浏览文件 @
db422d1d
...
...
@@ -102,7 +102,7 @@
"node"
:
">= 6.9.0"
},
"dependencies"
:
{
"
@types/selenium-webdriver
"
:
"
2.53.4
0
"
,
"
@types/selenium-webdriver
"
:
"
3.0.
0
"
,
"
@types/socket.io
"
:
"
1.4.28
"
,
"
body-parser
"
:
"
1.17.1
"
,
"
brolog
"
:
"
0.3.10
"
,
...
...
@@ -118,18 +118,18 @@
"
ws
"
:
"
2.2.0
"
},
"devDependencies"
:
{
"
@types/body-parser
"
:
"
0.0.34
"
,
"
@types/body-parser
"
:
"
1.16.0
"
,
"
@types/express
"
:
"
4.0.35
"
,
"
@types/fluent-ffmpeg
"
:
"
0.0.2
"
,
"
@types/mime
"
:
"
0.0.29
"
,
"
@types/node
"
:
"
7.0.
5
"
,
"
@types/node
"
:
"
7.0.
7
"
,
"
@types/request
"
:
"
0.0.41
"
,
"
@types/sinon
"
:
"
1.16.35
"
,
"
@types/ws
"
:
"
0.0.3
7
"
,
"
@types/ws
"
:
"
0.0.3
9
"
,
"
apiai
"
:
"
4.0.1
"
,
"
ava
"
:
"
0.18.2
"
,
"
babel-eslint
"
:
"
7.1.1
"
,
"
check-node-version
"
:
"
1.1.2
"
,
"
check-node-version
"
:
"
2.0.1
"
,
"
cookie-parser
"
:
"
1.4.3
"
,
"
coveralls
"
:
"
2.12.0
"
,
"
cross-env
"
:
"
3.2.3
"
,
...
...
@@ -137,19 +137,19 @@
"
eslint-plugin-ava
"
:
"
4.2.0
"
,
"
finis
"
:
"
0.0.2
"
,
"
fluent-ffmpeg
"
:
"
2.1.0
"
,
"
nyc
"
:
"
10.1.2
"
,
"
jsdoc-to-markdown
"
:
"
^3.0.0
"
,
"
nyc
"
:
"
10.1.0
"
,
"
qrcode-terminal
"
:
"
0.11.0
"
,
"
request
"
:
"
2.80.0
"
,
"
shx
"
:
"
0.2.2
"
,
"
sinon
"
:
"
2.0.0-pre.6
"
,
"
sloc
"
:
"
0.2.0
"
,
"
ts-node
"
:
"
2.1.0
"
,
"
tslint
"
:
"
4.5.
0
"
,
"
tslint
"
:
"
4.5.
1
"
,
"
tslint-jsdoc-rules
"
:
"
^0.1.2
"
,
"
tuling123-client
"
:
"
0.0.1
"
,
"
typescript
"
:
"
2.2.1
"
,
"
yarn
"
:
"
0.2
0.4
"
"
yarn
"
:
"
0.2
1.3
"
},
"files_comment__whitelist_npm_publish"
:
"http://stackoverflow.com/a/8617868/1123955"
,
"files"
:
[
...
...
src/config.ts
浏览文件 @
db422d1d
...
...
@@ -218,6 +218,7 @@ export {
/**
* to handle unhandled exceptions
*/
/*
process.on('unhandledRejection', (reason, promise) => {
log.error('Config', '###########################')
log.error('Config', 'unhandledRejection: %s %s', reason, promise)
...
...
@@ -226,3 +227,4 @@ process.on('unhandledRejection', (reason, promise) => {
log.error('Config', 'unhandledRejection::catch(%s)', err.message || err)
})
})
*/
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录