提交 00fb2905 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

send message to self when receive SIGTERM

上级 f6e6603c
......@@ -81,9 +81,9 @@ bot
.on('message', async m => {
try {
const room = m.room()
console.log((room ? '[' + room.topic() + ']' : '')
+ '<' + m.from().name() + '>'
+ ':' + m.toStringDigest(),
console.log(
(room ? `${room}` : '')
+ `${m.from()}:${m}`,
)
if (/^(ding|ping|bing|code)$/i.test(m.content()) && !m.self()) {
......@@ -119,11 +119,31 @@ bot.on('error', async e => {
await bot.stop()
})
let quiting = false
finis(async (code, signal) => {
const exitMsg = `Wechaty exit ${code} because of ${signal} `
console.log(exitMsg)
if (quiting) {
log.warn('Bot', 'finis(%s, %s) called when quiting... just wait...', code, signal)
return
}
quiting = true
log.info('Bot', 'finis(%s, %s)', code, signal)
const exitMsg = `Wechaty will exit ${code} because of ${signal} `
if (bot.logonoff()) {
log.info('Bot', 'finis() stoping bot')
await bot.say(exitMsg).catch(console.error)
} else {
log.info('Bot', 'finis() bot had been already stopped')
}
process.exit(code)
setTimeout(async () => {
log.info('Bot', 'finis() setTimeout() going to exit with %d', code)
try {
if (bot.logonoff()) {
await bot.stop()
}
} catch (e) {
log.error('Bot', 'finis() setTimeout() exception: %s', e)
} finally {
process.exit(code)
}
}, 3 * 1000)
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册