mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a2989d3b38 | ||
![]() |
fc731b60d5 | ||
![]() |
193980dd4a | ||
![]() |
73ea130e40 | ||
![]() |
5667e6aaee | ||
![]() |
fbd626131d | ||
![]() |
7b82444338 | ||
![]() |
8108b9f565 | ||
![]() |
c6ddd00cd9 | ||
![]() |
20c0c00fa0 | ||
![]() |
1f90364ba6 | ||
![]() |
49ea4d31a5 | ||
![]() |
dc35f1456a | ||
![]() |
0ebeb90804 | ||
![]() |
3ef5436c98 | ||
![]() |
de7996d789 | ||
![]() |
ac52d9bae2 | ||
![]() |
cb02df3b76 | ||
![]() |
5fc5a6f1a6 | ||
![]() |
726a0d0394 | ||
![]() |
6edf5345a3 | ||
![]() |
242bbfdb14 | ||
![]() |
89e7712676 | ||
![]() |
9525786929 | ||
![]() |
72088e41a8 | ||
![]() |
a3ed9ff2ef | ||
![]() |
ff16dc73ec | ||
![]() |
2da4ef5f0f | ||
![]() |
eaf481799d | ||
![]() |
1f72863aba | ||
![]() |
6b353fd8d8 | ||
![]() |
56cde4ad79 | ||
![]() |
3b86d3c632 | ||
![]() |
4ac7a25afb | ||
![]() |
8248011a12 | ||
![]() |
5f454456d2 | ||
![]() |
e99a619c23 | ||
![]() |
1fc791bb68 | ||
![]() |
f1d83f7c16 | ||
![]() |
527bb72bcf | ||
![]() |
d78409fd07 | ||
![]() |
d5e7e8944f | ||
![]() |
fb405a5c1c | ||
![]() |
a9e471deca | ||
![]() |
9cd15ae337 |
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCatQQ",
|
"name": "NapCatQQ",
|
||||||
"slug": "NapCat.Framework",
|
"slug": "NapCat.Framework",
|
||||||
"description": "高性能的 OneBot 11 协议实现",
|
"description": "高性能的 OneBot 11 协议实现",
|
||||||
"version": "4.2.41",
|
"version": "4.2.54",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "4.2.41",
|
"version": "4.2.54",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||||
|
@@ -175,10 +175,9 @@ export async function checkUriType(Uri: string) {
|
|||||||
return { Uri: Uri, Type: FileUriType.Unknown };
|
return { Uri: Uri, Type: FileUriType.Unknown };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uriToLocalFile(dir: string, uri: string): Promise<Uri2LocalRes> {
|
export async function uriToLocalFile(dir: string, uri: string, filename: string = randomUUID(), headers?: Record<string, string>): Promise<Uri2LocalRes> {
|
||||||
const { Uri: HandledUri, Type: UriType } = await checkUriType(uri);
|
const { Uri: HandledUri, Type: UriType } = await checkUriType(uri);
|
||||||
|
|
||||||
const filename = randomUUID();
|
|
||||||
const filePath = path.join(dir, filename);
|
const filePath = path.join(dir, filename);
|
||||||
|
|
||||||
switch (UriType) {
|
switch (UriType) {
|
||||||
@@ -191,7 +190,7 @@ export async function uriToLocalFile(dir: string, uri: string): Promise<Uri2Loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
case FileUriType.Remote: {
|
case FileUriType.Remote: {
|
||||||
const buffer = await httpDownload(HandledUri);
|
const buffer = await httpDownload({ url: HandledUri, headers: headers });
|
||||||
fs.writeFileSync(filePath, buffer, { flag: 'wx' });
|
fs.writeFileSync(filePath, buffer, { flag: 'wx' });
|
||||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||||
}
|
}
|
||||||
@@ -206,4 +205,4 @@ export async function uriToLocalFile(dir: string, uri: string): Promise<Uri2Loca
|
|||||||
default:
|
default:
|
||||||
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
129
src/common/umami.ts
Normal file
129
src/common/umami.ts
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import https from 'node:https';
|
||||||
|
import { napCatVersion } from './version';
|
||||||
|
import os from 'os';
|
||||||
|
export class UmamiTraceCore {
|
||||||
|
napcatVersion = napCatVersion;
|
||||||
|
qqversion = '1.0.0';
|
||||||
|
guid = 'default-user';
|
||||||
|
heartbeatInterval: NodeJS.Timeout | null = null;
|
||||||
|
website: string = '596cbbb2-1740-4373-a807-cf3d0637bfa7';
|
||||||
|
referrer: string = 'https://trace.napneko.icu/';
|
||||||
|
hostname: string = 'trace.napneko.icu';
|
||||||
|
ua: string = '';
|
||||||
|
workname: string = 'default';
|
||||||
|
init(qqversion: string, guid: string, workname: string) {
|
||||||
|
this.qqversion = qqversion;
|
||||||
|
this.workname = workname;
|
||||||
|
let UaList = {
|
||||||
|
'linux': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/124.0.0.0 Safari/537.36 PTST/240508.140043',
|
||||||
|
'win32': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.2128.93 Safari/537.36',
|
||||||
|
'darwin': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const ntVersion = os.release();
|
||||||
|
UaList.win32 = `Mozilla/5.0 (Windows NT ${ntVersion}; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.2128.93 Safari/537.36`;
|
||||||
|
} else if (process.platform === 'darwin') {
|
||||||
|
const macVersion = os.release();
|
||||||
|
UaList.darwin = `Mozilla/5.0 (Macintosh; Intel Mac OS X ${macVersion}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36`;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.ua = UaList.win32;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ua = UaList[process.platform as keyof typeof UaList] || UaList.win32;
|
||||||
|
|
||||||
|
this.identifyUser(guid);
|
||||||
|
this.startHeartbeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
identifyUser(guid: string) {
|
||||||
|
this.guid = guid;
|
||||||
|
const data = {
|
||||||
|
napcat_version: this.napcatVersion,
|
||||||
|
qq_version: this.qqversion,
|
||||||
|
guid: guid,
|
||||||
|
workname: this.workname,
|
||||||
|
};
|
||||||
|
this.sendRequest({ website: this.website, ...data }, 'identify');
|
||||||
|
}
|
||||||
|
|
||||||
|
sendEvent(event: string, data?: object) {
|
||||||
|
const env = process.env;
|
||||||
|
const language = env.LANG || env.LANGUAGE || env.LC_ALL || env.LC_MESSAGES;
|
||||||
|
const payload = {
|
||||||
|
name: event,
|
||||||
|
hostname: this.hostname,
|
||||||
|
referrer: this.referrer,
|
||||||
|
website: this.website,
|
||||||
|
language: language || 'en-US',
|
||||||
|
napcat_version: this.napcatVersion,
|
||||||
|
qq_version: this.qqversion,
|
||||||
|
workname: this.workname,
|
||||||
|
...data
|
||||||
|
};
|
||||||
|
this.sendRequest(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendTrace(eventName: string, data: string = '') {
|
||||||
|
const payload = {
|
||||||
|
website: this.website,
|
||||||
|
hostname: this.hostname,
|
||||||
|
title: 'NapCat ' + this.napcatVersion,
|
||||||
|
url: `/${this.qqversion}/${this.napcatVersion}/${this.workname}/${eventName}` + (!!data ? `?data=${data}` : ''),
|
||||||
|
referrer: this.referrer,
|
||||||
|
};
|
||||||
|
this.sendRequest(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRequest(payload: object, type = 'event') {
|
||||||
|
const options = {
|
||||||
|
hostname: '104.19.42.72', // 固定 IP 或者从 hostUrl 获取
|
||||||
|
port: 443,
|
||||||
|
path: '/api/send',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"Host": "umami.napneko.icu",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": this.ua
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const request = https.request(options, (res) => {
|
||||||
|
res.on('error', (error) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
res.on('data', (data) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
request.write(JSON.stringify({ type, payload }));
|
||||||
|
request.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
startHeartbeat() {
|
||||||
|
if (this.heartbeatInterval) {
|
||||||
|
clearInterval(this.heartbeatInterval);
|
||||||
|
}
|
||||||
|
this.heartbeatInterval = setInterval(() => {
|
||||||
|
this.sendEvent('heartbeat', {
|
||||||
|
title: 'NapCat ' + this.napcatVersion,
|
||||||
|
language: process.env.LANG || 'en-US',
|
||||||
|
url: `/${this.qqversion}/${this.napcatVersion}/${this.workname}/heartbeat`,
|
||||||
|
version: this.napcatVersion,
|
||||||
|
qq_version: this.qqversion,
|
||||||
|
user_id: this.guid
|
||||||
|
});
|
||||||
|
}, 5 * 60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
stopHeartbeat() {
|
||||||
|
if (this.heartbeatInterval) {
|
||||||
|
clearInterval(this.heartbeatInterval);
|
||||||
|
this.heartbeatInterval = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const UmamiTrace = new UmamiTraceCore();
|
@@ -1 +1 @@
|
|||||||
export const napCatVersion = '4.2.41';
|
export const napCatVersion = '4.2.54';
|
||||||
|
@@ -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.sendTrace('event/kickoff');
|
||||||
|
} else {
|
||||||
|
UmamiTrace.sendTrace('event/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;
|
||||||
|
@@ -56,6 +56,7 @@ export interface GrayTipElement {
|
|||||||
aioOpGrayTipElement: TipAioOpGrayTipElement;
|
aioOpGrayTipElement: TipAioOpGrayTipElement;
|
||||||
groupElement: TipGroupElement;
|
groupElement: TipGroupElement;
|
||||||
xmlElement: {
|
xmlElement: {
|
||||||
|
busiId: string;
|
||||||
content: string;
|
content: string;
|
||||||
templId: string;
|
templId: string;
|
||||||
};
|
};
|
||||||
|
@@ -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() {
|
||||||
@@ -25,8 +26,10 @@ export async function NCoreInitFramework(
|
|||||||
console.log('NapCat Framework App Loading...');
|
console.log('NapCat Framework App Loading...');
|
||||||
|
|
||||||
process.on('uncaughtException', (err) => {
|
process.on('uncaughtException', (err) => {
|
||||||
|
UmamiTrace.sendTrace('uncaught/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) => {
|
||||||
console.log('[NapCat] [Error] unhandledRejection:', reason);
|
console.log('[NapCat] [Error] unhandledRejection:', reason);
|
||||||
});
|
});
|
||||||
@@ -35,6 +38,10 @@ export async function NCoreInitFramework(
|
|||||||
const logger = new LogWrapper(pathWrapper.logsPath);
|
const logger = new LogWrapper(pathWrapper.logsPath);
|
||||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
||||||
|
let guid = loginService.getMachineGuid();
|
||||||
|
UmamiTrace.init(basicInfoWrapper.getFullQQVesion(), guid,'framework');
|
||||||
|
UmamiTrace.sendTrace('boot/init');
|
||||||
|
UmamiTrace.sendTrace('login/success');
|
||||||
//直到登录成功后,执行下一步
|
//直到登录成功后,执行下一步
|
||||||
const selfInfo = await new Promise<SelfInfo>((resolveSelfInfo) => {
|
const selfInfo = await new Promise<SelfInfo>((resolveSelfInfo) => {
|
||||||
const loginListener = new NodeIKernelLoginListener();
|
const loginListener = new NodeIKernelLoginListener();
|
||||||
|
@@ -2,7 +2,7 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
|||||||
import { ActionName } from '@/onebot/action/router';
|
import { ActionName } from '@/onebot/action/router';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { join as joinPath } from 'node:path';
|
import { join as joinPath } from 'node:path';
|
||||||
import { calculateFileMD5, httpDownload } from '@/common/file';
|
import { calculateFileMD5, uriToLocalFile } from '@/common/file';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { Static, Type } from '@sinclair/typebox';
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
@@ -26,17 +26,20 @@ export default class GoCQHTTPDownloadFile extends OneBotAction<Payload, FileResp
|
|||||||
async _handle(payload: Payload): Promise<FileResponse> {
|
async _handle(payload: Payload): Promise<FileResponse> {
|
||||||
const isRandomName = !payload.name;
|
const isRandomName = !payload.name;
|
||||||
const name = payload.name || randomUUID();
|
const name = payload.name || randomUUID();
|
||||||
const filePath = joinPath(this.core.NapCatTempPath, name);
|
let result: Awaited<ReturnType<typeof uriToLocalFile>>;
|
||||||
|
|
||||||
if (payload.base64) {
|
if (payload.base64) {
|
||||||
fs.writeFileSync(filePath, payload.base64, 'base64');
|
result = await uriToLocalFile(this.core.NapCatTempPath, `base64://${payload.base64}`, name);
|
||||||
} else if (payload.url) {
|
} else if (payload.url) {
|
||||||
const headers = this.getHeaders(payload.headers);
|
const headers = this.getHeaders(payload.headers);
|
||||||
const buffer = await httpDownload({ url: payload.url, headers: headers });
|
result = await uriToLocalFile(this.core.NapCatTempPath, payload.url, name, headers);
|
||||||
fs.writeFileSync(filePath, Buffer.from(buffer), 'binary');
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('不存在任何文件, 无法下载');
|
throw new Error('不存在任何文件, 无法下载');
|
||||||
}
|
}
|
||||||
|
if (!result.success) {
|
||||||
|
throw new Error(result.errMsg);
|
||||||
|
}
|
||||||
|
const filePath = result.path;
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
|
|
||||||
if (isRandomName) {
|
if (isRandomName) {
|
||||||
|
@@ -104,7 +104,8 @@ import { GetGuildList } from './guild/GetGuildList';
|
|||||||
import { GetGuildProfile } from './guild/GetGuildProfile';
|
import { GetGuildProfile } from './guild/GetGuildProfile';
|
||||||
import { GetClientkey } from './extends/GetClientkey';
|
import { GetClientkey } from './extends/GetClientkey';
|
||||||
import { SendPacket } from './extends/SendPacket';
|
import { SendPacket } from './extends/SendPacket';
|
||||||
|
import { SendPoke } from "@/onebot/action/packet/SendPoke";
|
||||||
|
|
||||||
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||||
|
|
||||||
const actionHandlers = [
|
const actionHandlers = [
|
||||||
@@ -220,6 +221,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
|||||||
new SendGroupAiRecord(obContext, core),
|
new SendGroupAiRecord(obContext, core),
|
||||||
new GetAiCharacters(obContext, core),
|
new GetAiCharacters(obContext, core),
|
||||||
new SendPacket(obContext, core),
|
new SendPacket(obContext, core),
|
||||||
|
new SendPoke(obContext, core),
|
||||||
];
|
];
|
||||||
|
|
||||||
type HandlerUnion = typeof actionHandlers[number];
|
type HandlerUnion = typeof actionHandlers[number];
|
||||||
|
23
src/onebot/action/packet/SendPoke.ts
Normal file
23
src/onebot/action/packet/SendPoke.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { ActionName } from '@/onebot/action/router';
|
||||||
|
import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus";
|
||||||
|
import { Static, Type } from '@sinclair/typebox';
|
||||||
|
|
||||||
|
const SchemaData = Type.Object({
|
||||||
|
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||||
|
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Payload = Static<typeof SchemaData>;
|
||||||
|
|
||||||
|
export class SendPoke extends GetPacketStatusDepends<Payload, any> {
|
||||||
|
actionName = ActionName.SendPoke;
|
||||||
|
payloadSchema = SchemaData;
|
||||||
|
|
||||||
|
async _handle(payload: Payload) {
|
||||||
|
if (payload.group_id) {
|
||||||
|
this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id);
|
||||||
|
} else {
|
||||||
|
this.core.apis.PacketApi.pkt.operation.FriendPoke(+payload.user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -145,4 +145,6 @@ export const ActionName = {
|
|||||||
SendGroupAiRecord: "send_group_ai_record",
|
SendGroupAiRecord: "send_group_ai_record",
|
||||||
|
|
||||||
GetClientkey: "get_clientkey",
|
GetClientkey: "get_clientkey",
|
||||||
|
|
||||||
|
SendPoke: 'send_poke',
|
||||||
} as const;
|
} as const;
|
||||||
|
@@ -8,6 +8,8 @@ import {
|
|||||||
NapCatCore,
|
NapCatCore,
|
||||||
NTGrayTipElementSubTypeV2,
|
NTGrayTipElementSubTypeV2,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
|
TipGroupElement,
|
||||||
|
TipGroupElementType,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
import { OB11GroupBanEvent } from '@/onebot/event/notice/OB11GroupBanEvent';
|
import { OB11GroupBanEvent } from '@/onebot/event/notice/OB11GroupBanEvent';
|
||||||
@@ -19,8 +21,10 @@ import { OB11GroupPokeEvent } from '@/onebot/event/notice/OB11PokeEvent';
|
|||||||
import { OB11GroupEssenceEvent } from '@/onebot/event/notice/OB11GroupEssenceEvent';
|
import { OB11GroupEssenceEvent } from '@/onebot/event/notice/OB11GroupEssenceEvent';
|
||||||
import { OB11GroupTitleEvent } from '@/onebot/event/notice/OB11GroupTitleEvent';
|
import { OB11GroupTitleEvent } from '@/onebot/event/notice/OB11GroupTitleEvent';
|
||||||
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
||||||
|
import { OB11GroupNameEvent } from '../event/notice/OB11GroupNameEvent';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
import { FileNapCatOneBotUUID } from '@/common/helper';
|
import { FileNapCatOneBotUUID } from '@/common/helper';
|
||||||
|
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||||
|
|
||||||
export class OneBotGroupApi {
|
export class OneBotGroupApi {
|
||||||
obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
@@ -204,13 +208,63 @@ export class OneBotGroupApi {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async parseGroupElement(msg: RawMessage, element: TipGroupElement, elementWrapper: GrayTipElement) {
|
||||||
|
if (element.type === TipGroupElementType.KGROUPNAMEMODIFIED) {
|
||||||
|
this.core.context.logger.logDebug('收到群名称变更事件', element);
|
||||||
|
return new OB11GroupNameEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
parseInt(await this.core.apis.UserApi.getUinByUidV2(element.memberUid)),
|
||||||
|
element.groupName,
|
||||||
|
);
|
||||||
|
} else if (element.type === TipGroupElementType.KSHUTUP) {
|
||||||
|
let event = await this.parseGroupBanEvent(msg.peerUid, elementWrapper);
|
||||||
|
return event;
|
||||||
|
} else if (element.type === TipGroupElementType.KMEMBERADD) {
|
||||||
|
// 自己的通知 协议推送为type->85 在这里实现为了避免邀请出现问题
|
||||||
|
if (element.memberUid == this.core.selfInfo.uid) {
|
||||||
|
this.core.apis.GroupApi.refreshGroupMemberCache(msg.peerUid).then().catch();
|
||||||
|
return new OB11GroupIncreaseEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
+this.core.selfInfo.uin,
|
||||||
|
element.adminUid ? +await this.core.apis.UserApi.getUinByUidV2(element.adminUid) : 0,
|
||||||
|
'approve'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async parseSelfInviteEvent(msg: RawMessage, inviterUin: string, inviteeUin: string) {
|
||||||
|
return new OB11GroupIncreaseEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
+inviteeUin,
|
||||||
|
+inviterUin,
|
||||||
|
'invite'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async parseGrayTipElement(msg: RawMessage, grayTipElement: GrayTipElement) {
|
async parseGrayTipElement(msg: RawMessage, grayTipElement: GrayTipElement) {
|
||||||
if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_GROUP) {
|
if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_GROUP) {
|
||||||
// 解析群组事件 由sysmsg解析
|
// 解析群组事件 由sysmsg解析
|
||||||
// return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement);
|
return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement);
|
||||||
|
|
||||||
} else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
} else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
||||||
// 筛选出表情回应 事件
|
// 筛选自身入群情况
|
||||||
|
// if (grayTipElement.xmlElement.busiId === '10145') {
|
||||||
|
// const inviteData = new fastXmlParser.XMLParser({
|
||||||
|
// ignoreAttributes: false,
|
||||||
|
// attributeNamePrefix: '',
|
||||||
|
// }).parse(grayTipElement.xmlElement.content);
|
||||||
|
|
||||||
|
// const inviterUin: string = inviteData.gtip.qq[0].jp;
|
||||||
|
// const inviteeUin: string = inviteData.gtip.qq[1].jp;
|
||||||
|
// //刷新群缓存
|
||||||
|
// if (inviteeUin === this.core.selfInfo.uin) {
|
||||||
|
// this.core.apis.GroupApi.refreshGroupMemberCache(msg.peerUid).then().catch();
|
||||||
|
// return this.parseSelfInviteEvent(msg, inviterUin, inviteeUin);
|
||||||
|
// }
|
||||||
|
// } else
|
||||||
if (grayTipElement.xmlElement?.templId === '10382') {
|
if (grayTipElement.xmlElement?.templId === '10382') {
|
||||||
return await this.obContext.apis.GroupApi.parseGroupEmojiLikeEventByGrayTip(msg.peerUid, grayTipElement);
|
return await this.obContext.apis.GroupApi.parseGroupEmojiLikeEventByGrayTip(msg.peerUid, grayTipElement);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -972,6 +972,7 @@ export class OneBotMsgApi {
|
|||||||
|
|
||||||
return { path, fileName: inputdata.name ?? fileName };
|
return { path, fileName: inputdata.name ?? fileName };
|
||||||
}
|
}
|
||||||
|
|
||||||
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 130:
|
case 130:
|
||||||
@@ -985,12 +986,41 @@ export class OneBotMsgApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async waitGroupNotify(groupUin: string, memberUid?: string, operatorUid?: string) {
|
||||||
|
let groupRole = this.core.apis.GroupApi.groupMemberCache.get(groupUin)?.get(this.core.selfInfo.uid.toString())?.role;
|
||||||
|
let isAdminOrOwner = groupRole === 3 || groupRole === 4;
|
||||||
|
|
||||||
|
if (isAdminOrOwner && !operatorUid) {
|
||||||
|
let dataNotify: GroupNotify | undefined;
|
||||||
|
await this.core.eventWrapper.registerListen('NodeIKernelGroupListener/onGroupNotifiesUpdated',
|
||||||
|
(doubt, notifies) => {
|
||||||
|
for (const notify of notifies) {
|
||||||
|
if (notify.group.groupCode === groupUin && notify.user1.uid === memberUid) {
|
||||||
|
dataNotify = notify;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}, 1, 1000).catch(undefined);
|
||||||
|
if (dataNotify) {
|
||||||
|
return !dataNotify.actionUser.uid ? dataNotify.user2.uid : dataNotify.actionUser.uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return operatorUid;
|
||||||
|
}
|
||||||
|
|
||||||
async parseSysMessage(msg: number[]) {
|
async parseSysMessage(msg: number[]) {
|
||||||
const SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg));
|
const SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg));
|
||||||
|
// 邀请需要解grayTipElement
|
||||||
if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) {
|
if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) {
|
||||||
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
||||||
this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch();
|
this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch();
|
||||||
const operatorUid = groupChange.operatorInfo?.toString();
|
let operatorUid = await this.waitGroupNotify(
|
||||||
|
groupChange.groupUin.toString(),
|
||||||
|
groupChange.memberUid,
|
||||||
|
groupChange.operatorInfo ? Buffer.from(groupChange.operatorInfo).toString() : ''
|
||||||
|
);
|
||||||
return new OB11GroupIncreaseEvent(
|
return new OB11GroupIncreaseEvent(
|
||||||
this.core,
|
this.core,
|
||||||
groupChange.groupUin,
|
groupChange.groupUin,
|
||||||
@@ -998,12 +1028,17 @@ export class OneBotMsgApi {
|
|||||||
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
|
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
|
||||||
groupChange.decreaseType == 131 ? 'invite' : 'approve',
|
groupChange.decreaseType == 131 ? 'invite' : 'approve',
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) {
|
} else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) {
|
||||||
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
||||||
// 自身被踢出时operatorInfo会是一个protobuf 否则大多数情况为一个string
|
// 自身被踢出时operatorInfo会是一个protobuf 否则大多数情况为一个string
|
||||||
const operatorUid = groupChange.decreaseType === 3 && groupChange.operatorInfo ?
|
let operatorUid = await this.waitGroupNotify(
|
||||||
new NapProtoMsg(GroupChangeInfo).decode(groupChange.operatorInfo).operator?.operatorUid :
|
groupChange.groupUin.toString(),
|
||||||
groupChange.operatorInfo?.toString();
|
groupChange.memberUid,
|
||||||
|
groupChange.decreaseType === 3 && groupChange.operatorInfo ?
|
||||||
|
new NapProtoMsg(GroupChangeInfo).decode(groupChange.operatorInfo).operator?.operatorUid :
|
||||||
|
groupChange.operatorInfo?.toString()
|
||||||
|
);
|
||||||
if (groupChange.memberUid === this.core.selfInfo.uid) {
|
if (groupChange.memberUid === this.core.selfInfo.uid) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.core.apis.GroupApi.groupMemberCache.delete(groupChange.groupUin.toString());
|
this.core.apis.GroupApi.groupMemberCache.delete(groupChange.groupUin.toString());
|
||||||
@@ -1103,8 +1138,7 @@ export class OneBotMsgApi {
|
|||||||
'',
|
'',
|
||||||
request_seq
|
request_seq
|
||||||
);
|
);
|
||||||
}
|
} else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
||||||
else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
|
||||||
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
src/onebot/event/notice/OB11GroupNameEvent.ts
Normal file
13
src/onebot/event/notice/OB11GroupNameEvent.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { OB11GroupNoticeEvent } from './OB11GroupNoticeEvent';
|
||||||
|
import { NapCatCore } from '@/core';
|
||||||
|
|
||||||
|
export class OB11GroupNameEvent extends OB11GroupNoticeEvent {
|
||||||
|
notice_type = 'notify';
|
||||||
|
sub_type = 'group_name';
|
||||||
|
name_new: string;
|
||||||
|
|
||||||
|
constructor(core: NapCatCore, groupId: number, userId: number, nameNew: string) {
|
||||||
|
super(core, groupId, userId);
|
||||||
|
this.name_new = nameNew;
|
||||||
|
}
|
||||||
|
}
|
@@ -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.sendTrace('uncaught/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) => {
|
||||||
@@ -151,6 +153,7 @@ async function handleLogin(
|
|||||||
};
|
};
|
||||||
|
|
||||||
loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => {
|
loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => {
|
||||||
|
UmamiTrace.sendTrace('qrlogin/error', [errType, errCode, errMsg].toString());
|
||||||
if (!isLogined) {
|
if (!isLogined) {
|
||||||
logger.logError('[Core] [Login] Login Error,ErrCode: ', errCode, ' ErrMsg:', errMsg);
|
logger.logError('[Core] [Login] Login Error,ErrCode: ', errCode, ' ErrMsg:', errMsg);
|
||||||
if (errType == 1 && errCode == 3) {
|
if (errType == 1 && errCode == 3) {
|
||||||
@@ -161,7 +164,8 @@ async function handleLogin(
|
|||||||
};
|
};
|
||||||
|
|
||||||
loginListener.onLoginFailed = (args) => {
|
loginListener.onLoginFailed = (args) => {
|
||||||
logger.logError('[Core] [Login] Login Error , ErrInfo: ', args);
|
UmamiTrace.sendTrace('login/error', args.toString());
|
||||||
|
logger.logError('[Core] [Login] Login Error , ErrInfo: ', args.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
loginService.addKernelLoginListener(proxiedListenerOf(loginListener, logger));
|
loginService.addKernelLoginListener(proxiedListenerOf(loginListener, logger));
|
||||||
@@ -222,7 +226,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 +270,6 @@ 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);
|
||||||
|
|
||||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
||||||
|
|
||||||
@@ -295,9 +298,10 @@ export async function NCoreInitShell() {
|
|||||||
|
|
||||||
const dataTimestape = new Date().getTime().toString();
|
const dataTimestape = new Date().getTime().toString();
|
||||||
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
o3Service.reportAmgomWeather('login', 'a1', [dataTimestape, '0', '0']);
|
||||||
|
UmamiTrace.init(basicInfoWrapper.getFullQQVesion(), loginService.getMachineGuid(), 'shell');
|
||||||
|
UmamiTrace.sendTrace('boot/init');
|
||||||
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
const selfInfo = await handleLogin(loginService, logger, pathWrapper, quickLoginUin, historyLoginList);
|
||||||
|
UmamiTrace.sendTrace('login/success');
|
||||||
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')));
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ export class WebUiConfigWrapper {
|
|||||||
try {
|
try {
|
||||||
const configPath = resolve(webUiPathWrapper.configPath, './webui.json');
|
const configPath = resolve(webUiPathWrapper.configPath, './webui.json');
|
||||||
|
|
||||||
if (!await fs.access(configPath, constants.R_OK | constants.W_OK).then(() => true).catch(() => false)) {
|
if (!await fs.access(configPath, constants.R_OK).then(() => true).catch(() => false)) {
|
||||||
await fs.writeFile(configPath, JSON.stringify(defaultconfig, null, 4));
|
await fs.writeFile(configPath, JSON.stringify(defaultconfig, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user