From 9711eb8da3a1cb4fa4dfd23792bb989013040a5b Mon Sep 17 00:00:00 2001 From: chentianyu Date: Mon, 9 Oct 2023 21:49:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=99=BB=E5=BD=95Api=20user=20=E5=80=BC=E4=B8=BAundefined?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/route/loginCheck.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/route/loginCheck.js b/src/route/loginCheck.js index ed569a7..a4b0ff3 100644 --- a/src/route/loginCheck.js +++ b/src/route/loginCheck.js @@ -4,6 +4,7 @@ const { TextMsg } = require('../utils/msg') // 登录 module.exports = function registerLoginCheck({ app, bot }) { let message, + currentUser = null, logOutWhenError = false, success = false @@ -11,10 +12,12 @@ module.exports = function registerLoginCheck({ app, bot }) { .on('scan', qrcode => { message = 'https://wechaty.js.org/qrcode/' + encodeURIComponent(qrcode) success = false + currentUser = null }) .on('login', user => { message = user + 'is already login' success = true + currentUser = user logOutWhenError = false sendMsg2RecvdApi(new TextMsg({ text: JSON.stringify({ event: 'login', user }), @@ -23,6 +26,7 @@ module.exports = function registerLoginCheck({ app, bot }) { }) .on('logout', user => { message = '' + currentUser = null success = false // 登出时给接收消息api发送特殊文本 sendMsg2RecvdApi(new TextMsg({ @@ -33,19 +37,20 @@ module.exports = function registerLoginCheck({ app, bot }) { .on('error', error => { // 报错时接收特殊文本 sendMsg2RecvdApi(new TextMsg({ - text: JSON.stringify({ event: 'error', error }), + text: JSON.stringify({ event: 'error', error, user: currentUser }), isSystemEvent: true })) // 处理异常错误后的登出上报,每次登录成功后掉线只上报一次 if (!logOutWhenError && !bot.isLoggedIn) { - logOutWhenError = true - success = false - message = '' sendMsg2RecvdApi(new TextMsg({ - text: JSON.stringify({ event: 'logout', user }), + text: JSON.stringify({ event: 'logout', user: currentUser }), isSystemEvent: true })) + success = false + message = '' + logOutWhenError = true + currentUser = null } })