mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: umami 统计追踪
This commit is contained in:
41
src/common/umami.ts
Normal file
41
src/common/umami.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import https from 'node:https';
|
||||||
|
import { napCatVersion } from './version';
|
||||||
|
|
||||||
|
export class umamiTrace {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let request = https.request({
|
||||||
|
hostname: '104.19.42.72',// 固定 IP
|
||||||
|
port: 443,
|
||||||
|
path: '/api/send',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Host": "umami.napneko.icu",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": `Mozilla/5.0 Umami/${process.version}`
|
||||||
|
}
|
||||||
|
}, (res) => {
|
||||||
|
res.on('error', (error) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
res.on('data', (data) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
request.write(JSON.stringify(StatesData));
|
||||||
|
request.end();
|
||||||
|
}
|
||||||
|
}
|
@@ -30,6 +30,7 @@ import os from 'node:os';
|
|||||||
import { NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/core/listeners';
|
import { NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/core/listeners';
|
||||||
import { proxiedListenerOf } from '@/common/proxy-handler';
|
import { proxiedListenerOf } from '@/common/proxy-handler';
|
||||||
import { NTQQPacketApi } from './apis/packet';
|
import { NTQQPacketApi } from './apis/packet';
|
||||||
|
import { umamiTrace } from '@/common/umami';
|
||||||
export * from './wrapper';
|
export * from './wrapper';
|
||||||
export * from './types';
|
export * from './types';
|
||||||
export * from './services';
|
export * from './services';
|
||||||
@@ -152,7 +153,13 @@ export class NapCatCore {
|
|||||||
// Renamed from 'InitDataListener'
|
// Renamed from 'InitDataListener'
|
||||||
async initNapCatCoreListeners() {
|
async initNapCatCoreListeners() {
|
||||||
const msgListener = new NodeIKernelMsgListener();
|
const msgListener = new NodeIKernelMsgListener();
|
||||||
|
|
||||||
msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => {
|
msgListener.onKickedOffLine = (Info: KickedOffLineInfo) => {
|
||||||
|
if (this.context.workingEnv === NapCatCoreWorkingEnv.Framework) {
|
||||||
|
umamiTrace.trackEvent('framework/kickoff');
|
||||||
|
} else {
|
||||||
|
umamiTrace.trackEvent('shell/kickoff');
|
||||||
|
}
|
||||||
// 下线通知
|
// 下线通知
|
||||||
this.context.logger.logError('[KickedOffLine] [' + Info.tipsTitle + '] ' + Info.tipsDesc);
|
this.context.logger.logError('[KickedOffLine] [' + Info.tipsTitle + '] ' + Info.tipsDesc);
|
||||||
this.selfInfo.online = false;
|
this.selfInfo.online = false;
|
||||||
|
@@ -9,6 +9,7 @@ import { NodeIKernelLoginService } from '@/core/services';
|
|||||||
import { NodeIQQNTWrapperSession, WrapperNodeApi } from '@/core/wrapper';
|
import { NodeIQQNTWrapperSession, WrapperNodeApi } from '@/core/wrapper';
|
||||||
import { InitWebUi, WebUiConfig } from '@/webui';
|
import { InitWebUi, WebUiConfig } from '@/webui';
|
||||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
|
import { umamiTrace } from '@/common/umami';
|
||||||
|
|
||||||
//Framework ES入口文件
|
//Framework ES入口文件
|
||||||
export async function getWebUiUrl() {
|
export async function getWebUiUrl() {
|
||||||
@@ -23,8 +24,9 @@ export async function NCoreInitFramework(
|
|||||||
) {
|
) {
|
||||||
//在进入本层前是否登录未进行判断
|
//在进入本层前是否登录未进行判断
|
||||||
console.log('NapCat Framework App Loading...');
|
console.log('NapCat Framework App Loading...');
|
||||||
|
umamiTrace.trackEvent('framework/login');
|
||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
|
umamiTrace.trackEvent('framework/error', err.message);
|
||||||
console.log('[NapCat] [Error] Unhandled Exception:', err.message);
|
console.log('[NapCat] [Error] Unhandled Exception:', err.message);
|
||||||
});
|
});
|
||||||
process.on('unhandledRejection', (reason, promise) => {
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
|
@@ -29,9 +29,11 @@ import { InitWebUi } from '@/webui';
|
|||||||
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
||||||
import { napCatVersion } from '@/common/version';
|
import { napCatVersion } from '@/common/version';
|
||||||
import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener';
|
import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener';
|
||||||
|
import { umamiTrace } from '@/common/umami';
|
||||||
// NapCat Shell App ES 入口文件
|
// NapCat Shell App ES 入口文件
|
||||||
async function handleUncaughtExceptions(logger: LogWrapper) {
|
async function handleUncaughtExceptions(logger: LogWrapper) {
|
||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
|
umamiTrace.trackEvent('framework/error', err.message);
|
||||||
logger.logError('[NapCat] [Error] Unhandled Exception:', err.message);
|
logger.logError('[NapCat] [Error] Unhandled Exception:', err.message);
|
||||||
});
|
});
|
||||||
process.on('unhandledRejection', (reason, promise) => {
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
@@ -222,7 +224,7 @@ async function handleLogin(
|
|||||||
logger.log(`可用于快速登录的 QQ:\n${historyLoginList
|
logger.log(`可用于快速登录的 QQ:\n${historyLoginList
|
||||||
.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
||||||
.join('\n')
|
.join('\n')
|
||||||
}`);
|
}`);
|
||||||
}
|
}
|
||||||
loginService.getQRCodePicture();
|
loginService.getQRCodePicture();
|
||||||
}
|
}
|
||||||
@@ -266,7 +268,7 @@ export async function NCoreInitShell() {
|
|||||||
const pathWrapper = new NapCatPathWrapper();
|
const pathWrapper = new NapCatPathWrapper();
|
||||||
const logger = new LogWrapper(pathWrapper.logsPath);
|
const logger = new LogWrapper(pathWrapper.logsPath);
|
||||||
handleUncaughtExceptions(logger);
|
handleUncaughtExceptions(logger);
|
||||||
|
umamiTrace.trackEvent('shell/boot');
|
||||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
||||||
|
|
||||||
@@ -297,7 +299,7 @@ export async function NCoreInitShell() {
|
|||||||
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
||||||
|
|
||||||
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
||||||
|
umamiTrace.trackEvent('shell/login');
|
||||||
const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
const amgomDataPiece = 'eb1fd6ac257461580dc7438eb099f23aae04ca679f4d88f53072dc56e3bb1129';
|
||||||
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
o3Service.setAmgomDataPiece(basicInfoWrapper.QQVersionAppid, new Uint8Array(Buffer.from(amgomDataPiece, 'hex')));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user