From eaf481799db64111e6e125d010531d89c195cce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Sun, 29 Dec 2024 15:44:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=BD=E8=B8=AA=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/umami.ts | 18 +++++++++++++----- src/framework/napcat.ts | 9 ++++++++- src/shell/base.ts | 7 +++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/common/umami.ts b/src/common/umami.ts index cde1ff67e..3faace4ac 100644 --- a/src/common/umami.ts +++ b/src/common/umami.ts @@ -2,17 +2,25 @@ import https from 'node:https'; import { napCatVersion } from './version'; export class umamiTrace { + static napcatVersion = napCatVersion; + static qqversion = '1.0.0'; + + static init(qqversion: string) { + this.qqversion = qqversion; + setInterval(() => { + this.trackEvent('heartbeat'); + }, 5 * 60 * 1000); + } + static trackEvent(eventName: string, info?: string) { const StatesData = { type: 'event', payload: { 'website': '596cbbb2-1740-4373-a807-cf3d0637bfa7', 'hostname': 'trace.napneko.icu', - 'language': process.env.LANG || 'en-US', - 'title': 'NapCat ' + napCatVersion, - 'url': '/' + napCatVersion + '/' + eventName, - 'referrer': 'https://trace.napneko.icu/' + napCatVersion, - 'info': info + 'title': 'NapCat ' + umamiTrace.napcatVersion, + 'url': '/' + umamiTrace.qqversion + '/' + umamiTrace.napcatVersion + '/' + eventName, + 'referrer': 'https://napcat.onebot.napneko.icu/' + umamiTrace.qqversion + '/' + umamiTrace.napcatVersion + '/' + info, } }; diff --git a/src/framework/napcat.ts b/src/framework/napcat.ts index 78e27d0d4..e6d749bb7 100644 --- a/src/framework/napcat.ts +++ b/src/framework/napcat.ts @@ -24,19 +24,26 @@ export async function NCoreInitFramework( ) { //在进入本层前是否登录未进行判断 console.log('NapCat Framework App Loading...'); - umamiTrace.trackEvent('framework/login'); + process.on('uncaughtException', (err) => { umamiTrace.trackEvent('framework/error', err.message); console.log('[NapCat] [Error] Unhandled Exception:', err.message); }); + process.on('unhandledRejection', (reason, promise) => { console.log('[NapCat] [Error] unhandledRejection:', reason); }); + process.on('exit', (code: number) => { + umamiTrace.trackEvent('framework/exit', code.toString()); + }); + const pathWrapper = new NapCatPathWrapper(); const logger = new LogWrapper(pathWrapper.logsPath); const basicInfoWrapper = new QQBasicInfoWrapper({ logger }); const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion()); + umamiTrace.init(basicInfoWrapper.getFullQQVesion()); + umamiTrace.trackEvent('framework/login'); //直到登录成功后,执行下一步 const selfInfo = await new Promise((resolveSelfInfo) => { const loginListener = new NodeIKernelLoginListener(); diff --git a/src/shell/base.ts b/src/shell/base.ts index 5b60770e9..121bc25c6 100644 --- a/src/shell/base.ts +++ b/src/shell/base.ts @@ -270,10 +270,13 @@ export async function NCoreInitShell() { const pathWrapper = new NapCatPathWrapper(); const logger = new LogWrapper(pathWrapper.logsPath); handleUncaughtExceptions(logger); - umamiTrace.trackEvent('shell/boot'); + process.on('exit', (code: number) => { + umamiTrace.trackEvent('framework/exit', code.toString()); + }); const basicInfoWrapper = new QQBasicInfoWrapper({ logger }); const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion()); - + umamiTrace.init(basicInfoWrapper.getFullQQVesion()); + umamiTrace.trackEvent('shell/boot'); const o3Service = wrapper.NodeIO3MiscService.get(); o3Service.addO3MiscListener(new NodeIO3MiscListener());