From d626f872e6db38c941c0be996a73dc4e3c384dc2 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, 2 Feb 2025 20:16:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E7=B1=BB=E5=9E=8B=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eslint.config.mjs | 88 ++++++++------------------- src/common/audio.ts | 6 +- src/common/cancel-task.ts | 37 ----------- src/common/event.ts | 18 +++--- src/common/ffmpeg-worker.ts | 45 +++++++------- src/common/ffmpeg.ts | 1 - src/common/file.ts | 2 +- src/common/helper.ts | 2 +- src/common/message-unique.ts | 17 ++++-- src/common/request.ts | 12 ++-- src/core/apis/file.ts | 18 +++--- src/onebot/network/http-server-sse.ts | 5 +- src/onebot/network/http-server.ts | 4 +- src/universal/LiteLoader.d.ts | 6 -- src/universal/napcat.ts | 9 ++- tsconfig.json | 22 +++++-- 16 files changed, 119 insertions(+), 173 deletions(-) delete mode 100644 src/universal/LiteLoader.d.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index adf72e5e..6859bd8b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,70 +1,30 @@ -import typescriptEslint from "@typescript-eslint/eslint-plugin"; -import _import from "eslint-plugin-import"; -import { fixupPluginRules } from "@eslint/compat"; +import eslint from '@eslint/js'; +import tsEslintPlugin from '@typescript-eslint/eslint-plugin'; +import tsEslintParser from '@typescript-eslint/parser'; import globals from "globals"; -import tsParser from "@typescript-eslint/parser"; -import path from "node:path"; -import { fileURLToPath } from "node:url"; -import js from "@eslint/js"; -import { FlatCompat } from "@eslint/eslintrc"; -const filename = fileURLToPath(import.meta.url); -const dirname = path.dirname(filename); -const compat = new FlatCompat({ - baseDirectory: dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all -}); - -export default [{ - ignores: ["src/core/proto/"], -}, ...compat.extends("eslint:recommended", "plugin:@typescript-eslint/recommended"), { - plugins: { - "@typescript-eslint": typescriptEslint, - import: fixupPluginRules(_import), - }, - - languageOptions: { - globals: { - ...globals.browser, - ...globals.node, - }, - - parser: tsParser, - ecmaVersion: "latest", - sourceType: "module", - }, - - settings: { - "import/parsers": { - "@typescript-eslint/parser": [".ts"], - }, - - "import/resolver": { - typescript: { - alwaysTryTypes: true, +const customTsFlatConfig = [ + { + name: 'typescript-eslint/base', + languageOptions: { + parser: tsEslintParser, + sourceType: 'module', + globals: { + ...globals.browser, + ...globals.node, }, }, - }, - - rules: { - indent: ["error", 4], - semi: ["error", "always"], - "no-unused-vars": "off", - "no-async-promise-executor": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/no-var-requires": "off", - "object-curly-spacing": ["error", "always"], - }, -}, { - files: ["**/.eslintrc.{js,cjs}"], - - languageOptions: { - globals: { - ...globals.node, + files: ['**/*.{ts,tsx}'], + rules: { + ...tsEslintPlugin.configs.recommended.rules, + 'quotes': ['error', 'single'], // 使用单引号 + 'semi': ['error', 'always'], // 强制使用分号 + 'indent': ['error', 4], // 使用 4 空格缩进 + }, + plugins: { + '@typescript-eslint': tsEslintPlugin, }, - ecmaVersion: 5, - sourceType: "commonjs", }, -}]; +]; + +export default [eslint.configs.recommended, ...customTsFlatConfig]; \ No newline at end of file diff --git a/src/common/audio.ts b/src/common/audio.ts index 2cd7bbf6..771c57f3 100644 --- a/src/common/audio.ts +++ b/src/common/audio.ts @@ -28,11 +28,11 @@ async function handleWavFile( file: Buffer, filePath: string, pcmPath: string, - logger: LogWrapper + _logger: LogWrapper ): Promise<{ input: Buffer; sampleRate: number }> { const { fmt } = getWavFileInfo(file); if (!ALLOW_SAMPLE_RATE.includes(fmt.sampleRate)) { - return { input: await FFmpegService.convert(filePath, pcmPath, logger), sampleRate: 24000 }; + return { input: await FFmpegService.convert(filePath, pcmPath), sampleRate: 24000 }; } return { input: file, sampleRate: fmt.sampleRate }; } @@ -46,7 +46,7 @@ export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: Log const pcmPath = `${pttPath}.pcm`; const { input, sampleRate } = isWav(file) ? (await handleWavFile(file, filePath, pcmPath, logger)) - : { input: await FFmpegService.convert(filePath, pcmPath, logger), sampleRate: 24000 }; + : { input: await FFmpegService.convert(filePath, pcmPath), sampleRate: 24000 }; const silk = await piscina.run({ input: input, sampleRate: sampleRate }); await fsPromise.writeFile(pttPath, Buffer.from(silk.data)); logger.log(`语音文件${filePath}转换成功!`, pttPath, '时长:', silk.duration); diff --git a/src/common/cancel-task.ts b/src/common/cancel-task.ts index 9fa8161a..454f2a62 100644 --- a/src/common/cancel-task.ts +++ b/src/common/cancel-task.ts @@ -73,40 +73,3 @@ export class CancelableTask { }; } } - -async function demoAwait() { - const executor: TaskExecutor = async (resolve, reject, onCancel) => { - let count = 0; - const intervalId = setInterval(() => { - count++; - console.log(`Task is running... Count: ${count}`); - if (count === 5) { - clearInterval(intervalId); - resolve(count); - } - }, 1000); - - onCancel(() => { - clearInterval(intervalId); - console.log('Task has been canceled.'); - reject(new Error('Task was canceled')); - }); - }; - - const task = new CancelableTask(executor); - - task.onCancel(() => { - console.log('Cancel listener triggered.'); - }); - - setTimeout(() => { - task.cancel(); // 取消任务 - }, 6000); - - try { - const result = await task; - console.log(`Task completed with result: ${result}`); - } catch (error) { - console.error('Task failed:', error); - } -} \ No newline at end of file diff --git a/src/common/event.ts b/src/common/event.ts index 33492011..ed2e36af 100644 --- a/src/common/event.ts +++ b/src/common/event.ts @@ -60,12 +60,16 @@ export class NTEventWrapper { [key: string]: () => { [key: string]: (...params: Parameters) => Promise> }; }; if (eventNameArr.length > 1) { - const serviceName = 'get' + eventNameArr[0].replace('NodeIKernel', ''); + const serviceName = 'get' + (eventNameArr[0]?.replace('NodeIKernel', '') ?? ''); const eventName = eventNameArr[1]; - const services = (this.WrapperSession as unknown as eventType)[serviceName](); + const services = (this.WrapperSession as unknown as eventType)[serviceName]?.(); + if (!services || !eventName) { + return undefined; + } let event = services[eventName]; + //重新绑定this - event = event.bind(services); + event = event?.bind(services); if (event) { return event as T; } @@ -126,8 +130,8 @@ export class NTEventWrapper { ) { return new Promise>((resolve, reject) => { const ListenerNameList = listenerAndMethod.split('/'); - const ListenerMainName = ListenerNameList[0]; - const ListenerSubName = ListenerNameList[1]; + const ListenerMainName = ListenerNameList[0] ?? ''; + const ListenerSubName = ListenerNameList[1] ?? ''; const id = randomUUID(); let complete = 0; let retData: Parameters | undefined = undefined; @@ -205,8 +209,8 @@ export class NTEventWrapper { } const ListenerNameList = listenerAndMethod.split('/'); - const ListenerMainName = ListenerNameList[0]; - const ListenerSubName = ListenerNameList[1]; + const ListenerMainName = ListenerNameList[0]??""; + const ListenerSubName = ListenerNameList[1]??""; return new Promise<[EventRet: Awaited>, ...Parameters]>( (resolve, reject) => { diff --git a/src/common/ffmpeg-worker.ts b/src/common/ffmpeg-worker.ts index 7ee7b2d8..a97cdd4a 100644 --- a/src/common/ffmpeg-worker.ts +++ b/src/common/ffmpeg-worker.ts @@ -1,18 +1,17 @@ import { FFmpeg } from '@ffmpeg.wasm/main'; import { randomUUID } from 'crypto'; import { readFileSync, statSync, writeFileSync } from 'fs'; -import type { LogWrapper } from './log'; import type { VideoInfo } from './video'; import { fileTypeFromFile } from 'file-type'; import imageSize from 'image-size'; - class FFmpegService { +class FFmpegService { public static async extractThumbnail(videoPath: string, thumbnailPath: string): Promise { const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' }); const videoFileName = `${randomUUID()}.mp4`; const outputFileName = `${randomUUID()}.jpg`; try { ffmpegInstance.fs.writeFile(videoFileName, readFileSync(videoPath)); - let code = await ffmpegInstance.run('-i', videoFileName, '-ss', '00:00:01.000', '-vframes', '1', outputFileName); + const code = await ffmpegInstance.run('-i', videoFileName, '-ss', '00:00:01.000', '-vframes', '1', outputFileName); if (code !== 0) { throw new Error('Error extracting thumbnail: FFmpeg process exited with code ' + code); } @@ -44,7 +43,7 @@ import imageSize from 'image-size'; const params = format === 'amr' ? ['-f', 's16le', '-ar', '24000', '-ac', '1', '-i', inputFileName, '-ar', '8000', '-b:a', '12.2k', outputFileName] : ['-f', 's16le', '-ar', '24000', '-ac', '1', '-i', inputFileName, outputFileName]; - let code = await ffmpegInstance.run(...params); + const code = await ffmpegInstance.run(...params); if (code !== 0) { throw new Error('Error extracting thumbnail: FFmpeg process exited with code ' + code); } @@ -74,7 +73,7 @@ import imageSize from 'image-size'; try { ffmpegInstance.fs.writeFile(inputFileName, readFileSync(filePath)); const params = ['-y', '-i', inputFileName, '-ar', '24000', '-ac', '1', '-f', 's16le', outputFileName]; - let code = await ffmpegInstance.run(...params); + const code = await ffmpegInstance.run(...params); if (code !== 0) { throw new Error('FFmpeg process exited with code ' + code); } @@ -96,27 +95,27 @@ import imageSize from 'image-size'; } } } - + public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise { await FFmpegService.extractThumbnail(videoPath, thumbnailPath); - let fileType = (await fileTypeFromFile(videoPath))?.ext ?? 'mp4'; + const fileType = (await fileTypeFromFile(videoPath))?.ext ?? 'mp4'; const inputFileName = `${randomUUID()}.${fileType}`; const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' }); ffmpegInstance.fs.writeFile(inputFileName, readFileSync(videoPath)); ffmpegInstance.setLogging(true); let duration = 60; - ffmpegInstance.setLogger((level, ...msg) => { + ffmpegInstance.setLogger((_level, ...msg) => { const message = msg.join(' '); const durationMatch = message.match(/Duration: (\d+):(\d+):(\d+\.\d+)/); if (durationMatch) { - const hours = parseInt(durationMatch[1], 10); - const minutes = parseInt(durationMatch[2], 10); - const seconds = parseFloat(durationMatch[3]); + const hours = parseInt(durationMatch[1] ?? "0", 10); + const minutes = parseInt(durationMatch[2] ?? "0", 10); + const seconds = parseFloat(durationMatch[3] ?? "0"); duration = hours * 3600 + minutes * 60 + seconds; } }); await ffmpegInstance.run('-i', inputFileName); - let image = imageSize(thumbnailPath); + const image = imageSize(thumbnailPath); ffmpegInstance.fs.unlink(inputFileName); const fileSize = statSync(videoPath).size; return { @@ -126,7 +125,7 @@ import imageSize from 'image-size'; format: fileType, size: fileSize, filePath: videoPath - } + }; } } type FFmpegMethod = 'extractThumbnail' | 'convertFile' | 'convert' | 'getVideoInfo'; @@ -137,15 +136,15 @@ interface FFmpegTask { } export default async function handleFFmpegTask({ method, args }: FFmpegTask): Promise { switch (method) { - case 'extractThumbnail': - return await FFmpegService.extractThumbnail(...args as [string, string]); - case 'convertFile': - return await FFmpegService.convertFile(...args as [string, string, string]); - case 'convert': - return await FFmpegService.convert(...args as [string, string]); - case 'getVideoInfo': - return await FFmpegService.getVideoInfo(...args as [string, string]); - default: - throw new Error(`Unknown method: ${method}`); + case 'extractThumbnail': + return await FFmpegService.extractThumbnail(...args as [string, string]); + case 'convertFile': + return await FFmpegService.convertFile(...args as [string, string, string]); + case 'convert': + return await FFmpegService.convert(...args as [string, string]); + case 'getVideoInfo': + return await FFmpegService.getVideoInfo(...args as [string, string]); + default: + throw new Error(`Unknown method: ${method}`); } } \ No newline at end of file diff --git a/src/common/ffmpeg.ts b/src/common/ffmpeg.ts index efc72571..57e15e22 100644 --- a/src/common/ffmpeg.ts +++ b/src/common/ffmpeg.ts @@ -1,6 +1,5 @@ import Piscina from "piscina"; import { VideoInfo } from "./video"; -import type { LogWrapper } from "./log"; type EncodeArgs = { method: 'extractThumbnail' | 'convertFile' | 'convert' | 'getVideoInfo'; diff --git a/src/common/file.ts b/src/common/file.ts index 0bb65789..4ffe8386 100644 --- a/src/common/file.ts +++ b/src/common/file.ts @@ -190,7 +190,7 @@ export async function uriToLocalFile(dir: string, uri: string, filename: string } case FileUriType.Remote: { - const buffer = await httpDownload({ url: HandledUri, headers: headers }); + const buffer = await httpDownload({ url: HandledUri, headers: headers ?? {} }); fs.writeFileSync(filePath, buffer); return { success: true, errMsg: '', fileName: filename, path: filePath }; } diff --git a/src/common/helper.ts b/src/common/helper.ts index f426cf6c..24da598d 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -166,7 +166,7 @@ export function calcQQLevel(level?: QQLevel) { } export function stringifyWithBigInt(obj: any) { - return JSON.stringify(obj, (key, value) => + return JSON.stringify(obj, (_key, value) => typeof value === 'bigint' ? value.toString() : value ); } diff --git a/src/common/message-unique.ts b/src/common/message-unique.ts index cc4187e7..3f6785f2 100644 --- a/src/common/message-unique.ts +++ b/src/common/message-unique.ts @@ -68,7 +68,10 @@ export class LimitedHashTable { const listSize = Math.min(size, keyList.length); for (let i = 0; i < listSize; i++) { const key = keyList[listSize - i]; - result.push({ key, value: this.keyToValue.get(key)! }); + if (key !== undefined) { + result.push({ key, value: this.keyToValue.get(key)! }); + } + } return result; } @@ -96,8 +99,10 @@ class MessageUniqueWrapper { createUniqueMsgId(peer: Peer, msgId: string) { const key = `${msgId}|${peer.chatType}|${peer.peerUid}`; const hash = crypto.createHash('md5').update(key).digest(); - //设置第一个bit为0 保证shortId为正数 - hash[0] &= 0x7f; + if (hash[0]) { + //设置第一个bit为0 保证shortId为正数 + hash[0] &= 0x7f; + } const shortId = hash.readInt32BE(0); //减少性能损耗 this.msgIdMap.set(msgId, shortId); @@ -110,11 +115,11 @@ class MessageUniqueWrapper { if (data) { const [msgId, chatTypeStr, peerUid] = data.split('|'); const peer: Peer = { - chatType: parseInt(chatTypeStr), - peerUid, + chatType: parseInt(chatTypeStr ?? '0'), + peerUid: peerUid ?? '', guildId: '', }; - return { MsgId: msgId, Peer: peer }; + return { MsgId: msgId ?? '0', Peer: peer }; } return undefined; } diff --git a/src/common/request.ts b/src/common/request.ts index 11523842..b089b28d 100644 --- a/src/common/request.ts +++ b/src/common/request.ts @@ -41,11 +41,13 @@ export class RequestUtil { private static extractCookies(setCookieHeaders: string[], cookies: { [key: string]: string }) { setCookieHeaders.forEach((cookie) => { - const parts = cookie.split(';')[0].split('='); - const key = parts[0]; - const value = parts[1]; - if (key && value && key.length > 0 && value.length > 0) { - cookies[key] = value; + const parts = cookie.split(';')[0]?.split('='); + if (parts) { + const key = parts[0]; + const value = parts[1]; + if (key && value && key.length > 0 && value.length > 0) { + cookies[key] = value; + } } }); } diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index a9122391..b8629a6d 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -40,7 +40,7 @@ export class NTQQFileApi { this.rkeyManager = new RkeyManager([ 'https://rkey.napneko.icu/rkeys' ], - this.context.logger + this.context.logger ); } @@ -274,18 +274,18 @@ export class NTQQFileApi { element.elementType === ElementType.FILE ) { switch (element.elementType) { - case ElementType.PIC: + case ElementType.PIC: element.picElement!.sourcePath = elementResults[elementIndex]; - break; - case ElementType.VIDEO: + break; + case ElementType.VIDEO: element.videoElement!.filePath = elementResults[elementIndex]; - break; - case ElementType.PTT: + break; + case ElementType.PTT: element.pttElement!.filePath = elementResults[elementIndex]; - break; - case ElementType.FILE: + break; + case ElementType.FILE: element.fileElement!.filePath = elementResults[elementIndex]; - break; + break; } elementIndex++; } diff --git a/src/onebot/network/http-server-sse.ts b/src/onebot/network/http-server-sse.ts index 893dfce7..6b4839ed 100644 --- a/src/onebot/network/http-server-sse.ts +++ b/src/onebot/network/http-server-sse.ts @@ -1,12 +1,11 @@ import { OB11EmitEventContent } from './index'; import { Request, Response } from 'express'; -import { OB11Response } from '@/onebot/action/OneBotAction'; import { OB11HttpServerAdapter } from './http-server'; export class OB11HttpSSEServerAdapter extends OB11HttpServerAdapter { private sseClients: Response[] = []; - async handleRequest(req: Request, res: Response): Promise { + override async handleRequest(req: Request, res: Response): Promise { if (req.path === '/_events') { return this.createSseSupport(req, res); } else { @@ -26,7 +25,7 @@ export class OB11HttpSSEServerAdapter extends OB11HttpServerAdapter { }); } - onEvent(event: T) { + override onEvent(event: T) { this.sseClients.forEach((res) => { res.write(`data: ${JSON.stringify(event)}\n\n`); }); diff --git a/src/onebot/network/http-server.ts b/src/onebot/network/http-server.ts index 0b659901..f4f5b207 100644 --- a/src/onebot/network/http-server.ts +++ b/src/onebot/network/http-server.ts @@ -18,7 +18,7 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter super(name, config, core, obContext, actions); } - onEvent(event: T) { + onEvent(_event: T) { // http server is passive, no need to emit event } @@ -65,7 +65,7 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter return res.status(400).send('Invalid JSON'); } }); - req.on('error', (err) => { + req.on('error', (_err) => { return res.status(400).send('Invalid JSON'); }); }); diff --git a/src/universal/LiteLoader.d.ts b/src/universal/LiteLoader.d.ts deleted file mode 100644 index df151232..00000000 --- a/src/universal/LiteLoader.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare global { - namespace globalThis { - var LiteLoader: symbol; - } -} -export {}; \ No newline at end of file diff --git a/src/universal/napcat.ts b/src/universal/napcat.ts index 016a4158..d5fd0d5b 100644 --- a/src/universal/napcat.ts +++ b/src/universal/napcat.ts @@ -1,6 +1,13 @@ import { NCoreInitShell } from "@/shell/base"; export * from "@/framework/napcat"; export * from "@/shell/base"; -if (global.LiteLoader == undefined) { + +interface LiteLoaderGlobal extends Global { + LiteLoader?: unknown; +} + +declare const global: LiteLoaderGlobal; + +if (global.LiteLoader === undefined) { NCoreInitShell(); } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 48537ae5..c5c47900 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,8 +18,8 @@ "noEmit": true, "jsx": "preserve", "strict": true, - "noUnusedLocals": false, - "noUnusedParameters": false, + "noUnusedLocals": true, + "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "sourceMap": true, "paths": { @@ -28,8 +28,22 @@ ], "@webapi/*": [ "./src/webui/src/*" - ], - } + ] + }, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "alwaysStrict": true, + "noImplicitThis": true, + "noImplicitReturns": false, // false for now + "noPropertyAccessFromIndexSignature": false, // false for now + "noUncheckedIndexedAccess": true, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "useUnknownInCatchVariables": true, + "noImplicitOverride": true, + "strictPropertyInitialization": true }, "include": [ "src/**/*.ts" From ac193cc94a1449cb54fb1e2f290445acab1122b2 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, 2 Feb 2025 20:17:28 +0800 Subject: [PATCH 2/3] style: lint --- src/common/audio-worker.ts | 2 +- src/common/audio.ts | 4 +- src/common/config-base.ts | 8 +-- src/common/event.ts | 4 +- src/common/ffmpeg-worker.ts | 6 +- src/common/ffmpeg.ts | 4 +- src/common/file-uuid.ts | 8 +-- src/common/forward-msg-builder.ts | 24 +++---- src/common/helper.ts | 6 +- src/common/log.ts | 2 +- src/common/qq-basic-info.ts | 6 +- src/core/adapters/NodeIDependsAdapter.ts | 2 +- src/core/apis/packet.ts | 8 +-- src/core/apis/webapi.ts | 20 +++--- src/core/helper/adaptDecoder.ts | 2 +- src/core/helper/rkey.ts | 2 +- src/core/helper/status.ts | 4 +- src/core/index.ts | 6 +- src/core/packet/client/baseClient.ts | 12 ++-- src/core/packet/client/nativeClient.ts | 20 +++--- src/core/packet/client/wsClient.ts | 14 ++--- src/core/packet/clientSession.ts | 4 +- src/core/packet/context/clientContext.ts | 30 ++++----- src/core/packet/context/loggerContext.ts | 6 +- src/core/packet/context/napCoreContext.ts | 2 +- src/core/packet/context/operationContext.ts | 22 +++---- src/core/packet/context/packetContext.ts | 14 ++--- src/core/packet/highway/client.ts | 10 +-- src/core/packet/highway/frame.ts | 2 +- src/core/packet/highway/highwayContext.ts | 62 +++++++++---------- .../highway/uploader/highwayHttpUploader.ts | 12 ++-- .../highway/uploader/highwayTcpUploader.ts | 16 ++--- .../highway/uploader/highwayUploader.ts | 12 ++-- src/core/packet/highway/utils.ts | 4 +- src/core/packet/message/builder.ts | 16 ++--- src/core/packet/message/converter.ts | 8 +-- src/core/packet/message/element.ts | 36 +++++------ src/core/packet/message/message.ts | 4 +- .../transformer/action/FetchAiVoiceList.ts | 10 +-- .../packet/transformer/action/GetAiVoice.ts | 10 +-- .../action/GetMiniAppAdaptShareInfo.ts | 20 +++--- .../transformer/action/GetStrangerInfo.ts | 8 +-- .../packet/transformer/action/GroupSign.ts | 10 +-- .../packet/transformer/action/ImageOCR.ts | 18 +++--- .../packet/transformer/action/SendPoke.ts | 8 +-- .../transformer/action/SetSpecialTitle.ts | 8 +-- src/core/packet/transformer/base.ts | 4 +- .../transformer/highway/DownloadGroupFile.ts | 8 +-- .../transformer/highway/DownloadGroupPtt.ts | 8 +-- .../transformer/highway/DownloadImage.ts | 10 +-- .../highway/DownloadOfflineFile.ts | 8 +-- .../highway/DownloadPrivateFile.ts | 8 +-- .../transformer/highway/FetchSessionKey.ts | 10 +-- .../transformer/highway/UploadGroupFile.ts | 10 +-- .../transformer/highway/UploadGroupImage.ts | 12 ++-- .../transformer/highway/UploadGroupPtt.ts | 14 ++--- .../transformer/highway/UploadGroupVideo.ts | 20 +++--- .../transformer/highway/UploadPrivateFile.ts | 14 ++--- .../transformer/highway/UploadPrivateImage.ts | 12 ++-- .../transformer/highway/UploadPrivatePtt.ts | 14 ++--- .../transformer/highway/UploadPrivateVideo.ts | 20 +++--- .../transformer/message/UploadForwardMsg.ts | 14 ++--- src/core/packet/transformer/oidb/oidbBase.ts | 6 +- .../packet/transformer/proto/action/action.ts | 6 +- .../proto/action/miniAppAdaptShareInfo.ts | 2 +- .../transformer/proto/highway/highway.ts | 4 +- src/core/packet/transformer/proto/index.ts | 50 +++++++-------- .../transformer/proto/message/action.ts | 4 +- .../packet/transformer/proto/message/c2c.ts | 2 +- .../transformer/proto/message/component.ts | 4 +- .../transformer/proto/message/element.ts | 2 +- .../packet/transformer/proto/message/group.ts | 2 +- .../transformer/proto/message/groupAdmin.ts | 2 +- .../transformer/proto/message/message.ts | 4 +- .../transformer/proto/message/notify.ts | 2 +- .../transformer/proto/message/routing.ts | 2 +- .../transformer/proto/oidb/Oidb.0XE37_800.ts | 4 +- .../transformer/proto/oidb/Oidb.0XFE1_2.ts | 2 +- .../transformer/proto/oidb/Oidb.0x6D6.ts | 2 +- .../transformer/proto/oidb/Oidb.0x8FC_2.ts | 2 +- .../transformer/proto/oidb/Oidb.0x9067_202.ts | 4 +- .../transformer/proto/oidb/Oidb.0x929.ts | 4 +- .../transformer/proto/oidb/Oidb.0xE07.ts | 2 +- .../transformer/proto/oidb/Oidb.0xE37_1200.ts | 2 +- .../transformer/proto/oidb/Oidb.0xE37_1700.ts | 2 +- .../transformer/proto/oidb/Oidb.0xEB7.ts | 2 +- .../transformer/proto/oidb/Oidb.0xED3_1.ts | 2 +- .../packet/transformer/proto/oidb/OidbBase.ts | 2 +- .../proto/oidb/common/Ntv2.RichMediaReq.ts | 2 +- .../proto/oidb/common/Ntv2.RichMediaResp.ts | 4 +- .../packet/transformer/system/FetchRkey.ts | 8 +-- src/core/packet/utils/crypto/hash.ts | 2 +- .../utils/crypto/sha1StreamBytesTransform.ts | 4 +- src/core/packet/utils/helper/miniAppHelper.ts | 24 +++---- src/core/services/NodeIKernelMSFService.ts | 2 +- src/core/services/NodeIO3MiscService.ts | 2 +- src/core/types/element.ts | 2 +- src/onebot/action/extends/GetAiCharacters.ts | 4 +- src/onebot/action/extends/GetMiniAppArk.ts | 6 +- src/onebot/action/extends/GetRkey.ts | 2 +- src/onebot/action/extends/GetUserStatus.ts | 2 +- src/onebot/action/extends/SetSpecialTittle.ts | 2 +- src/onebot/action/file/GetGroupFileUrl.ts | 2 +- .../action/go-cqhttp/GoCQHTTPGetModelShow.ts | 2 +- src/onebot/action/group/GetAiRecord.ts | 4 +- src/onebot/action/group/GetGroupMemberInfo.ts | 2 +- src/onebot/action/group/GroupPoke.ts | 2 +- src/onebot/action/group/SendGroupAiRecord.ts | 8 +-- src/onebot/action/index.ts | 16 ++--- src/onebot/action/msg/SendMsg.ts | 14 ++--- src/onebot/action/packet/GetPacketStatus.ts | 4 +- src/onebot/action/packet/SendPoke.ts | 2 +- src/onebot/action/router.ts | 16 ++--- src/onebot/action/user/FriendPoke.ts | 2 +- src/onebot/api/group.ts | 4 +- src/onebot/api/msg.ts | 12 ++-- src/onebot/api/user.ts | 6 +- src/onebot/helper/data.ts | 2 +- src/onebot/index.ts | 4 +- src/onebot/network/adapter.ts | 12 ++-- src/onebot/network/http-client.ts | 2 +- src/onebot/network/http-server.ts | 6 +- src/onebot/network/index.ts | 2 +- src/onebot/network/plugin.ts | 2 +- src/onebot/network/websocket-client.ts | 4 +- src/onebot/network/websocket-server.ts | 4 +- src/onebot/types/message.ts | 2 +- src/plugin/index.ts | 8 +-- src/shell/base.ts | 2 +- src/shell/napcat.ts | 2 +- src/universal/napcat.ts | 6 +- src/webui/src/api/Proxy.ts | 8 +-- src/webui/src/api/Status.ts | 2 +- src/webui/src/router/Base.ts | 2 +- src/webui/src/types/data.d.ts | 2 +- 135 files changed, 529 insertions(+), 529 deletions(-) diff --git a/src/common/audio-worker.ts b/src/common/audio-worker.ts index 8d84d3b2..64d48039 100644 --- a/src/common/audio-worker.ts +++ b/src/common/audio-worker.ts @@ -1,4 +1,4 @@ -import { encode } from "silk-wasm"; +import { encode } from 'silk-wasm'; export interface EncodeArgs { input: ArrayBufferView | ArrayBuffer diff --git a/src/common/audio.ts b/src/common/audio.ts index 771c57f3..6f7a8f49 100644 --- a/src/common/audio.ts +++ b/src/common/audio.ts @@ -4,8 +4,8 @@ import path from 'node:path'; import { randomUUID } from 'crypto'; import { EncodeResult, getDuration, getWavFileInfo, isSilk, isWav } from 'silk-wasm'; import { LogWrapper } from '@/common/log'; -import { EncodeArgs } from "@/common/audio-worker"; -import { FFmpegService } from "@/common/ffmpeg"; +import { EncodeArgs } from '@/common/audio-worker'; +import { FFmpegService } from '@/common/ffmpeg'; const ALLOW_SAMPLE_RATE = [8000, 12000, 16000, 24000, 32000, 44100, 48000]; diff --git a/src/common/config-base.ts b/src/common/config-base.ts index 7b8be702..c0f4a427 100644 --- a/src/common/config-base.ts +++ b/src/common/config-base.ts @@ -39,9 +39,9 @@ export abstract class ConfigBase { if (!fs.existsSync(configPath) && copy_default) { try { fs.writeFileSync(configPath, fs.readFileSync(this.getConfigPath(undefined), 'utf-8')); - this.core.context.logger.log(`[Core] [Config] 配置文件创建成功!\n`); + this.core.context.logger.log('[Core] [Config] 配置文件创建成功!\n'); } catch (e: any) { - this.core.context.logger.logError(`[Core] [Config] 创建配置文件时发生错误:`, e.message); + this.core.context.logger.logError('[Core] [Config] 创建配置文件时发生错误:', e.message); } } else if (!fs.existsSync(configPath) && !copy_default) { fs.writeFileSync(configPath, '{}'); @@ -52,9 +52,9 @@ export abstract class ConfigBase { return this.configData; } catch (e: any) { if (e instanceof SyntaxError) { - this.core.context.logger.logError(`[Core] [Config] 配置文件格式错误,请检查配置文件:`, e.message); + this.core.context.logger.logError('[Core] [Config] 配置文件格式错误,请检查配置文件:', e.message); } else { - this.core.context.logger.logError(`[Core] [Config] 读取配置文件时发生错误:`, e.message); + this.core.context.logger.logError('[Core] [Config] 读取配置文件时发生错误:', e.message); } return {} as T; } diff --git a/src/common/event.ts b/src/common/event.ts index ed2e36af..dcc5eee5 100644 --- a/src/common/event.ts +++ b/src/common/event.ts @@ -209,8 +209,8 @@ export class NTEventWrapper { } const ListenerNameList = listenerAndMethod.split('/'); - const ListenerMainName = ListenerNameList[0]??""; - const ListenerSubName = ListenerNameList[1]??""; + const ListenerMainName = ListenerNameList[0]??''; + const ListenerSubName = ListenerNameList[1]??''; return new Promise<[EventRet: Awaited>, ...Parameters]>( (resolve, reject) => { diff --git a/src/common/ffmpeg-worker.ts b/src/common/ffmpeg-worker.ts index a97cdd4a..146595a4 100644 --- a/src/common/ffmpeg-worker.ts +++ b/src/common/ffmpeg-worker.ts @@ -108,9 +108,9 @@ class FFmpegService { const message = msg.join(' '); const durationMatch = message.match(/Duration: (\d+):(\d+):(\d+\.\d+)/); if (durationMatch) { - const hours = parseInt(durationMatch[1] ?? "0", 10); - const minutes = parseInt(durationMatch[2] ?? "0", 10); - const seconds = parseFloat(durationMatch[3] ?? "0"); + const hours = parseInt(durationMatch[1] ?? '0', 10); + const minutes = parseInt(durationMatch[2] ?? '0', 10); + const seconds = parseFloat(durationMatch[3] ?? '0'); duration = hours * 3600 + minutes * 60 + seconds; } }); diff --git a/src/common/ffmpeg.ts b/src/common/ffmpeg.ts index 57e15e22..81dea249 100644 --- a/src/common/ffmpeg.ts +++ b/src/common/ffmpeg.ts @@ -1,5 +1,5 @@ -import Piscina from "piscina"; -import { VideoInfo } from "./video"; +import Piscina from 'piscina'; +import { VideoInfo } from './video'; type EncodeArgs = { method: 'extractThumbnail' | 'convertFile' | 'convert' | 'getVideoInfo'; diff --git a/src/common/file-uuid.ts b/src/common/file-uuid.ts index 0f359ac5..d96797c6 100644 --- a/src/common/file-uuid.ts +++ b/src/common/file-uuid.ts @@ -83,7 +83,7 @@ class FileUUIDManager { this.cache = new TimeBasedCache(5000, ttl); } - public encode(data: FileUUIDData, endString: string = "", customUUID?: string): string { + public encode(data: FileUUIDData, endString: string = '', customUUID?: string): string { const uuid = customUUID ? customUUID : randomUUID().replace(/-/g, '') + endString; this.cache.put(uuid, data); return uuid; @@ -101,7 +101,7 @@ export class FileNapCatOneBotUUIDWrap { this.manager = new FileUUIDManager(ttl); } - public encodeModelId(peer: Peer, modelId: string, fileId: string, fileUUID: string = "", endString: string = "", customUUID?: string): string { + public encodeModelId(peer: Peer, modelId: string, fileId: string, fileUUID: string = '', endString: string = '', customUUID?: string): string { return this.manager.encode({ peer, modelId, fileId, fileUUID }, endString, customUUID); } @@ -109,8 +109,8 @@ export class FileNapCatOneBotUUIDWrap { return this.manager.decode(uuid); } - public encode(peer: Peer, msgId: string, elementId: string, fileUUID: string = "", customUUID?: string): string { - return this.manager.encode({ peer, msgId, elementId, fileUUID }, "", customUUID); + public encode(peer: Peer, msgId: string, elementId: string, fileUUID: string = '', customUUID?: string): string { + return this.manager.encode({ peer, msgId, elementId, fileUUID }, '', customUUID); } public decode(uuid: string): FileUUIDData | undefined { diff --git a/src/common/forward-msg-builder.ts b/src/common/forward-msg-builder.ts index c091c542..8aba1408 100644 --- a/src/common/forward-msg-builder.ts +++ b/src/common/forward-msg-builder.ts @@ -1,5 +1,5 @@ -import * as crypto from "node:crypto"; -import { PacketMsg } from "@/core/packet/message/message"; +import * as crypto from 'node:crypto'; +import { PacketMsg } from '@/core/packet/message/message'; interface ForwardMsgJson { app: string @@ -50,15 +50,15 @@ interface ForwardAdaptMsgElement { } export class ForwardMsgBuilder { - private static build(resId: string, msg: ForwardAdaptMsg[], source?: string, news?: ForwardMsgJsonMetaDetail["news"], summary?: string, prompt?: string): ForwardMsgJson { + private static build(resId: string, msg: ForwardAdaptMsg[], source?: string, news?: ForwardMsgJsonMetaDetail['news'], summary?: string, prompt?: string): ForwardMsgJson { const id = crypto.randomUUID(); const isGroupMsg = msg.some(m => m.isGroupMsg); if (!source) { - source = isGroupMsg ? "群聊的聊天记录" : msg.map(m => m.senderName).filter((v, i, a) => a.indexOf(v) === i).slice(0, 4).join('和') + '的聊天记录'; + source = isGroupMsg ? '群聊的聊天记录' : msg.map(m => m.senderName).filter((v, i, a) => a.indexOf(v) === i).slice(0, 4).join('和') + '的聊天记录'; } if (!news) { news = msg.length === 0 ? [{ - text: "Nya~ This message is send from NapCat.Packet!", + text: 'Nya~ This message is send from NapCat.Packet!', }] : msg.map(m => ({ text: `${m.senderName}: ${m.msg?.map(msg => msg.preview).join('')}`, })); @@ -67,15 +67,15 @@ export class ForwardMsgBuilder { summary = `查看${msg.length}条转发消息`; } if (!prompt) { - prompt = "[聊天记录]"; + prompt = '[聊天记录]'; } return { - app: "com.tencent.multimsg", + app: 'com.tencent.multimsg', config: { autosize: 1, forward: 1, round: 1, - type: "normal", + type: 'normal', width: 300 }, desc: prompt, @@ -93,8 +93,8 @@ export class ForwardMsgBuilder { } }, prompt, - ver: "0.0.0.5", - view: "contact", + ver: '0.0.0.5', + view: 'contact', }; } @@ -102,12 +102,12 @@ export class ForwardMsgBuilder { return this.build(resId, []); } - static fromPacketMsg(resId: string, packetMsg: PacketMsg[], source?: string, news?: ForwardMsgJsonMetaDetail["news"], summary?: string, prompt?: string): ForwardMsgJson { + static fromPacketMsg(resId: string, packetMsg: PacketMsg[], source?: string, news?: ForwardMsgJsonMetaDetail['news'], summary?: string, prompt?: string): ForwardMsgJson { return this.build(resId, packetMsg.map(msg => ({ senderName: msg.senderName, isGroupMsg: msg.groupId !== undefined, msg: msg.msg.map(m => ({ - preview: m.valid ? m.toPreview() : "[该消息类型暂不支持查看]", + preview: m.valid ? m.toPreview() : '[该消息类型暂不支持查看]', })) })), source, news, summary, prompt); } diff --git a/src/common/helper.ts b/src/common/helper.ts index 24da598d..129d5a7f 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -172,8 +172,8 @@ export function stringifyWithBigInt(obj: any) { } export function parseAppidFromMajor(nodeMajor: string): string | undefined { - const hexSequence = "A4 09 00 00 00 35"; - const sequenceBytes = Buffer.from(hexSequence.replace(/ /g, ""), "hex"); + const hexSequence = 'A4 09 00 00 00 35'; + const sequenceBytes = Buffer.from(hexSequence.replace(/ /g, ''), 'hex'); const filePath = path.resolve(nodeMajor); const fileContent = fs.readFileSync(filePath); @@ -192,7 +192,7 @@ export function parseAppidFromMajor(nodeMajor: string): string | undefined { const content = fileContent.subarray(start, end); if (!content.every(byte => byte === 0x00)) { try { - return content.toString("utf-8"); + return content.toString('utf-8'); } catch (error) { break; } diff --git a/src/common/log.ts b/src/common/log.ts index ea9beb09..5dfc0028 100644 --- a/src/common/log.ts +++ b/src/common/log.ts @@ -303,7 +303,7 @@ function textElementToText(textElement: any): string { const originalContentLines = textElement.content.split('\n'); return `${originalContentLines[0]}${originalContentLines.length > 1 ? ' ...' : ''}`; } else if (textElement.atType === NTMsgAtType.ATTYPEALL) { - return `@全体成员`; + return '@全体成员'; } else if (textElement.atType === NTMsgAtType.ATTYPEONE) { return `${textElement.content} (${textElement.atUid})`; } diff --git a/src/common/qq-basic-info.ts b/src/common/qq-basic-info.ts index 389d4a8c..a965146b 100644 --- a/src/common/qq-basic-info.ts +++ b/src/common/qq-basic-info.ts @@ -86,14 +86,14 @@ export class QQBasicInfoWrapper { try { const majorAppid = this.getAppidV2ByMajor(fullVersion); if (majorAppid) { - this.context.logger.log(`[QQ版本兼容性检测] 当前版本Appid未内置 通过Major获取 为了更好的性能请尝试更新NapCat`); + this.context.logger.log('[QQ版本兼容性检测] 当前版本Appid未内置 通过Major获取 为了更好的性能请尝试更新NapCat'); return { appid: majorAppid, qua: this.getQUAFallback() }; } } catch (error) { - this.context.logger.log(`[QQ版本兼容性检测] 通过Major 获取Appid异常 请检测NapCat/QQNT是否正常`); + this.context.logger.log('[QQ版本兼容性检测] 通过Major 获取Appid异常 请检测NapCat/QQNT是否正常'); } // 最终兜底为老版本 - this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`); + this.context.logger.log('[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常'); this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`,); return { appid: this.getAppIdFallback(), qua: this.getQUAFallback() }; } diff --git a/src/core/adapters/NodeIDependsAdapter.ts b/src/core/adapters/NodeIDependsAdapter.ts index 8af142c5..03652aff 100644 --- a/src/core/adapters/NodeIDependsAdapter.ts +++ b/src/core/adapters/NodeIDependsAdapter.ts @@ -1,4 +1,4 @@ -import { MsfChangeReasonType, MsfStatusType } from "@/core/types/adapter"; +import { MsfChangeReasonType, MsfStatusType } from '@/core/types/adapter'; export class NodeIDependsAdapter { onMSFStatusChange(statusType: MsfStatusType, changeReasonType: MsfChangeReasonType) { diff --git a/src/core/apis/packet.ts b/src/core/apis/packet.ts index 358cea68..8b573631 100644 --- a/src/core/apis/packet.ts +++ b/src/core/apis/packet.ts @@ -1,9 +1,9 @@ import * as os from 'os'; import offset from '@/core/external/offset.json'; -import { InstanceContext, NapCatCore } from "@/core"; -import { LogWrapper } from "@/common/log"; -import { PacketClientSession } from "@/core/packet/clientSession"; -import { napCatVersion } from "@/common/version"; +import { InstanceContext, NapCatCore } from '@/core'; +import { LogWrapper } from '@/common/log'; +import { PacketClientSession } from '@/core/packet/clientSession'; +import { napCatVersion } from '@/common/version'; interface OffsetType { [key: string]: { diff --git a/src/core/apis/webapi.ts b/src/core/apis/webapi.ts index 37707f24..f6b436c1 100644 --- a/src/core/apis/webapi.ts +++ b/src/core/apis/webapi.ts @@ -322,18 +322,18 @@ export class NTQQWebApi { data: pskey, appid: 5 }, - appid: "qun", + appid: 'qun', checksum: img_md5, check_type: 0, file_len: img_size, env: { - refer: "qzone", - deviceInfo: "h5" + refer: 'qzone', + deviceInfo: 'h5' }, model: 0, biz_req: { sPicTitle: img_name, - sPicDesc: "", + sPicDesc: '', sAlbumName: sAlbumName, sAlbumID: sAlbumID, iAlbumTypeID: 0, @@ -341,7 +341,7 @@ export class NTQQWebApi { iUploadType: 0, iUpPicType: 0, iBatchID: time, - sPicPath: "", + sPicPath: '', iPicWidth: 0, iPicHight: 0, iWaterType: 0, @@ -349,19 +349,19 @@ export class NTQQWebApi { iNeedFeeds: 1, iUploadTime: time, mapExt: { - appid: "qun", + appid: 'qun', userid: gc } }, - session: "", + session: '', asy_upload: 0, - cmd: "FileUpload" + cmd: 'FileUpload' }] }; const api = `https://h5.qzone.qq.com/webapp/json/sliceUpload/FileBatchControl/${img_md5}?g_tk=${GTK}`; const post = await RequestUtil.HttpGetJson(api, 'POST', body, { - "Cookie": cookie, - "Content-Type": "application/json" + 'Cookie': cookie, + 'Content-Type': 'application/json' }); return post; diff --git a/src/core/helper/adaptDecoder.ts b/src/core/helper/adaptDecoder.ts index f3910363..f6298592 100644 --- a/src/core/helper/adaptDecoder.ts +++ b/src/core/helper/adaptDecoder.ts @@ -1,5 +1,5 @@ // TODO: further refactor in NapCat.Packet v2 -import { NapProtoMsg, ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { NapProtoMsg, ProtoField, ScalarType } from '@napneko/nap-proto-core'; const LikeDetail = { txt: ProtoField(1, ScalarType.STRING), diff --git a/src/core/helper/rkey.ts b/src/core/helper/rkey.ts index 25e6e8e2..5e0cb588 100644 --- a/src/core/helper/rkey.ts +++ b/src/core/helper/rkey.ts @@ -32,7 +32,7 @@ export class RkeyManager { } if (this.failureCount >= this.FAILURE_LIMIT) { - this.logger.logError(`[Rkey] 服务存在异常, 图片使用FallBack机制`); + this.logger.logError('[Rkey] 服务存在异常, 图片使用FallBack机制'); throw new Error('获取rkey失败次数过多,请稍后再试'); } diff --git a/src/core/helper/status.ts b/src/core/helper/status.ts index efcd1818..b3884de0 100644 --- a/src/core/helper/status.ts +++ b/src/core/helper/status.ts @@ -1,5 +1,5 @@ -import os from "node:os"; -import EventEmitter from "node:events"; +import os from 'node:os'; +import EventEmitter from 'node:events'; export interface SystemStatus { cpu: { diff --git a/src/core/index.ts b/src/core/index.ts index 05f40714..0552f2ac 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -52,7 +52,7 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi { } let wrapperNodePath = path.resolve(appPath, 'wrapper.node'); if (!fs.existsSync(wrapperNodePath)) { - wrapperNodePath = path.join(appPath, `./resources/app/wrapper.node`); + wrapperNodePath = path.join(appPath, './resources/app/wrapper.node'); } //老版本兼容 未来去掉 if (!fs.existsSync(wrapperNodePath)) { @@ -74,7 +74,7 @@ export function getMajorPath(QQVersion: string): string { } let majorPath = path.resolve(appPath, 'major.node'); if (!fs.existsSync(majorPath)) { - majorPath = path.join(appPath, `./resources/app/major.node`); + majorPath = path.join(appPath, './resources/app/major.node'); } //老版本兼容 未来去掉 if (!fs.existsSync(majorPath)) { @@ -177,7 +177,7 @@ export class NapCatCore { profileListener.onSelfStatusChanged = (Info: SelfStatusInfo) => { if (Info.status == 20) { this.selfInfo.online = false; - this.context.logger.log("账号状态变更为离线"); + this.context.logger.log('账号状态变更为离线'); } else { this.selfInfo.online = true; } diff --git a/src/core/packet/client/baseClient.ts b/src/core/packet/client/baseClient.ts index 4a8fab29..df5e15dd 100644 --- a/src/core/packet/client/baseClient.ts +++ b/src/core/packet/client/baseClient.ts @@ -1,9 +1,9 @@ -import { LRUCache } from "@/common/lru-cache"; -import crypto, { createHash } from "crypto"; -import { OidbPacket, PacketHexStr } from "@/core/packet/transformer/base"; -import { LogStack } from "@/core/packet/context/clientContext"; -import { NapCoreContext } from "@/core/packet/context/napCoreContext"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; +import { LRUCache } from '@/common/lru-cache'; +import crypto, { createHash } from 'crypto'; +import { OidbPacket, PacketHexStr } from '@/core/packet/transformer/base'; +import { LogStack } from '@/core/packet/context/clientContext'; +import { NapCoreContext } from '@/core/packet/context/napCoreContext'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; export interface RecvPacket { type: string, // 仅recv diff --git a/src/core/packet/client/nativeClient.ts b/src/core/packet/client/nativeClient.ts index da03b5a5..ad3ae995 100644 --- a/src/core/packet/client/nativeClient.ts +++ b/src/core/packet/client/nativeClient.ts @@ -1,13 +1,13 @@ -import { createHash } from "crypto"; -import path, { dirname } from "path"; -import { fileURLToPath } from "url"; -import fs from "fs"; -import { IPacketClient } from "@/core/packet/client/baseClient"; -import { constants } from "node:os"; -import { LRUCache } from "@/common/lru-cache"; -import { LogStack } from "@/core/packet/context/clientContext"; -import { NapCoreContext } from "@/core/packet/context/napCoreContext"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; +import { createHash } from 'crypto'; +import path, { dirname } from 'path'; +import { fileURLToPath } from 'url'; +import fs from 'fs'; +import { IPacketClient } from '@/core/packet/client/baseClient'; +import { constants } from 'node:os'; +import { LRUCache } from '@/common/lru-cache'; +import { LogStack } from '@/core/packet/context/clientContext'; +import { NapCoreContext } from '@/core/packet/context/napCoreContext'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; // 0 send 1 recv export interface NativePacketExportType { diff --git a/src/core/packet/client/wsClient.ts b/src/core/packet/client/wsClient.ts index c744f84e..6c86b054 100644 --- a/src/core/packet/client/wsClient.ts +++ b/src/core/packet/client/wsClient.ts @@ -1,8 +1,8 @@ -import { Data, WebSocket, ErrorEvent } from "ws"; -import { IPacketClient, RecvPacket } from "@/core/packet/client/baseClient"; -import { LogStack } from "@/core/packet/context/clientContext"; -import { NapCoreContext } from "@/core/packet/context/napCoreContext"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; +import { Data, WebSocket, ErrorEvent } from 'ws'; +import { IPacketClient, RecvPacket } from '@/core/packet/client/baseClient'; +import { LogStack } from '@/core/packet/context/clientContext'; +import { NapCoreContext } from '@/core/packet/context/napCoreContext'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; export class WsPacketClient extends IPacketClient { private websocket: WebSocket | null = null; @@ -23,7 +23,7 @@ export class WsPacketClient extends IPacketClient { check(): boolean { if (!this.napcore.config.packetServer) { - this.logStack.pushLogWarn(`wsPacketClient 未配置服务器地址`); + this.logStack.pushLogWarn('wsPacketClient 未配置服务器地址'); return false; } return true; @@ -80,7 +80,7 @@ export class WsPacketClient extends IPacketClient { }; this.websocket.onclose = () => { this.available = false; - this.logger.warn(`WebSocket 连接关闭,尝试重连...`); + this.logger.warn('WebSocket 连接关闭,尝试重连...'); reject(new Error('WebSocket 连接关闭')); }; this.websocket.onmessage = (event) => this.handleMessage(event.data).catch(err => { diff --git a/src/core/packet/clientSession.ts b/src/core/packet/clientSession.ts index 3faea314..4f2dc55a 100644 --- a/src/core/packet/clientSession.ts +++ b/src/core/packet/clientSession.ts @@ -1,5 +1,5 @@ -import { PacketContext } from "@/core/packet/context/packetContext"; -import { NapCatCore } from "@/core"; +import { PacketContext } from '@/core/packet/context/packetContext'; +import { NapCatCore } from '@/core'; export class PacketClientSession { private readonly context: PacketContext; diff --git a/src/core/packet/context/clientContext.ts b/src/core/packet/context/clientContext.ts index 168a9abc..98eb145a 100644 --- a/src/core/packet/context/clientContext.ts +++ b/src/core/packet/context/clientContext.ts @@ -1,9 +1,9 @@ -import { IPacketClient } from "@/core/packet/client/baseClient"; -import { NativePacketClient } from "@/core/packet/client/nativeClient"; -import { WsPacketClient } from "@/core/packet/client/wsClient"; -import { OidbPacket } from "@/core/packet/transformer/base"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; -import { NapCoreContext } from "@/core/packet/context/napCoreContext"; +import { IPacketClient } from '@/core/packet/client/baseClient'; +import { NativePacketClient } from '@/core/packet/client/nativeClient'; +import { WsPacketClient } from '@/core/packet/client/wsClient'; +import { OidbPacket } from '@/core/packet/transformer/base'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; +import { NapCoreContext } from '@/core/packet/context/napCoreContext'; type clientPriority = { [key: number]: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => IPacketClient; @@ -77,22 +77,22 @@ export class PacketClientContext { async sendOidbPacket(pkt: OidbPacket, rsp?: T): Promise { const raw = await this._client.sendOidbPacket(pkt, rsp); - return (rsp ? Buffer.from(raw.hex_data, "hex") : undefined) as T extends true ? Buffer : void; + return (rsp ? Buffer.from(raw.hex_data, 'hex') : undefined) as T extends true ? Buffer : void; } private newClient(): IPacketClient { const prefer = this.napCore.config.packetBackend; let client: IPacketClient | null; switch (prefer) { - case "native": - this.logger.info("使用指定的 NativePacketClient 作为后端"); + case 'native': + this.logger.info('使用指定的 NativePacketClient 作为后端'); client = new NativePacketClient(this.napCore, this.logger, this.logStack); break; - case "frida": - this.logger.info("[Core] [Packet] 使用指定的 FridaPacketClient 作为后端"); + case 'frida': + this.logger.info('[Core] [Packet] 使用指定的 FridaPacketClient 作为后端'); client = new WsPacketClient(this.napCore, this.logger, this.logStack); break; - case "auto": + case 'auto': case undefined: client = this.judgeClient(); break; @@ -101,10 +101,10 @@ export class PacketClientContext { client = null; } if (!client?.check()) { - throw new Error("[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!"); + throw new Error('[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!'); } if (!client) { - throw new Error("[Core] [Packet] 后端异常,NapCat.Packet将不会加载!"); + throw new Error('[Core] [Packet] 后端异常,NapCat.Packet将不会加载!'); } return client; } @@ -120,7 +120,7 @@ export class PacketClientContext { .sort((a, b) => b.score - a.score); const selectedClient = sortedClients[0]?.client; if (!selectedClient) { - throw new Error("[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!"); + throw new Error('[Core] [Packet] 无可用的后端,NapCat.Packet将不会加载!'); } this.logger.info(`自动选择 ${selectedClient.constructor.name} 作为后端`); return selectedClient; diff --git a/src/core/packet/context/loggerContext.ts b/src/core/packet/context/loggerContext.ts index 8c855f8f..86e89806 100644 --- a/src/core/packet/context/loggerContext.ts +++ b/src/core/packet/context/loggerContext.ts @@ -1,5 +1,5 @@ -import { LogLevel, LogWrapper } from "@/common/log"; -import { NapCoreContext } from "@/core/packet/context/napCoreContext"; +import { LogLevel, LogWrapper } from '@/common/log'; +import { NapCoreContext } from '@/core/packet/context/napCoreContext'; // TODO: check bind? export class PacketLogger { @@ -10,7 +10,7 @@ export class PacketLogger { } private _log(level: LogLevel, ...msg: any[]): void { - this.napLogger._log(level, "[Core] [Packet] " + msg); + this.napLogger._log(level, '[Core] [Packet] ' + msg); } debug(...msg: any[]): void { diff --git a/src/core/packet/context/napCoreContext.ts b/src/core/packet/context/napCoreContext.ts index d19c8616..15209bff 100644 --- a/src/core/packet/context/napCoreContext.ts +++ b/src/core/packet/context/napCoreContext.ts @@ -1,4 +1,4 @@ -import { NapCatCore } from "@/core"; +import { NapCatCore } from '@/core'; export interface NapCoreCompatBasicInfo { readonly uin: number; diff --git a/src/core/packet/context/operationContext.ts b/src/core/packet/context/operationContext.ts index 0fe50b62..6cf58ffe 100644 --- a/src/core/packet/context/operationContext.ts +++ b/src/core/packet/context/operationContext.ts @@ -1,20 +1,20 @@ import * as crypto from 'crypto'; -import { PacketContext } from "@/core/packet/context/packetContext"; -import * as trans from "@/core/packet/transformer"; -import { PacketMsg } from "@/core/packet/message/message"; +import { PacketContext } from '@/core/packet/context/packetContext'; +import * as trans from '@/core/packet/transformer'; +import { PacketMsg } from '@/core/packet/message/message'; import { PacketMsgFileElement, PacketMsgPicElement, PacketMsgPttElement, PacketMsgVideoElement -} from "@/core/packet/message/element"; -import { ChatType } from "@/core"; -import { MiniAppRawData, MiniAppReqParams } from "@/core/packet/entities/miniApp"; -import { AIVoiceChatType } from "@/core/packet/entities/aiChat"; -import { NapProtoDecodeStructType, NapProtoEncodeStructType } from "@napneko/nap-proto-core"; -import { IndexNode, MsgInfo } from "@/core/packet/transformer/proto"; -import { OidbPacket } from "@/core/packet/transformer/base"; -import { ImageOcrResult } from "@/core/packet/entities/ocrResult"; +} from '@/core/packet/message/element'; +import { ChatType } from '@/core'; +import { MiniAppRawData, MiniAppReqParams } from '@/core/packet/entities/miniApp'; +import { AIVoiceChatType } from '@/core/packet/entities/aiChat'; +import { NapProtoDecodeStructType, NapProtoEncodeStructType } from '@napneko/nap-proto-core'; +import { IndexNode, MsgInfo } from '@/core/packet/transformer/proto'; +import { OidbPacket } from '@/core/packet/transformer/base'; +import { ImageOcrResult } from '@/core/packet/entities/ocrResult'; export class PacketOperationContext { private readonly context: PacketContext; diff --git a/src/core/packet/context/packetContext.ts b/src/core/packet/context/packetContext.ts index b5484e5d..6a158166 100644 --- a/src/core/packet/context/packetContext.ts +++ b/src/core/packet/context/packetContext.ts @@ -1,10 +1,10 @@ -import { PacketHighwayContext } from "@/core/packet/highway/highwayContext"; -import { NapCatCore } from "@/core"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; -import { NapCoreContext } from "@/core/packet/context/napCoreContext"; -import { PacketClientContext } from "@/core/packet/context/clientContext"; -import { PacketOperationContext } from "@/core/packet/context/operationContext"; -import { PacketMsgConverter } from "@/core/packet/message/converter"; +import { PacketHighwayContext } from '@/core/packet/highway/highwayContext'; +import { NapCatCore } from '@/core'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; +import { NapCoreContext } from '@/core/packet/context/napCoreContext'; +import { PacketClientContext } from '@/core/packet/context/clientContext'; +import { PacketOperationContext } from '@/core/packet/context/operationContext'; +import { PacketMsgConverter } from '@/core/packet/message/converter'; export class PacketContext { readonly msgConverter: PacketMsgConverter; diff --git a/src/core/packet/highway/client.ts b/src/core/packet/highway/client.ts index e4c4d7fc..18274c64 100644 --- a/src/core/packet/highway/client.ts +++ b/src/core/packet/highway/client.ts @@ -1,9 +1,9 @@ import * as stream from 'node:stream'; -import { ReadStream } from "node:fs"; -import { HighwayTcpUploader } from "@/core/packet/highway/uploader/highwayTcpUploader"; -import { HighwayHttpUploader } from "@/core/packet/highway/uploader/highwayHttpUploader"; -import { PacketHighwaySig } from "@/core/packet/highway/highwayContext"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; +import { ReadStream } from 'node:fs'; +import { HighwayTcpUploader } from '@/core/packet/highway/uploader/highwayTcpUploader'; +import { HighwayHttpUploader } from '@/core/packet/highway/uploader/highwayHttpUploader'; +import { PacketHighwaySig } from '@/core/packet/highway/highwayContext'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; export interface PacketHighwayTrans { uin: string; diff --git a/src/core/packet/highway/frame.ts b/src/core/packet/highway/frame.ts index e0f87c4b..96806d2c 100644 --- a/src/core/packet/highway/frame.ts +++ b/src/core/packet/highway/frame.ts @@ -1,4 +1,4 @@ -import assert from "node:assert"; +import assert from 'node:assert'; export class Frame{ static pack(head: Buffer, body: Buffer): Buffer { diff --git a/src/core/packet/highway/highwayContext.ts b/src/core/packet/highway/highwayContext.ts index 2fdd6f52..76904cfd 100644 --- a/src/core/packet/highway/highwayContext.ts +++ b/src/core/packet/highway/highwayContext.ts @@ -1,22 +1,22 @@ -import { PacketHighwayClient } from "@/core/packet/highway/client"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; -import FetchSessionKey from "@/core/packet/transformer/highway/FetchSessionKey"; -import { int32ip2str, oidbIpv4s2HighwayIpv4s } from "@/core/packet/highway/utils"; +import { PacketHighwayClient } from '@/core/packet/highway/client'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; +import FetchSessionKey from '@/core/packet/transformer/highway/FetchSessionKey'; +import { int32ip2str, oidbIpv4s2HighwayIpv4s } from '@/core/packet/highway/utils'; import { PacketMsgFileElement, PacketMsgPicElement, PacketMsgPttElement, PacketMsgVideoElement -} from "@/core/packet/message/element"; -import { ChatType, Peer } from "@/core"; -import { calculateSha1, calculateSha1StreamBytes, computeMd5AndLengthWithLimit } from "@/core/packet/utils/crypto/hash"; -import UploadGroupImage from "@/core/packet/transformer/highway/UploadGroupImage"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import * as proto from "@/core/packet/transformer/proto"; -import * as trans from "@/core/packet/transformer"; -import fs from "fs"; -import { NapCoreContext } from "@/core/packet/context/napCoreContext"; -import { PacketClientContext } from "@/core/packet/context/clientContext"; +} from '@/core/packet/message/element'; +import { ChatType, Peer } from '@/core'; +import { calculateSha1, calculateSha1StreamBytes, computeMd5AndLengthWithLimit } from '@/core/packet/utils/crypto/hash'; +import UploadGroupImage from '@/core/packet/transformer/highway/UploadGroupImage'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import * as proto from '@/core/packet/transformer/proto'; +import * as trans from '@/core/packet/transformer'; +import fs from 'fs'; +import { NapCoreContext } from '@/core/packet/context/napCoreContext'; +import { PacketClientContext } from '@/core/packet/context/clientContext'; export const BlockSize = 1024 * 1024; @@ -142,7 +142,7 @@ export class PacketHighwayContext { const resp = await this.client.sendOidbPacket(req, true); const preRespData = UploadGroupImage.parse(resp); const ukey = preRespData.upload.uKey; - if (ukey && ukey != "") { + if (ukey && ukey != '') { this.logger.debug(`[Highway] uploadGroupImageReq get upload ukey: ${ukey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[0].index; const sha1 = Buffer.from(index.info.fileSha1, 'hex'); @@ -179,7 +179,7 @@ export class PacketHighwayContext { const resp = await this.client.sendOidbPacket(req, true); const preRespData = trans.UploadPrivateImage.parse(resp); const ukey = preRespData.upload.uKey; - if (ukey && ukey != "") { + if (ukey && ukey != '') { this.logger.debug(`[Highway] uploadC2CImageReq get upload ukey: ${ukey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[0].index; const sha1 = Buffer.from(index.info.fileSha1, 'hex'); @@ -210,14 +210,14 @@ export class PacketHighwayContext { } private async uploadGroupVideo(groupUin: number, video: PacketMsgVideoElement): Promise { - if (!video.filePath || !video.thumbPath) throw new Error("video.filePath or video.thumbPath is empty"); + if (!video.filePath || !video.thumbPath) throw new Error('video.filePath or video.thumbPath is empty'); video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex'); video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex'); const req = trans.UploadGroupVideo.build(groupUin, video); const resp = await this.client.sendOidbPacket(req, true); const preRespData = trans.UploadGroupVideo.parse(resp); const ukey = preRespData.upload.uKey; - if (ukey && ukey != "") { + if (ukey && ukey != '') { this.logger.debug(`[Highway] uploadGroupVideoReq get upload video ukey: ${ukey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[0].index; const md5 = Buffer.from(index.info.fileHash, 'hex'); @@ -244,7 +244,7 @@ export class PacketHighwayContext { this.logger.debug(`[Highway] uploadGroupVideoReq get upload invalid ukey ${ukey}, don't need upload!`); } const subFile = preRespData.upload.subFileInfos[0]; - if (subFile.uKey && subFile.uKey != "") { + if (subFile.uKey && subFile.uKey != '') { this.logger.debug(`[Highway] uploadGroupVideoReq get upload video thumb ukey: ${subFile.uKey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[1].index; const md5 = Buffer.from(index.info.fileHash, 'hex'); @@ -275,14 +275,14 @@ export class PacketHighwayContext { } private async uploadC2CVideo(peerUid: string, video: PacketMsgVideoElement): Promise { - if (!video.filePath || !video.thumbPath) throw new Error("video.filePath or video.thumbPath is empty"); + if (!video.filePath || !video.thumbPath) throw new Error('video.filePath or video.thumbPath is empty'); video.fileSha1 = Buffer.from(await calculateSha1(video.filePath)).toString('hex'); video.thumbSha1 = Buffer.from(await calculateSha1(video.thumbPath)).toString('hex'); const req = trans.UploadPrivateVideo.build(peerUid, video); const resp = await this.client.sendOidbPacket(req, true); const preRespData = trans.UploadPrivateVideo.parse(resp); const ukey = preRespData.upload.uKey; - if (ukey && ukey != "") { + if (ukey && ukey != '') { this.logger.debug(`[Highway] uploadC2CVideoReq get upload video ukey: ${ukey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[0].index; const md5 = Buffer.from(index.info.fileHash, 'hex'); @@ -309,7 +309,7 @@ export class PacketHighwayContext { this.logger.debug(`[Highway] uploadC2CVideoReq get upload invalid ukey ${ukey}, don't need upload!`); } const subFile = preRespData.upload.subFileInfos[0]; - if (subFile.uKey && subFile.uKey != "") { + if (subFile.uKey && subFile.uKey != '') { this.logger.debug(`[Highway] uploadC2CVideoReq get upload video thumb ukey: ${subFile.uKey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[1].index; const md5 = Buffer.from(index.info.fileHash, 'hex'); @@ -345,7 +345,7 @@ export class PacketHighwayContext { const resp = await this.client.sendOidbPacket(req, true); const preRespData = trans.UploadGroupPtt.parse(resp); const ukey = preRespData.upload.uKey; - if (ukey && ukey != "") { + if (ukey && ukey != '') { this.logger.debug(`[Highway] uploadGroupPttReq get upload ptt ukey: ${ukey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[0].index; const md5 = Buffer.from(index.info.fileHash, 'hex'); @@ -381,7 +381,7 @@ export class PacketHighwayContext { const resp = await this.client.sendOidbPacket(req, true); const preRespData = trans.UploadPrivatePtt.parse(resp); const ukey = preRespData.upload.uKey; - if (ukey && ukey != "") { + if (ukey && ukey != '') { this.logger.debug(`[Highway] uploadC2CPttReq get upload ptt ukey: ${ukey}, need upload!`); const index = preRespData.upload.msgInfo.msgInfoBody[0].index; const md5 = Buffer.from(index.info.fileHash, 'hex'); @@ -419,7 +419,7 @@ export class PacketHighwayContext { const resp = await this.client.sendOidbPacket(req, true); const preRespData = trans.UploadGroupFile.parse(resp); if (!preRespData?.upload?.boolFileExist) { - this.logger.debug(`[Highway] uploadGroupFileReq file not exist, need upload!`); + this.logger.debug('[Highway] uploadGroupFileReq file not exist, need upload!'); const ext = new NapProtoMsg(proto.FileUploadExt).encode({ unknown1: 100, unknown2: 1, @@ -439,9 +439,9 @@ export class PacketHighwayContext { }, clientInfo: { clientType: 3, - appId: "100", + appId: '100', terminalType: 3, - clientVer: "1.1.1", + clientVer: '1.1.1', unknown: 4 }, fileNameInfo: { @@ -469,7 +469,7 @@ export class PacketHighwayContext { ext ); } else { - this.logger.debug(`[Highway] uploadGroupFileReq file exist, don't need upload!`); + this.logger.debug('[Highway] uploadGroupFileReq file exist, don\'t need upload!'); } file.fileUuid = preRespData.upload.fileId; } @@ -482,7 +482,7 @@ export class PacketHighwayContext { const res = await this.client.sendOidbPacket(req, true); const preRespData = trans.UploadPrivateFile.parse(res); if (!preRespData.upload?.boolFileExist) { - this.logger.debug(`[Highway] uploadC2CFileReq file not exist, need upload!`); + this.logger.debug('[Highway] uploadC2CFileReq file not exist, need upload!'); const ext = new NapProtoMsg(proto.FileUploadExt).encode({ unknown1: 100, unknown2: 1, @@ -500,9 +500,9 @@ export class PacketHighwayContext { }, clientInfo: { clientType: 3, - appId: "100", + appId: '100', terminalType: 3, - clientVer: "1.1.1", + clientVer: '1.1.1', unknown: 4 }, fileNameInfo: { diff --git a/src/core/packet/highway/uploader/highwayHttpUploader.ts b/src/core/packet/highway/uploader/highwayHttpUploader.ts index 962261a2..4c14ce87 100644 --- a/src/core/packet/highway/uploader/highwayHttpUploader.ts +++ b/src/core/packet/highway/uploader/highwayHttpUploader.ts @@ -1,9 +1,9 @@ -import crypto from "node:crypto"; -import http from "node:http"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { IHighwayUploader } from "@/core/packet/highway/uploader/highwayUploader"; -import { Frame } from "@/core/packet/highway/frame"; -import * as proto from "@/core/packet/transformer/proto"; +import crypto from 'node:crypto'; +import http from 'node:http'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { IHighwayUploader } from '@/core/packet/highway/uploader/highwayUploader'; +import { Frame } from '@/core/packet/highway/frame'; +import * as proto from '@/core/packet/transformer/proto'; export class HighwayHttpUploader extends IHighwayUploader { async upload(): Promise { diff --git a/src/core/packet/highway/uploader/highwayTcpUploader.ts b/src/core/packet/highway/uploader/highwayTcpUploader.ts index 69e02ed2..35f23b21 100644 --- a/src/core/packet/highway/uploader/highwayTcpUploader.ts +++ b/src/core/packet/highway/uploader/highwayTcpUploader.ts @@ -1,11 +1,11 @@ -import net from "node:net"; -import stream from "node:stream"; -import crypto from "node:crypto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { BlockSize } from "@/core/packet/highway/highwayContext"; -import { Frame } from "@/core/packet/highway/frame"; -import { IHighwayUploader } from "@/core/packet/highway/uploader/highwayUploader"; -import * as proto from "@/core/packet/transformer/proto"; +import net from 'node:net'; +import stream from 'node:stream'; +import crypto from 'node:crypto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { BlockSize } from '@/core/packet/highway/highwayContext'; +import { Frame } from '@/core/packet/highway/frame'; +import { IHighwayUploader } from '@/core/packet/highway/uploader/highwayUploader'; +import * as proto from '@/core/packet/transformer/proto'; class HighwayTcpUploaderTransform extends stream.Transform { uploader: HighwayTcpUploader; diff --git a/src/core/packet/highway/uploader/highwayUploader.ts b/src/core/packet/highway/uploader/highwayUploader.ts index c8902dff..57d71409 100644 --- a/src/core/packet/highway/uploader/highwayUploader.ts +++ b/src/core/packet/highway/uploader/highwayUploader.ts @@ -1,8 +1,8 @@ -import * as tea from "@/core/packet/utils/crypto/tea"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { PacketHighwayTrans } from "@/core/packet/highway/client"; -import { PacketLogger } from "@/core/packet/context/loggerContext"; -import * as proto from "@/core/packet/transformer/proto"; +import * as tea from '@/core/packet/utils/crypto/tea'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { PacketHighwayTrans } from '@/core/packet/highway/client'; +import { PacketLogger } from '@/core/packet/context/loggerContext'; +import * as proto from '@/core/packet/transformer/proto'; export abstract class IHighwayUploader { readonly trans: PacketHighwayTrans; @@ -32,7 +32,7 @@ export abstract class IHighwayUploader { msgBaseHead: { version: 1, uin: this.trans.uin, - command: "PicUp.DataUp", + command: 'PicUp.DataUp', seq: 0, retryTimes: 0, appId: 1600001604, diff --git a/src/core/packet/highway/utils.ts b/src/core/packet/highway/utils.ts index 64b84cef..18cf7462 100644 --- a/src/core/packet/highway/utils.ts +++ b/src/core/packet/highway/utils.ts @@ -1,5 +1,5 @@ -import { NapProtoEncodeStructType } from "@napneko/nap-proto-core"; -import * as proto from "@/core/packet/transformer/proto"; +import { NapProtoEncodeStructType } from '@napneko/nap-proto-core'; +import * as proto from '@/core/packet/transformer/proto'; export const int32ip2str = (ip: number) => { diff --git a/src/core/packet/message/builder.ts b/src/core/packet/message/builder.ts index addb8771..2503645b 100644 --- a/src/core/packet/message/builder.ts +++ b/src/core/packet/message/builder.ts @@ -1,14 +1,14 @@ -import * as crypto from "crypto"; -import { PushMsgBody } from "@/core/packet/transformer/proto"; -import { NapProtoEncodeStructType } from "@napneko/nap-proto-core"; -import { PacketMsg, PacketSendMsgElement } from "@/core/packet/message/message"; -import { IPacketMsgElement, PacketMsgTextElement } from "@/core/packet/message/element"; -import { SendTextElement } from "@/core"; +import * as crypto from 'crypto'; +import { PushMsgBody } from '@/core/packet/transformer/proto'; +import { NapProtoEncodeStructType } from '@napneko/nap-proto-core'; +import { PacketMsg, PacketSendMsgElement } from '@/core/packet/message/message'; +import { IPacketMsgElement, PacketMsgTextElement } from '@/core/packet/message/element'; +import { SendTextElement } from '@/core'; export class PacketMsgBuilder { protected static failBackText = new PacketMsgTextElement( { - textElement: { content: "[该消息类型暂不支持查看]" } + textElement: { content: '[该消息类型暂不支持查看]' } } as SendTextElement ); @@ -24,7 +24,7 @@ export class PacketMsgBuilder { } return { responseHead: { - fromUid: "", + fromUid: '', fromUin: node.senderUin, toUid: node.groupId ? undefined : selfUid, forward: node.groupId ? undefined : { diff --git a/src/core/packet/message/converter.ts b/src/core/packet/message/converter.ts index cb193ed4..f995ac3e 100644 --- a/src/core/packet/message/converter.ts +++ b/src/core/packet/message/converter.ts @@ -15,7 +15,7 @@ import { SendStructLongMsgElement, SendTextElement, SendVideoElement -} from "@/core"; +} from '@/core'; import { IPacketMsgElement, PacketMsgAtElement, @@ -30,8 +30,8 @@ import { PacketMsgTextElement, PacketMsgVideoElement, PacketMultiMsgElement -} from "@/core/packet/message/element"; -import { PacketMsg, PacketSendMsgElement } from "@/core/packet/message/message"; +} from '@/core/packet/message/element'; +import { PacketMsg, PacketSendMsgElement } from '@/core/packet/message/message'; const SupportedElementTypes = [ ElementType.TEXT, @@ -146,7 +146,7 @@ export class PacketMsgConverter { ? msg.sendMemberName : msg.sendNickName && msg.sendNickName !== '' ? msg.sendNickName - : "QQ用户", + : 'QQ用户', time: +msg.msgTime, msg: msg.elements.map((element) => { if (!this.isValidElementType(element.elementType)) return null; diff --git a/src/core/packet/message/element.ts b/src/core/packet/message/element.ts index 3dfd7ec3..24861c5e 100644 --- a/src/core/packet/message/element.ts +++ b/src/core/packet/message/element.ts @@ -1,5 +1,5 @@ -import * as zlib from "node:zlib"; -import { NapProtoEncodeStructType, NapProtoMsg } from "@napneko/nap-proto-core"; +import * as zlib from 'node:zlib'; +import { NapProtoEncodeStructType, NapProtoMsg } from '@napneko/nap-proto-core'; import { CustomFace, Elem, @@ -12,7 +12,7 @@ import { OidbSvcTrpcTcp0XE37_800Response, FileExtra, GroupFileExtra -} from "@/core/packet/transformer/proto"; +} from '@/core/packet/transformer/proto'; import { BaseEmojiType, FaceType, @@ -29,9 +29,9 @@ import { SendStructLongMsgElement, SendTextElement, SendVideoElement -} from "@/core"; -import { ForwardMsgBuilder } from "@/common/forward-msg-builder"; -import { PacketMsg, PacketSendMsgElement } from "@/core/packet/message/message"; +} from '@/core'; +import { ForwardMsgBuilder } from '@/common/forward-msg-builder'; +import { PacketMsg, PacketSendMsgElement } from '@/core/packet/message/message'; // raw <-> packet // TODO: SendStructLongMsgElement @@ -153,7 +153,7 @@ export class PacketMsgReplyElement extends IPacketMsgElement { } toPreview(): string { - return "[回复消息]"; + return '[回复消息]'; } } @@ -175,12 +175,12 @@ export class PacketMsgFaceElement extends IPacketMsgElement { commonElem: { serviceType: 37, pbElem: new NapProtoMsg(QBigFaceExtra).encode({ - aniStickerPackId: "1", - aniStickerId: "8", + aniStickerPackId: '1', + aniStickerId: '8', faceId: this.faceId, sourceType: 1, resultId: this.resultId, - preview: "", + preview: '', randomType: 1 }), businessType: 1 @@ -198,8 +198,8 @@ export class PacketMsgFaceElement extends IPacketMsgElement { serviceType: 33, pbElem: new NapProtoMsg(QSmallFaceExtra).encode({ faceId: this.faceId, - preview: "", - preview2: "" + preview: '', + preview2: '' }), businessType: 1 } @@ -208,7 +208,7 @@ export class PacketMsgFaceElement extends IPacketMsgElement { } toPreview(): string { - return "[表情]"; + return '[表情]'; } } @@ -341,7 +341,7 @@ export class PacketMsgVideoElement extends IPacketMsgElement { } toPreview(): string { - return "[视频]"; + return '[视频]'; } } @@ -378,7 +378,7 @@ export class PacketMsgPttElement extends IPacketMsgElement { } toPreview(): string { - return "[语音]"; + return '[语音]'; } } @@ -450,7 +450,7 @@ export class PacketMsgFileElement extends IPacketMsgElement { fileSize: BigInt(this.fileSize), fileName: this.fileName, fileSha: this.fileSha1, - extInfoString: "", + extInfoString: '', fileMd5: this.fileMd5, } } @@ -489,7 +489,7 @@ export class PacketMsgLightAppElement extends IPacketMsgElement } toPreview(): string { - return "[卡片消息]"; + return '[卡片消息]'; } } @@ -540,6 +540,6 @@ export class PacketMultiMsgElement extends IPacketMsgElement { constructor() { diff --git a/src/core/packet/transformer/action/GetAiVoice.ts b/src/core/packet/transformer/action/GetAiVoice.ts index d5b9c6c1..5cb3483c 100644 --- a/src/core/packet/transformer/action/GetAiVoice.ts +++ b/src/core/packet/transformer/action/GetAiVoice.ts @@ -1,8 +1,8 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import { AIVoiceChatType } from "@/core/packet/entities/aiChat"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import { AIVoiceChatType } from '@/core/packet/entities/aiChat'; class GetAiVoice extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/action/GetMiniAppAdaptShareInfo.ts b/src/core/packet/transformer/action/GetMiniAppAdaptShareInfo.ts index b67818ce..135c86d4 100644 --- a/src/core/packet/transformer/action/GetMiniAppAdaptShareInfo.ts +++ b/src/core/packet/transformer/action/GetMiniAppAdaptShareInfo.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketHexStrBuilder, PacketTransformer } from "@/core/packet/transformer/base"; -import { MiniAppReqParams } from "@/core/packet/entities/miniApp"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketHexStrBuilder, PacketTransformer } from '@/core/packet/transformer/base'; +import { MiniAppReqParams } from '@/core/packet/entities/miniApp'; class GetMiniAppAdaptShareInfo extends PacketTransformer { constructor() { @@ -23,24 +23,24 @@ class GetMiniAppAdaptShareInfo extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/action/GroupSign.ts b/src/core/packet/transformer/action/GroupSign.ts index e8379279..11858847 100644 --- a/src/core/packet/transformer/action/GroupSign.ts +++ b/src/core/packet/transformer/action/GroupSign.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class GroupSign extends PacketTransformer { constructor() { @@ -14,7 +14,7 @@ class GroupSign extends PacketTransformer { body: { uin: String(uin), groupUin: String(groupCode), - version: "9.0.90" + version: '9.0.90' } } ); diff --git a/src/core/packet/transformer/action/ImageOCR.ts b/src/core/packet/transformer/action/ImageOCR.ts index 1f05a91c..02217f79 100644 --- a/src/core/packet/transformer/action/ImageOCR.ts +++ b/src/core/packet/transformer/action/ImageOCR.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class ImageOCR extends PacketTransformer { constructor() { @@ -16,11 +16,11 @@ class ImageOCR extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/action/SetSpecialTitle.ts b/src/core/packet/transformer/action/SetSpecialTitle.ts index ce99e023..c7dbb2ff 100644 --- a/src/core/packet/transformer/action/SetSpecialTitle.ts +++ b/src/core/packet/transformer/action/SetSpecialTitle.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class SetSpecialTitle extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/base.ts b/src/core/packet/transformer/base.ts index eda5b730..3df5df0e 100644 --- a/src/core/packet/transformer/base.ts +++ b/src/core/packet/transformer/base.ts @@ -1,5 +1,5 @@ -import { NapProtoDecodeStructType } from "@napneko/nap-proto-core"; -import { PacketMsgBuilder } from "@/core/packet/message/builder"; +import { NapProtoDecodeStructType } from '@napneko/nap-proto-core'; +import { PacketMsgBuilder } from '@/core/packet/message/builder'; export type PacketHexStr = string & { readonly hexNya: unique symbol }; diff --git a/src/core/packet/transformer/highway/DownloadGroupFile.ts b/src/core/packet/transformer/highway/DownloadGroupFile.ts index 00e077ff..c5b381dc 100644 --- a/src/core/packet/transformer/highway/DownloadGroupFile.ts +++ b/src/core/packet/transformer/highway/DownloadGroupFile.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class DownloadGroupFile extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/DownloadGroupPtt.ts b/src/core/packet/transformer/highway/DownloadGroupPtt.ts index c724868a..cc5028a3 100644 --- a/src/core/packet/transformer/highway/DownloadGroupPtt.ts +++ b/src/core/packet/transformer/highway/DownloadGroupPtt.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoEncodeStructType, NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoEncodeStructType, NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class DownloadGroupPtt extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/DownloadImage.ts b/src/core/packet/transformer/highway/DownloadImage.ts index 8d99fa2d..389e69bd 100644 --- a/src/core/packet/transformer/highway/DownloadImage.ts +++ b/src/core/packet/transformer/highway/DownloadImage.ts @@ -1,8 +1,8 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoEncodeStructType, NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import { IndexNode } from "@/core/packet/transformer/proto"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoEncodeStructType, NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import { IndexNode } from '@/core/packet/transformer/proto'; class DownloadImage extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/DownloadOfflineFile.ts b/src/core/packet/transformer/highway/DownloadOfflineFile.ts index 1ca3af7b..278f877a 100644 --- a/src/core/packet/transformer/highway/DownloadOfflineFile.ts +++ b/src/core/packet/transformer/highway/DownloadOfflineFile.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class DownloadOfflineFile extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/DownloadPrivateFile.ts b/src/core/packet/transformer/highway/DownloadPrivateFile.ts index 6355c08e..fd3027b8 100644 --- a/src/core/packet/transformer/highway/DownloadPrivateFile.ts +++ b/src/core/packet/transformer/highway/DownloadPrivateFile.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class DownloadPrivateFile extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/FetchSessionKey.ts b/src/core/packet/transformer/highway/FetchSessionKey.ts index 324968e9..263326f5 100644 --- a/src/core/packet/transformer/highway/FetchSessionKey.ts +++ b/src/core/packet/transformer/highway/FetchSessionKey.ts @@ -1,6 +1,6 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketHexStrBuilder, PacketTransformer } from "@/core/packet/transformer/base"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketHexStrBuilder, PacketTransformer } from '@/core/packet/transformer/base'; class FetchSessionKey extends PacketTransformer { constructor() { @@ -20,11 +20,11 @@ class FetchSessionKey extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/UploadGroupImage.ts b/src/core/packet/transformer/highway/UploadGroupImage.ts index 15d2f715..245a4af4 100644 --- a/src/core/packet/transformer/highway/UploadGroupImage.ts +++ b/src/core/packet/transformer/highway/UploadGroupImage.ts @@ -1,9 +1,9 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import crypto from "node:crypto"; -import { PacketMsgPicElement } from "@/core/packet/message/element"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import crypto from 'node:crypto'; +import { PacketMsgPicElement } from '@/core/packet/message/element'; class UploadGroupImage extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/UploadGroupPtt.ts b/src/core/packet/transformer/highway/UploadGroupPtt.ts index 820c56de..272c090b 100644 --- a/src/core/packet/transformer/highway/UploadGroupPtt.ts +++ b/src/core/packet/transformer/highway/UploadGroupPtt.ts @@ -1,9 +1,9 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import crypto from "node:crypto"; -import { PacketMsgPttElement } from "@/core/packet/message/element"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import crypto from 'node:crypto'; +import { PacketMsgPttElement } from '@/core/packet/message/element'; class UploadGroupPtt extends PacketTransformer { constructor() { @@ -57,7 +57,7 @@ class UploadGroupPtt extends PacketTransformer { compatQMsgSceneType: 2, extBizInfo: { pic: { - textSummary: "Nya~", + textSummary: 'Nya~', }, video: { bytesPbReserve: Buffer.alloc(0), diff --git a/src/core/packet/transformer/highway/UploadGroupVideo.ts b/src/core/packet/transformer/highway/UploadGroupVideo.ts index 0f8e12b8..9637f5d0 100644 --- a/src/core/packet/transformer/highway/UploadGroupVideo.ts +++ b/src/core/packet/transformer/highway/UploadGroupVideo.ts @@ -1,9 +1,9 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import crypto from "node:crypto"; -import { PacketMsgVideoElement } from "@/core/packet/message/element"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import crypto from 'node:crypto'; +import { PacketMsgVideoElement } from '@/core/packet/message/element'; class UploadGroupVideo extends PacketTransformer { constructor() { @@ -11,7 +11,7 @@ class UploadGroupVideo extends PacketTransformer } build(groupUin: number, video: PacketMsgVideoElement): OidbPacket { - if (!video.fileSize || !video.thumbSize) throw new Error("video.fileSize or video.thumbSize is empty"); + if (!video.fileSize || !video.thumbSize) throw new Error('video.fileSize or video.thumbSize is empty'); const data = new NapProtoMsg(proto.NTV2RichMediaReq).encode({ reqHead: { common: { @@ -37,7 +37,7 @@ class UploadGroupVideo extends PacketTransformer fileSize: +video.fileSize, fileHash: video.fileMd5, fileSha1: video.fileSha1, - fileName: "nya.mp4", + fileName: 'nya.mp4', type: { type: 2, picFormat: 0, @@ -55,7 +55,7 @@ class UploadGroupVideo extends PacketTransformer fileSize: +video.thumbSize, fileHash: video.thumbMd5, fileSha1: video.thumbSha1, - fileName: "nya.jpg", + fileName: 'nya.jpg', type: { type: 1, picFormat: 0, @@ -77,7 +77,7 @@ class UploadGroupVideo extends PacketTransformer extBizInfo: { pic: { bizType: 0, - textSummary: "Nya~", + textSummary: 'Nya~', }, video: { bytesPbReserve: Buffer.from([0x80, 0x01, 0x00]), diff --git a/src/core/packet/transformer/highway/UploadPrivateFile.ts b/src/core/packet/transformer/highway/UploadPrivateFile.ts index 30a94f4c..8083f785 100644 --- a/src/core/packet/transformer/highway/UploadPrivateFile.ts +++ b/src/core/packet/transformer/highway/UploadPrivateFile.ts @@ -1,9 +1,9 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import { PacketMsgFileElement } from "@/core/packet/message/element"; -import { computeMd5AndLengthWithLimit } from "@/core/packet/utils/crypto/hash"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import { PacketMsgFileElement } from '@/core/packet/message/element'; +import { computeMd5AndLengthWithLimit } from '@/core/packet/utils/crypto/hash'; class UploadPrivateFile extends PacketTransformer { constructor() { @@ -21,7 +21,7 @@ class UploadPrivateFile extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/highway/UploadPrivatePtt.ts b/src/core/packet/transformer/highway/UploadPrivatePtt.ts index e943bfd1..07b151de 100644 --- a/src/core/packet/transformer/highway/UploadPrivatePtt.ts +++ b/src/core/packet/transformer/highway/UploadPrivatePtt.ts @@ -1,9 +1,9 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import crypto from "node:crypto"; -import { PacketMsgPttElement } from "@/core/packet/message/element"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import crypto from 'node:crypto'; +import { PacketMsgPttElement } from '@/core/packet/message/element'; class UploadPrivatePtt extends PacketTransformer { constructor() { @@ -58,7 +58,7 @@ class UploadPrivatePtt extends PacketTransformer compatQMsgSceneType: 1, extBizInfo: { pic: { - textSummary: "Nya~", + textSummary: 'Nya~', }, ptt: { bytesReserve: Buffer.from([0x08, 0x00, 0x38, 0x00]), diff --git a/src/core/packet/transformer/highway/UploadPrivateVideo.ts b/src/core/packet/transformer/highway/UploadPrivateVideo.ts index f47312c5..24c05093 100644 --- a/src/core/packet/transformer/highway/UploadPrivateVideo.ts +++ b/src/core/packet/transformer/highway/UploadPrivateVideo.ts @@ -1,9 +1,9 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; -import crypto from "node:crypto"; -import { PacketMsgVideoElement } from "@/core/packet/message/element"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; +import crypto from 'node:crypto'; +import { PacketMsgVideoElement } from '@/core/packet/message/element'; class UploadPrivateVideo extends PacketTransformer { constructor() { @@ -11,7 +11,7 @@ class UploadPrivateVideo extends PacketTransformer { constructor() { @@ -14,7 +14,7 @@ class UploadForwardMsg extends PacketTransformer { const longMsgResultData = new NapProtoMsg(proto.LongMsgResult).encode( { action: { - actionCommand: "MultiMsg", + actionCommand: 'MultiMsg', actionData: { msgBody: msgBody } @@ -38,7 +38,7 @@ class UploadForwardMsg extends PacketTransformer { } ); return { - cmd: "trpc.group.long_msg_interface.MsgService.SsoSendLongMsg", + cmd: 'trpc.group.long_msg_interface.MsgService.SsoSendLongMsg', data: PacketHexStrBuilder(req) }; } diff --git a/src/core/packet/transformer/oidb/oidbBase.ts b/src/core/packet/transformer/oidb/oidbBase.ts index 23cffefc..83cf0ee4 100644 --- a/src/core/packet/transformer/oidb/oidbBase.ts +++ b/src/core/packet/transformer/oidb/oidbBase.ts @@ -1,6 +1,6 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketHexStrBuilder, PacketTransformer } from "@/core/packet/transformer/base"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketHexStrBuilder, PacketTransformer } from '@/core/packet/transformer/base'; class OidbBase extends PacketTransformer { constructor() { diff --git a/src/core/packet/transformer/proto/action/action.ts b/src/core/packet/transformer/proto/action/action.ts index 90f5add8..bd135726 100644 --- a/src/core/packet/transformer/proto/action/action.ts +++ b/src/core/packet/transformer/proto/action/action.ts @@ -1,6 +1,6 @@ -import { ScalarType } from "@protobuf-ts/runtime"; -import { ProtoField } from "@napneko/nap-proto-core"; -import { ContentHead, MessageBody, MessageControl, RoutingHead } from "@/core/packet/transformer/proto"; +import { ScalarType } from '@protobuf-ts/runtime'; +import { ProtoField } from '@napneko/nap-proto-core'; +import { ContentHead, MessageBody, MessageControl, RoutingHead } from '@/core/packet/transformer/proto'; export const FaceRoamRequest = { comm: ProtoField(1, () => PlatInfo, true), diff --git a/src/core/packet/transformer/proto/action/miniAppAdaptShareInfo.ts b/src/core/packet/transformer/proto/action/miniAppAdaptShareInfo.ts index c931992d..08e3c2a1 100644 --- a/src/core/packet/transformer/proto/action/miniAppAdaptShareInfo.ts +++ b/src/core/packet/transformer/proto/action/miniAppAdaptShareInfo.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const MiniAppAdaptShareInfoReq = { appId: ProtoField(2, ScalarType.STRING), diff --git a/src/core/packet/transformer/proto/highway/highway.ts b/src/core/packet/transformer/proto/highway/highway.ts index faeef73a..8e15e4e3 100644 --- a/src/core/packet/transformer/proto/highway/highway.ts +++ b/src/core/packet/transformer/proto/highway/highway.ts @@ -1,5 +1,5 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; -import { MsgInfoBody } from "@/core/packet/transformer/proto"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; +import { MsgInfoBody } from '@/core/packet/transformer/proto'; export const DataHighwayHead = { version: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/transformer/proto/index.ts b/src/core/packet/transformer/proto/index.ts index 4e2aa3a8..4f9534ab 100644 --- a/src/core/packet/transformer/proto/index.ts +++ b/src/core/packet/transformer/proto/index.ts @@ -1,32 +1,32 @@ // action folder -export * from "./action/action"; -export * from "./action/miniAppAdaptShareInfo"; +export * from './action/action'; +export * from './action/miniAppAdaptShareInfo'; // highway folder -export * from "./highway/highway"; +export * from './highway/highway'; // message folder -export * from "./message/action"; -export * from "./message/c2c"; -export * from "./message/component"; -export * from "./message/element"; -export * from "./message/group"; -export * from "./message/message"; -export * from "./message/notify"; -export * from "./message/routing"; +export * from './message/action'; +export * from './message/c2c'; +export * from './message/component'; +export * from './message/element'; +export * from './message/group'; +export * from './message/message'; +export * from './message/notify'; +export * from './message/routing'; // oidb folder -export * from "./oidb/common/Ntv2.RichMediaReq"; -export * from "./oidb/common/Ntv2.RichMediaResp"; -export * from "./oidb/Oidb.0x6D6"; -export * from "./oidb/Oidb.0x8FC_2"; -export * from "./oidb/Oidb.0x9067_202"; -export * from "./oidb/Oidb.0x929"; -export * from "./oidb/Oidb.0xE37_1200"; -export * from "./oidb/Oidb.0xE37_1700"; -export * from "./oidb/Oidb.0XE37_800"; -export * from "./oidb/Oidb.0xEB7"; -export * from "./oidb/Oidb.0xED3_1"; -export * from "./oidb/Oidb.0XFE1_2"; -export * from "./oidb/OidbBase"; -export * from "./oidb/Oidb.0xE07"; +export * from './oidb/common/Ntv2.RichMediaReq'; +export * from './oidb/common/Ntv2.RichMediaResp'; +export * from './oidb/Oidb.0x6D6'; +export * from './oidb/Oidb.0x8FC_2'; +export * from './oidb/Oidb.0x9067_202'; +export * from './oidb/Oidb.0x929'; +export * from './oidb/Oidb.0xE37_1200'; +export * from './oidb/Oidb.0xE37_1700'; +export * from './oidb/Oidb.0XE37_800'; +export * from './oidb/Oidb.0xEB7'; +export * from './oidb/Oidb.0xED3_1'; +export * from './oidb/Oidb.0XFE1_2'; +export * from './oidb/OidbBase'; +export * from './oidb/Oidb.0xE07'; diff --git a/src/core/packet/transformer/proto/message/action.ts b/src/core/packet/transformer/proto/message/action.ts index 369c57d4..74f47132 100644 --- a/src/core/packet/transformer/proto/message/action.ts +++ b/src/core/packet/transformer/proto/message/action.ts @@ -1,5 +1,5 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; -import { PushMsgBody } from "@/core/packet/transformer/proto"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; +import { PushMsgBody } from '@/core/packet/transformer/proto'; export const LongMsgResult = { action: ProtoField(2, () => LongMsgAction) diff --git a/src/core/packet/transformer/proto/message/c2c.ts b/src/core/packet/transformer/proto/message/c2c.ts index e3025754..cc99f6f2 100644 --- a/src/core/packet/transformer/proto/message/c2c.ts +++ b/src/core/packet/transformer/proto/message/c2c.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const C2C = { uin: ProtoField(1, ScalarType.UINT32, true), diff --git a/src/core/packet/transformer/proto/message/component.ts b/src/core/packet/transformer/proto/message/component.ts index a6bb7749..3299f0ef 100644 --- a/src/core/packet/transformer/proto/message/component.ts +++ b/src/core/packet/transformer/proto/message/component.ts @@ -1,5 +1,5 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; -import { Elem } from "@/core/packet/transformer/proto"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; +import { Elem } from '@/core/packet/transformer/proto'; export const Attr = { codePage: ProtoField(1, ScalarType.INT32), diff --git a/src/core/packet/transformer/proto/message/element.ts b/src/core/packet/transformer/proto/message/element.ts index ab419029..2e674860 100644 --- a/src/core/packet/transformer/proto/message/element.ts +++ b/src/core/packet/transformer/proto/message/element.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const Elem = { text: ProtoField(1, () => Text, true), diff --git a/src/core/packet/transformer/proto/message/group.ts b/src/core/packet/transformer/proto/message/group.ts index c483850f..ceaef2b2 100644 --- a/src/core/packet/transformer/proto/message/group.ts +++ b/src/core/packet/transformer/proto/message/group.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const GroupRecallMsg = { type: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/transformer/proto/message/groupAdmin.ts b/src/core/packet/transformer/proto/message/groupAdmin.ts index 42030063..7f0df482 100644 --- a/src/core/packet/transformer/proto/message/groupAdmin.ts +++ b/src/core/packet/transformer/proto/message/groupAdmin.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const GroupAdminExtra = { adminUid: ProtoField(1, ScalarType.STRING), diff --git a/src/core/packet/transformer/proto/message/message.ts b/src/core/packet/transformer/proto/message/message.ts index 3b5a6be2..24200ca1 100644 --- a/src/core/packet/transformer/proto/message/message.ts +++ b/src/core/packet/transformer/proto/message/message.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; import { C2C, ForwardHead, @@ -8,7 +8,7 @@ import { ResponseGrp, RichText, Trans0X211, WPATmp -} from "@/core/packet/transformer/proto"; +} from '@/core/packet/transformer/proto'; export const ContentHead = { type: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/transformer/proto/message/notify.ts b/src/core/packet/transformer/proto/message/notify.ts index 3b246780..5e573e59 100644 --- a/src/core/packet/transformer/proto/message/notify.ts +++ b/src/core/packet/transformer/proto/message/notify.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const FriendRecall = { info: ProtoField(1, () => FriendRecallInfo), diff --git a/src/core/packet/transformer/proto/message/routing.ts b/src/core/packet/transformer/proto/message/routing.ts index 619e395b..0af33197 100644 --- a/src/core/packet/transformer/proto/message/routing.ts +++ b/src/core/packet/transformer/proto/message/routing.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const ForwardHead = { field1: ProtoField(1, ScalarType.UINT32, true), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0XE37_800.ts b/src/core/packet/transformer/proto/oidb/Oidb.0XE37_800.ts index 8496fd5d..58f5904a 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0XE37_800.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0XE37_800.ts @@ -1,5 +1,5 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; -import { OidbSvcTrpcTcp0XE37_800_1200Metadata } from "@/core/packet/transformer/proto"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; +import { OidbSvcTrpcTcp0XE37_800_1200Metadata } from '@/core/packet/transformer/proto'; export const OidbSvcTrpcTcp0XE37_800 = { subCommand: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0XFE1_2.ts b/src/core/packet/transformer/proto/oidb/Oidb.0XFE1_2.ts index 679fcd69..c4ec293a 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0XFE1_2.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0XFE1_2.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const OidbSvcTrpcTcp0XFE1_2 = { uin: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0x6D6.ts b/src/core/packet/transformer/proto/oidb/Oidb.0x6D6.ts index 657cea98..be61b443 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0x6D6.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0x6D6.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const OidbSvcTrpcTcp0x6D6 = { file: ProtoField(1, () => OidbSvcTrpcTcp0x6D6Upload, true), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0x8FC_2.ts b/src/core/packet/transformer/proto/oidb/Oidb.0x8FC_2.ts index 2fc08f6e..e96dd951 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0x8FC_2.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0x8FC_2.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; //设置群头衔 OidbSvcTrpcTcp.0x8fc_2 diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0x9067_202.ts b/src/core/packet/transformer/proto/oidb/Oidb.0x9067_202.ts index b500bcc8..8ebf3367 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0x9067_202.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0x9067_202.ts @@ -1,5 +1,5 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; -import { MultiMediaReqHead } from "./common/Ntv2.RichMediaReq"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; +import { MultiMediaReqHead } from './common/Ntv2.RichMediaReq'; //Req export const OidbSvcTrpcTcp0X9067_202 = { diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0x929.ts b/src/core/packet/transformer/proto/oidb/Oidb.0x929.ts index 7bcd587f..0f5837b4 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0x929.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0x929.ts @@ -1,5 +1,5 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; -import { MsgInfo } from "@/core/packet/transformer/proto"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; +import { MsgInfo } from '@/core/packet/transformer/proto'; export const OidbSvcTrpcTcp0X929D_0 = { diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0xE07.ts b/src/core/packet/transformer/proto/oidb/Oidb.0xE07.ts index f94bd18e..4ec47095 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0xE07.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0xE07.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const OidbSvcTrpcTcp0xE07_0 = { version: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1200.ts b/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1200.ts index 1c0e55d3..70dbc934 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1200.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1200.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const OidbSvcTrpcTcp0XE37_1200 = { subCommand: ProtoField(1, ScalarType.UINT32, true), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1700.ts b/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1700.ts index 12fb9c5c..8fbe5a34 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1700.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0xE37_1700.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const OidbSvcTrpcTcp0XE37_1700 = { command: ProtoField(1, ScalarType.UINT32, true), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0xEB7.ts b/src/core/packet/transformer/proto/oidb/Oidb.0xEB7.ts index 43eec544..c7c7ed80 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0xEB7.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0xEB7.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const OidbSvcTrpcTcp0XEB7_Body = { uin: ProtoField(1, ScalarType.STRING), diff --git a/src/core/packet/transformer/proto/oidb/Oidb.0xED3_1.ts b/src/core/packet/transformer/proto/oidb/Oidb.0xED3_1.ts index 46c47957..fa071cba 100644 --- a/src/core/packet/transformer/proto/oidb/Oidb.0xED3_1.ts +++ b/src/core/packet/transformer/proto/oidb/Oidb.0xED3_1.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; // Send Poke export const OidbSvcTrpcTcp0XED3_1 = { diff --git a/src/core/packet/transformer/proto/oidb/OidbBase.ts b/src/core/packet/transformer/proto/oidb/OidbBase.ts index fb5c94eb..5557d755 100644 --- a/src/core/packet/transformer/proto/oidb/OidbBase.ts +++ b/src/core/packet/transformer/proto/oidb/OidbBase.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const OidbSvcTrpcTcpBase = { command: ProtoField(1, ScalarType.UINT32), diff --git a/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaReq.ts b/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaReq.ts index a85fd55c..66f60203 100644 --- a/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaReq.ts +++ b/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaReq.ts @@ -1,4 +1,4 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; export const NTV2RichMediaReq = { ReqHead: ProtoField(1, () => MultiMediaReqHead), diff --git a/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaResp.ts b/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaResp.ts index 72c12ed7..d63e81a2 100644 --- a/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaResp.ts +++ b/src/core/packet/transformer/proto/oidb/common/Ntv2.RichMediaResp.ts @@ -1,5 +1,5 @@ -import { ProtoField, ScalarType } from "@napneko/nap-proto-core"; -import { CommonHead, MsgInfo, PicUrlExtInfo, VideoExtInfo } from "@/core/packet/transformer/proto"; +import { ProtoField, ScalarType } from '@napneko/nap-proto-core'; +import { CommonHead, MsgInfo, PicUrlExtInfo, VideoExtInfo } from '@/core/packet/transformer/proto'; export const NTV2RichMediaResp = { diff --git a/src/core/packet/transformer/system/FetchRkey.ts b/src/core/packet/transformer/system/FetchRkey.ts index 76507bc6..b461e4fb 100644 --- a/src/core/packet/transformer/system/FetchRkey.ts +++ b/src/core/packet/transformer/system/FetchRkey.ts @@ -1,7 +1,7 @@ -import * as proto from "@/core/packet/transformer/proto"; -import { NapProtoMsg } from "@napneko/nap-proto-core"; -import { OidbPacket, PacketTransformer } from "@/core/packet/transformer/base"; -import OidbBase from "@/core/packet/transformer/oidb/oidbBase"; +import * as proto from '@/core/packet/transformer/proto'; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OidbPacket, PacketTransformer } from '@/core/packet/transformer/base'; +import OidbBase from '@/core/packet/transformer/oidb/oidbBase'; class FetchRkey extends PacketTransformer { constructor() { diff --git a/src/core/packet/utils/crypto/hash.ts b/src/core/packet/utils/crypto/hash.ts index 6f2eae88..d80d3c49 100644 --- a/src/core/packet/utils/crypto/hash.ts +++ b/src/core/packet/utils/crypto/hash.ts @@ -2,7 +2,7 @@ import * as crypto from 'crypto'; import * as stream from 'stream'; import * as fs from 'fs'; -import { CalculateStreamBytesTransform } from "@/core/packet/utils/crypto/sha1StreamBytesTransform"; +import { CalculateStreamBytesTransform } from '@/core/packet/utils/crypto/sha1StreamBytesTransform'; function sha1Stream(readable: stream.Readable) { return new Promise((resolve, reject) => { diff --git a/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts b/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts index 95f743fa..172186ee 100644 --- a/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts +++ b/src/core/packet/utils/crypto/sha1StreamBytesTransform.ts @@ -1,5 +1,5 @@ -import * as stream from "node:stream"; -import { Sha1Stream } from "@/core/packet/utils/crypto/sha1Stream"; +import * as stream from 'node:stream'; +import { Sha1Stream } from '@/core/packet/utils/crypto/sha1Stream'; export class CalculateStreamBytesTransform extends stream.Transform { private readonly blockSize = 1024 * 1024; diff --git a/src/core/packet/utils/helper/miniAppHelper.ts b/src/core/packet/utils/helper/miniAppHelper.ts index 66b9642a..2f3acd06 100644 --- a/src/core/packet/utils/helper/miniAppHelper.ts +++ b/src/core/packet/utils/helper/miniAppHelper.ts @@ -4,12 +4,12 @@ import { MiniAppRawData, MiniAppReqCustomParams, MiniAppReqTemplateParams -} from "@/core/packet/entities/miniApp"; +} from '@/core/packet/entities/miniApp'; -type MiniAppTemplateNameList = "bili" | "weibo"; +type MiniAppTemplateNameList = 'bili' | 'weibo'; export abstract class MiniAppInfo { - static readonly sdkId: string = "V1_PC_MINISDK_99.99.99_1_APP_A"; + static readonly sdkId: string = 'V1_PC_MINISDK_99.99.99_1_APP_A'; template: MiniAppReqTemplateParams; private static readonly appMap = new Map(); @@ -26,17 +26,17 @@ export abstract class MiniAppInfo { constructor() { super({ sdkId: MiniAppInfo.sdkId, - appId: "1109937557", + appId: '1109937557', scene: 1, templateType: 1, businessType: 0, verType: 3, shareType: 0, - versionId: "cfc5f7b05b44b5956502edaecf9d2240", + versionId: 'cfc5f7b05b44b5956502edaecf9d2240', withShareTicket: 0, - iconUrl: "https://miniapp.gtimg.cn/public/appicon/51f90239b78a2e4994c11215f4c4ba15_200.jpg" + iconUrl: 'https://miniapp.gtimg.cn/public/appicon/51f90239b78a2e4994c11215f4c4ba15_200.jpg' }); - MiniAppInfo.appMap.set("bili", this); + MiniAppInfo.appMap.set('bili', this); } }; @@ -44,17 +44,17 @@ export abstract class MiniAppInfo { constructor() { super({ sdkId: MiniAppInfo.sdkId, - appId: "1109224783", + appId: '1109224783', scene: 1, templateType: 1, businessType: 0, verType: 3, shareType: 0, - versionId: "e482a3cc4e574d9b772e96ba6eec9ba2", + versionId: 'e482a3cc4e574d9b772e96ba6eec9ba2', withShareTicket: 0, - iconUrl: "https://miniapp.gtimg.cn/public/appicon/35bbb44dc68e65194cfacfb206b8f1f7_200.jpg" + iconUrl: 'https://miniapp.gtimg.cn/public/appicon/35bbb44dc68e65194cfacfb206b8f1f7_200.jpg' }); - MiniAppInfo.appMap.set("weibo", this); + MiniAppInfo.appMap.set('weibo', this); } }; } @@ -76,7 +76,7 @@ export class MiniAppInfoHelper { view: rawData.appView, meta: rawData.metaData, miniappShareOrigin: 3, - miniappOpenRefer: "10002", + miniappOpenRefer: '10002', }; } diff --git a/src/core/services/NodeIKernelMSFService.ts b/src/core/services/NodeIKernelMSFService.ts index c5b975fa..b280819d 100644 --- a/src/core/services/NodeIKernelMSFService.ts +++ b/src/core/services/NodeIKernelMSFService.ts @@ -1,4 +1,4 @@ -import { GeneralCallResult } from "./common"; +import { GeneralCallResult } from './common'; export interface NodeIKernelMSFService { getServerTime(): string; diff --git a/src/core/services/NodeIO3MiscService.ts b/src/core/services/NodeIO3MiscService.ts index 7d0e80d9..e90f892f 100644 --- a/src/core/services/NodeIO3MiscService.ts +++ b/src/core/services/NodeIO3MiscService.ts @@ -1,4 +1,4 @@ -import { NodeIO3MiscListener } from "@/core/listeners/NodeIO3MiscListener"; +import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener'; export interface NodeIO3MiscService { get(): NodeIO3MiscService; diff --git a/src/core/types/element.ts b/src/core/types/element.ts index e6c71c57..e2210d28 100644 --- a/src/core/types/element.ts +++ b/src/core/types/element.ts @@ -1,4 +1,4 @@ -import { ElementType, MessageElement, NTGrayTipElementSubTypeV2, PicSubType, PicType, TipAioOpGrayTipElement, TipGroupElement, NTVideoType, FaceType } from "./msg"; +import { ElementType, MessageElement, NTGrayTipElementSubTypeV2, PicSubType, PicType, TipAioOpGrayTipElement, TipGroupElement, NTVideoType, FaceType } from './msg'; type ElementFullBase = Omit; diff --git a/src/onebot/action/extends/GetAiCharacters.ts b/src/onebot/action/extends/GetAiCharacters.ts index f9df0fbe..00ef15c9 100644 --- a/src/onebot/action/extends/GetAiCharacters.ts +++ b/src/onebot/action/extends/GetAiCharacters.ts @@ -1,6 +1,6 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; -import { AIVoiceChatType } from "@/core/packet/entities/aiChat"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; +import { AIVoiceChatType } from '@/core/packet/entities/aiChat'; import { Type, Static } from '@sinclair/typebox'; const SchemaData = Type.Object({ diff --git a/src/onebot/action/extends/GetMiniAppArk.ts b/src/onebot/action/extends/GetMiniAppArk.ts index 138f5b8f..93bd28e4 100644 --- a/src/onebot/action/extends/GetMiniAppArk.ts +++ b/src/onebot/action/extends/GetMiniAppArk.ts @@ -1,7 +1,7 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; -import { MiniAppInfo, MiniAppInfoHelper } from "@/core/packet/utils/helper/miniAppHelper"; -import { MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams } from "@/core/packet/entities/miniApp"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; +import { MiniAppInfo, MiniAppInfoHelper } from '@/core/packet/utils/helper/miniAppHelper'; +import { MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams } from '@/core/packet/entities/miniApp'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Union([ diff --git a/src/onebot/action/extends/GetRkey.ts b/src/onebot/action/extends/GetRkey.ts index aa38c6d0..33cf5a21 100644 --- a/src/onebot/action/extends/GetRkey.ts +++ b/src/onebot/action/extends/GetRkey.ts @@ -1,5 +1,5 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; export class GetRkey extends GetPacketStatusDepends> { actionName = ActionName.GetRkey; diff --git a/src/onebot/action/extends/GetUserStatus.ts b/src/onebot/action/extends/GetUserStatus.ts index 56c36b7f..12719cb6 100644 --- a/src/onebot/action/extends/GetUserStatus.ts +++ b/src/onebot/action/extends/GetUserStatus.ts @@ -1,5 +1,5 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ diff --git a/src/onebot/action/extends/SetSpecialTittle.ts b/src/onebot/action/extends/SetSpecialTittle.ts index 5c862e57..cb17e777 100644 --- a/src/onebot/action/extends/SetSpecialTittle.ts +++ b/src/onebot/action/extends/SetSpecialTittle.ts @@ -1,5 +1,5 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ diff --git a/src/onebot/action/file/GetGroupFileUrl.ts b/src/onebot/action/file/GetGroupFileUrl.ts index d1209588..e4e10e90 100644 --- a/src/onebot/action/file/GetGroupFileUrl.ts +++ b/src/onebot/action/file/GetGroupFileUrl.ts @@ -1,6 +1,6 @@ import { ActionName } from '@/onebot/action/router'; import { FileNapCatOneBotUUID } from '@/common/file-uuid'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ diff --git a/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts b/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts index 2e61f13d..bfdc75b7 100644 --- a/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts +++ b/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts @@ -18,7 +18,7 @@ export class GoCQHTTPGetModelShow extends OneBotAction { } return [{ variants: { - model_show: "napcat", + model_show: 'napcat', need_pay: false } }]; diff --git a/src/onebot/action/group/GetAiRecord.ts b/src/onebot/action/group/GetAiRecord.ts index 15e1f094..64d1f765 100644 --- a/src/onebot/action/group/GetAiRecord.ts +++ b/src/onebot/action/group/GetAiRecord.ts @@ -1,6 +1,6 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; -import { AIVoiceChatType } from "@/core/packet/entities/aiChat"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; +import { AIVoiceChatType } from '@/core/packet/entities/aiChat'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ diff --git a/src/onebot/action/group/GetGroupMemberInfo.ts b/src/onebot/action/group/GetGroupMemberInfo.ts index 408a51ce..3745102b 100644 --- a/src/onebot/action/group/GetGroupMemberInfo.ts +++ b/src/onebot/action/group/GetGroupMemberInfo.ts @@ -46,7 +46,7 @@ class GetGroupMemberInfo extends OneBotAction { const member = await this.getGroupMemberInfo(payload, uid, isNocache); if (!member) { - this.core.context.logger.logDebug(`获取群成员详细信息失败, 只能返回基础信息`); + this.core.context.logger.logDebug('获取群成员详细信息失败, 只能返回基础信息'); } return OB11Construct.groupMember(payload.group_id.toString(), member); diff --git a/src/onebot/action/group/GroupPoke.ts b/src/onebot/action/group/GroupPoke.ts index 27a91c75..5bdda381 100644 --- a/src/onebot/action/group/GroupPoke.ts +++ b/src/onebot/action/group/GroupPoke.ts @@ -1,5 +1,5 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ diff --git a/src/onebot/action/group/SendGroupAiRecord.ts b/src/onebot/action/group/SendGroupAiRecord.ts index 38aa1e8c..2dfa3a78 100644 --- a/src/onebot/action/group/SendGroupAiRecord.ts +++ b/src/onebot/action/group/SendGroupAiRecord.ts @@ -1,8 +1,8 @@ import { ActionName } from '@/onebot/action/router'; -import { GetPacketStatusDepends } from "@/onebot/action/packet/GetPacketStatus"; -import { uriToLocalFile } from "@/common/file"; -import { ChatType, Peer } from "@/core"; -import { AIVoiceChatType } from "@/core/packet/entities/aiChat"; +import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; +import { uriToLocalFile } from '@/common/file'; +import { ChatType, Peer } from '@/core'; +import { AIVoiceChatType } from '@/core/packet/entities/aiChat'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index 439c8b55..ea430d63 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -85,9 +85,9 @@ import { GetRkey } from './extends/GetRkey'; import { SetSpecialTittle } from './extends/SetSpecialTittle'; import { GetGroupShutList } from './group/GetGroupShutList'; import { GetGroupMemberList } from './group/GetGroupMemberList'; -import { GetGroupFileUrl } from "@/onebot/action/file/GetGroupFileUrl"; -import { GetPacketStatus } from "@/onebot/action/packet/GetPacketStatus"; -import { FriendPoke } from "@/onebot/action/user/FriendPoke"; +import { GetGroupFileUrl } from '@/onebot/action/file/GetGroupFileUrl'; +import { GetPacketStatus } from '@/onebot/action/packet/GetPacketStatus'; +import { FriendPoke } from '@/onebot/action/user/FriendPoke'; import { GetCredentials } from './system/GetCredentials'; import { SendGroupSign, SetGroupSign } from './extends/SetGroupSign'; import { GoCQHTTPGetGroupAtAllRemain } from './go-cqhttp/GetGroupAtAllRemain'; @@ -95,15 +95,15 @@ import { GoCQHTTPCheckUrlSafely } from './go-cqhttp/GoCQHTTPCheckUrlSafely'; import { GoCQHTTPGetModelShow } from './go-cqhttp/GoCQHTTPGetModelShow'; import { GoCQHTTPSetModelShow } from './go-cqhttp/GoCQHTTPSetModelShow'; import { GoCQHTTPDeleteFriend } from './go-cqhttp/GoCQHTTPDeleteFriend'; -import { GetMiniAppArk } from "@/onebot/action/extends/GetMiniAppArk"; -import { GetAiRecord } from "@/onebot/action/group/GetAiRecord"; -import { SendGroupAiRecord } from "@/onebot/action/group/SendGroupAiRecord"; -import { GetAiCharacters } from "@/onebot/action/extends/GetAiCharacters"; +import { GetMiniAppArk } from '@/onebot/action/extends/GetMiniAppArk'; +import { GetAiRecord } from '@/onebot/action/group/GetAiRecord'; +import { SendGroupAiRecord } from '@/onebot/action/group/SendGroupAiRecord'; +import { GetAiCharacters } from '@/onebot/action/extends/GetAiCharacters'; import { GetGuildList } from './guild/GetGuildList'; import { GetGuildProfile } from './guild/GetGuildProfile'; import { GetClientkey } from './extends/GetClientkey'; import { SendPacket } from './extends/SendPacket'; -import { SendPoke } from "@/onebot/action/packet/SendPoke"; +import { SendPoke } from '@/onebot/action/packet/SendPoke'; export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCore) { diff --git a/src/onebot/action/msg/SendMsg.ts b/src/onebot/action/msg/SendMsg.ts index bf24a18a..c391724e 100644 --- a/src/onebot/action/msg/SendMsg.ts +++ b/src/onebot/action/msg/SendMsg.ts @@ -11,10 +11,10 @@ import { decodeCQCode } from '@/onebot/helper/cqcode'; import { MessageUnique } from '@/common/message-unique'; import { ChatType, ElementType, NapCatCore, Peer, RawMessage, SendArkElement, SendMessageElement } from '@/core'; import { OneBotAction } from '@/onebot/action/OneBotAction'; -import { ForwardMsgBuilder } from "@/common/forward-msg-builder"; -import { stringifyWithBigInt } from "@/common/helper"; -import { PacketMsg } from "@/core/packet/message/message"; -import { rawMsgWithSendMsg } from "@/core/packet/message/converter"; +import { ForwardMsgBuilder } from '@/common/forward-msg-builder'; +import { stringifyWithBigInt } from '@/common/helper'; +import { PacketMsg } from '@/core/packet/message/message'; +import { rawMsgWithSendMsg } from '@/core/packet/message/converter'; export interface ReturnDataType { message_id: number; @@ -174,7 +174,7 @@ export class SendMsgBase extends OneBotAction { if (getSpecialMsgNum({ message: OB11Data }, OB11MessageDataType.node)) { const uploadReturnData = await this.uploadForwardedNodesPacket(msgPeer, OB11Data as OB11MessageNode[], node.data.source, node.data.news, node.data.summary, node.data.prompt, { user_id: (node.data.user_id ?? node.data.uin)?.toString() ?? parentMeta?.user_id ?? this.core.selfInfo.uin, - nickname: (node.data.nickname || node.data.name) ?? parentMeta?.nickname ?? "QQ用户", + nickname: (node.data.nickname || node.data.name) ?? parentMeta?.nickname ?? 'QQ用户', }, dp + 1); sendElements = uploadReturnData?.finallySendElements ? [uploadReturnData.finallySendElements] : []; } else { @@ -184,7 +184,7 @@ export class SendMsgBase extends OneBotAction { const packetMsgElements: rawMsgWithSendMsg = { senderUin: Number((node.data.user_id ?? node.data.uin) ?? parentMeta?.user_id) || +this.core.selfInfo.uin, - senderName: (node.data.nickname || node.data.name) ?? parentMeta?.nickname ?? "QQ用户", + senderName: (node.data.nickname || node.data.name) ?? parentMeta?.nickname ?? 'QQ用户', groupId: msgPeer.chatType === ChatType.KCHATTYPEGROUP ? +msgPeer.peerUid : undefined, time: Number(node.data.time) || Date.now(), msg: sendElements, @@ -219,7 +219,7 @@ export class SendMsgBase extends OneBotAction { return { finallySendElements: { elementType: ElementType.ARK, - elementId: "", + elementId: '', arkElement: { bytesData: JSON.stringify(forwardJson), }, diff --git a/src/onebot/action/packet/GetPacketStatus.ts b/src/onebot/action/packet/GetPacketStatus.ts index caab75ff..c0ecf08e 100644 --- a/src/onebot/action/packet/GetPacketStatus.ts +++ b/src/onebot/action/packet/GetPacketStatus.ts @@ -7,8 +7,8 @@ export abstract class GetPacketStatusDepends extends OneBotAction undefined, - [OB11MessageDataType.contact]: async ({ data: { type = "qq", id } }, context) => { - if (type === "qq") { + [OB11MessageDataType.contact]: async ({ data: { type = 'qq', id } }, context) => { + if (type === 'qq') { const arkJson = await this.core.apis.UserApi.getBuddyRecommendContactArkJson(id.toString(), ''); return this.ob11ToRawConverters.json({ data: { data: arkJson.arkMsg }, type: OB11MessageDataType.json }, context); - } else if (type === "group") { + } else if (type === 'group') { const arkJson = await this.core.apis.GroupApi.getGroupRecommendContactArkJson(id.toString()); return this.ob11ToRawConverters.json({ data: { data: arkJson.arkJson }, diff --git a/src/onebot/api/user.ts b/src/onebot/api/user.ts index ae8f43fe..769e60bc 100644 --- a/src/onebot/api/user.ts +++ b/src/onebot/api/user.ts @@ -1,7 +1,7 @@ import { GrayTipRovokeElement, NapCatCore, RawMessage } from '@/core'; import { NapCatOneBot11Adapter } from '@/onebot'; import { OB11ProfileLikeEvent } from '@/onebot/event/notice/OB11ProfileLikeEvent'; -import { decodeProfileLikeTip } from "@/core/helper/adaptDecoder"; +import { decodeProfileLikeTip } from '@/core/helper/adaptDecoder'; export class OneBotUserApi { obContext: NapCatOneBot11Adapter; @@ -15,12 +15,12 @@ export class OneBotUserApi { async parseLikeEvent(wrappedBody: Uint8Array): Promise { const likeTip = decodeProfileLikeTip(wrappedBody); if (likeTip?.msgType !== 0 || likeTip?.subType !== 203) return; - this.core.context.logger.logDebug("收到点赞通知消息"); + this.core.context.logger.logDebug('收到点赞通知消息'); const likeMsg = likeTip.content.msg; if (!likeMsg) return; const detail = likeMsg.detail; if (!detail) return; - const times = detail.txt.match(/\d+/) ?? "0"; + const times = detail.txt.match(/\d+/) ?? '0'; return new OB11ProfileLikeEvent( this.core, Number(detail.uin), diff --git a/src/onebot/helper/data.ts b/src/onebot/helper/data.ts index be562a5a..0227661f 100644 --- a/src/onebot/helper/data.ts +++ b/src/onebot/helper/data.ts @@ -23,7 +23,7 @@ export class OB11Construct { ...rawFriend.baseInfo, ...rawFriend.coreInfo, user_id: parseInt(rawFriend.coreInfo.uin), - nickname: rawFriend.coreInfo.nick ?? "", + nickname: rawFriend.coreInfo.nick ?? '', remark: rawFriend.coreInfo.remark ?? rawFriend.coreInfo.nick, sex: this.sex(rawFriend.baseInfo.sex), level: 0, diff --git a/src/onebot/index.ts b/src/onebot/index.ts index feacf3be..fe9d48dc 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -50,7 +50,7 @@ import { } from './config/config'; import { OB11Message } from './types'; import { OB11PluginAdapter } from './network/plugin'; -import { IOB11NetworkAdapter } from "@/onebot/network/adapter"; +import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; import { OB11HttpSSEServerAdapter } from './network/http-server-sse'; //OneBot实现类 @@ -82,7 +82,7 @@ export class NapCatOneBot11Adapter { this.networkManager = new OB11NetworkManager(); } async creatOneBotLog(ob11Config: OneBotConfig) { - let log = `[network] 配置加载\n`; + let log = '[network] 配置加载\n'; for (const key of ob11Config.network.httpServers) { log += `HTTP服务: ${key.host}:${key.port}, : ${key.enable ? '已启动' : '未启动'}\n`; } diff --git a/src/onebot/network/adapter.ts b/src/onebot/network/adapter.ts index b2578455..a8a49451 100644 --- a/src/onebot/network/adapter.ts +++ b/src/onebot/network/adapter.ts @@ -1,9 +1,9 @@ -import { NetworkAdapterConfig } from "@/onebot/config/config"; -import { LogWrapper } from "@/common/log"; -import { NapCatCore } from "@/core"; -import { NapCatOneBot11Adapter } from "@/onebot"; -import { ActionMap } from "@/onebot/action"; -import { OB11EmitEventContent, OB11NetworkReloadType } from "@/onebot/network/index"; +import { NetworkAdapterConfig } from '@/onebot/config/config'; +import { LogWrapper } from '@/common/log'; +import { NapCatCore } from '@/core'; +import { NapCatOneBot11Adapter } from '@/onebot'; +import { ActionMap } from '@/onebot/action'; +import { OB11EmitEventContent, OB11NetworkReloadType } from '@/onebot/network/index'; export abstract class IOB11NetworkAdapter { name: string; diff --git a/src/onebot/network/http-client.ts b/src/onebot/network/http-client.ts index a346d0d8..91911227 100644 --- a/src/onebot/network/http-client.ts +++ b/src/onebot/network/http-client.ts @@ -6,7 +6,7 @@ import { NapCatOneBot11Adapter } from '..'; import { RequestUtil } from '@/common/request'; import { HttpClientConfig } from '@/onebot/config/config'; import { ActionMap } from '@/onebot/action'; -import { IOB11NetworkAdapter } from "@/onebot/network/adapter"; +import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; import json5 from 'json5'; export class OB11HttpClientAdapter extends IOB11NetworkAdapter { diff --git a/src/onebot/network/http-server.ts b/src/onebot/network/http-server.ts index f4f5b207..c9a125e3 100644 --- a/src/onebot/network/http-server.ts +++ b/src/onebot/network/http-server.ts @@ -6,8 +6,8 @@ import { OB11Response } from '@/onebot/action/OneBotAction'; import { ActionMap } from '@/onebot/action'; import cors from 'cors'; import { HttpServerConfig } from '@/onebot/config/config'; -import { NapCatOneBot11Adapter } from "@/onebot"; -import { IOB11NetworkAdapter } from "@/onebot/network/adapter"; +import { NapCatOneBot11Adapter } from '@/onebot'; +import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; import json5 from 'json5'; export class OB11HttpServerAdapter extends IOB11NetworkAdapter { @@ -119,7 +119,7 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter async handleRequest(req: Request, res: Response) { if (!this.isEnable) { - this.core.context.logger.log(`[OneBot] [HTTP Server Adapter] Server is closed`); + this.core.context.logger.log('[OneBot] [HTTP Server Adapter] Server is closed'); return res.json(OB11Response.error('Server is closed', 200)); } diff --git a/src/onebot/network/index.ts b/src/onebot/network/index.ts index 464b8b6a..13dcf325 100644 --- a/src/onebot/network/index.ts +++ b/src/onebot/network/index.ts @@ -1,7 +1,7 @@ import { OneBotEvent } from '@/onebot/event/OneBotEvent'; import { OB11Message } from '@/onebot'; import { NetworkAdapterConfig } from '@/onebot/config/config'; -import { IOB11NetworkAdapter } from "@/onebot/network/adapter"; +import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; export type OB11EmitEventContent = OneBotEvent | OB11Message; export enum OB11NetworkReloadType { diff --git a/src/onebot/network/plugin.ts b/src/onebot/network/plugin.ts index 16683cf0..717276d9 100644 --- a/src/onebot/network/plugin.ts +++ b/src/onebot/network/plugin.ts @@ -4,7 +4,7 @@ import { NapCatCore } from '@/core'; import { PluginConfig } from '../config/config'; import { plugin_onmessage } from '@/plugin'; import { ActionMap } from '../action'; -import { IOB11NetworkAdapter } from "@/onebot/network/adapter"; +import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; export class OB11PluginAdapter extends IOB11NetworkAdapter { constructor( diff --git a/src/onebot/network/websocket-client.ts b/src/onebot/network/websocket-client.ts index 3f6cc1d3..d6e4e1c2 100644 --- a/src/onebot/network/websocket-client.ts +++ b/src/onebot/network/websocket-client.ts @@ -7,8 +7,8 @@ import { OB11Response } from '@/onebot/action/OneBotAction'; import { ActionMap } from '@/onebot/action'; import { LifeCycleSubType, OB11LifeCycleEvent } from '@/onebot/event/meta/OB11LifeCycleEvent'; import { WebsocketClientConfig } from '@/onebot/config/config'; -import { NapCatOneBot11Adapter } from "@/onebot"; -import { IOB11NetworkAdapter } from "@/onebot/network/adapter"; +import { NapCatOneBot11Adapter } from '@/onebot'; +import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; import json5 from 'json5'; export class OB11WebSocketClientAdapter extends IOB11NetworkAdapter { diff --git a/src/onebot/network/websocket-server.ts b/src/onebot/network/websocket-server.ts index f2e4ca25..d4ac3dd5 100644 --- a/src/onebot/network/websocket-server.ts +++ b/src/onebot/network/websocket-server.ts @@ -10,8 +10,8 @@ import { IncomingMessage } from 'http'; import { ActionMap } from '@/onebot/action'; import { LifeCycleSubType, OB11LifeCycleEvent } from '@/onebot/event/meta/OB11LifeCycleEvent'; import { WebsocketServerConfig } from '@/onebot/config/config'; -import { NapCatOneBot11Adapter } from "@/onebot"; -import { IOB11NetworkAdapter } from "@/onebot/network/adapter"; +import { NapCatOneBot11Adapter } from '@/onebot'; +import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; import json5 from 'json5'; export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter { diff --git a/src/onebot/types/message.ts b/src/onebot/types/message.ts index 6d9aabd0..8f311e87 100644 --- a/src/onebot/types/message.ts +++ b/src/onebot/types/message.ts @@ -102,7 +102,7 @@ export interface OB11MessageText { export interface OB11MessageContext { type: OB11MessageDataType.contact; data: { - type: "qq" | "group"; + type: 'qq' | 'group'; id: string; }; } diff --git a/src/plugin/index.ts b/src/plugin/index.ts index 4b070b7b..bf518971 100644 --- a/src/plugin/index.ts +++ b/src/plugin/index.ts @@ -1,7 +1,7 @@ -import { NapCatOneBot11Adapter, OB11Message } from "@/onebot"; -import { NapCatCore } from "@/core"; -import { ActionMap } from "@/onebot/action"; -import { OB11PluginAdapter } from "@/onebot/network/plugin"; +import { NapCatOneBot11Adapter, OB11Message } from '@/onebot'; +import { NapCatCore } from '@/core'; +import { ActionMap } from '@/onebot/action'; +import { OB11PluginAdapter } from '@/onebot/network/plugin'; export const plugin_onmessage = async (adapter: string, core: NapCatCore, obCtx: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap, instance: OB11PluginAdapter) => { if (message.raw_message === 'ping') { diff --git a/src/shell/base.ts b/src/shell/base.ts index b2d5a243..46a380e0 100644 --- a/src/shell/base.ts +++ b/src/shell/base.ts @@ -273,7 +273,7 @@ export async function NCoreInitShell() { const o3Service = wrapper.NodeIO3MiscService.get(); o3Service.addO3MiscListener(new NodeIO3MiscListener()); - logger.log(`[NapCat] [Core] NapCat.Core Version: ` + napCatVersion); + logger.log('[NapCat] [Core] NapCat.Core Version: ' + napCatVersion); InitWebUi(logger, pathWrapper).then().catch(e => logger.logError(e)); const engine = wrapper.NodeIQQNTWrapperEngine.get(); diff --git a/src/shell/napcat.ts b/src/shell/napcat.ts index f2a05426..c2913eba 100644 --- a/src/shell/napcat.ts +++ b/src/shell/napcat.ts @@ -1,3 +1,3 @@ -import { NCoreInitShell } from "./base"; +import { NCoreInitShell } from './base'; NCoreInitShell(); \ No newline at end of file diff --git a/src/universal/napcat.ts b/src/universal/napcat.ts index d5fd0d5b..a4559d0c 100644 --- a/src/universal/napcat.ts +++ b/src/universal/napcat.ts @@ -1,6 +1,6 @@ -import { NCoreInitShell } from "@/shell/base"; -export * from "@/framework/napcat"; -export * from "@/shell/base"; +import { NCoreInitShell } from '@/shell/base'; +export * from '@/framework/napcat'; +export * from '@/shell/base'; interface LiteLoaderGlobal extends Global { LiteLoader?: unknown; diff --git a/src/webui/src/api/Proxy.ts b/src/webui/src/api/Proxy.ts index f211ab5c..aa5404ff 100644 --- a/src/webui/src/api/Proxy.ts +++ b/src/webui/src/api/Proxy.ts @@ -1,10 +1,10 @@ -import { RequestHandler } from "express"; -import { RequestUtil } from "@/common/request"; -import { sendError, sendSuccess } from "../utils/response"; +import { RequestHandler } from 'express'; +import { RequestUtil } from '@/common/request'; +import { sendError, sendSuccess } from '../utils/response'; export const GetProxyHandler: RequestHandler = async (req, res) => { let { url } = req.query; - if (url && typeof url === "string") { + if (url && typeof url === 'string') { url = decodeURIComponent(url); const responseText = await RequestUtil.HttpGetText(url); res.send(sendSuccess(res, responseText)); diff --git a/src/webui/src/api/Status.ts b/src/webui/src/api/Status.ts index 4ca75efd..5566bd6a 100644 --- a/src/webui/src/api/Status.ts +++ b/src/webui/src/api/Status.ts @@ -1,5 +1,5 @@ import { RequestHandler } from 'express'; -import { SystemStatus, statusHelperSubscription } from "@/core/helper/status"; +import { SystemStatus, statusHelperSubscription } from '@/core/helper/status'; export const StatusRealTimeHandler: RequestHandler = async (req, res) => { res.setHeader('Content-Type', 'text/event-stream'); diff --git a/src/webui/src/router/Base.ts b/src/webui/src/router/Base.ts index 38a35292..0ec78532 100644 --- a/src/webui/src/router/Base.ts +++ b/src/webui/src/router/Base.ts @@ -1,6 +1,6 @@ import { Router } from 'express'; import { PackageInfoHandler, QQVersionHandler } from '../api/BaseInfo'; -import { StatusRealTimeHandler } from "@webapi/api/Status"; +import { StatusRealTimeHandler } from '@webapi/api/Status'; import { GetProxyHandler } from '../api/Proxy'; const router = Router(); diff --git a/src/webui/src/types/data.d.ts b/src/webui/src/types/data.d.ts index 2eb6c4a8..fb9a644e 100644 --- a/src/webui/src/types/data.d.ts +++ b/src/webui/src/types/data.d.ts @@ -1,5 +1,5 @@ import type { LoginListItem, SelfInfo } from '@/core'; -import type { OneBotConfig } from "@/onebot/config/config"; +import type { OneBotConfig } from '@/onebot/config/config'; interface LoginRuntimeType { LoginCurrentTime: number; From 15854c605b00c9ba34a94ad5fc67678c86616539 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, 2 Feb 2025 23:22:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?style:=20=E5=BC=BA=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=A4=A7=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 4 +- eslint.config.mjs | 2 + napcat.webui/src/types/user.d.ts | 2 +- src/common/audio.ts | 13 ++-- src/common/cancel-task.ts | 45 +++++++------ src/common/config-base.ts | 12 ++-- src/common/decorator.ts | 22 ------- src/common/event.ts | 2 + src/common/ffmpeg-worker.ts | 1 + src/common/ffmpeg.ts | 1 + src/common/file.ts | 5 +- src/common/helper.ts | 6 +- src/common/log.ts | 7 +- src/common/proxy-handler.ts | 2 + src/common/qq-basic-info.ts | 3 +- src/common/request.ts | 1 + src/common/store.ts | 4 +- src/common/system.ts | 2 +- src/common/types.ts | 8 +-- src/core/adapters/NodeIDependsAdapter.ts | 7 +- src/core/adapters/NodeIDispatcherAdapter.ts | 7 +- src/core/adapters/NodeIGlobalAdapter.ts | 17 ++--- src/core/apis/file.ts | 39 ++++++----- src/core/apis/friend.ts | 10 +-- src/core/apis/group.ts | 8 ++- src/core/apis/index.ts | 4 +- src/core/apis/msg.ts | 4 +- src/core/apis/system.ts | 2 +- src/core/apis/user.ts | 8 +-- src/core/apis/webapi.ts | 45 +++++++++---- src/core/helper/rkey.ts | 2 +- src/core/helper/status.ts | 8 +-- src/core/index.ts | 4 +- src/core/packet/client/wsClient.ts | 2 +- src/core/packet/context/clientContext.ts | 4 +- src/core/packet/context/loggerContext.ts | 1 + src/core/packet/context/operationContext.ts | 2 +- src/core/packet/highway/client.ts | 3 +- .../highway/uploader/highwayTcpUploader.ts | 4 +- src/core/packet/message/element.ts | 62 +++++++++--------- src/core/packet/utils/crypto/sha1Stream.ts | 2 + .../utils/crypto/sha1StreamBytesTransform.ts | 5 +- src/core/packet/utils/crypto/tea.ts | 2 + src/core/services/NodeIKernelAlbumService.ts | 44 ++++++------- .../services/NodeIKernelCollectionService.ts | 36 +++++------ src/core/services/NodeIKernelGroupService.ts | 6 +- src/core/services/NodeIKernelLoginService.ts | 2 +- .../services/NodeIKernelMsgBackupService.ts | 22 +++---- src/core/services/NodeIKernelMsgService.ts | 6 +- .../NodeIKernelOnlineStatusService.ts | 2 +- .../services/NodeIKernelProfileService.ts | 8 +-- .../NodeIKernelRecentContactService.ts | 10 +-- .../services/NodeIKernelRichMediaService.ts | 8 +-- src/core/services/NodeIKernelRobotService.ts | 2 +- src/core/services/NodeIKernelSearchService.ts | 64 +++++++++---------- .../services/NodeIKernelTianShuService.ts | 2 +- .../NodeIKernelUnitedConfigService.ts | 6 +- src/core/types/element.ts | 2 +- src/core/types/file.ts | 5 ++ src/core/types/group.ts | 14 ++-- src/core/types/user.ts | 20 +++--- src/core/types/webapi.ts | 6 +- src/core/wrapper.ts | 8 +-- src/framework/liteloader.cjs | 2 +- src/framework/napcat.ts | 2 +- src/onebot/action/OneBotAction.ts | 20 +++--- src/onebot/action/extends/CreateCollection.ts | 6 +- src/onebot/action/extends/FetchCustomFace.ts | 4 +- src/onebot/action/extends/FetchEmojiLike.ts | 8 ++- src/onebot/action/extends/GetAiCharacters.ts | 4 +- src/onebot/action/extends/GetClientkey.ts | 2 +- .../action/extends/GetCollectionList.ts | 7 +- .../action/extends/GetFriendWithCategory.ts | 6 +- .../action/extends/GetGroupAddRequest.ts | 4 +- src/onebot/action/extends/GetGroupInfoEx.ts | 6 +- src/onebot/action/extends/GetMiniAppArk.ts | 4 +- src/onebot/action/extends/GetProfileLike.ts | 23 ++++++- src/onebot/action/extends/GetRkey.ts | 4 +- src/onebot/action/extends/GetRobotUinRange.ts | 4 +- src/onebot/action/extends/GetUserStatus.ts | 4 +- src/onebot/action/extends/OCRImage.ts | 9 +-- src/onebot/action/extends/SendPacket.ts | 9 +-- src/onebot/action/extends/SetGroupSign.ts | 8 +-- src/onebot/action/extends/SetInputStatus.ts | 6 +- src/onebot/action/extends/SetLongNick.ts | 6 +- src/onebot/action/extends/SetOnlineStatus.ts | 4 +- src/onebot/action/extends/SetQQAvatar.ts | 4 +- src/onebot/action/extends/SetSpecialTittle.ts | 6 +- src/onebot/action/extends/ShareContact.ts | 17 +++-- .../action/extends/TranslateEnWordToZn.ts | 6 +- src/onebot/action/file/GetFile.ts | 4 +- src/onebot/action/file/GetGroupFileUrl.ts | 4 +- src/onebot/action/file/GetImage.ts | 2 +- src/onebot/action/file/GetRecord.ts | 10 +-- .../action/go-cqhttp/CreateGroupFileFolder.ts | 11 ++-- .../action/go-cqhttp/DeleteGroupFile.ts | 7 +- .../action/go-cqhttp/DeleteGroupFileFolder.ts | 7 +- src/onebot/action/go-cqhttp/DownloadFile.ts | 4 +- src/onebot/action/go-cqhttp/GetForwardMsg.ts | 13 ++-- .../action/go-cqhttp/GetFriendMsgHistory.ts | 6 +- .../action/go-cqhttp/GetGroupAtAllRemain.ts | 12 ++-- .../go-cqhttp/GetGroupFileSystemInfo.ts | 13 ++-- .../action/go-cqhttp/GetGroupFilesByFolder.ts | 9 ++- .../action/go-cqhttp/GetGroupHonorInfo.ts | 6 +- .../action/go-cqhttp/GetGroupMsgHistory.ts | 6 +- .../action/go-cqhttp/GetGroupRootFiles.ts | 4 +- .../action/go-cqhttp/GetOnlineClient.ts | 7 +- .../action/go-cqhttp/GetStrangerInfo.ts | 10 +-- .../go-cqhttp/GoCQHTTPCheckUrlSafely.ts | 8 +-- .../action/go-cqhttp/GoCQHTTPDeleteFriend.ts | 6 +- .../action/go-cqhttp/GoCQHTTPGetModelShow.ts | 13 ++-- .../action/go-cqhttp/GoCQHTTPSetModelShow.ts | 8 +-- src/onebot/action/go-cqhttp/QuickAction.ts | 2 +- src/onebot/action/go-cqhttp/SendForwardMsg.ts | 23 ++++--- .../action/go-cqhttp/SendGroupNotice.ts | 4 +- .../action/go-cqhttp/SetGroupPortrait.ts | 9 +-- src/onebot/action/go-cqhttp/SetQQProfile.ts | 8 +-- .../action/go-cqhttp/UploadGroupFile.ts | 6 +- .../action/go-cqhttp/UploadPrivateFile.ts | 9 ++- src/onebot/action/group/DelEssenceMsg.ts | 9 ++- src/onebot/action/group/DelGroupNotice.ts | 6 +- src/onebot/action/group/GetAiRecord.ts | 7 +- src/onebot/action/group/GetGroupEssence.ts | 12 ++-- .../action/group/GetGroupIgnoredNotifies.ts | 2 +- src/onebot/action/group/GetGroupInfo.ts | 4 +- src/onebot/action/group/GetGroupList.ts | 4 +- src/onebot/action/group/GetGroupMemberInfo.ts | 4 +- src/onebot/action/group/GetGroupMemberList.ts | 4 +- src/onebot/action/group/GetGroupNotice.ts | 7 +- src/onebot/action/group/GetGroupShutList.ts | 7 +- src/onebot/action/group/GroupPoke.ts | 6 +- src/onebot/action/group/SendGroupAiRecord.ts | 6 +- src/onebot/action/group/SendGroupMsg.ts | 6 +- src/onebot/action/group/SetEssenceMsg.ts | 8 +-- src/onebot/action/group/SetGroupAddRequest.ts | 4 +- src/onebot/action/group/SetGroupAdmin.ts | 4 +- src/onebot/action/group/SetGroupBan.ts | 4 +- src/onebot/action/group/SetGroupCard.ts | 4 +- src/onebot/action/group/SetGroupKick.ts | 4 +- src/onebot/action/group/SetGroupLeave.ts | 8 +-- src/onebot/action/group/SetGroupName.ts | 4 +- src/onebot/action/group/SetGroupWholeBan.ts | 4 +- src/onebot/action/guild/GetGuildList.ts | 8 +-- src/onebot/action/guild/GetGuildProfile.ts | 8 +-- src/onebot/action/index.ts | 10 +-- src/onebot/action/msg/DeleteMsg.ts | 4 +- src/onebot/action/msg/ForwardSingleMsg.ts | 8 +-- src/onebot/action/msg/GetMsg.ts | 12 ++-- src/onebot/action/msg/MarkMsgAsRead.ts | 14 ++-- src/onebot/action/msg/SendMsg.ts | 62 +++++++++--------- src/onebot/action/msg/SendPrivateMsg.ts | 6 +- src/onebot/action/msg/SetMsgEmojiLike.ts | 8 +-- src/onebot/action/packet/GetPacketStatus.ts | 10 +-- src/onebot/action/packet/SendPoke.ts | 6 +- src/onebot/action/router.ts | 4 -- src/onebot/action/system/CanSendImage.ts | 8 +-- src/onebot/action/system/CanSendRecord.ts | 6 +- src/onebot/action/system/GetCSRF.ts | 6 +- src/onebot/action/system/GetCredentials.ts | 6 +- src/onebot/action/system/GetLoginInfo.ts | 4 +- src/onebot/action/system/GetStatus.ts | 11 +++- src/onebot/action/system/GetSystemMsg.ts | 2 +- src/onebot/action/system/GetVersionInfo.ts | 13 ++-- src/onebot/action/user/FriendPoke.ts | 6 +- src/onebot/action/user/GetCookies.ts | 6 +- src/onebot/action/user/GetFriendList.ts | 4 +- src/onebot/action/user/GetRecentContact.ts | 10 +-- src/onebot/action/user/SendLike.ts | 4 +- src/onebot/action/user/SetFriendAddRequest.ts | 4 +- src/onebot/api/friend.ts | 3 +- src/onebot/api/group.ts | 24 ++++--- src/onebot/api/msg.ts | 52 +++++++++------ src/onebot/api/quick-action.ts | 6 +- src/onebot/api/user.ts | 2 +- src/onebot/event/notice/OB11PokeEvent.ts | 8 +-- .../event/notice/OB11ProfileLikeEvent.ts | 2 +- src/onebot/event/request/OB11FriendRequest.ts | 2 +- src/onebot/event/request/OB11GroupRequest.ts | 4 +- src/onebot/helper/cqcode.ts | 19 +++--- src/onebot/index.ts | 27 +++----- src/onebot/network/adapter.ts | 2 +- src/onebot/network/http-server-sse.ts | 6 +- src/onebot/network/http-server.ts | 32 ++++++---- src/onebot/network/websocket-client.ts | 17 ++--- src/onebot/network/websocket-server.ts | 18 +++--- src/onebot/types/data.ts | 1 - src/onebot/types/message.ts | 2 +- src/plugin/index.ts | 2 +- src/shell/base.ts | 25 ++++---- src/universal/napcat.ts | 8 +-- tsconfig.json | 6 +- 191 files changed, 923 insertions(+), 806 deletions(-) delete mode 100644 src/common/decorator.ts create mode 100644 src/core/types/file.ts diff --git a/.editorconfig b/.editorconfig index e73bbcf5..c90a6350 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,7 +12,7 @@ insert_final_newline = true # Set default charset charset = utf-8 -# 2 space indentation +# 4 space indentation [*.{cjs,mjs,js,jsx,ts,tsx,css,scss,sass,html,json}] indent_style = space indent_size = 4 @@ -21,4 +21,4 @@ indent_size = 4 charset = latin1 # Unfortunately, EditorConfig doesn't support space configuration inside import braces directly. -# You'll need to rely on your linter/formatter like ESLint or Prettier for that. +# You'll need to rely on your linter/formatter like ESLint or Prettier for that. \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs index 6859bd8b..ae25a7a3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -12,6 +12,7 @@ const customTsFlatConfig = [ globals: { ...globals.browser, ...globals.node, + NodeJS: 'readonly', // 添加 NodeJS 全局变量 }, }, files: ['**/*.{ts,tsx}'], @@ -24,6 +25,7 @@ const customTsFlatConfig = [ plugins: { '@typescript-eslint': tsEslintPlugin, }, + ignores: ['src/webui/**'], // 忽略 src/webui/ 目录所有文件 }, ]; diff --git a/napcat.webui/src/types/user.d.ts b/napcat.webui/src/types/user.d.ts index 53a98bde..a5fcc293 100644 --- a/napcat.webui/src/types/user.d.ts +++ b/napcat.webui/src/types/user.d.ts @@ -164,7 +164,7 @@ interface CommonExt { address: string regTime: number interest: string - labels: unknown[] + labels: string[] qqLevel: QQLevel } diff --git a/src/common/audio.ts b/src/common/audio.ts index 6f7a8f49..92b22365 100644 --- a/src/common/audio.ts +++ b/src/common/audio.ts @@ -27,8 +27,7 @@ async function guessDuration(pttPath: string, logger: LogWrapper) { async function handleWavFile( file: Buffer, filePath: string, - pcmPath: string, - _logger: LogWrapper + pcmPath: string ): Promise<{ input: Buffer; sampleRate: number }> { const { fmt } = getWavFileInfo(file); if (!ALLOW_SAMPLE_RATE.includes(fmt.sampleRate)) { @@ -45,7 +44,7 @@ export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: Log logger.log(`语音文件${filePath}需要转换成silk`); const pcmPath = `${pttPath}.pcm`; const { input, sampleRate } = isWav(file) - ? (await handleWavFile(file, filePath, pcmPath, logger)) + ? (await handleWavFile(file, filePath, pcmPath)) : { input: await FFmpegService.convert(filePath, pcmPath), sampleRate: 24000 }; const silk = await piscina.run({ input: input, sampleRate: sampleRate }); await fsPromise.writeFile(pttPath, Buffer.from(silk.data)); @@ -59,8 +58,8 @@ export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: Log let duration = 0; try { duration = getDuration(file) / 1000; - } catch (e: any) { - logger.log('获取语音文件时长失败, 使用文件大小推测时长', filePath, e.stack); + } catch (e: unknown) { + logger.log('获取语音文件时长失败, 使用文件大小推测时长', filePath, (e as Error).stack); duration = await guessDuration(filePath, logger); } return { @@ -69,8 +68,8 @@ export async function encodeSilk(filePath: string, TEMP_DIR: string, logger: Log duration, }; } - } catch (error: any) { - logger.logError('convert silk failed', error.stack); + } catch (error: unknown) { + logger.logError('convert silk failed', (error as Error).stack); return {}; } } diff --git a/src/common/cancel-task.ts b/src/common/cancel-task.ts index 454f2a62..b81a64a2 100644 --- a/src/common/cancel-task.ts +++ b/src/common/cancel-task.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ export type TaskExecutor = (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void, onCancel: (callback: () => void) => void) => void | Promise; export class CancelableTask { @@ -7,30 +8,34 @@ export class CancelableTask { private cancelListeners: Array<() => void> = []; constructor(executor: TaskExecutor) { - this.promise = new Promise(async (resolve, reject) => { + this.promise = new Promise((resolve, reject) => { const onCancel = (callback: () => void) => { this.cancelCallback = callback; }; - try { - await executor( - (value) => { - if (!this.isCanceled) { - resolve(value); - } - }, - (reason) => { - if (!this.isCanceled) { - reject(reason); - } - }, - onCancel - ); - } catch (error) { - if (!this.isCanceled) { - reject(error); + const execute = async () => { + try { + await executor( + (value) => { + if (!this.isCanceled) { + resolve(value); + } + }, + (reason) => { + if (!this.isCanceled) { + reject(reason); + } + }, + onCancel + ); + } catch (error) { + if (!this.isCanceled) { + reject(error); + } } - } + }; + + execute(); }); } @@ -72,4 +77,4 @@ export class CancelableTask { next: () => this.promise.then(value => ({ value, done: true })), }; } -} +} \ No newline at end of file diff --git a/src/common/config-base.ts b/src/common/config-base.ts index c0f4a427..50274f08 100644 --- a/src/common/config-base.ts +++ b/src/common/config-base.ts @@ -40,8 +40,8 @@ export abstract class ConfigBase { try { fs.writeFileSync(configPath, fs.readFileSync(this.getConfigPath(undefined), 'utf-8')); this.core.context.logger.log('[Core] [Config] 配置文件创建成功!\n'); - } catch (e: any) { - this.core.context.logger.logError('[Core] [Config] 创建配置文件时发生错误:', e.message); + } catch (e: unknown) { + this.core.context.logger.logError('[Core] [Config] 创建配置文件时发生错误:', (e as Error).message); } } else if (!fs.existsSync(configPath) && !copy_default) { fs.writeFileSync(configPath, '{}'); @@ -50,11 +50,11 @@ export abstract class ConfigBase { this.configData = json5.parse(fs.readFileSync(configPath, 'utf-8')); this.core.context.logger.logDebug(`[Core] [Config] 配置文件${configPath}加载`, this.configData); return this.configData; - } catch (e: any) { + } catch (e: unknown) { if (e instanceof SyntaxError) { this.core.context.logger.logError('[Core] [Config] 配置文件格式错误,请检查配置文件:', e.message); } else { - this.core.context.logger.logError('[Core] [Config] 读取配置文件时发生错误:', e.message); + this.core.context.logger.logError('[Core] [Config] 读取配置文件时发生错误:', (e as Error).message); } return {} as T; } @@ -67,8 +67,8 @@ export abstract class ConfigBase { const configPath = this.getConfigPath(selfInfo.uin); try { fs.writeFileSync(configPath, JSON.stringify(newConfigData, this.getKeys(), 2)); - } catch (e: any) { - this.core.context.logger.logError(`保存配置文件 ${configPath} 时发生错误:`, e.message); + } catch (e: unknown) { + this.core.context.logger.logError(`保存配置文件 ${configPath} 时发生错误:`, (e as Error).message); } } } diff --git a/src/common/decorator.ts b/src/common/decorator.ts deleted file mode 100644 index bea6e9f0..00000000 --- a/src/common/decorator.ts +++ /dev/null @@ -1,22 +0,0 @@ -// decoratorAsyncMethod(this,function,wrapper) -async function decoratorMethod( - target: T, - method: () => Promise, - wrapper: (result: R) => Promise, - executeImmediately: boolean = true -): Promise { - const execute = async () => { - try { - const result = await method.call(target); - return wrapper(result); - } catch (error) { - return Promise.reject(error instanceof Error ? error : new Error(String(error))); - } - }; - - if (executeImmediately) { - return execute(); - } else { - return execute; - } -} \ No newline at end of file diff --git a/src/common/event.ts b/src/common/event.ts index dcc5eee5..ca0e2405 100644 --- a/src/common/event.ts +++ b/src/common/event.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { NodeIQQNTWrapperSession } from '@/core/wrapper'; import { randomUUID } from 'crypto'; import { ListenerNamingMapping, ServiceNamingMapping } from '@/core'; @@ -75,6 +76,7 @@ export class NTEventWrapper { } return undefined; } + return undefined; } createListenerFunction(listenerMainName: string, uniqueCode: string = ''): T { diff --git a/src/common/ffmpeg-worker.ts b/src/common/ffmpeg-worker.ts index 146595a4..38b0afa8 100644 --- a/src/common/ffmpeg-worker.ts +++ b/src/common/ffmpeg-worker.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { FFmpeg } from '@ffmpeg.wasm/main'; import { randomUUID } from 'crypto'; import { readFileSync, statSync, writeFileSync } from 'fs'; diff --git a/src/common/ffmpeg.ts b/src/common/ffmpeg.ts index 81dea249..29e2ba87 100644 --- a/src/common/ffmpeg.ts +++ b/src/common/ffmpeg.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import Piscina from 'piscina'; import { VideoInfo } from './video'; diff --git a/src/common/file.ts b/src/common/file.ts index 4ffe8386..4133cf7b 100644 --- a/src/common/file.ts +++ b/src/common/file.ts @@ -58,8 +58,8 @@ function timeoutPromise(timeout: number, errorMsg: string): Promise { async function checkFile(path: string): Promise { try { await stat(path); - } catch (error: any) { - if (error.code === 'ENOENT') { + } catch (error: unknown) { + if ((error as Error & { code: string }).code === 'ENOENT') { // 如果文件不存在,则抛出一个错误 throw new Error(`文件不存在: ${path}`); } else { @@ -169,6 +169,7 @@ export async function checkUriType(Uri: string) { const data = uri.split(',')[1]; if (data) return { Uri: data, Type: FileUriType.Base64 }; } + return; }, Uri); if (OtherFileRet) return OtherFileRet; diff --git a/src/common/helper.ts b/src/common/helper.ts index 129d5a7f..e97de9b2 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import path from 'node:path'; import fs from 'fs'; import os from 'node:os'; import { QQLevel } from '@/core'; +import { QQVersionConfigType } from './types'; export async function solveProblem any>(func: T, ...args: Parameters): Promise | undefined> { return new Promise | undefined>((resolve) => { try { const result = func(...args); resolve(result); - } catch (e) { + } catch { resolve(undefined); } }); @@ -193,7 +195,7 @@ export function parseAppidFromMajor(nodeMajor: string): string | undefined { if (!content.every(byte => byte === 0x00)) { try { return content.toString('utf-8'); - } catch (error) { + } catch { break; } } diff --git a/src/common/log.ts b/src/common/log.ts index 5dfc0028..5d29867a 100644 --- a/src/common/log.ts +++ b/src/common/log.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import winston, { format, transports } from 'winston'; import { truncateString } from '@/common/helper'; import path from 'node:path'; @@ -34,7 +35,7 @@ class Subscription { for (const history of Subscription.history) { try { listener(history); - } catch (_) { + } catch { // ignore } } @@ -68,7 +69,7 @@ export class LogWrapper { format: format.combine( format.timestamp({ format: 'MM-DD HH:mm:ss' }), format.printf(({ timestamp, level, message, ...meta }) => { - const userInfo = meta.userInfo ? `${meta.userInfo} | ` : ''; + const userInfo = meta['userInfo'] ? `${meta['userInfo']} | ` : ''; return `${timestamp} [${level}] ${userInfo}${message}`; }) ), @@ -83,7 +84,7 @@ export class LogWrapper { format: format.combine( format.colorize(), format.printf(({ timestamp, level, message, ...meta }) => { - const userInfo = meta.userInfo ? `${meta.userInfo} | ` : ''; + const userInfo = meta['userInfo'] ? `${meta['userInfo']} | ` : ''; return `${timestamp} [${level}] ${userInfo}${message}`; }) ), diff --git a/src/common/proxy-handler.ts b/src/common/proxy-handler.ts index a6a8f915..3bcaf1a3 100644 --- a/src/common/proxy-handler.ts +++ b/src/common/proxy-handler.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { LogWrapper } from '@/common/log'; export function proxyHandlerOf(logger: LogWrapper) { @@ -5,6 +6,7 @@ export function proxyHandlerOf(logger: LogWrapper) { get(target: any, prop: any, receiver: any) { if (typeof target[prop] === 'undefined') { // 如果方法不存在,返回一个函数,这个函数调用existentMethod + // eslint-disable-next-line @typescript-eslint/no-unused-vars return (..._args: unknown[]) => { logger.logDebug(`${target.constructor.name} has no method ${prop}`); }; diff --git a/src/common/qq-basic-info.ts b/src/common/qq-basic-info.ts index a965146b..b468e908 100644 --- a/src/common/qq-basic-info.ts +++ b/src/common/qq-basic-info.ts @@ -4,6 +4,7 @@ import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfig import AppidTable from '@/core/external/appid.json'; import { LogWrapper } from '@/common/log'; import { getMajorPath } from '@/core'; +import { QQAppidTableType, QQPackageInfoType, QQVersionConfigType } from './types'; export class QQBasicInfoWrapper { QQMainPath: string | undefined; @@ -89,7 +90,7 @@ export class QQBasicInfoWrapper { this.context.logger.log('[QQ版本兼容性检测] 当前版本Appid未内置 通过Major获取 为了更好的性能请尝试更新NapCat'); return { appid: majorAppid, qua: this.getQUAFallback() }; } - } catch (error) { + } catch { this.context.logger.log('[QQ版本兼容性检测] 通过Major 获取Appid异常 请检测NapCat/QQNT是否正常'); } // 最终兜底为老版本 diff --git a/src/common/request.ts b/src/common/request.ts index b089b28d..6a4e7faa 100644 --- a/src/common/request.ts +++ b/src/common/request.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import https from 'node:https'; import http from 'node:http'; diff --git a/src/common/store.ts b/src/common/store.ts index a1dcd851..6c6b21c8 100644 --- a/src/common/store.ts +++ b/src/common/store.ts @@ -54,10 +54,10 @@ class Store { // 分批次扫描 while (scanned < this.scanLimit && this.scanCursor < keys.length) { const key = keys[this.scanCursor++]; - const entry = this.store.get(key)!; + const entry = this.store.get(key!)!; if (entry.expiresAt && entry.expiresAt < now) { - this.store.delete(key); + this.store.delete(key!); } scanned++; diff --git a/src/common/system.ts b/src/common/system.ts index a79a4c72..09122fe2 100644 --- a/src/common/system.ts +++ b/src/common/system.ts @@ -6,7 +6,7 @@ let osName: string; try { osName = os.hostname(); -} catch (e) { +} catch { osName = 'NapCat'; // + crypto.randomUUID().substring(0, 4); } diff --git a/src/common/types.ts b/src/common/types.ts index 91fa060d..61b52867 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -1,17 +1,17 @@ //QQVersionType -type QQPackageInfoType = { +export type QQPackageInfoType = { version: string; buildVersion: string; platform: string; eleArch: string; } -type QQVersionConfigType = { +export type QQVersionConfigType = { baseVersion: string; curVersion: string; prevVersion: string; - onErrorVersions: Array; + onErrorVersions: Array; buildId: string; } -type QQAppidTableType = { +export type QQAppidTableType = { [key: string]: { appid: string, qua: string }; } diff --git a/src/core/adapters/NodeIDependsAdapter.ts b/src/core/adapters/NodeIDependsAdapter.ts index 03652aff..36ca6cf6 100644 --- a/src/core/adapters/NodeIDependsAdapter.ts +++ b/src/core/adapters/NodeIDependsAdapter.ts @@ -1,15 +1,16 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { MsfChangeReasonType, MsfStatusType } from '@/core/types/adapter'; export class NodeIDependsAdapter { - onMSFStatusChange(statusType: MsfStatusType, changeReasonType: MsfChangeReasonType) { + onMSFStatusChange(_statusType: MsfStatusType, _changeReasonType: MsfChangeReasonType) { } - onMSFSsoError(args: unknown) { + onMSFSsoError(_args: unknown) { } - getGroupCode(args: unknown) { + getGroupCode(_args: unknown) { } } diff --git a/src/core/adapters/NodeIDispatcherAdapter.ts b/src/core/adapters/NodeIDispatcherAdapter.ts index 0bd5c702..a70182da 100644 --- a/src/core/adapters/NodeIDispatcherAdapter.ts +++ b/src/core/adapters/NodeIDispatcherAdapter.ts @@ -1,10 +1,11 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ export class NodeIDispatcherAdapter { - dispatchRequest(arg: unknown) { + dispatchRequest(_arg: unknown) { } - dispatchCall(arg: unknown) { + dispatchCall(_arg: unknown) { } - dispatchCallWithJson(arg: unknown) { + dispatchCallWithJson(_arg: unknown) { } } diff --git a/src/core/adapters/NodeIGlobalAdapter.ts b/src/core/adapters/NodeIGlobalAdapter.ts index 6b5ccb83..3ab6a33a 100644 --- a/src/core/adapters/NodeIGlobalAdapter.ts +++ b/src/core/adapters/NodeIGlobalAdapter.ts @@ -1,25 +1,26 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ export class NodeIGlobalAdapter { - onLog(...args: unknown[]) { + onLog(..._args: unknown[]) { } - onGetSrvCalTime(...args: unknown[]) { + onGetSrvCalTime(..._args: unknown[]) { } - onShowErrUITips(...args: unknown[]) { + onShowErrUITips(..._args: unknown[]) { } - fixPicImgType(...args: unknown[]) { + fixPicImgType(..._args: unknown[]) { } - getAppSetting(...args: unknown[]) { + getAppSetting(..._args: unknown[]) { } - onInstallFinished(...args: unknown[]) { + onInstallFinished(..._args: unknown[]) { } - onUpdateGeneralFlag(...args: unknown[]) { + onUpdateGeneralFlag(..._args: unknown[]) { } - onGetOfflineMsg(...args: unknown[]) { + onGetOfflineMsg(..._args: unknown[]) { } } diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index b8629a6d..81afbfb0 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -27,6 +27,7 @@ import { encodeSilk } from '@/common/audio'; import { SendMessageContext } from '@/onebot/api'; import { getFileTypeForSendType } from '../helper/msg'; import { FFmpegService } from '@/common/ffmpeg'; +import { rkeyDataType } from '../types/file'; export class NTQQFileApi { context: InstanceContext; @@ -61,7 +62,7 @@ export class NTQQFileApi { async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) { const fileMd5 = await calculateFileMD5(filePath); - const extOrEmpty = await fileTypeFromFile(filePath).then(e => e?.ext ?? '').catch(e => ''); + const extOrEmpty = await fileTypeFromFile(filePath).then(e => e?.ext ?? '').catch(() => ''); const ext = extOrEmpty ? `.${extOrEmpty}` : ''; let fileName = `${path.basename(filePath)}`; if (fileName.indexOf('.') === -1) { @@ -140,7 +141,7 @@ export class NTQQFileApi { }; } - async createValidSendVideoElement(context: SendMessageContext, filePath: string, fileName: string = '', diyThumbPath: string = ''): Promise { + async createValidSendVideoElement(context: SendMessageContext, filePath: string, fileName: string = '', _diyThumbPath: string = ''): Promise { let videoInfo = { width: 1920, height: 1080, @@ -170,10 +171,16 @@ export class NTQQFileApi { const thumbPath = pathLib.join(pathLib.dirname(thumbDir), `${md5}_0.png`); try { videoInfo = await FFmpegService.getVideoInfo(filePath, thumbPath); - } catch (error) { + } catch { fs.writeFileSync(thumbPath, Buffer.from(defaultVideoThumbB64, 'base64')); } - + if (_diyThumbPath) { + try { + await this.copyFile(_diyThumbPath, thumbPath); + } catch (e) { + this.context.logger.logError('复制自定义缩略图失败', e); + } + } const thumbSize = (await fsPromises.stat(thumbPath)).size; const thumbMd5 = await calculateFileMD5(thumbPath); context.deleteAfterSentFiles.push(path); @@ -275,16 +282,16 @@ export class NTQQFileApi { ) { switch (element.elementType) { case ElementType.PIC: - element.picElement!.sourcePath = elementResults[elementIndex]; + element.picElement!.sourcePath = elementResults?.[elementIndex] ?? ''; break; case ElementType.VIDEO: - element.videoElement!.filePath = elementResults[elementIndex]; + element.videoElement!.filePath = elementResults?.[elementIndex] ?? ''; break; case ElementType.PTT: - element.pttElement!.filePath = elementResults[elementIndex]; + element.pttElement!.filePath = elementResults?.[elementIndex] ?? ''; break; case ElementType.FILE: - element.fileElement!.filePath = elementResults[elementIndex]; + element.fileElement!.filePath = elementResults?.[elementIndex] ?? ''; break; } elementIndex++; @@ -299,7 +306,7 @@ export class NTQQFileApi { if (force) { try { await fsPromises.unlink(sourcePath); - } catch (e) { + } catch { // } } else { @@ -401,27 +408,27 @@ export class NTQQFileApi { } private async getRkeyData() { - const rkeyData = { + const rkeyData: rkeyDataType = { private_rkey: 'CAQSKAB6JWENi5LM_xp9vumLbuThJSaYf-yzMrbZsuq7Uz2qEc3Rbib9LP4', group_rkey: 'CAQSKAB6JWENi5LM_xp9vumLbuThJSaYf-yzMrbZsuq7Uz2qffcqm614gds', online_rkey: false }; try { - if (this.core.apis.PacketApi.available) { + if (this.core.apis.PacketApi.available && this.packetRkey?.[0] && this.packetRkey?.[1]) { const rkey_expired_private = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000; const rkey_expired_group = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000; if (rkey_expired_private || rkey_expired_group) { this.packetRkey = await this.core.apis.PacketApi.pkt.operation.FetchRkey(); } if (this.packetRkey && this.packetRkey.length > 0) { - rkeyData.group_rkey = this.packetRkey[1].rkey.slice(6); - rkeyData.private_rkey = this.packetRkey[0].rkey.slice(6); + rkeyData.group_rkey = this.packetRkey[1]?.rkey.slice(6) ?? ''; + rkeyData.private_rkey = this.packetRkey[0]?.rkey.slice(6) ?? ''; rkeyData.online_rkey = true; } } - } catch (error: any) { - this.context.logger.logError('获取rkey失败', error.message); + } catch (error: unknown) { + this.context.logger.logError('获取rkey失败', (error as Error).message); } if (!rkeyData.online_rkey) { @@ -438,7 +445,7 @@ export class NTQQFileApi { return rkeyData; } - private getImageUrlFromParsedUrl(imageFileId: string, appid: string, rkeyData: any): string { + private getImageUrlFromParsedUrl(imageFileId: string, appid: string, rkeyData: rkeyDataType): string { const rkey = appid === '1406' ? rkeyData.private_rkey : rkeyData.group_rkey; if (rkeyData.online_rkey) { return IMAGE_HTTP_HOST_NT + `/download?appid=${appid}&fileid=${imageFileId}&rkey=${rkey}`; diff --git a/src/core/apis/friend.ts b/src/core/apis/friend.ts index 7714d683..c03a1999 100644 --- a/src/core/apis/friend.ts +++ b/src/core/apis/friend.ts @@ -13,7 +13,7 @@ export class NTQQFriendApi { async setBuddyRemark(uid: string, remark: string) { return this.context.session.getBuddyService().setBuddyRemark({ uid, remark }); } - async getBuddyV2SimpleInfoMap(refresh = false) { + async getBuddyV2SimpleInfoMap() { const buddyService = this.context.session.getBuddyService(); const buddyListV2 = await buddyService.getBuddyListV2('0', BuddyListReqType.KNOMAL); const uids = buddyListV2.data.flatMap(item => item.buddyUids); @@ -24,13 +24,13 @@ export class NTQQFriendApi { ); } - async getBuddy(refresh = false): Promise { - return Array.from((await this.getBuddyV2SimpleInfoMap(refresh)).values()); + async getBuddy(): Promise { + return Array.from((await this.getBuddyV2SimpleInfoMap()).values()); } - async getBuddyIdMap(refresh = false): Promise> { + async getBuddyIdMap(): Promise> { const retMap: LimitedHashTable = new LimitedHashTable(5000); - const data = await this.getBuddyV2SimpleInfoMap(refresh); + const data = await this.getBuddyV2SimpleInfoMap(); data.forEach((value) => retMap.set(value.uin!, value.uid!)); return retMap; } diff --git a/src/core/apis/group.ts b/src/core/apis/group.ts index 6686aabe..4ac216b7 100644 --- a/src/core/apis/group.ts +++ b/src/core/apis/group.ts @@ -59,7 +59,7 @@ export class NTQQGroupApi { }, pskey); } - async getGroupShutUpMemberList(groupCode: string) { + async getGroupShutUpMemberList(groupCode: string): Promise { const executor: TaskExecutor = async (resolve, reject, onCancel) => { this.core.eventWrapper.registerListen( 'NodeIKernelGroupListener/onShutUpMemberListChanged', @@ -215,6 +215,9 @@ export class NTQQGroupApi { guildId: '', peerUid: groupCode, }, msgId, 1, false); + if (!MsgData.msgList[0]) { + throw new Error('消息不存在'); + } const param = { groupCode: groupCode, msgRandom: parseInt(MsgData.msgList[0].msgRandom), @@ -255,6 +258,9 @@ export class NTQQGroupApi { guildId: '', peerUid: groupCode, }, msgId, 1, false); + if (!MsgData.msgList[0]) { + throw new Error('消息不存在'); + } const param = { groupCode: groupCode, msgRandom: parseInt(MsgData.msgList[0].msgRandom), diff --git a/src/core/apis/index.ts b/src/core/apis/index.ts index 27e42258..ccc437fe 100644 --- a/src/core/apis/index.ts +++ b/src/core/apis/index.ts @@ -4,4 +4,6 @@ export * from './group'; export * from './msg'; export * from './user'; export * from './webapi'; -export * from './system'; \ No newline at end of file +export * from './system'; +export * from './packet'; +export * from './file'; \ No newline at end of file diff --git a/src/core/apis/msg.ts b/src/core/apis/msg.ts index 239ce18f..d7f9844d 100644 --- a/src/core/apis/msg.ts +++ b/src/core/apis/msg.ts @@ -201,7 +201,7 @@ export class NTQQMsgApi { return this.context.session.getMsgService().getTempChatInfo(chatType, peerUid); } - async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { + async sendMsg(peer: Peer, msgElements: SendMessageElement[], timeout = 10000) { //唉?!我有个想法 if (peer.chatType === ChatType.KCHATTYPETEMPC2CFROMGROUP && peer.guildId && peer.guildId !== '') { const member = await this.core.apis.GroupApi.getGroupMember(peer.guildId, peer.peerUid); @@ -268,7 +268,7 @@ export class NTQQMsgApi { if (!arkElement) { continue; } - const forwardData: any = JSON.parse(arkElement.arkElement?.bytesData ?? ''); + const forwardData: { app: string } = JSON.parse(arkElement.arkElement?.bytesData ?? ''); if (forwardData.app != 'com.tencent.multimsg') { continue; } diff --git a/src/core/apis/system.ts b/src/core/apis/system.ts index f79b4b53..53245a77 100644 --- a/src/core/apis/system.ts +++ b/src/core/apis/system.ts @@ -25,7 +25,7 @@ export class NTQQSystemApi { this.context.session.getMsgService().getOnLineDev(); } - async getArkJsonCollection(cid: string) { + async getArkJsonCollection() { return await this.core.eventWrapper.callNoListenerEvent('NodeIKernelCollectionService/collectionArkShare', '1717662698058'); } diff --git a/src/core/apis/user.ts b/src/core/apis/user.ts index f9af85e4..2177feb9 100644 --- a/src/core/apis/user.ts +++ b/src/core/apis/user.ts @@ -69,7 +69,7 @@ export class NTQQUserApi { } async fetchUserDetailInfo(uid: string, mode: UserDetailSource = UserDetailSource.KDB) { - const [_retData, profile] = await this.core.eventWrapper.callNormalEventV2( + const [, profile] = await this.core.eventWrapper.callNormalEventV2( 'NodeIKernelProfileService/fetchUserDetailInfo', 'NodeIKernelProfileListener/onUserDetailInfoChanged', [ @@ -130,10 +130,10 @@ export class NTQQUserApi { const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + this.core.selfInfo.uin + '&clientkey=' + ClientKeyData.clientKey + '&u1=https%3A%2F%2F' + domain + '%2F' + this.core.selfInfo.uin + '%2Finfocenter&keyindex=19%27'; const data = await RequestUtil.HttpsGetCookies(requestUrl); - if (!data.p_skey || data.p_skey.length == 0) { + if (!data['p_skey'] || data['p_skey'].length == 0) { try { const pskey = (await this.getPSkey([domain])).domainPskeyMap.get(domain); - if (pskey) data.p_skey = pskey; + if (pskey) data['p_skey'] = pskey; } catch { return data; } @@ -145,7 +145,7 @@ export class NTQQUserApi { return await this.context.session.getTipOffService().getPskey(domainList, true); } - async getRobotUinRange(): Promise> { + async getRobotUinRange(): Promise> { const robotUinRanges = await this.context.session.getRobotService().getRobotUinRange({ justFetchMsgConfig: '1', type: 1, diff --git a/src/core/apis/webapi.ts b/src/core/apis/webapi.ts index f6b436c1..edfad136 100644 --- a/src/core/apis/webapi.ts +++ b/src/core/apis/webapi.ts @@ -32,7 +32,7 @@ export class NTQQWebApi { }).toString()}`; try { return RequestUtil.HttpGetText(url, 'GET', '', { 'Cookie': this.cookieToString(cookieObject) }); - } catch (e) { + } catch { return undefined; } } @@ -67,7 +67,7 @@ export class NTQQWebApi { } } - async getGroupMembers(GroupCode: string, cached: boolean = true): Promise { + async getGroupMembers(GroupCode: string): Promise { //logDebug('webapi 获取群成员', GroupCode); const memberData: Array = new Array(); const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com'); @@ -88,7 +88,9 @@ export class NTQQWebApi { return []; } else { for (const key in fastRet.mems) { - memberData.push(fastRet.mems[key]); + if (fastRet.mems[key]) { + memberData.push(fastRet.mems[key]); + } } } //初始化获取PageNum @@ -116,7 +118,9 @@ export class NTQQWebApi { continue; } for (const key in ret.mems) { - memberData.push(ret.mems[key]); + if (ret.mems[key]) { + memberData.push(ret.mems[key]); + } } } return memberData; @@ -185,7 +189,7 @@ export class NTQQWebApi { { 'Cookie': this.cookieToString(cookieObject) } ); return ret; - } catch (e) { + } catch { return undefined; } } @@ -210,12 +214,12 @@ export class NTQQWebApi { { 'Cookie': this.cookieToString(cookieObject) } ); return ret?.ec === 0 ? ret : undefined; - } catch (e) { + } catch { return undefined; } } - private async getDataInternal(cookieObject: any, groupCode: string, type: number) { + private async getDataInternal(cookieObject: { [key: string]: string }, groupCode: string, type: number) { let resJson; try { const res = await RequestUtil.HttpGetText( @@ -228,7 +232,7 @@ export class NTQQWebApi { { 'Cookie': this.cookieToString(cookieObject) } ); const match = /window\.__INITIAL_STATE__=(.*?);/.exec(res); - if (match) { + if (match?.[1]) { resJson = JSON.parse(match[1].trim()); } return type === 1 ? resJson?.talkativeList : resJson?.actorList; @@ -238,13 +242,18 @@ export class NTQQWebApi { } } - private async getHonorList(cookieObject: any, groupCode: string, type: number) { + private async getHonorList(cookieObject: { [key: string]: string }, groupCode: string, type: number) { const data = await this.getDataInternal(cookieObject, groupCode, type); if (!data) { this.context.logger.logError(`获取类型 ${type} 的荣誉信息失败`); return []; } - return data.map((item: any) => ({ + return data.map((item: { + uin: string, + name: string, + avatar: string, + desc: string, + }) => ({ user_id: item?.uin, nickname: item?.name, avatar: item?.avatar, @@ -254,7 +263,15 @@ export class NTQQWebApi { async getGroupHonorInfo(groupCode: string, getType: WebHonorType) { const cookieObject = await this.core.apis.UserApi.getCookies('qun.qq.com'); - const HonorInfo: any = { group_id: groupCode }; + let HonorInfo = { + group_id: groupCode, + current_talkative: {}, + talkative_list: [], + performer_list: [], + legend_list: [], + emotion_list: [], + strong_newbie_list: [], + }; if (getType === WebHonorType.TALKATIVE || getType === WebHonorType.ALL) { const talkativeList = await this.getHonorList(cookieObject, groupCode, 1); @@ -284,12 +301,12 @@ export class NTQQWebApi { return HonorInfo; } - private cookieToString(cookieObject: any) { + private cookieToString(cookieObject: { [key: string]: string }) { return Object.entries(cookieObject).map(([key, value]) => `${key}=${value}`).join('; '); } - public getBknFromCookie(cookieObject: any) { - const sKey = cookieObject.skey as string; + public getBknFromCookie(cookieObject: { [key: string]: string }) { + const sKey = cookieObject['skey'] as string; let hash = 5381; for (let i = 0; i < sKey.length; i++) { diff --git a/src/core/helper/rkey.ts b/src/core/helper/rkey.ts index 5e0cb588..ecc3634d 100644 --- a/src/core/helper/rkey.ts +++ b/src/core/helper/rkey.ts @@ -51,7 +51,7 @@ export class RkeyManager { return now > this.rkeyData.expired_time; } - async refreshRkey(): Promise { + async refreshRkey() { //刷新rkey for (const url of this.serverUrl) { try { diff --git a/src/core/helper/status.ts b/src/core/helper/status.ts index b3884de0..7aca69a7 100644 --- a/src/core/helper/status.ts +++ b/src/core/helper/status.ts @@ -35,9 +35,9 @@ export class StatusHelper { const { total, active } = currentTimes.map((times, index) => { const prevTimes = this.cpuTimes[index]; const totalCurrent = times.user + times.nice + times.sys + times.idle + times.irq; - const totalPrev = prevTimes.user + prevTimes.nice + prevTimes.sys + prevTimes.idle + prevTimes.irq; + const totalPrev = (prevTimes?.user ?? 0) + (prevTimes?.nice ?? 0) + (prevTimes?.sys ?? 0) + (prevTimes?.idle ?? 0) + (prevTimes?.irq ?? 0); const activeCurrent = totalCurrent - times.idle; - const activePrev = totalPrev - prevTimes.idle; + const activePrev = totalPrev - (prevTimes?.idle ?? 0); return { total: totalCurrent - totalPrev, active: activeCurrent - activePrev @@ -49,8 +49,8 @@ export class StatusHelper { this.cpuTimes = currentTimes; return { usage: this.replaceNaN(((active / total) * 100)).toFixed(2), - model: os.cpus()[0].model, - speed: os.cpus()[0].speed, + model: os.cpus()[0]?.model ?? 'none', + speed: os.cpus()[0]?.speed ?? 0, core: os.cpus().length }; } diff --git a/src/core/index.ts b/src/core/index.ts index 0552f2ac..5933e2dd 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -24,7 +24,7 @@ import path from 'node:path'; import fs from 'node:fs'; import { hostname, systemName, systemVersion } from '@/common/system'; import { NTEventWrapper } from '@/common/event'; -import { GroupMember, KickedOffLineInfo, SelfInfo, SelfStatusInfo } from '@/core/types'; +import { KickedOffLineInfo, SelfInfo, SelfStatusInfo } from '@/core/types'; import { NapCatConfigLoader } from '@/core/helper/config'; import os from 'node:os'; import { NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/core/listeners'; @@ -58,7 +58,7 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi { if (!fs.existsSync(wrapperNodePath)) { wrapperNodePath = path.join(path.dirname(process.execPath), `./resources/app/versions/${QQVersion}/wrapper.node`); } - const nativemodule: any = { exports: {} }; + const nativemodule: { exports: WrapperNodeApi } = { exports: {} as WrapperNodeApi }; process.dlopen(nativemodule, wrapperNodePath); return nativemodule.exports; } diff --git a/src/core/packet/client/wsClient.ts b/src/core/packet/client/wsClient.ts index 6c86b054..dc4d9929 100644 --- a/src/core/packet/client/wsClient.ts +++ b/src/core/packet/client/wsClient.ts @@ -52,7 +52,7 @@ export class WsPacketClient extends IPacketClient { try { await this.connect(); return; - } catch (error) { + } catch { this.reconnectAttempts++; this.logStack.pushLogWarn(`第 ${this.reconnectAttempts}/${this.maxReconnectAttempts} 次尝试重连失败!`); await this.delay(5000); diff --git a/src/core/packet/context/clientContext.ts b/src/core/packet/context/clientContext.ts index 98eb145a..9e77bd7e 100644 --- a/src/core/packet/context/clientContext.ts +++ b/src/core/packet/context/clientContext.ts @@ -5,11 +5,11 @@ import { OidbPacket } from '@/core/packet/transformer/base'; import { PacketLogger } from '@/core/packet/context/loggerContext'; import { NapCoreContext } from '@/core/packet/context/napCoreContext'; -type clientPriority = { +type clientPriorityType = { [key: number]: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => IPacketClient; } -const clientPriority: clientPriority = { +const clientPriority: clientPriorityType = { 10: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => new NativePacketClient(napCore, logger, logStack), 1: (napCore: NapCoreContext, logger: PacketLogger, logStack: LogStack) => new WsPacketClient(napCore, logger, logStack), }; diff --git a/src/core/packet/context/loggerContext.ts b/src/core/packet/context/loggerContext.ts index 86e89806..3b12015c 100644 --- a/src/core/packet/context/loggerContext.ts +++ b/src/core/packet/context/loggerContext.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { LogLevel, LogWrapper } from '@/common/log'; import { NapCoreContext } from '@/core/packet/context/napCoreContext'; diff --git a/src/core/packet/context/operationContext.ts b/src/core/packet/context/operationContext.ts index 6cf58ffe..fa354f94 100644 --- a/src/core/packet/context/operationContext.ts +++ b/src/core/packet/context/operationContext.ts @@ -61,7 +61,7 @@ export class PacketOperationContext { } status = Number((extBigInt & 0xff00n) + ((extBigInt >> 16n) & 0xffn)); return { status: 10, ext_status: status }; - } catch (e) { + } catch { return undefined; } } diff --git a/src/core/packet/highway/client.ts b/src/core/packet/highway/client.ts index 18274c64..d5c55362 100644 --- a/src/core/packet/highway/client.ts +++ b/src/core/packet/highway/client.ts @@ -27,7 +27,8 @@ export class PacketHighwayClient { port: number = 80; logger: PacketLogger; - constructor(sig: PacketHighwaySig, logger: PacketLogger, server: string = 'htdata3.qq.com', port: number = 80) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + constructor(sig: PacketHighwaySig, logger: PacketLogger, _server: string = 'htdata3.qq.com', _port: number = 80) { this.sig = sig; this.logger = logger; } diff --git a/src/core/packet/highway/uploader/highwayTcpUploader.ts b/src/core/packet/highway/uploader/highwayTcpUploader.ts index 35f23b21..9b98bddc 100644 --- a/src/core/packet/highway/uploader/highwayTcpUploader.ts +++ b/src/core/packet/highway/uploader/highwayTcpUploader.ts @@ -17,7 +17,8 @@ class HighwayTcpUploaderTransform extends stream.Transform { this.offset = 0; } - _transform(data: Buffer, _: BufferEncoding, callback: stream.TransformCallback) { + // eslint-disable-next-line no-undef + override _transform(data: Buffer, _: BufferEncoding, callback: stream.TransformCallback) { let chunkOffset = 0; while (chunkOffset < data.length) { const chunkSize = Math.min(BlockSize, data.length - chunkOffset); @@ -60,6 +61,7 @@ export class HighwayTcpUploader extends IHighwayUploader { socket.end(); reject(new Error('Upload aborted due to timeout')); } + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [head, _] = Frame.unpack(chunk); handleRspHeader(head); }); diff --git a/src/core/packet/message/element.ts b/src/core/packet/message/element.ts index 24861c5e..3a1197ba 100644 --- a/src/core/packet/message/element.ts +++ b/src/core/packet/message/element.ts @@ -14,7 +14,6 @@ import { GroupFileExtra } from '@/core/packet/transformer/proto'; import { - BaseEmojiType, FaceType, NTMsgAtType, PicType, @@ -36,7 +35,8 @@ import { PacketMsg, PacketSendMsgElement } from '@/core/packet/message/message'; // raw <-> packet // TODO: SendStructLongMsgElement export abstract class IPacketMsgElement { - protected constructor(rawElement: T) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + protected constructor(_rawElement: T) { } get valid(): boolean { @@ -64,7 +64,7 @@ export class PacketMsgTextElement extends IPacketMsgElement { this.text = element.textElement.content; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { return [{ text: { str: this.text @@ -72,7 +72,7 @@ export class PacketMsgTextElement extends IPacketMsgElement { }]; } - toPreview(): string { + override toPreview(): string { return this.text; } } @@ -87,7 +87,7 @@ export class PacketMsgAtElement extends PacketMsgTextElement { this.atAll = element.textElement.atType === NTMsgAtType.ATTYPEALL; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { return [{ text: { str: this.text, @@ -127,7 +127,7 @@ export class PacketMsgReplyElement extends IPacketMsgElement { return this.messageClientSeq === 0; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { return [{ srcMsg: { origSeqs: [this.isGroupReply ? this.messageClientSeq : this.messageSeq], @@ -152,7 +152,7 @@ export class PacketMsgReplyElement extends IPacketMsgElement { }]; } - toPreview(): string { + override toPreview(): string { return '[回复消息]'; } } @@ -169,7 +169,7 @@ export class PacketMsgFaceElement extends IPacketMsgElement { this.isLargeFace = element.faceElement.faceType === FaceType.AniSticke; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { if (this.isLargeFace) { return [{ commonElem: { @@ -207,7 +207,7 @@ export class PacketMsgFaceElement extends IPacketMsgElement { } } - toPreview(): string { + override toPreview(): string { return '[表情]'; } } @@ -226,7 +226,7 @@ export class PacketMsgMarkFaceElement extends IPacketMsgElement[] { + override buildElement(): NapProtoEncodeStructType[] { return [{ marketFace: { faceName: this.emojiName, @@ -245,7 +245,7 @@ export class PacketMsgMarkFaceElement extends IPacketMsgElement { ) : element.picElement.summary; } - get valid(): boolean { + override get valid(): boolean { return !!this.msgInfo; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { if (!this.msgInfo) return []; return [{ commonElem: { @@ -295,7 +295,7 @@ export class PacketMsgPicElement extends IPacketMsgElement { }]; } - toPreview(): string { + override toPreview(): string { return this.summary; } } @@ -318,18 +318,18 @@ export class PacketMsgVideoElement extends IPacketMsgElement { this.fileSize = element.videoElement.fileSize; this.filePath = element.videoElement.filePath; this.thumbSize = element.videoElement.thumbSize; - this.thumbPath = element.videoElement.thumbPath?.get(0); + this.thumbPath = element.videoElement.thumbPath?.get(0) as string | undefined; this.fileMd5 = element.videoElement.videoMd5; this.thumbMd5 = element.videoElement.thumbMd5; this.thumbWidth = element.videoElement.thumbWidth; this.thumbHeight = element.videoElement.thumbHeight; } - get valid(): boolean { + override get valid(): boolean { return !!this.msgInfo; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { if (!this.msgInfo) return []; return [{ commonElem: { @@ -340,7 +340,7 @@ export class PacketMsgVideoElement extends IPacketMsgElement { }]; } - toPreview(): string { + override toPreview(): string { return '[视频]'; } } @@ -361,11 +361,11 @@ export class PacketMsgPttElement extends IPacketMsgElement { this.fileDuration = Math.round(element.pttElement.duration); // TODO: cc } - get valid(): boolean { + override get valid(): boolean { return false; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { return []; // if (!this.msgInfo) return []; // return [{ @@ -377,7 +377,7 @@ export class PacketMsgPttElement extends IPacketMsgElement { // }]; } - toPreview(): string { + override toPreview(): string { return '[语音]'; } } @@ -402,11 +402,11 @@ export class PacketMsgFileElement extends IPacketMsgElement { this.fileSize = +element.fileElement.fileSize; } - get valid(): boolean { + override get valid(): boolean { return this.isGroupFile || Boolean(this._e37_800_rsp); } - buildContent(): Uint8Array | undefined { + override buildContent(): Uint8Array | undefined { if (this.isGroupFile || !this._e37_800_rsp) return undefined; return new NapProtoMsg(FileExtra).encode({ file: { @@ -437,7 +437,7 @@ export class PacketMsgFileElement extends IPacketMsgElement { }); } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { if (!this.isGroupFile) return []; const lb = Buffer.alloc(2); const transElemVal = new NapProtoMsg(GroupFileExtra).encode({ @@ -464,7 +464,7 @@ export class PacketMsgFileElement extends IPacketMsgElement { }]; } - toPreview(): string { + override toPreview(): string { return `[文件]${this.fileName}`; } } @@ -477,7 +477,7 @@ export class PacketMsgLightAppElement extends IPacketMsgElement this.payload = element.arkElement.bytesData; } - buildElement(): NapProtoEncodeStructType[] { + override buildElement(): NapProtoEncodeStructType[] { return [{ lightAppElem: { data: Buffer.concat([ @@ -488,7 +488,7 @@ export class PacketMsgLightAppElement extends IPacketMsgElement }]; } - toPreview(): string { + override toPreview(): string { return '[卡片消息]'; } } @@ -501,7 +501,7 @@ export class PacketMsgMarkDownElement extends IPacketMsgElement[] { + override buildElement(): NapProtoEncodeStructType[] { return [{ commonElem: { serviceType: 45, @@ -513,7 +513,7 @@ export class PacketMsgMarkDownElement extends IPacketMsgElement[] { + override buildElement(): NapProtoEncodeStructType[] { return [{ lightAppElem: { data: Buffer.concat([ @@ -539,7 +539,7 @@ export class PacketMultiMsgElement extends IPacketMsgElement 0) this.sha1.update(this.buffer); const finalDigest = this.sha1.final(); diff --git a/src/core/packet/utils/crypto/tea.ts b/src/core/packet/utils/crypto/tea.ts index 94826a38..4b23cc11 100644 --- a/src/core/packet/utils/crypto/tea.ts +++ b/src/core/packet/utils/crypto/tea.ts @@ -1,4 +1,6 @@ // love from https://github.com/LagrangeDev/lagrangejs/blob/main/src/core/tea.ts & https://github.com/takayama-lily/oicq/blob/main/lib/core/tea.ts +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-nocheck const BUF7 = Buffer.alloc(7); const deltas = [ 0x9e3779b9, 0x3c6ef372, 0xdaa66d2b, 0x78dde6e4, 0x1715609d, 0xb54cda56, 0x5384540f, 0xf1bbcdc8, 0x8ff34781, diff --git a/src/core/services/NodeIKernelAlbumService.ts b/src/core/services/NodeIKernelAlbumService.ts index 1d1ca68c..07c80489 100644 --- a/src/core/services/NodeIKernelAlbumService.ts +++ b/src/core/services/NodeIKernelAlbumService.ts @@ -1,47 +1,47 @@ export interface NodeIKernelAlbumService { - setAlbumServiceInfo(...args: any[]): unknown;// needs 3 arguments + setAlbumServiceInfo(...args: unknown[]): unknown;// needs 3 arguments - getMainPage(...args: any[]): unknown;// needs 2 arguments + getMainPage(...args: unknown[]): unknown;// needs 2 arguments - getAlbumList(...args: any[]): unknown;// needs 1 arguments + getAlbumList(...args: unknown[]): unknown;// needs 1 arguments - getAlbumInfo(...args: any[]): unknown;// needs 1 arguments + getAlbumInfo(...args: unknown[]): unknown;// needs 1 arguments - deleteAlbum(...args: any[]): unknown;// needs 3 arguments + deleteAlbum(...args: unknown[]): unknown;// needs 3 arguments - addAlbum(...args: any[]): unknown;// needs 2 arguments + addAlbum(...args: unknown[]): unknown;// needs 2 arguments - deleteMedias(...args: any[]): unknown;// needs 4 arguments + deleteMedias(...args: unknown[]): unknown;// needs 4 arguments - modifyAlbum(...args: any[]): unknown;// needs 3 arguments + modifyAlbum(...args: unknown[]): unknown;// needs 3 arguments - getMediaList(...args: any[]): unknown;// needs 1 arguments + getMediaList(...args: unknown[]): unknown;// needs 1 arguments - quoteToQzone(...args: any[]): unknown;// needs 1 arguments + quoteToQzone(...args: unknown[]): unknown;// needs 1 arguments - quoteToQunAlbum(...args: any[]): unknown;// needs 1 arguments + quoteToQunAlbum(...args: unknown[]): unknown;// needs 1 arguments - queryQuoteToQunAlbumStatus(...args: any[]): unknown;// needs 1 arguments + queryQuoteToQunAlbumStatus(...args: unknown[]): unknown;// needs 1 arguments - getQunFeeds(...args: any[]): unknown;//needs 1 arguments + getQunFeeds(...args: unknown[]): unknown;//needs 1 arguments - getQunFeedDetail(...args: any[]): unknown;// needs 1 arguments + getQunFeedDetail(...args: unknown[]): unknown;// needs 1 arguments - getQunNoticeList(...args: any[]): unknown;// needs 4 arguments + getQunNoticeList(...args: unknown[]): unknown;// needs 4 arguments - getQunComment(...args: any[]): unknown;// needs 1 arguments + getQunComment(...args: unknown[]): unknown;// needs 1 arguments - getQunLikes(...args: any[]): unknown;// needs 4 arguments + getQunLikes(...args: unknown[]): unknown;// needs 4 arguments - deleteQunFeed(...args: any[]): unknown;// needs 1 arguments + deleteQunFeed(...args: unknown[]): unknown;// needs 1 arguments - doQunComment(...args: any[]): unknown;// needs 6 arguments + doQunComment(...args: unknown[]): unknown;// needs 6 arguments - doQunReply(...args: any[]): unknown;// needs 7 arguments + doQunReply(...args: unknown[]): unknown;// needs 7 arguments - doQunLike(...args: any[]): unknown;// needs 5 arguments + doQunLike(...args: unknown[]): unknown;// needs 5 arguments - getRedPoints(...args: any[]): unknown;// needs 3 arguments + getRedPoints(...args: unknown[]): unknown;// needs 3 arguments } diff --git a/src/core/services/NodeIKernelCollectionService.ts b/src/core/services/NodeIKernelCollectionService.ts index 2bbdd459..673c8ead 100644 --- a/src/core/services/NodeIKernelCollectionService.ts +++ b/src/core/services/NodeIKernelCollectionService.ts @@ -1,7 +1,7 @@ import { GeneralCallResult } from './common'; export interface NodeIKernelCollectionService { - addKernelCollectionListener(...args: any[]): void;//needs 1 arguments + addKernelCollectionListener(...args: unknown[]): void;//needs 1 arguments removeKernelCollectionListener(listenerId: number): void; @@ -55,37 +55,37 @@ export interface NodeIKernelCollectionService { } >; - getCollectionContent(...args: any[]): unknown;//needs 5 arguments + getCollectionContent(...args: unknown[]): unknown;//needs 5 arguments - getCollectionCustomGroupList(...args: any[]): unknown;//needs 0 arguments + getCollectionCustomGroupList(...args: unknown[]): unknown;//needs 0 arguments - getCollectionUserInfo(...args: any[]): unknown;//needs 0 arguments + getCollectionUserInfo(...args: unknown[]): unknown;//needs 0 arguments - searchCollectionItemList(...args: any[]): unknown;//needs 2 arguments + searchCollectionItemList(...args: unknown[]): unknown;//needs 2 arguments - addMsgToCollection(...args: any[]): unknown;//needs 2 arguments + addMsgToCollection(...args: unknown[]): unknown;//needs 2 arguments - collectionArkShare(...args: any[]): unknown;//needs 1 arguments + collectionArkShare(...args: unknown[]): unknown;//needs 1 arguments - collectionFileForward(...args: any[]): unknown;//needs 3 arguments + collectionFileForward(...args: unknown[]): unknown;//needs 3 arguments - downloadCollectionFile(...args: any[]): unknown;//needs 4 arguments + downloadCollectionFile(...args: unknown[]): unknown;//needs 4 arguments - downloadCollectionFileThumbPic(...args: any[]): unknown;//needs 4 arguments + downloadCollectionFileThumbPic(...args: unknown[]): unknown;//needs 4 arguments - downloadCollectionPic(...args: any[]): unknown;//needs 3 arguments + downloadCollectionPic(...args: unknown[]): unknown;//needs 3 arguments - cancelDownloadCollectionFile(...args: any[]): unknown;//needs 1 arguments + cancelDownloadCollectionFile(...args: unknown[]): unknown;//needs 1 arguments - deleteCollectionItemList(...args: any[]): unknown;//needs 1 arguments + deleteCollectionItemList(...args: unknown[]): unknown;//needs 1 arguments - editCollectionItem(...args: any[]): unknown;//needs 2 arguments + editCollectionItem(...args: unknown[]): unknown;//needs 2 arguments - getEditPicInfoByPath(...args: any[]): unknown;//needs 1 arguments + getEditPicInfoByPath(...args: unknown[]): unknown;//needs 1 arguments - collectionFastUpload(...args: any[]): unknown;//needs 1 arguments + collectionFastUpload(...args: unknown[]): unknown;//needs 1 arguments - editCollectionItemAfterFastUpload(...args: any[]): unknown;//needs 2 arguments + editCollectionItemAfterFastUpload(...args: unknown[]): unknown;//needs 2 arguments - createNewCollectionItem(...args: any[]): unknown;//needs 1 arguments + createNewCollectionItem(...args: unknown[]): unknown;//needs 1 arguments } diff --git a/src/core/services/NodeIKernelGroupService.ts b/src/core/services/NodeIKernelGroupService.ts index 2a4ed5a0..bb300121 100644 --- a/src/core/services/NodeIKernelGroupService.ts +++ b/src/core/services/NodeIKernelGroupService.ts @@ -20,7 +20,7 @@ export interface NodeIKernelGroupService { getAllGroupPrivilegeFlag(troopUinList: string[], serviceType: number): Promise; // <--- getGroupExt0xEF0Info(enableGroupCodes: string[], bannedGroupCodes: string[], filter: GroupExt0xEF0InfoFilter, forceFetch: boolean): - Promise } }>; + Promise } }>; kickMemberV2(param: KickMemberV2Req): Promise; @@ -153,7 +153,7 @@ export interface NodeIKernelGroupService { getMemberExtInfo(param: GroupExtParam): Promise;//req - getGroupAllInfo(groupId: string, sourceId: number): Promise; + getGroupAllInfo(groupId: string, sourceId: number): Promise; getDiscussExistInfo(): unknown; @@ -213,7 +213,7 @@ export interface NodeIKernelGroupService { deleteGroupBulletin(groupCode: string, seq: string, noticeId: string): void; - publishGroupBulletin(groupCode: string, pskey: string, data: any): Promise; + publishGroupBulletin(groupCode: string, pskey: string, data: unknown): Promise; publishInstructionForNewcomers(groupCode: string, arg: unknown): void; diff --git a/src/core/services/NodeIKernelLoginService.ts b/src/core/services/NodeIKernelLoginService.ts index c3294606..8c90144a 100644 --- a/src/core/services/NodeIKernelLoginService.ts +++ b/src/core/services/NodeIKernelLoginService.ts @@ -82,7 +82,7 @@ export interface NodeIKernelLoginService { quickLoginWithUin(uin: string): Promise; - passwordLogin(param: PasswordLoginArgType): Promise; + passwordLogin(param: PasswordLoginArgType): Promise; getQRCodePicture(): boolean; } diff --git a/src/core/services/NodeIKernelMsgBackupService.ts b/src/core/services/NodeIKernelMsgBackupService.ts index 395edd04..c0364e20 100644 --- a/src/core/services/NodeIKernelMsgBackupService.ts +++ b/src/core/services/NodeIKernelMsgBackupService.ts @@ -3,25 +3,25 @@ export interface NodeIKernelMsgBackupService { removeKernelMsgBackupListener(listenerId: number): void; - getMsgBackupLocation(...args: any[]): unknown;// needs 0 arguments + getMsgBackupLocation(...args: unknown[]): unknown;// needs 0 arguments - setMsgBackupLocation(...args: any[]): unknown;// needs 1 arguments + setMsgBackupLocation(...args: unknown[]): unknown;// needs 1 arguments - requestMsgBackup(...args: any[]): unknown;// needs 0 arguments + requestMsgBackup(...args: unknown[]): unknown;// needs 0 arguments - requestMsgRestore(...args: any[]): unknown;// needs 1 arguments + requestMsgRestore(...args: unknown[]): unknown;// needs 1 arguments - requestMsgMigrate(...args: any[]): unknown;// needs 1 arguments + requestMsgMigrate(...args: unknown[]): unknown;// needs 1 arguments - getLocalStorageBackup(...args: any[]): unknown;// needs 0 arguments + getLocalStorageBackup(...args: unknown[]): unknown;// needs 0 arguments - deleteLocalBackup(...args: any[]): unknown;// needs 1 arguments + deleteLocalBackup(...args: unknown[]): unknown;// needs 1 arguments - clearCache(...args: any[]): unknown;// needs 0 arguments + clearCache(...args: unknown[]): unknown;// needs 0 arguments - start(...args: any[]): unknown;// needs 1 arguments + start(...args: unknown[]): unknown;// needs 1 arguments - stop(...args: any[]): unknown;// needs 1 arguments + stop(...args: unknown[]): unknown;// needs 1 arguments - pause(...args: any[]): unknown;// needs 2 arguments + pause(...args: unknown[]): unknown;// needs 2 arguments } diff --git a/src/core/services/NodeIKernelMsgService.ts b/src/core/services/NodeIKernelMsgService.ts index 6776998c..0d0c9a44 100644 --- a/src/core/services/NodeIKernelMsgService.ts +++ b/src/core/services/NodeIKernelMsgService.ts @@ -10,7 +10,7 @@ export interface NodeIKernelMsgService { addKernelMsgListener(nodeIKernelMsgListener: NodeIKernelMsgListener): number; - sendMsg(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map): Promise; + sendMsg(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map): Promise; recallMsg(peer: Peer, msgIds: string[]): Promise; @@ -114,9 +114,9 @@ export interface NodeIKernelMsgService { addLocalTofuRecordMsg(...args: unknown[]): unknown; - addLocalRecordMsg(Peer: Peer, msgId: string, ele: MessageElement, attr: Array | number, front: boolean): Promise; + addLocalRecordMsg(Peer: Peer, msgId: string, ele: MessageElement, attr: Array | number, front: boolean): Promise; - deleteMsg(Peer: Peer, msgIds: Array): Promise; + deleteMsg(Peer: Peer, msgIds: Array): Promise; updateElementExtBufForUI(...args: unknown[]): unknown; diff --git a/src/core/services/NodeIKernelOnlineStatusService.ts b/src/core/services/NodeIKernelOnlineStatusService.ts index 4cb372a7..39124b78 100644 --- a/src/core/services/NodeIKernelOnlineStatusService.ts +++ b/src/core/services/NodeIKernelOnlineStatusService.ts @@ -30,7 +30,7 @@ export interface NodeIKernelOnlineStatusService { checkLikeStatus(param: { businessType: number, uins: string[] - }): Promise; + }): Promise; isNull(): boolean; } diff --git a/src/core/services/NodeIKernelProfileService.ts b/src/core/services/NodeIKernelProfileService.ts index e4f6e6a6..3a017050 100644 --- a/src/core/services/NodeIKernelProfileService.ts +++ b/src/core/services/NodeIKernelProfileService.ts @@ -3,11 +3,11 @@ import { BizKey, ModifyProfileParams, NodeIKernelProfileListener, ProfileBizType import { GeneralCallResult } from '@/core/services/common'; export interface NodeIKernelProfileService { - getOtherFlag(callfrom: string, uids: string[]): Promise>; + getOtherFlag(callfrom: string, uids: string[]): Promise>; - getVasInfo(callfrom: string, uids: string[]): Promise>; + getVasInfo(callfrom: string, uids: string[]): Promise>; - getRelationFlag(callfrom: string, uids: string[]): Promise>; + getRelationFlag(callfrom: string, uids: string[]): Promise>; getUidByUin(callfrom: string, uin: Array): Map; @@ -70,7 +70,7 @@ export interface NodeIKernelProfileService { getProfileQzonePicInfo(uid: string, type: number, force: boolean): Promise; // UserRemarkServiceImpl::getStrangerRemarkByUid [] - getCoreInfo(sceneId: string, arg: any[]): unknown; + getCoreInfo(sceneId: string, arg: unknown[]): unknown; isNull(): boolean; } diff --git a/src/core/services/NodeIKernelRecentContactService.ts b/src/core/services/NodeIKernelRecentContactService.ts index 6031e36a..6c793d81 100644 --- a/src/core/services/NodeIKernelRecentContactService.ts +++ b/src/core/services/NodeIKernelRecentContactService.ts @@ -20,10 +20,10 @@ export interface NodeIKernelRecentContactService { errMsg: string, sortedContactList: Array, changedList: Array<{ - remark: any; - peerName: any; - sendMemberName: any; - sendNickName: any; + remark: unknown; + peerName: unknown; + sendMemberName: unknown; + sendNickName: unknown; peerUid: string; peerUin: string, msgTime: string, chatType: ChatType, msgId: string }> } @@ -59,7 +59,7 @@ export interface NodeIKernelRecentContactService { deleteRecentContactsVer2(...args: unknown[]): unknown; // 1 arguments - getRecentContactList(): Promise; + getRecentContactList(): Promise; getMsgUnreadCount(): unknown; diff --git a/src/core/services/NodeIKernelRichMediaService.ts b/src/core/services/NodeIKernelRichMediaService.ts index 9bb00831..83ebeaf8 100644 --- a/src/core/services/NodeIKernelRichMediaService.ts +++ b/src/core/services/NodeIKernelRichMediaService.ts @@ -158,7 +158,7 @@ export interface NodeIKernelRichMediaService { downloadFileForFileInfo(fileInfo: CommonFileInfo[], savePath: string): unknown; createGroupFolder(GroupCode: string, FolderName: string): Promise } + resultWithGroupItem: { result: unknown, groupItem: Array } }>; downloadFile(commonFile: CommonFileInfo, arg2: unknown, arg3: unknown, savePath: string): unknown; @@ -217,9 +217,9 @@ export interface NodeIKernelRichMediaService { deleteGroupFile(GroupCode: string, params: Array, Files: Array): Promise - failFileIdList: Array + result: unknown + successFileIdList: Array + failFileIdList: Array } }>; diff --git a/src/core/services/NodeIKernelRobotService.ts b/src/core/services/NodeIKernelRobotService.ts index f3c88a20..21a41aa9 100644 --- a/src/core/services/NodeIKernelRobotService.ts +++ b/src/core/services/NodeIKernelRobotService.ts @@ -29,7 +29,7 @@ export interface NodeIKernelRobotService { setRobotPickTts(arg1: unknown, arg2: unknown): unknown; - getRobotUinRange(data: any): Promise<{ response: { robotUinRanges: any } }>; + getRobotUinRange(data: unknown): Promise<{ response: { robotUinRanges: Array } }>; isNull(): boolean; } diff --git a/src/core/services/NodeIKernelSearchService.ts b/src/core/services/NodeIKernelSearchService.ts index 5608d1cf..56eeb992 100644 --- a/src/core/services/NodeIKernelSearchService.ts +++ b/src/core/services/NodeIKernelSearchService.ts @@ -18,65 +18,65 @@ export interface NodeIKernelSearchService { searchLocalInfo(keywords: string, type: number/*4*/): unknown; - cancelSearchLocalInfo(...args: any[]): unknown;// needs 3 arguments + cancelSearchLocalInfo(...args: unknown[]): unknown;// needs 3 arguments - searchBuddyChatInfo(...args: any[]): unknown;// needs 2 arguments + searchBuddyChatInfo(...args: unknown[]): unknown;// needs 2 arguments - searchMoreBuddyChatInfo(...args: any[]): unknown;// needs 1 arguments + searchMoreBuddyChatInfo(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchBuddyChatInfo(...args: any[]): unknown;// needs 3 arguments + cancelSearchBuddyChatInfo(...args: unknown[]): unknown;// needs 3 arguments - searchContact(...args: any[]): unknown;// needs 2 arguments + searchContact(...args: unknown[]): unknown;// needs 2 arguments - searchMoreContact(...args: any[]): unknown;// needs 1 arguments + searchMoreContact(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchContact(...args: any[]): unknown;// needs 3 arguments + cancelSearchContact(...args: unknown[]): unknown;// needs 3 arguments - searchGroupChatInfo(...args: any[]): unknown;// needs 3 arguments + searchGroupChatInfo(...args: unknown[]): unknown;// needs 3 arguments - resetSearchGroupChatInfoSortType(...args: any[]): unknown;// needs 3 arguments + resetSearchGroupChatInfoSortType(...args: unknown[]): unknown;// needs 3 arguments - resetSearchGroupChatInfoFilterMembers(...args: any[]): unknown;// needs 3 arguments + resetSearchGroupChatInfoFilterMembers(...args: unknown[]): unknown;// needs 3 arguments - searchMoreGroupChatInfo(...args: any[]): unknown;// needs 1 arguments + searchMoreGroupChatInfo(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchGroupChatInfo(...args: any[]): unknown;// needs 3 arguments + cancelSearchGroupChatInfo(...args: unknown[]): unknown;// needs 3 arguments - searchChatsWithKeywords(...args: any[]): unknown;// needs 3 arguments + searchChatsWithKeywords(...args: unknown[]): unknown;// needs 3 arguments - searchMoreChatsWithKeywords(...args: any[]): unknown;// needs 1 arguments + searchMoreChatsWithKeywords(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchChatsWithKeywords(...args: any[]): unknown;// needs 3 arguments + cancelSearchChatsWithKeywords(...args: unknown[]): unknown;// needs 3 arguments - searchChatMsgs(...args: any[]): unknown;// needs 2 arguments + searchChatMsgs(...args: unknown[]): unknown;// needs 2 arguments - searchMoreChatMsgs(...args: any[]): unknown;// needs 1 arguments + searchMoreChatMsgs(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchChatMsgs(...args: any[]): unknown;// needs 3 arguments + cancelSearchChatMsgs(...args: unknown[]): unknown;// needs 3 arguments - searchMsgWithKeywords(...args: any[]): unknown;// needs 2 arguments + searchMsgWithKeywords(...args: unknown[]): unknown;// needs 2 arguments - searchMoreMsgWithKeywords(...args: any[]): unknown;// needs 1 arguments + searchMoreMsgWithKeywords(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchMsgWithKeywords(...args: any[]): unknown;// needs 3 arguments + cancelSearchMsgWithKeywords(...args: unknown[]): unknown;// needs 3 arguments searchFileWithKeywords(keywords: string[], source: number): Promise;// needs 2 arguments - searchMoreFileWithKeywords(...args: any[]): unknown;// needs 1 arguments + searchMoreFileWithKeywords(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchFileWithKeywords(...args: any[]): unknown;// needs 3 arguments + cancelSearchFileWithKeywords(...args: unknown[]): unknown;// needs 3 arguments - searchAtMeChats(...args: any[]): unknown;// needs 3 arguments + searchAtMeChats(...args: unknown[]): unknown;// needs 3 arguments - searchMoreAtMeChats(...args: any[]): unknown;// needs 1 arguments + searchMoreAtMeChats(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchAtMeChats(...args: any[]): unknown;// needs 3 arguments + cancelSearchAtMeChats(...args: unknown[]): unknown;// needs 3 arguments - searchChatAtMeMsgs(...args: any[]): unknown;// needs 1 arguments + searchChatAtMeMsgs(...args: unknown[]): unknown;// needs 1 arguments - searchMoreChatAtMeMsgs(...args: any[]): unknown;// needs 1 arguments + searchMoreChatAtMeMsgs(...args: unknown[]): unknown;// needs 1 arguments - cancelSearchChatAtMeMsgs(...args: any[]): unknown;// needs 3 arguments + cancelSearchChatAtMeMsgs(...args: unknown[]): unknown;// needs 3 arguments addSearchHistory(param: { type: number,//4 @@ -127,10 +127,10 @@ export interface NodeIKernelSearchService { id?: number }>; - removeSearchHistory(...args: any[]): unknown;// needs 1 arguments + removeSearchHistory(...args: unknown[]): unknown;// needs 1 arguments - searchCache(...args: any[]): unknown;// needs 3 arguments + searchCache(...args: unknown[]): unknown;// needs 3 arguments - clearSearchCache(...args: any[]): unknown;// needs 1 arguments + clearSearchCache(...args: unknown[]): unknown;// needs 1 arguments } diff --git a/src/core/services/NodeIKernelTianShuService.ts b/src/core/services/NodeIKernelTianShuService.ts index 3cb883b3..05548a2f 100644 --- a/src/core/services/NodeIKernelTianShuService.ts +++ b/src/core/services/NodeIKernelTianShuService.ts @@ -3,6 +3,6 @@ export interface NodeIKernelTianShuService { removeKernelTianShuListener(listenerId:number): void; - reportTianShuNumeralRed(...args: any[]): unknown;// needs 1 arguments + reportTianShuNumeralRed(...args: unknown[]): unknown;// needs 1 arguments } diff --git a/src/core/services/NodeIKernelUnitedConfigService.ts b/src/core/services/NodeIKernelUnitedConfigService.ts index d3481cfc..7604891d 100644 --- a/src/core/services/NodeIKernelUnitedConfigService.ts +++ b/src/core/services/NodeIKernelUnitedConfigService.ts @@ -4,11 +4,11 @@ export interface NodeIKernelUnitedConfigService { removeKernelUnitedConfigListener(listenerId:number): void; - fetchUnitedSwitchConfig(...args: any[]): unknown;// needs 1 arguments + fetchUnitedSwitchConfig(...args: unknown[]): unknown;// needs 1 arguments - isUnitedConfigSwitchOn(...args: any[]): unknown;// needs 1 arguments + isUnitedConfigSwitchOn(...args: unknown[]): unknown;// needs 1 arguments - registerUnitedConfigPushGroupList(...args: any[]): unknown;// needs 1 arguments + registerUnitedConfigPushGroupList(...args: unknown[]): unknown;// needs 1 arguments fetchUnitedCommendConfig(ids: `${string}`[]): void diff --git a/src/core/types/element.ts b/src/core/types/element.ts index e2210d28..15fa13b8 100644 --- a/src/core/types/element.ts +++ b/src/core/types/element.ts @@ -94,7 +94,7 @@ export interface VideoElement { thumbHeight?: number; busiType?: 0; // subBusiType?: 0; // 未知 - thumbPath?: Map; + thumbPath?: Map; transferStatus?: 0; // 未知 progress?: 0; // 下载进度? invalidState?: 0; // 未知 diff --git a/src/core/types/file.ts b/src/core/types/file.ts new file mode 100644 index 00000000..02d21ff6 --- /dev/null +++ b/src/core/types/file.ts @@ -0,0 +1,5 @@ +export interface rkeyDataType { + private_rkey: string; + group_rkey: string; + online_rkey: boolean; +}; \ No newline at end of file diff --git a/src/core/types/group.ts b/src/core/types/group.ts index 862cb3a3..c8ec6f9a 100644 --- a/src/core/types/group.ts +++ b/src/core/types/group.ts @@ -33,7 +33,7 @@ export interface GroupDetailInfo { groupQuestion: string; certType: number; richFingerMemo: string; - tagRecord: any[]; + tagRecord: unknown[]; shutUpAllTimestamp: number; shutUpMeTimestamp: number; groupTypeFlag: number; @@ -73,7 +73,7 @@ export interface GroupDetailInfo { cmdUinFlagExt3Grocery: number; groupCardPrefix: { introduction: string; - rptPrefix: any[]; + rptPrefix: unknown[]; }; groupExt: { groupInfoExtSeq: number; @@ -102,13 +102,13 @@ export interface GroupDetailInfo { showPlayTogetherSwitch: number; groupFlagPro1: string; groupBindGuildIds: { - guildIds: any[]; + guildIds: unknown[]; }; viewedMsgDisappearTime: string; groupExtFlameData: { switchState: number; state: number; - dayNums: any[]; + dayNums: unknown[]; version: number; updateTime: string; isDisplayDayNum: boolean; @@ -116,7 +116,7 @@ export interface GroupDetailInfo { groupBindGuildSwitch: number; groupAioBindGuildId: string; groupExcludeGuildIds: { - guildIds: any[]; + guildIds: unknown[]; }; fullGroupExpansionSwitch: number; fullGroupExpansionSeq: string; @@ -157,10 +157,10 @@ export interface GroupDetailInfo { headPortraitSeq: number; groupHeadPortrait: { portraitCnt: number; - portraitInfo: any[]; + portraitInfo: unknown[]; defaultId: number; verifyingPortraitCnt: number; - verifyingPortraitInfo: any[]; + verifyingPortraitInfo: unknown[]; }; cmdUinJoinMsgSeq: number; cmdUinJoinRealMsgSeq: number; diff --git a/src/core/types/user.ts b/src/core/types/user.ts index 1757c308..f6393ccd 100644 --- a/src/core/types/user.ts +++ b/src/core/types/user.ts @@ -77,7 +77,7 @@ interface VideoInfo { // 扩展在线业务信息 interface ExtOnlineBusinessInfo { buf: string; - customStatus: any; + customStatus: unknown; videoBizInfo: VideoBizInfo; videoInfo: VideoInfo; } @@ -97,7 +97,7 @@ interface UserStatus { termType: number; netType: number; iconType: number; - customStatus: any; + customStatus: unknown; setTime: string; specialFlag: number; abiFlag: number; @@ -112,8 +112,8 @@ interface UserStatus { // 特权图标 interface PrivilegeIcon { jumpUrl: string; - openIconList: any[]; - closeIconList: any[]; + openIconList: unknown[]; + closeIconList: unknown[]; } // 增值服务信息 @@ -137,7 +137,7 @@ interface VasInfo { fontEffect: number; newLoverDiamondFlag: number; extendNameplateId: number; - diyNameplateIDs: any[]; + diyNameplateIDs: unknown[]; vipStartFlag: number; vipDataFlag: number; gameNameplateId: string; @@ -183,7 +183,7 @@ interface CommonExt { address: string; regTime: number; interest: string; - labels: any[]; + labels: string[]; qqLevel: QQLevel; } @@ -214,8 +214,8 @@ export interface SimpleInfo { status: UserStatus | null; vasInfo: VasInfo | null; relationFlags: RelationFlags | null; - otherFlags: any; - intimate: any; + otherFlags: unknown; + intimate: unknown; } // 好友类型 @@ -229,7 +229,7 @@ export interface SelfStatusInfo { termType: number; netType: number; iconType: number; - customStatus: any; + customStatus: unknown; setTime: string; } @@ -248,7 +248,7 @@ export interface ModifyProfileParams { longNick: string; sex: NTSex; birthday: { birthday_year: string, birthday_month: string, birthday_day: string }; - location: any; + location: unknown; } // 好友资料点赞请求 diff --git a/src/core/types/webapi.ts b/src/core/types/webapi.ts index 7632b149..c689d860 100644 --- a/src/core/types/webapi.ts +++ b/src/core/types/webapi.ts @@ -46,7 +46,7 @@ export interface WebApiGroupMemberRet { em: string; cache: number; adm_num: number; - levelname: any; + levelname: string; mems: WebApiGroupMember[]; count: number; svr_time: number; @@ -99,7 +99,7 @@ export interface WebApiGroupNoticeRet { sta: number, gln: number tst: number, - ui: any + ui: unknown server_time: number svrt: number ad: number @@ -115,7 +115,7 @@ export interface GroupEssenceMsg { add_digest_uin: string; add_digest_nick: string; add_digest_time: number; - msg_content: any[]; + msg_content: unknown[]; can_be_removed: true; } diff --git a/src/core/wrapper.ts b/src/core/wrapper.ts index 9d569ccf..33c92d69 100644 --- a/src/core/wrapper.ts +++ b/src/core/wrapper.ts @@ -71,7 +71,7 @@ export interface NodeQQNTWrapperUtil { getPinyin(arg0: string, arg1: boolean): unknown; - matchInPinyin(arg0: any[], arg1: string): unknown; //参数特复杂 arg0是个复杂数据类型 + matchInPinyin(arg0: unknown[], arg1: string): unknown; //参数特复杂 arg0是个复杂数据类型 makeDirByPath(arg0: string): unknown; @@ -91,7 +91,7 @@ export interface NodeQQNTWrapperUtil { resetUserDataSavePathToDocument(): unknown; - getSoBuildInfo(): any; //例如 0[0]_d491dc01e0a_0 + getSoBuildInfo(): unknown; //例如 0[0]_d491dc01e0a_0 registerCountInstruments(arg0: string, arg1: string[], arg2: number, arg3: number): unknown; @@ -123,9 +123,9 @@ export interface NodeQQNTWrapperUtil { checkNewUserDataSaveDirAvailable(arg0: string): unknown; - copyUserData(arg0: string, arg1: string): Promise; + copyUserData(arg0: string, arg1: string): Promise; - setUserDataSaveDirectory(arg0: string): Promise; + setUserDataSaveDirectory(arg0: string): Promise; hasOtherRunningQQProcess(): boolean; diff --git a/src/framework/liteloader.cjs b/src/framework/liteloader.cjs index beaf7b3f..8b693797 100644 --- a/src/framework/liteloader.cjs +++ b/src/framework/liteloader.cjs @@ -2,7 +2,7 @@ const { ipcMain, BrowserWindow } = require('electron'); const napcat = require('./napcat.cjs'); const { shell } = require('electron'); -ipcMain.handle('napcat_get_webui', async (event, arg) => { +ipcMain.handle('napcat_get_webui', async () => { return napcat.NCgetWebUiUrl(); }); ipcMain.on('open_external_url', (event, url) => { diff --git a/src/framework/napcat.ts b/src/framework/napcat.ts index 84c4c448..b1451dc2 100644 --- a/src/framework/napcat.ts +++ b/src/framework/napcat.ts @@ -28,7 +28,7 @@ export async function NCoreInitFramework( console.log('[NapCat] [Error] Unhandled Exception:', err.message); }); - process.on('unhandledRejection', (reason, promise) => { + process.on('unhandledRejection', (reason) => { console.log('[NapCat] [Error] unhandledRejection:', reason); }); diff --git a/src/onebot/action/OneBotAction.ts b/src/onebot/action/OneBotAction.ts index 108c7587..e4ec6ebf 100644 --- a/src/onebot/action/OneBotAction.ts +++ b/src/onebot/action/OneBotAction.ts @@ -5,7 +5,7 @@ import { NapCatOneBot11Adapter, OB11Return } from '@/onebot'; import { NetworkAdapterConfig } from '../config/config'; export class OB11Response { - private static createResponse(data: T, status: string, retcode: number, message: string = '', echo: any = null): OB11Return { + private static createResponse(data: T, status: string, retcode: number, message: string = '', echo: unknown = null): OB11Return { return { status, retcode, @@ -20,11 +20,11 @@ export class OB11Response { return this.createResponse(data, status, retcode, message); } - static ok(data: T, echo: any = null): OB11Return { + static ok(data: T, echo: unknown = null): OB11Return { return this.createResponse(data, 'ok', 0, '', echo); } - static error(err: string, retcode: number, echo: any = null): OB11Return { + static error(err: string, retcode: number, echo: unknown = null): OB11Return { return this.createResponse(null, 'failed', retcode, err, echo); } } @@ -32,8 +32,8 @@ export class OB11Response { export abstract class OneBotAction { actionName: typeof ActionName[keyof typeof ActionName] = ActionName.Unknown; core: NapCatCore; - private validate: ValidateFunction | undefined = undefined; - payloadSchema: any = undefined; + private validate?: ValidateFunction = undefined; + payloadSchema?: unknown = undefined; obContext: NapCatOneBot11Adapter; constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { @@ -64,13 +64,13 @@ export abstract class OneBotAction { try { const resData = await this._handle(payload, adaptername, config); return OB11Response.ok(resData); - } catch (e: any) { + } catch (e: unknown) { this.core.context.logger.logError('发生错误', e); - return OB11Response.error((e as Error).message.toString() || e?.stack?.toString() || '未知错误,可能操作超时', 200); + return OB11Response.error((e as Error).message.toString() || (e as Error)?.stack?.toString() || '未知错误,可能操作超时', 200); } } - public async websocketHandle(payload: PayloadType, echo: any, adaptername: string, config: NetworkAdapterConfig): Promise> { + public async websocketHandle(payload: PayloadType, echo: unknown, adaptername: string, config: NetworkAdapterConfig): Promise> { const result = await this.check(payload); if (!result.valid) { return OB11Response.error(result.message, 1400, echo); @@ -78,9 +78,9 @@ export abstract class OneBotAction { try { const resData = await this._handle(payload, adaptername, config); return OB11Response.ok(resData, echo); - } catch (e: any) { + } catch (e: unknown) { this.core.context.logger.logError('发生错误', e); - return OB11Response.error((e as Error).message.toString() || e.stack?.toString(), 1200, echo); + return OB11Response.error(((e as Error).message.toString() || (e as Error).stack?.toString()) ?? 'Error', 1200, echo); } } diff --git a/src/onebot/action/extends/CreateCollection.ts b/src/onebot/action/extends/CreateCollection.ts index 2d902ad0..3f9c841f 100644 --- a/src/onebot/action/extends/CreateCollection.ts +++ b/src/onebot/action/extends/CreateCollection.ts @@ -9,9 +9,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class CreateCollection extends OneBotAction { - actionName = ActionName.CreateCollection; - payloadSchema = SchemaData; +export class CreateCollection extends OneBotAction { + override actionName = ActionName.CreateCollection; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return await this.core.apis.CollectionApi.createCollection( diff --git a/src/onebot/action/extends/FetchCustomFace.ts b/src/onebot/action/extends/FetchCustomFace.ts index 9a0cfdc8..f2850097 100644 --- a/src/onebot/action/extends/FetchCustomFace.ts +++ b/src/onebot/action/extends/FetchCustomFace.ts @@ -9,8 +9,8 @@ const SchemaData = Type.Object({ type Payload = Static; export class FetchCustomFace extends OneBotAction { - actionName = ActionName.FetchCustomFace; - payloadSchema = SchemaData; + override actionName = ActionName.FetchCustomFace; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+payload.count); diff --git a/src/onebot/action/extends/FetchEmojiLike.ts b/src/onebot/action/extends/FetchEmojiLike.ts index 59094576..39bab1a7 100644 --- a/src/onebot/action/extends/FetchEmojiLike.ts +++ b/src/onebot/action/extends/FetchEmojiLike.ts @@ -2,6 +2,7 @@ import { Type, Static } from '@sinclair/typebox'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { MessageUnique } from '@/common/message-unique'; +import { type NTQQMsgApi } from '@/core/apis'; const SchemaData = Type.Object({ message_id: Type.Union([Type.Number(), Type.String()]), @@ -12,14 +13,15 @@ const SchemaData = Type.Object({ type Payload = Static; -export class FetchEmojiLike extends OneBotAction { - actionName = ActionName.FetchEmojiLike; - payloadSchema = SchemaData; +export class FetchEmojiLike extends OneBotAction>> { + override actionName = ActionName.FetchEmojiLike; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id); if (!msgIdPeer) throw new Error('消息不存在'); const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0]; + if (!msg) throw new Error('消息不存在'); return await this.core.apis.MsgApi.getMsgEmojiLikesList( msgIdPeer.Peer, msg.msgSeq, payload.emojiId.toString(), payload.emojiType.toString(), +payload.count ); diff --git a/src/onebot/action/extends/GetAiCharacters.ts b/src/onebot/action/extends/GetAiCharacters.ts index 00ef15c9..4ddc26e4 100644 --- a/src/onebot/action/extends/GetAiCharacters.ts +++ b/src/onebot/action/extends/GetAiCharacters.ts @@ -20,8 +20,8 @@ interface GetAiCharactersResponse { } export class GetAiCharacters extends GetPacketStatusDepends { - actionName = ActionName.GetAiCharacters; - payloadSchema = SchemaData; + override actionName = ActionName.GetAiCharacters; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const rawList = await this.core.apis.PacketApi.pkt.operation.FetchAiVoiceList(+payload.group_id, +payload.chat_type as AIVoiceChatType); diff --git a/src/onebot/action/extends/GetClientkey.ts b/src/onebot/action/extends/GetClientkey.ts index b63cf9ed..dfd774da 100644 --- a/src/onebot/action/extends/GetClientkey.ts +++ b/src/onebot/action/extends/GetClientkey.ts @@ -6,7 +6,7 @@ interface GetClientkeyResponse { } export class GetClientkey extends OneBotAction { - actionName = ActionName.GetClientkey; + override actionName = ActionName.GetClientkey; async _handle() { return { clientkey: (await this.core.apis.UserApi.forceFetchClientKey()).clientKey }; diff --git a/src/onebot/action/extends/GetCollectionList.ts b/src/onebot/action/extends/GetCollectionList.ts index a80484dd..2de4305f 100644 --- a/src/onebot/action/extends/GetCollectionList.ts +++ b/src/onebot/action/extends/GetCollectionList.ts @@ -1,3 +1,4 @@ +import { type NTQQCollectionApi } from '@/core/apis/collection'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { Type, Static } from '@sinclair/typebox'; @@ -9,9 +10,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GetCollectionList extends OneBotAction { - actionName = ActionName.GetCollectionList; - payloadSchema = SchemaData; +export class GetCollectionList extends OneBotAction>> { + override actionName = ActionName.GetCollectionList; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return await this.core.apis.CollectionApi.getAllCollection(+payload.category, +payload.count); diff --git a/src/onebot/action/extends/GetFriendWithCategory.ts b/src/onebot/action/extends/GetFriendWithCategory.ts index 5fb0560d..4251b475 100644 --- a/src/onebot/action/extends/GetFriendWithCategory.ts +++ b/src/onebot/action/extends/GetFriendWithCategory.ts @@ -2,10 +2,10 @@ import { OB11Construct } from '@/onebot/helper/data'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -export class GetFriendWithCategory extends OneBotAction { - actionName = ActionName.GetFriendsWithCategory; +export class GetFriendWithCategory extends OneBotAction { + override actionName = ActionName.GetFriendsWithCategory; - async _handle(payload: void) { + async _handle() { return (await this.core.apis.FriendApi.getBuddyV2ExWithCate()).map(category => ({ ...category, buddyList: OB11Construct.friends(category.buddyList), diff --git a/src/onebot/action/extends/GetGroupAddRequest.ts b/src/onebot/action/extends/GetGroupAddRequest.ts index 1469292a..164bc1fd 100644 --- a/src/onebot/action/extends/GetGroupAddRequest.ts +++ b/src/onebot/action/extends/GetGroupAddRequest.ts @@ -4,9 +4,9 @@ import { ActionName } from '@/onebot/action/router'; import { Notify } from '@/onebot/types'; export default class GetGroupAddRequest extends OneBotAction { - actionName = ActionName.GetGroupIgnoreAddRequest; + override actionName = ActionName.GetGroupIgnoreAddRequest; - async _handle(payload: null): Promise { + async _handle(): Promise { const NTQQUserApi = this.core.apis.UserApi; const NTQQGroupApi = this.core.apis.GroupApi; const ignoredNotifies = await NTQQGroupApi.getSingleScreenNotifies(true, 10); diff --git a/src/onebot/action/extends/GetGroupInfoEx.ts b/src/onebot/action/extends/GetGroupInfoEx.ts index 54b2a65f..c566a105 100644 --- a/src/onebot/action/extends/GetGroupInfoEx.ts +++ b/src/onebot/action/extends/GetGroupInfoEx.ts @@ -7,9 +7,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GetGroupInfoEx extends OneBotAction { - actionName = ActionName.GetGroupInfoEx; - payloadSchema = SchemaData; +export class GetGroupInfoEx extends OneBotAction { + override actionName = ActionName.GetGroupInfoEx; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return (await this.core.apis.GroupApi.getGroupExtFE0Info([payload.group_id.toString()])).result.groupExtInfos.get(payload.group_id.toString()); diff --git a/src/onebot/action/extends/GetMiniAppArk.ts b/src/onebot/action/extends/GetMiniAppArk.ts index 93bd28e4..6ab90445 100644 --- a/src/onebot/action/extends/GetMiniAppArk.ts +++ b/src/onebot/action/extends/GetMiniAppArk.ts @@ -38,8 +38,8 @@ type Payload = Static; export class GetMiniAppArk extends GetPacketStatusDepends { - actionName = ActionName.GetMiniAppArk; - payloadSchema = SchemaData; + override actionName = ActionName.GetMiniAppArk; + override payloadSchema = SchemaData; async _handle(payload: Payload) { let reqParam: MiniAppReqParams; diff --git a/src/onebot/action/extends/GetProfileLike.ts b/src/onebot/action/extends/GetProfileLike.ts index db7b207a..bd6f39c7 100644 --- a/src/onebot/action/extends/GetProfileLike.ts +++ b/src/onebot/action/extends/GetProfileLike.ts @@ -1,3 +1,4 @@ +import { NTVoteInfo } from '@/core'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { Type, Static } from '@sinclair/typebox'; @@ -10,9 +11,25 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GetProfileLike extends OneBotAction { - actionName = ActionName.GetProfileLike; - payloadSchema = SchemaData; +export class GetProfileLike extends OneBotAction; + total_count: number; + last_time: number; + today_count: number; + }; + voteInfo: { + total_count: number; + new_count: number; + new_nearby_count: number; + last_visit_time: number; + userInfos: Array; + }; +}> { + override actionName = ActionName.GetProfileLike; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const isSelf = this.core.selfInfo.uin === payload.user_id || !payload.user_id; const userUid = isSelf || !payload.user_id ? this.core.selfInfo.uid : await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString()); diff --git a/src/onebot/action/extends/GetRkey.ts b/src/onebot/action/extends/GetRkey.ts index 33cf5a21..9b5d08bf 100644 --- a/src/onebot/action/extends/GetRkey.ts +++ b/src/onebot/action/extends/GetRkey.ts @@ -1,8 +1,8 @@ import { ActionName } from '@/onebot/action/router'; import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; -export class GetRkey extends GetPacketStatusDepends> { - actionName = ActionName.GetRkey; +export class GetRkey extends GetPacketStatusDepends> { + override actionName = ActionName.GetRkey; async _handle() { return await this.core.apis.PacketApi.pkt.operation.FetchRkey(); diff --git a/src/onebot/action/extends/GetRobotUinRange.ts b/src/onebot/action/extends/GetRobotUinRange.ts index 734cc456..e3c9c8a4 100644 --- a/src/onebot/action/extends/GetRobotUinRange.ts +++ b/src/onebot/action/extends/GetRobotUinRange.ts @@ -1,8 +1,8 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -export class GetRobotUinRange extends OneBotAction> { - actionName = ActionName.GetRobotUinRange; +export class GetRobotUinRange extends OneBotAction> { + override actionName = ActionName.GetRobotUinRange; async _handle() { return await this.core.apis.UserApi.getRobotUinRange(); diff --git a/src/onebot/action/extends/GetUserStatus.ts b/src/onebot/action/extends/GetUserStatus.ts index 12719cb6..3987c81a 100644 --- a/src/onebot/action/extends/GetUserStatus.ts +++ b/src/onebot/action/extends/GetUserStatus.ts @@ -9,8 +9,8 @@ const SchemaData = Type.Object({ type Payload = Static; export class GetUserStatus extends GetPacketStatusDepends { - actionName = ActionName.GetUserStatus; - payloadSchema = SchemaData; + override actionName = ActionName.GetUserStatus; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return await this.core.apis.PacketApi.pkt.operation.GetStrangerStatus(+payload.user_id); diff --git a/src/onebot/action/extends/OCRImage.ts b/src/onebot/action/extends/OCRImage.ts index 35c1a6a6..3b45c64e 100644 --- a/src/onebot/action/extends/OCRImage.ts +++ b/src/onebot/action/extends/OCRImage.ts @@ -3,6 +3,7 @@ import { ActionName } from '@/onebot/action/router'; import { checkFileExist, uriToLocalFile } from '@/common/file'; import fs from 'fs'; import { Static, Type } from '@sinclair/typebox'; +import { GeneralCallResultStatus } from '@/core'; const SchemaData = Type.Object({ image: Type.String(), @@ -10,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; -class OCRImageBase extends OneBotAction { - payloadSchema = SchemaData; +class OCRImageBase extends OneBotAction { + override payloadSchema = SchemaData; async _handle(payload: Payload) { const { path, success } = await uriToLocalFile(this.core.NapCatTempPath, payload.image); @@ -35,9 +36,9 @@ class OCRImageBase extends OneBotAction { } export class OCRImage extends OCRImageBase { - actionName = ActionName.OCRImage; + override actionName = ActionName.OCRImage; } export class IOCRImage extends OCRImageBase { - actionName = ActionName.IOCRImage; + override actionName = ActionName.IOCRImage; } \ No newline at end of file diff --git a/src/onebot/action/extends/SendPacket.ts b/src/onebot/action/extends/SendPacket.ts index cf077e2e..479b10f7 100644 --- a/src/onebot/action/extends/SendPacket.ts +++ b/src/onebot/action/extends/SendPacket.ts @@ -1,3 +1,4 @@ +import { PacketHexStr } from '@/core/packet/transformer/base'; import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; import { ActionName } from '@/onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; @@ -10,12 +11,12 @@ const SchemaData = Type.Object({ type Payload = Static; -export class SendPacket extends GetPacketStatusDepends { - payloadSchema = SchemaData; - actionName = ActionName.SendPacket; +export class SendPacket extends GetPacketStatusDepends { + override payloadSchema = SchemaData; + override actionName = ActionName.SendPacket; async _handle(payload: Payload) { const rsp = typeof payload.rsp === 'boolean' ? payload.rsp : payload.rsp === 'true'; - const data = await this.core.apis.PacketApi.pkt.operation.sendPacket({ cmd: payload.cmd, data: payload.data as any }, rsp); + const data = await this.core.apis.PacketApi.pkt.operation.sendPacket({ cmd: payload.cmd, data: payload.data as PacketHexStr }, rsp); return typeof data === 'object' ? data.toString('hex') : undefined; } } diff --git a/src/onebot/action/extends/SetGroupSign.ts b/src/onebot/action/extends/SetGroupSign.ts index 86c6f792..716aca22 100644 --- a/src/onebot/action/extends/SetGroupSign.ts +++ b/src/onebot/action/extends/SetGroupSign.ts @@ -8,8 +8,8 @@ const SchemaData = Type.Object({ type Payload = Static; -class SetGroupSignBase extends GetPacketStatusDepends { - payloadSchema = SchemaData; +class SetGroupSignBase extends GetPacketStatusDepends { + override payloadSchema = SchemaData; async _handle(payload: Payload) { return await this.core.apis.PacketApi.pkt.operation.GroupSign(+payload.group_id); @@ -17,9 +17,9 @@ class SetGroupSignBase extends GetPacketStatusDepends { } export class SetGroupSign extends SetGroupSignBase { - actionName = ActionName.SetGroupSign; + override actionName = ActionName.SetGroupSign; } export class SendGroupSign extends SetGroupSignBase { - actionName = ActionName.SendGroupSign; + override actionName = ActionName.SendGroupSign; } diff --git a/src/onebot/action/extends/SetInputStatus.ts b/src/onebot/action/extends/SetInputStatus.ts index 174b6cb6..448c00ff 100644 --- a/src/onebot/action/extends/SetInputStatus.ts +++ b/src/onebot/action/extends/SetInputStatus.ts @@ -10,9 +10,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class SetInputStatus extends OneBotAction { - actionName = ActionName.SetInputStatus; - +export class SetInputStatus extends OneBotAction { + override actionName = ActionName.SetInputStatus; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString()); if (!uid) throw new Error('uid is empty'); diff --git a/src/onebot/action/extends/SetLongNick.ts b/src/onebot/action/extends/SetLongNick.ts index e57df3a3..5169bada 100644 --- a/src/onebot/action/extends/SetLongNick.ts +++ b/src/onebot/action/extends/SetLongNick.ts @@ -8,9 +8,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class SetLongNick extends OneBotAction { - actionName = ActionName.SetLongNick; - payloadSchema = SchemaData; +export class SetLongNick extends OneBotAction { + override actionName = ActionName.SetLongNick; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return await this.core.apis.UserApi.setLongNick(payload.longNick); diff --git a/src/onebot/action/extends/SetOnlineStatus.ts b/src/onebot/action/extends/SetOnlineStatus.ts index 8ce7a80d..6e1782e9 100644 --- a/src/onebot/action/extends/SetOnlineStatus.ts +++ b/src/onebot/action/extends/SetOnlineStatus.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export class SetOnlineStatus extends OneBotAction { - actionName = ActionName.SetOnlineStatus; - payloadSchema = SchemaData; + override actionName = ActionName.SetOnlineStatus; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const ret = await this.core.apis.UserApi.setSelfOnlineStatus( diff --git a/src/onebot/action/extends/SetQQAvatar.ts b/src/onebot/action/extends/SetQQAvatar.ts index d5b656a1..c4e019aa 100644 --- a/src/onebot/action/extends/SetQQAvatar.ts +++ b/src/onebot/action/extends/SetQQAvatar.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetAvatar extends OneBotAction { - actionName = ActionName.SetQQAvatar; - payloadSchema = SchemaData; + override actionName = ActionName.SetQQAvatar; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.file)); if (!success) { diff --git a/src/onebot/action/extends/SetSpecialTittle.ts b/src/onebot/action/extends/SetSpecialTittle.ts index cb17e777..c512c9bf 100644 --- a/src/onebot/action/extends/SetSpecialTittle.ts +++ b/src/onebot/action/extends/SetSpecialTittle.ts @@ -10,9 +10,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class SetSpecialTittle extends GetPacketStatusDepends { - actionName = ActionName.SetSpecialTittle; - payloadSchema = SchemaData; +export class SetSpecialTittle extends GetPacketStatusDepends { + override actionName = ActionName.SetSpecialTittle; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString()); diff --git a/src/onebot/action/extends/ShareContact.ts b/src/onebot/action/extends/ShareContact.ts index 595d1a3e..22c8654b 100644 --- a/src/onebot/action/extends/ShareContact.ts +++ b/src/onebot/action/extends/ShareContact.ts @@ -1,3 +1,4 @@ +import { GeneralCallResult } from '@/core'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; @@ -10,9 +11,12 @@ const SchemaData = Type.Object({ type Payload = Static; -export class SharePeer extends OneBotAction { - actionName = ActionName.SharePeer; - payloadSchema = SchemaData; +export class SharePeer extends OneBotAction { + override actionName = ActionName.SharePeer; + override payloadSchema = SchemaData; async _handle(payload: Payload) { if (payload.group_id) { @@ -20,6 +24,7 @@ export class SharePeer extends OneBotAction { } else if (payload.user_id) { return await this.core.apis.UserApi.getBuddyRecommendContactArkJson(payload.user_id.toString(), payload.phoneNumber); } + throw new Error('group_id or user_id is required'); } } @@ -29,9 +34,9 @@ const SchemaDataGroupEx = Type.Object({ type PayloadGroupEx = Static; -export class ShareGroupEx extends OneBotAction { - actionName = ActionName.ShareGroupEx; - payloadSchema = SchemaDataGroupEx; +export class ShareGroupEx extends OneBotAction { + override actionName = ActionName.ShareGroupEx; + override payloadSchema = SchemaDataGroupEx; async _handle(payload: PayloadGroupEx) { return await this.core.apis.GroupApi.getArkJsonGroupShare(payload.group_id.toString()); diff --git a/src/onebot/action/extends/TranslateEnWordToZn.ts b/src/onebot/action/extends/TranslateEnWordToZn.ts index 0f1ade3d..2edb8b83 100644 --- a/src/onebot/action/extends/TranslateEnWordToZn.ts +++ b/src/onebot/action/extends/TranslateEnWordToZn.ts @@ -8,9 +8,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class TranslateEnWordToZn extends OneBotAction | null> { - actionName = ActionName.TranslateEnWordToZn; - payloadSchema = SchemaData; +export class TranslateEnWordToZn extends OneBotAction | null> { + override actionName = ActionName.TranslateEnWordToZn; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const ret = await this.core.apis.SystemApi.translateEnWordToZn(payload.words); diff --git a/src/onebot/action/file/GetFile.ts b/src/onebot/action/file/GetFile.ts index e971f3e0..853261cd 100644 --- a/src/onebot/action/file/GetFile.ts +++ b/src/onebot/action/file/GetFile.ts @@ -22,7 +22,7 @@ const GetFileBase_PayloadSchema = Type.Object({ export type GetFilePayload = Static; export class GetFileBase extends OneBotAction { - payloadSchema = GetFileBase_PayloadSchema; + override payloadSchema = GetFileBase_PayloadSchema; async _handle(payload: GetFilePayload): Promise { payload.file ||= payload.file_id || ''; @@ -113,5 +113,5 @@ export class GetFileBase extends OneBotAction { } export default class GetFile extends GetFileBase { - actionName = ActionName.GetFile; + override actionName = ActionName.GetFile; } diff --git a/src/onebot/action/file/GetGroupFileUrl.ts b/src/onebot/action/file/GetGroupFileUrl.ts index e4e10e90..0ae7d314 100644 --- a/src/onebot/action/file/GetGroupFileUrl.ts +++ b/src/onebot/action/file/GetGroupFileUrl.ts @@ -15,8 +15,8 @@ interface GetGroupFileUrlResponse { } export class GetGroupFileUrl extends GetPacketStatusDepends { - actionName = ActionName.GOCQHTTP_GetGroupFileUrl; - payloadSchema = SchemaData; + override actionName = ActionName.GOCQHTTP_GetGroupFileUrl; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id); diff --git a/src/onebot/action/file/GetImage.ts b/src/onebot/action/file/GetImage.ts index 3c032fbc..e021138c 100644 --- a/src/onebot/action/file/GetImage.ts +++ b/src/onebot/action/file/GetImage.ts @@ -3,5 +3,5 @@ import { ActionName } from '@/onebot/action/router'; export default class GetImage extends GetFileBase { - actionName = ActionName.GetImage; + override actionName = ActionName.GetImage; } \ No newline at end of file diff --git a/src/onebot/action/file/GetRecord.ts b/src/onebot/action/file/GetRecord.ts index d83d4e08..4a740362 100644 --- a/src/onebot/action/file/GetRecord.ts +++ b/src/onebot/action/file/GetRecord.ts @@ -4,16 +4,16 @@ import { promises as fs } from 'fs'; import { decode } from 'silk-wasm'; import { FFmpegService } from '@/common/ffmpeg'; -const out_format = ['mp3' , 'amr' , 'wma' , 'm4a' , 'spx' , 'ogg' , 'wav' , 'flac']; +const out_format = ['mp3', 'amr', 'wma', 'm4a', 'spx', 'ogg', 'wav', 'flac']; type Payload = { - out_format : string + out_format: string } & GetFilePayload export default class GetRecord extends GetFileBase { - actionName = ActionName.GetRecord; + override actionName = ActionName.GetRecord; - async _handle(payload: Payload): Promise { + override async _handle(payload: Payload): Promise { const res = await super._handle(payload); if (payload.out_format && typeof payload.out_format === 'string') { const inputFile = res.file; @@ -27,7 +27,7 @@ export default class GetRecord extends GetFileBase { await fs.access(inputFile); try { await fs.access(outputFile); - } catch (error) { + } catch { await this.decodeFile(inputFile, pcmFile); await FFmpegService.convertFile(pcmFile, outputFile, payload.out_format); } diff --git a/src/onebot/action/go-cqhttp/CreateGroupFileFolder.ts b/src/onebot/action/go-cqhttp/CreateGroupFileFolder.ts index 3764f148..760929ea 100644 --- a/src/onebot/action/go-cqhttp/CreateGroupFileFolder.ts +++ b/src/onebot/action/go-cqhttp/CreateGroupFileFolder.ts @@ -8,10 +8,13 @@ const SchemaData = Type.Object({ }); type Payload = Static; - -export class CreateGroupFileFolder extends OneBotAction { - actionName = ActionName.GoCQHTTP_CreateGroupFileFolder; - payloadSchema = SchemaData; +interface ResponseType{ + result:unknown; + groupItem:unknown; +} +export class CreateGroupFileFolder extends OneBotAction { + override actionName = ActionName.GoCQHTTP_CreateGroupFileFolder; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return (await this.core.apis.GroupApi.creatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem; } diff --git a/src/onebot/action/go-cqhttp/DeleteGroupFile.ts b/src/onebot/action/go-cqhttp/DeleteGroupFile.ts index c0b9a600..7db532a3 100644 --- a/src/onebot/action/go-cqhttp/DeleteGroupFile.ts +++ b/src/onebot/action/go-cqhttp/DeleteGroupFile.ts @@ -3,6 +3,7 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { FileNapCatOneBotUUID } from '@/common/file-uuid'; import { Static, Type } from '@sinclair/typebox'; +import { NTQQGroupApi } from '@/core/apis'; const SchemaData = Type.Object({ group_id: Type.Union([Type.Number(), Type.String()]), @@ -11,9 +12,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class DeleteGroupFile extends OneBotAction { - actionName = ActionName.GOCQHTTP_DeleteGroupFile; - payloadSchema = SchemaData; +export class DeleteGroupFile extends OneBotAction>> { + override actionName = ActionName.GOCQHTTP_DeleteGroupFile; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const data = FileNapCatOneBotUUID.decodeModelId(payload.file_id); if (!data || !data.fileId) throw new Error('Invalid file_id'); diff --git a/src/onebot/action/go-cqhttp/DeleteGroupFileFolder.ts b/src/onebot/action/go-cqhttp/DeleteGroupFileFolder.ts index f8a813a4..818c10a0 100644 --- a/src/onebot/action/go-cqhttp/DeleteGroupFileFolder.ts +++ b/src/onebot/action/go-cqhttp/DeleteGroupFileFolder.ts @@ -1,6 +1,7 @@ import { ActionName } from '@/onebot/action/router'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { Static, Type } from '@sinclair/typebox'; +import { NTQQGroupApi } from '@/core/apis'; const SchemaData = Type.Object({ group_id: Type.Union([Type.Number(), Type.String()]), @@ -10,9 +11,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class DeleteGroupFileFolder extends OneBotAction { - actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder; - payloadSchema = SchemaData; +export class DeleteGroupFileFolder extends OneBotAction>['groupFileCommonResult']> { + override actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return (await this.core.apis.GroupApi.delGroupFileFolder( payload.group_id.toString(), payload.folder ?? payload.folder_id ?? '')).groupFileCommonResult; diff --git a/src/onebot/action/go-cqhttp/DownloadFile.ts b/src/onebot/action/go-cqhttp/DownloadFile.ts index 4988efe2..32fabfb5 100644 --- a/src/onebot/action/go-cqhttp/DownloadFile.ts +++ b/src/onebot/action/go-cqhttp/DownloadFile.ts @@ -20,8 +20,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class GoCQHTTPDownloadFile extends OneBotAction { - actionName = ActionName.GoCQHTTP_DownloadFile; - payloadSchema = SchemaData; + override actionName = ActionName.GoCQHTTP_DownloadFile; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const isRandomName = !payload.name; diff --git a/src/onebot/action/go-cqhttp/GetForwardMsg.ts b/src/onebot/action/go-cqhttp/GetForwardMsg.ts index 41fb7fa1..f1bb51cb 100644 --- a/src/onebot/action/go-cqhttp/GetForwardMsg.ts +++ b/src/onebot/action/go-cqhttp/GetForwardMsg.ts @@ -11,9 +11,11 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GoCQHTTPGetForwardMsgAction extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetForwardMsg; - payloadSchema = SchemaData; +export class GoCQHTTPGetForwardMsgAction extends OneBotAction { + override actionName = ActionName.GoCQHTTP_GetForwardMsg; + override payloadSchema = SchemaData; private createTemplateNode(message: OB11Message): OB11MessageNode { return { @@ -49,7 +51,7 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction { return retMsg; } - async _handle(payload: Payload): Promise { + async _handle(payload: Payload) { const msgId = payload.message_id || payload.id; if (!msgId) { throw new Error('message_id is required'); @@ -67,6 +69,9 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction { } const singleMsg = data.msgList[0]; + if (!singleMsg) { + throw new Error('找不到相关的聊天记录'); + } const resMsg = (await this.obContext.apis.MsgApi.parseMessageV2(singleMsg))?.arrayMsg;//强制array 以便处理 if (!(resMsg?.message?.[0] as OB11MessageForward)?.data?.content) { throw new Error('找不到相关的聊天记录'); diff --git a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts index 75c98c2a..ef3db8d0 100644 --- a/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetFriendMsgHistory.ts @@ -21,10 +21,10 @@ const SchemaData = Type.Object({ type Payload = Static; export default class GetFriendMsgHistory extends OneBotAction { - actionName = ActionName.GetFriendMsgHistory; - payloadSchema = SchemaData; + override actionName = ActionName.GetFriendMsgHistory; + override payloadSchema = SchemaData; - async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig): Promise { + async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig): Promise { //处理参数 const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString()); diff --git a/src/onebot/action/go-cqhttp/GetGroupAtAllRemain.ts b/src/onebot/action/go-cqhttp/GetGroupAtAllRemain.ts index 64c4c10c..5d4939d2 100644 --- a/src/onebot/action/go-cqhttp/GetGroupAtAllRemain.ts +++ b/src/onebot/action/go-cqhttp/GetGroupAtAllRemain.ts @@ -7,10 +7,14 @@ const SchemaData = Type.Object({ }); type Payload = Static; - -export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain; - payloadSchema = SchemaData; +interface ResponseType { + can_at_all: boolean; + remain_at_all_count_for_group: number; + remain_at_all_count_for_uin: number; +} +export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction { + override actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const ret = await this.core.apis.GroupApi.getGroupRemainAtTimes(payload.group_id.toString()); diff --git a/src/onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts b/src/onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts index 6fe9fe9b..9f740732 100644 --- a/src/onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts +++ b/src/onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts @@ -14,15 +14,16 @@ export class GetGroupFileSystemInfo extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetGroupFileSystemInfo; - payloadSchema = SchemaData; + override actionName = ActionName.GoCQHTTP_GetGroupFileSystemInfo; + override payloadSchema = SchemaData; async _handle(payload: Payload) { + const groupFileCount = (await this.core.apis.GroupApi.getGroupFileCount([payload.group_id.toString()])).groupFileCounts[0]; + if (!groupFileCount) { + throw new Error('Group not found'); + } return { - file_count: - (await this.core.apis.GroupApi - .getGroupFileCount([payload.group_id.toString()])) - .groupFileCounts[0], + file_count: groupFileCount, limit_count: 10000, used_space: 0, total_space: 10 * 1024 * 1024 * 1024, diff --git a/src/onebot/action/go-cqhttp/GetGroupFilesByFolder.ts b/src/onebot/action/go-cqhttp/GetGroupFilesByFolder.ts index 360e263d..dc5813b8 100644 --- a/src/onebot/action/go-cqhttp/GetGroupFilesByFolder.ts +++ b/src/onebot/action/go-cqhttp/GetGroupFilesByFolder.ts @@ -13,9 +13,12 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GetGroupFilesByFolder extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder; - payloadSchema = SchemaData; +export class GetGroupFilesByFolder extends OneBotAction[], + folders: never[], +}> { + override actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), { diff --git a/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts b/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts index 6782228e..9ead4af2 100644 --- a/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts +++ b/src/onebot/action/go-cqhttp/GetGroupHonorInfo.ts @@ -10,9 +10,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GetGroupHonorInfo extends OneBotAction> { - actionName = ActionName.GetGroupHonorInfo; - payloadSchema = SchemaData; +export class GetGroupHonorInfo extends OneBotAction> { + override actionName = ActionName.GetGroupHonorInfo; + override payloadSchema = SchemaData; async _handle(payload: Payload) { if (!payload.type) { diff --git a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts index dc895279..e2fdf4e8 100644 --- a/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot/action/go-cqhttp/GetGroupMsgHistory.ts @@ -22,10 +22,10 @@ type Payload = Static; export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; - payloadSchema = SchemaData; + override actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; + override payloadSchema = SchemaData; - async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig): Promise { + async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig): Promise { //处理参数 const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder; const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() }; diff --git a/src/onebot/action/go-cqhttp/GetGroupRootFiles.ts b/src/onebot/action/go-cqhttp/GetGroupRootFiles.ts index 217e7956..a4c1c916 100644 --- a/src/onebot/action/go-cqhttp/GetGroupRootFiles.ts +++ b/src/onebot/action/go-cqhttp/GetGroupRootFiles.ts @@ -16,8 +16,8 @@ export class GetGroupRootFiles extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetGroupRootFiles; - payloadSchema = SchemaData; + override actionName = ActionName.GoCQHTTP_GetGroupRootFiles; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), { sortType: 1, diff --git a/src/onebot/action/go-cqhttp/GetOnlineClient.ts b/src/onebot/action/go-cqhttp/GetOnlineClient.ts index dc57e9d7..1b5c0dd1 100644 --- a/src/onebot/action/go-cqhttp/GetOnlineClient.ts +++ b/src/onebot/action/go-cqhttp/GetOnlineClient.ts @@ -2,10 +2,9 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { sleep } from '@/common/helper'; -export class GetOnlineClient extends OneBotAction> { - actionName = ActionName.GetOnlineClient; - - async _handle(payload: void) { +export class GetOnlineClient extends OneBotAction> { + override actionName = ActionName.GetOnlineClient; + async _handle() { //注册监听 this.core.apis.SystemApi.getOnlineDev(); await sleep(500); diff --git a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts index 4f8153e5..c8d53b0a 100644 --- a/src/onebot/action/go-cqhttp/GetStrangerInfo.ts +++ b/src/onebot/action/go-cqhttp/GetStrangerInfo.ts @@ -11,10 +11,10 @@ const SchemaData = Type.Object({ type Payload = Static; -export default class GoCQHTTPGetStrangerInfo extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetStrangerInfo; - payloadSchema = SchemaData; - async _handle(payload: Payload): Promise { +export default class GoCQHTTPGetStrangerInfo extends OneBotAction { + override actionName = ActionName.GoCQHTTP_GetStrangerInfo; + override payloadSchema = SchemaData; + async _handle(payload: Payload) { const user_id = payload.user_id.toString(); const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id); let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id)); @@ -28,7 +28,7 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction; -export class GoCQHTTPCheckUrlSafely extends OneBotAction { - actionName = ActionName.GoCQHTTP_CheckUrlSafely; - payloadSchema = SchemaData; +export class GoCQHTTPCheckUrlSafely extends OneBotAction { + override actionName = ActionName.GoCQHTTP_CheckUrlSafely; + override payloadSchema = SchemaData; - async _handle(payload: Payload) { + async _handle() { return { level: 1 }; } } diff --git a/src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts b/src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts index c67d283b..adc02cf9 100644 --- a/src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts +++ b/src/onebot/action/go-cqhttp/GoCQHTTPDeleteFriend.ts @@ -11,9 +11,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GoCQHTTPDeleteFriend extends OneBotAction { - actionName = ActionName.GoCQHTTP_DeleteFriend; - payloadSchema = SchemaData; +export class GoCQHTTPDeleteFriend extends OneBotAction { + override actionName = ActionName.GoCQHTTP_DeleteFriend; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const uin = payload.friend_id ?? payload.user_id ?? ''; diff --git a/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts b/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts index bfdc75b7..453db746 100644 --- a/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts +++ b/src/onebot/action/go-cqhttp/GoCQHTTPGetModelShow.ts @@ -3,14 +3,19 @@ import { ActionName } from '@/onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const SchemaData = Type.Object({ - model: Type.String(), + model: Type.String(), }); type Payload = Static; -export class GoCQHTTPGetModelShow extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetModelShow; - payloadSchema = SchemaData; +export class GoCQHTTPGetModelShow extends OneBotAction> { + override actionName = ActionName.GoCQHTTP_GetModelShow; + override payloadSchema = SchemaData; async _handle(payload: Payload) { if (!payload.model) { diff --git a/src/onebot/action/go-cqhttp/GoCQHTTPSetModelShow.ts b/src/onebot/action/go-cqhttp/GoCQHTTPSetModelShow.ts index 17ef253b..3ac4a9be 100644 --- a/src/onebot/action/go-cqhttp/GoCQHTTPSetModelShow.ts +++ b/src/onebot/action/go-cqhttp/GoCQHTTPSetModelShow.ts @@ -1,10 +1,10 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; //兼容性代码 -export class GoCQHTTPSetModelShow extends OneBotAction { - actionName = ActionName.GoCQHTTP_SetModelShow; +export class GoCQHTTPSetModelShow extends OneBotAction { + override actionName = ActionName.GoCQHTTP_SetModelShow; - async _handle(payload: void) { - return null; + async _handle() { + return; } } diff --git a/src/onebot/action/go-cqhttp/QuickAction.ts b/src/onebot/action/go-cqhttp/QuickAction.ts index 30eacaf7..e19e4eeb 100644 --- a/src/onebot/action/go-cqhttp/QuickAction.ts +++ b/src/onebot/action/go-cqhttp/QuickAction.ts @@ -8,7 +8,7 @@ interface Payload { } export class GoCQHTTPHandleQuickAction extends OneBotAction { - actionName = ActionName.GoCQHTTP_HandleQuickAction; + override actionName = ActionName.GoCQHTTP_HandleQuickAction; async _handle(payload: Payload): Promise { this.obContext.apis.QuickActionApi diff --git a/src/onebot/action/go-cqhttp/SendForwardMsg.ts b/src/onebot/action/go-cqhttp/SendForwardMsg.ts index 4633094a..304d6fe3 100644 --- a/src/onebot/action/go-cqhttp/SendForwardMsg.ts +++ b/src/onebot/action/go-cqhttp/SendForwardMsg.ts @@ -1,21 +1,26 @@ -import SendMsg, { normalize } from '@/onebot/action/msg/SendMsg'; +import { normalize, SendMsgBase } from '@/onebot/action/msg/SendMsg'; import { OB11PostSendMsg } from '@/onebot/types'; import { ActionName } from '@/onebot/action/router'; // 未验证 -export class GoCQHTTPSendForwardMsg extends SendMsg { - actionName = ActionName.GoCQHTTP_SendForwardMsg; - - protected async check(payload: OB11PostSendMsg) { +export class GoCQHTTPSendForwardMsgBase extends SendMsgBase { + protected override async check(payload: OB11PostSendMsg) { if (payload.messages) payload.message = normalize(payload.messages); return super.check(payload); } } +export class GoCQHTTPSendForwardMsg extends GoCQHTTPSendForwardMsgBase { + override actionName = ActionName.GoCQHTTP_SendForwardMsg; -export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsg { - actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg; + protected override async check(payload: OB11PostSendMsg) { + if (payload.messages) payload.message = normalize(payload.messages); + return super.check(payload); + } +} +export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase { + override actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg; } -export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg { - actionName = ActionName.GoCQHTTP_SendGroupForwardMsg; +export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsgBase { + override actionName = ActionName.GoCQHTTP_SendGroupForwardMsg; } diff --git a/src/onebot/action/go-cqhttp/SendGroupNotice.ts b/src/onebot/action/go-cqhttp/SendGroupNotice.ts index 6dd8a343..158886d9 100644 --- a/src/onebot/action/go-cqhttp/SendGroupNotice.ts +++ b/src/onebot/action/go-cqhttp/SendGroupNotice.ts @@ -18,8 +18,8 @@ const SchemaData = Type.Object({ type Payload = Static; export class SendGroupNotice extends OneBotAction { - actionName = ActionName.GoCQHTTP_SendGroupNotice; - + override actionName = ActionName.GoCQHTTP_SendGroupNotice; + override payloadSchema = SchemaData; async _handle(payload: Payload) { let UploadImage: { id: string, width: number, height: number } | undefined = undefined; diff --git a/src/onebot/action/go-cqhttp/SetGroupPortrait.ts b/src/onebot/action/go-cqhttp/SetGroupPortrait.ts index 41532109..bfe0997f 100644 --- a/src/onebot/action/go-cqhttp/SetGroupPortrait.ts +++ b/src/onebot/action/go-cqhttp/SetGroupPortrait.ts @@ -3,6 +3,7 @@ import { ActionName } from '@/onebot/action/router'; import { checkFileExistV2, uriToLocalFile } from '@/common/file'; import { Static, Type } from '@sinclair/typebox'; import fs from 'node:fs/promises'; +import { GeneralCallResult } from '@/core'; const SchemaData = Type.Object({ file: Type.String(), group_id: Type.Union([Type.Number(), Type.String()]) @@ -10,11 +11,11 @@ const SchemaData = Type.Object({ type Payload = Static; -export default class SetGroupPortrait extends OneBotAction { - actionName = ActionName.SetGroupPortrait; - payloadSchema = SchemaData; +export default class SetGroupPortrait extends OneBotAction { + override actionName = ActionName.SetGroupPortrait; + override payloadSchema = SchemaData; - async _handle(payload: Payload): Promise { + async _handle(payload: Payload): Promise { const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.file)); if (!success) { throw new Error(`头像${payload.file}设置失败,file字段可能格式不正确`); diff --git a/src/onebot/action/go-cqhttp/SetQQProfile.ts b/src/onebot/action/go-cqhttp/SetQQProfile.ts index 21b0623a..976d87b5 100644 --- a/src/onebot/action/go-cqhttp/SetQQProfile.ts +++ b/src/onebot/action/go-cqhttp/SetQQProfile.ts @@ -1,3 +1,4 @@ +import { NTQQUserApi } from '@/core/apis'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; @@ -9,10 +10,9 @@ const SchemaData = Type.Object({ }); type Payload = Static; - -export class SetQQProfile extends OneBotAction { - actionName = ActionName.SetQQProfile; - payloadSchema = SchemaData; +export class SetQQProfile extends OneBotAction> | null> { + override actionName = ActionName.SetQQProfile; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const self = this.core.selfInfo; diff --git a/src/onebot/action/go-cqhttp/UploadGroupFile.ts b/src/onebot/action/go-cqhttp/UploadGroupFile.ts index 3c44458a..906d7e91 100644 --- a/src/onebot/action/go-cqhttp/UploadGroupFile.ts +++ b/src/onebot/action/go-cqhttp/UploadGroupFile.ts @@ -17,8 +17,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class GoCQHTTPUploadGroupFile extends OneBotAction { - actionName = ActionName.GoCQHTTP_UploadGroupFile; - payloadSchema = SchemaData; + override actionName = ActionName.GoCQHTTP_UploadGroupFile; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { let file = payload.file; @@ -38,7 +38,7 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction deleteAfterSentFiles: [] }; const sendFileEle = await this.core.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name, payload.folder ?? payload.folder_id); - await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [sendFileEle], msgContext.deleteAfterSentFiles, true); + await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [sendFileEle], msgContext.deleteAfterSentFiles); return null; } } diff --git a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts index aa555852..f17e3edf 100644 --- a/src/onebot/action/go-cqhttp/UploadPrivateFile.ts +++ b/src/onebot/action/go-cqhttp/UploadPrivateFile.ts @@ -16,8 +16,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class GoCQHTTPUploadPrivateFile extends OneBotAction { - actionName = ActionName.GOCQHTTP_UploadPrivateFile; - payloadSchema = SchemaData; + override actionName = ActionName.GOCQHTTP_UploadPrivateFile; + override payloadSchema = SchemaData; async getPeer(payload: Payload): Promise { if (payload.user_id) { @@ -43,13 +43,12 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction; +export default class DelEssenceMsg extends OneBotAction { + override actionName = ActionName.DelEssenceMsg; + override payloadSchema = SchemaData; -export default class DelEssenceMsg extends OneBotAction { - actionName = ActionName.DelEssenceMsg; - payloadSchema = SchemaData; - - async _handle(payload: Payload): Promise { + async _handle(payload: Payload): Promise { const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id); if (!msg) { const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id); diff --git a/src/onebot/action/group/DelGroupNotice.ts b/src/onebot/action/group/DelGroupNotice.ts index 5b932ebf..04f9cbea 100644 --- a/src/onebot/action/group/DelGroupNotice.ts +++ b/src/onebot/action/group/DelGroupNotice.ts @@ -9,9 +9,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class DelGroupNotice extends OneBotAction { - actionName = ActionName.DelGroupNotice; - payloadSchema = SchemaData; +export class DelGroupNotice extends OneBotAction { + override actionName = ActionName.DelGroupNotice; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const group = payload.group_id.toString(); diff --git a/src/onebot/action/group/GetAiRecord.ts b/src/onebot/action/group/GetAiRecord.ts index 64d1f765..0eeac7ab 100644 --- a/src/onebot/action/group/GetAiRecord.ts +++ b/src/onebot/action/group/GetAiRecord.ts @@ -12,11 +12,14 @@ const SchemaData = Type.Object({ type Payload = Static; export class GetAiRecord extends GetPacketStatusDepends { - actionName = ActionName.GetAiRecord; - payloadSchema = SchemaData; + override actionName = ActionName.GetAiRecord; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const rawRsp = await this.core.apis.PacketApi.pkt.operation.GetAiVoice(+payload.group_id, payload.character, payload.text, AIVoiceChatType.Sound); + if (!rawRsp.msgInfoBody[0]) { + throw new Error('No voice data'); + } return await this.core.apis.PacketApi.pkt.operation.GetGroupPttUrl(+payload.group_id, rawRsp.msgInfoBody[0].index); } } diff --git a/src/onebot/action/group/GetGroupEssence.ts b/src/onebot/action/group/GetGroupEssence.ts index 8ce4fff5..91deb65c 100644 --- a/src/onebot/action/group/GetGroupEssence.ts +++ b/src/onebot/action/group/GetGroupEssence.ts @@ -12,9 +12,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GetGroupEssence extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetEssenceMsg; - payloadSchema = SchemaData; +export class GetGroupEssence extends OneBotAction { + override actionName = ActionName.GoCQHTTP_GetEssenceMsg; + override payloadSchema = SchemaData; private async msgSeqToMsgId(peer: Peer, msgSeq: string, msgRandom: string) { const replyMsgList = (await this.core.apis.MsgApi.getMsgsBySeqAndCount(peer, msgSeq, 1, true, true)).msgList.find((msg) => msg.msgSeq === msgSeq && msg.msgRandom === msgRandom); @@ -27,7 +27,7 @@ export class GetGroupEssence extends OneBotAction { }; } - async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig) { + async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) { const msglist = (await this.core.apis.WebApi.getGroupEssenceMsgAll(payload.group_id.toString())).flatMap((e) => e.data.msg_list); if (!msglist) { throw new Error('获取失败'); @@ -58,7 +58,9 @@ export class GetGroupEssence extends OneBotAction { }); const hash = crypto.createHash('md5').update(msgTempData).digest(); //设置第一个bit为0 保证shortId为正数 - hash[0] &= 0x7f; + if(hash[0]){ + hash[0] &= 0x7f; + } const shortId = hash.readInt32BE(0); this.core.apis.GroupApi.essenceLRU.set(shortId, msgTempData); return { diff --git a/src/onebot/action/group/GetGroupIgnoredNotifies.ts b/src/onebot/action/group/GetGroupIgnoredNotifies.ts index 0da3475c..51692b30 100644 --- a/src/onebot/action/group/GetGroupIgnoredNotifies.ts +++ b/src/onebot/action/group/GetGroupIgnoredNotifies.ts @@ -9,7 +9,7 @@ interface RetData { } export class GetGroupIgnoredNotifies extends OneBotAction { - actionName = ActionName.GetGroupIgnoredNotifies; + override actionName = ActionName.GetGroupIgnoredNotifies; async _handle(): Promise { const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50); diff --git a/src/onebot/action/group/GetGroupInfo.ts b/src/onebot/action/group/GetGroupInfo.ts index cb38ca04..3c47a9df 100644 --- a/src/onebot/action/group/GetGroupInfo.ts +++ b/src/onebot/action/group/GetGroupInfo.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; class GetGroupInfo extends OneBotAction { - actionName = ActionName.GetGroupInfo; - payloadSchema = SchemaData; + override actionName = ActionName.GetGroupInfo; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const group = (await this.core.apis.GroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString()); diff --git a/src/onebot/action/group/GetGroupList.ts b/src/onebot/action/group/GetGroupList.ts index 4a34128d..251b79aa 100644 --- a/src/onebot/action/group/GetGroupList.ts +++ b/src/onebot/action/group/GetGroupList.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; class GetGroupList extends OneBotAction { - actionName = ActionName.GetGroupList; - payloadSchema = SchemaData; + override actionName = ActionName.GetGroupList; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return OB11Construct.groups( diff --git a/src/onebot/action/group/GetGroupMemberInfo.ts b/src/onebot/action/group/GetGroupMemberInfo.ts index 3745102b..00e277c9 100644 --- a/src/onebot/action/group/GetGroupMemberInfo.ts +++ b/src/onebot/action/group/GetGroupMemberInfo.ts @@ -13,8 +13,8 @@ const SchemaData = Type.Object({ type Payload = Static; class GetGroupMemberInfo extends OneBotAction { - actionName = ActionName.GetGroupMemberInfo; - payloadSchema = SchemaData; + override actionName = ActionName.GetGroupMemberInfo; + override payloadSchema = SchemaData; private parseBoolean(value: boolean | string): boolean { return typeof value === 'string' ? value === 'true' : value; diff --git a/src/onebot/action/group/GetGroupMemberList.ts b/src/onebot/action/group/GetGroupMemberList.ts index d7ec9657..41e028bf 100644 --- a/src/onebot/action/group/GetGroupMemberList.ts +++ b/src/onebot/action/group/GetGroupMemberList.ts @@ -13,8 +13,8 @@ const SchemaData = Type.Object({ type Payload = Static; export class GetGroupMemberList extends OneBotAction { - actionName = ActionName.GetGroupMemberList; - payloadSchema = SchemaData; + override actionName = ActionName.GetGroupMemberList; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const groupIdStr = payload.group_id.toString(); diff --git a/src/onebot/action/group/GetGroupNotice.ts b/src/onebot/action/group/GetGroupNotice.ts index 84aa42c2..fe952557 100644 --- a/src/onebot/action/group/GetGroupNotice.ts +++ b/src/onebot/action/group/GetGroupNotice.ts @@ -25,8 +25,8 @@ type Payload = Static; type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed; export class GetGroupNotice extends OneBotAction { - actionName = ActionName.GoCQHTTP_GetGroupNotice; - payloadSchema = SchemaData; + override actionName = ActionName.GoCQHTTP_GetGroupNotice; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const group = payload.group_id.toString(); @@ -36,6 +36,9 @@ export class GetGroupNotice extends OneBotAction { } const retNotices: GroupNotice[] = new Array(); for (const key in ret.feeds) { + if (!ret.feeds[key]) { + continue; + } const retApiNotice: WebApiGroupNoticeFeed = ret.feeds[key]; const retNotice: GroupNotice = { notice_id: retApiNotice.fid, diff --git a/src/onebot/action/group/GetGroupShutList.ts b/src/onebot/action/group/GetGroupShutList.ts index 683a8c6b..05ab27de 100644 --- a/src/onebot/action/group/GetGroupShutList.ts +++ b/src/onebot/action/group/GetGroupShutList.ts @@ -1,3 +1,4 @@ +import { ShutUpGroupMember } from '@/core'; import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; @@ -8,9 +9,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GetGroupShutList extends OneBotAction { - actionName = ActionName.GetGroupShutList; - payloadSchema = SchemaData; +export class GetGroupShutList extends OneBotAction { + override actionName = ActionName.GetGroupShutList; + override payloadSchema = SchemaData; async _handle(payload: Payload) { return await this.core.apis.GroupApi.getGroupShutUpMemberList(payload.group_id.toString()); diff --git a/src/onebot/action/group/GroupPoke.ts b/src/onebot/action/group/GroupPoke.ts index 5bdda381..8dcc8815 100644 --- a/src/onebot/action/group/GroupPoke.ts +++ b/src/onebot/action/group/GroupPoke.ts @@ -9,9 +9,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class GroupPoke extends GetPacketStatusDepends { - actionName = ActionName.GroupPoke; - payloadSchema = SchemaData; +export class GroupPoke extends GetPacketStatusDepends { + override actionName = ActionName.GroupPoke; + override payloadSchema = SchemaData; async _handle(payload: Payload) { await this.core.apis.PacketApi.pkt.operation.GroupPoke(+payload.group_id, +payload.user_id); diff --git a/src/onebot/action/group/SendGroupAiRecord.ts b/src/onebot/action/group/SendGroupAiRecord.ts index 2dfa3a78..7cfd5f85 100644 --- a/src/onebot/action/group/SendGroupAiRecord.ts +++ b/src/onebot/action/group/SendGroupAiRecord.ts @@ -1,7 +1,5 @@ import { ActionName } from '@/onebot/action/router'; import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus'; -import { uriToLocalFile } from '@/common/file'; -import { ChatType, Peer } from '@/core'; import { AIVoiceChatType } from '@/core/packet/entities/aiChat'; import { Static, Type } from '@sinclair/typebox'; @@ -17,8 +15,8 @@ type Payload = Static; export class SendGroupAiRecord extends GetPacketStatusDepends { - actionName = ActionName.SendGroupAiRecord; - payloadSchema = SchemaData; + override actionName = ActionName.SendGroupAiRecord; + override payloadSchema = SchemaData; async _handle(payload: Payload) { await this.core.apis.PacketApi.pkt.operation.GetAiVoice(+payload.group_id, payload.character, payload.text, AIVoiceChatType.Sound); diff --git a/src/onebot/action/group/SendGroupMsg.ts b/src/onebot/action/group/SendGroupMsg.ts index c0723e41..e401abb5 100644 --- a/src/onebot/action/group/SendGroupMsg.ts +++ b/src/onebot/action/group/SendGroupMsg.ts @@ -4,10 +4,10 @@ import { OB11PostSendMsg } from '@/onebot/types'; // 未检测参数 class SendGroupMsg extends SendMsgBase { - actionName = ActionName.SendGroupMsg; - contextMode: ContextMode = ContextMode.Group; + override actionName = ActionName.SendGroupMsg; + override contextMode: ContextMode = ContextMode.Group; - protected async check(payload: OB11PostSendMsg): Promise { + protected override async check(payload: OB11PostSendMsg): Promise { delete payload.user_id; payload.message_type = 'group'; return super.check(payload); diff --git a/src/onebot/action/group/SetEssenceMsg.ts b/src/onebot/action/group/SetEssenceMsg.ts index 34502d3f..6578d641 100644 --- a/src/onebot/action/group/SetEssenceMsg.ts +++ b/src/onebot/action/group/SetEssenceMsg.ts @@ -9,11 +9,11 @@ const SchemaData = Type.Object({ type Payload = Static; -export default class SetEssenceMsg extends OneBotAction { - actionName = ActionName.SetEssenceMsg; - payloadSchema = SchemaData; +export default class SetEssenceMsg extends OneBotAction { + override actionName = ActionName.SetEssenceMsg; + override payloadSchema = SchemaData; - async _handle(payload: Payload): Promise { + async _handle(payload: Payload) { const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id); if (!msg) { throw new Error('msg not found'); diff --git a/src/onebot/action/group/SetGroupAddRequest.ts b/src/onebot/action/group/SetGroupAddRequest.ts index a06be36e..5f5f7cd2 100644 --- a/src/onebot/action/group/SetGroupAddRequest.ts +++ b/src/onebot/action/group/SetGroupAddRequest.ts @@ -12,8 +12,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetGroupAddRequest extends OneBotAction { - actionName = ActionName.SetGroupAddRequest; - payloadSchema = SchemaData; + override actionName = ActionName.SetGroupAddRequest; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const flag = payload.flag.toString(); diff --git a/src/onebot/action/group/SetGroupAdmin.ts b/src/onebot/action/group/SetGroupAdmin.ts index 42348791..ee70edfb 100644 --- a/src/onebot/action/group/SetGroupAdmin.ts +++ b/src/onebot/action/group/SetGroupAdmin.ts @@ -12,8 +12,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetGroupAdmin extends OneBotAction { - actionName = ActionName.SetGroupAdmin; - payloadSchema = SchemaData; + override actionName = ActionName.SetGroupAdmin; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const enable = typeof payload.enable === 'string' ? payload.enable === 'true' : !!payload.enable; diff --git a/src/onebot/action/group/SetGroupBan.ts b/src/onebot/action/group/SetGroupBan.ts index 7b73a007..120dfe45 100644 --- a/src/onebot/action/group/SetGroupBan.ts +++ b/src/onebot/action/group/SetGroupBan.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetGroupBan extends OneBotAction { - actionName = ActionName.SetGroupBan; - payloadSchema = SchemaData; + override actionName = ActionName.SetGroupBan; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString()); diff --git a/src/onebot/action/group/SetGroupCard.ts b/src/onebot/action/group/SetGroupCard.ts index 03a1b844..2e825c68 100644 --- a/src/onebot/action/group/SetGroupCard.ts +++ b/src/onebot/action/group/SetGroupCard.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetGroupCard extends OneBotAction { - actionName = ActionName.SetGroupCard; - payloadSchema = SchemaData; + override actionName = ActionName.SetGroupCard; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const member = await this.core.apis.GroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString()); diff --git a/src/onebot/action/group/SetGroupKick.ts b/src/onebot/action/group/SetGroupKick.ts index 339350f0..7b57d48c 100644 --- a/src/onebot/action/group/SetGroupKick.ts +++ b/src/onebot/action/group/SetGroupKick.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetGroupKick extends OneBotAction { - actionName = ActionName.SetGroupKick; - payloadSchema = SchemaData; + override actionName = ActionName.SetGroupKick; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const rejectReq = payload.reject_add_request?.toString() == 'true'; diff --git a/src/onebot/action/group/SetGroupLeave.ts b/src/onebot/action/group/SetGroupLeave.ts index 6618d9cd..4d9a4083 100644 --- a/src/onebot/action/group/SetGroupLeave.ts +++ b/src/onebot/action/group/SetGroupLeave.ts @@ -9,11 +9,11 @@ const SchemaData = Type.Object({ type Payload = Static; -export default class SetGroupLeave extends OneBotAction { - actionName = ActionName.SetGroupLeave; - payloadSchema = SchemaData; +export default class SetGroupLeave extends OneBotAction { + override actionName = ActionName.SetGroupLeave; + override payloadSchema = SchemaData; - async _handle(payload: Payload): Promise { + async _handle(payload: Payload): Promise { await this.core.apis.GroupApi.quitGroup(payload.group_id.toString()); } } diff --git a/src/onebot/action/group/SetGroupName.ts b/src/onebot/action/group/SetGroupName.ts index 0820d39b..cde09908 100644 --- a/src/onebot/action/group/SetGroupName.ts +++ b/src/onebot/action/group/SetGroupName.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetGroupName extends OneBotAction { - actionName = ActionName.SetGroupName; - payloadSchema = SchemaData; + override actionName = ActionName.SetGroupName; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const ret = await this.core.apis.GroupApi.setGroupName(payload.group_id.toString(), payload.group_name); diff --git a/src/onebot/action/group/SetGroupWholeBan.ts b/src/onebot/action/group/SetGroupWholeBan.ts index af9c5025..a4c84c44 100644 --- a/src/onebot/action/group/SetGroupWholeBan.ts +++ b/src/onebot/action/group/SetGroupWholeBan.ts @@ -10,8 +10,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetGroupWholeBan extends OneBotAction { - actionName = ActionName.SetGroupWholeBan; - payloadSchema = SchemaData; + override actionName = ActionName.SetGroupWholeBan; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const enable = payload.enable?.toString() !== 'false'; diff --git a/src/onebot/action/guild/GetGuildList.ts b/src/onebot/action/guild/GetGuildList.ts index de342d6d..a125c67e 100644 --- a/src/onebot/action/guild/GetGuildList.ts +++ b/src/onebot/action/guild/GetGuildList.ts @@ -1,10 +1,10 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -export class GetGuildList extends OneBotAction { - actionName = ActionName.GetGuildList; +export class GetGuildList extends OneBotAction { + override actionName = ActionName.GetGuildList; - async _handle(payload: null): Promise { - return null; + async _handle(): Promise { + return; } } diff --git a/src/onebot/action/guild/GetGuildProfile.ts b/src/onebot/action/guild/GetGuildProfile.ts index ff7a29d5..2dc40c29 100644 --- a/src/onebot/action/guild/GetGuildProfile.ts +++ b/src/onebot/action/guild/GetGuildProfile.ts @@ -1,10 +1,10 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -export class GetGuildProfile extends OneBotAction { - actionName = ActionName.GetGuildProfile; +export class GetGuildProfile extends OneBotAction { + override actionName = ActionName.GetGuildProfile; - async _handle(payload: null): Promise { - return null; + async _handle(): Promise { + return; } } diff --git a/src/onebot/action/index.ts b/src/onebot/action/index.ts index ea430d63..2ecea787 100644 --- a/src/onebot/action/index.ts +++ b/src/onebot/action/index.ts @@ -8,7 +8,6 @@ import SendGroupMsg from './group/SendGroupMsg'; import SendPrivateMsg from './msg/SendPrivateMsg'; import SendMsg from './msg/SendMsg'; import DeleteMsg from './msg/DeleteMsg'; -import { OneBotAction } from '@/onebot/action/OneBotAction'; import GetVersionInfo from './system/GetVersionInfo'; import CanSendRecord from './system/CanSendRecord'; import CanSendImage from './system/CanSendImage'; @@ -239,10 +238,11 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo _map.set(`${h.actionName}_rate_limited` as keyof MapType, h); }); - function get(key: K): MapType[K]; - function get(key: K): null; - function get(key: K): HandlerUnion | null | MapType[K] { - return _map.get(key as keyof MapType) ?? null; + // function get(key: K): MapType[K]; + // function get(key: K): null; + // function get(key: K): HandlerUnion | null | MapType[K] + function get(key: K): MapType[K] | undefined { + return _map.get(key as keyof MapType) as MapType[K] | undefined; } return { get }; diff --git a/src/onebot/action/msg/DeleteMsg.ts b/src/onebot/action/msg/DeleteMsg.ts index 7636561d..a4b27aa2 100644 --- a/src/onebot/action/msg/DeleteMsg.ts +++ b/src/onebot/action/msg/DeleteMsg.ts @@ -10,8 +10,8 @@ const SchemaData = Type.Object({ type Payload = Static; class DeleteMsg extends OneBotAction { - actionName = ActionName.DeleteMsg; - payloadSchema = SchemaData; + override actionName = ActionName.DeleteMsg; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id)); diff --git a/src/onebot/action/msg/ForwardSingleMsg.ts b/src/onebot/action/msg/ForwardSingleMsg.ts index 61beb99d..7156159c 100644 --- a/src/onebot/action/msg/ForwardSingleMsg.ts +++ b/src/onebot/action/msg/ForwardSingleMsg.ts @@ -42,11 +42,11 @@ class ForwardSingleMsg extends OneBotAction { } export class ForwardFriendSingleMsg extends ForwardSingleMsg { - payloadSchema = SchemaData; - actionName = ActionName.ForwardFriendSingleMsg; + override payloadSchema = SchemaData; + override actionName = ActionName.ForwardFriendSingleMsg; } export class ForwardGroupSingleMsg extends ForwardSingleMsg { - payloadSchema = SchemaData; - actionName = ActionName.ForwardGroupSingleMsg; + override payloadSchema = SchemaData; + override actionName = ActionName.ForwardGroupSingleMsg; } diff --git a/src/onebot/action/msg/GetMsg.ts b/src/onebot/action/msg/GetMsg.ts index 20721c98..08b2e955 100644 --- a/src/onebot/action/msg/GetMsg.ts +++ b/src/onebot/action/msg/GetMsg.ts @@ -15,11 +15,10 @@ const SchemaData = Type.Object({ type Payload = Static; class GetMsg extends OneBotAction { - actionName = ActionName.GetMsg; - payloadSchema = SchemaData; + override actionName = ActionName.GetMsg; + override payloadSchema = SchemaData; - async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig) { - // log("history msg ids", Object.keys(msgHistory)); + async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) { if (!payload.message_id) { throw Error('参数message_id不能为空'); } @@ -30,19 +29,20 @@ class GetMsg extends OneBotAction { } const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType }; const orimsg = this.obContext.recallMsgCache.get(msgIdWithPeer.MsgId); - let msg: RawMessage; + let msg: RawMessage|undefined; if (orimsg) { msg = orimsg; } else { msg = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()])).msgList[0]; } + if (!msg) throw Error('消息不存在'); const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat); if (!retMsg) throw Error('消息为空'); try { retMsg.message_id = MessageUnique.createUniqueMsgId(peer, msg.msgId)!; retMsg.message_seq = retMsg.message_id; retMsg.real_id = retMsg.message_id; - } catch (e) { + } catch { // ignored } return retMsg; diff --git a/src/onebot/action/msg/MarkMsgAsRead.ts b/src/onebot/action/msg/MarkMsgAsRead.ts index 1769c8f1..f36a653a 100644 --- a/src/onebot/action/msg/MarkMsgAsRead.ts +++ b/src/onebot/action/msg/MarkMsgAsRead.ts @@ -49,21 +49,21 @@ class MarkMsgAsRead extends OneBotAction { // 以下为非标准实现 export class MarkPrivateMsgAsRead extends MarkMsgAsRead { - payloadSchema = SchemaData; - actionName = ActionName.MarkPrivateMsgAsRead; + override payloadSchema = SchemaData; + override actionName = ActionName.MarkPrivateMsgAsRead; } export class MarkGroupMsgAsRead extends MarkMsgAsRead { - payloadSchema = SchemaData; - actionName = ActionName.MarkGroupMsgAsRead; + override payloadSchema = SchemaData; + override actionName = ActionName.MarkGroupMsgAsRead; } export class GoCQHTTPMarkMsgAsRead extends MarkMsgAsRead { - actionName = ActionName.GoCQHTTP_MarkMsgAsRead; + override actionName = ActionName.GoCQHTTP_MarkMsgAsRead; } -export class MarkAllMsgAsRead extends OneBotAction { - actionName = ActionName._MarkAllMsgAsRead; +export class MarkAllMsgAsRead extends OneBotAction { + override actionName = ActionName._MarkAllMsgAsRead; async _handle(): Promise { await this.core.apis.MsgApi.markAllMsgAsRead(); diff --git a/src/onebot/action/msg/SendMsg.ts b/src/onebot/action/msg/SendMsg.ts index c391724e..26a93ad2 100644 --- a/src/onebot/action/msg/SendMsg.ts +++ b/src/onebot/action/msg/SendMsg.ts @@ -36,10 +36,10 @@ export function normalize(message: OB11MessageMixType, autoEscape = false): OB11 ) : Array.isArray(message) ? message : [message]; } -export async function createContext(core: NapCatCore, payload: OB11PostContext, contextMode: ContextMode): Promise { - // This function determines the type of message by the existence of user_id / group_id, - // not message_type. - // This redundant design of Ob11 here should be blamed. +export async function createContext(core: NapCatCore, payload: OB11PostContext | undefined, contextMode: ContextMode = ContextMode.Normal): Promise { + if (!payload) { + throw new Error('请指定 group_id 或 user_id'); + } if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) { return { chatType: ChatType.KCHATTYPEGROUP, @@ -91,7 +91,7 @@ function getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType export class SendMsgBase extends OneBotAction { contextMode = ContextMode.Normal; - protected async check(payload: OB11PostSendMsg): Promise { + protected override async check(payload: OB11PostSendMsg): Promise { const messages = normalize(payload.message); const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node); if (nodeElementLength > 0 && nodeElementLength != messages.length) { @@ -121,8 +121,8 @@ export class SendMsgBase extends OneBotAction { returnMsgAndResId = packetMode ? await this.handleForwardedNodesPacket(peer, messages as OB11MessageNode[], payload.source, payload.news, payload.summary, payload.prompt) : await this.handleForwardedNodes(peer, messages as OB11MessageNode[]); - } catch (e: any) { - throw Error(packetMode ? `发送伪造合并转发消息失败: ${e?.stack}` : `发送合并转发消息失败: ${e?.stack}`); + } catch (e: unknown) { + throw Error(packetMode ? `发送伪造合并转发消息失败: ${(e as Error)?.stack}` : `发送合并转发消息失败: ${(e as Error)?.stack}`); } if (!returnMsgAndResId) { throw Error('发送合并转发消息失败:returnMsgAndResId 为空!'); @@ -133,7 +133,7 @@ export class SendMsgBase extends OneBotAction { peerUid: peer.peerUid, chatType: peer.chatType, }, (returnMsgAndResId.message).msgId); - return { message_id: msgShortId!, res_id: returnMsgAndResId.res_id }; + return { message_id: msgShortId!, res_id: returnMsgAndResId.res_id! }; } else if (returnMsgAndResId.res_id && !returnMsgAndResId.message) { throw Error(`发送转发消息(res_id:${returnMsgAndResId.res_id} 失败`); } @@ -185,7 +185,7 @@ export class SendMsgBase extends OneBotAction { const packetMsgElements: rawMsgWithSendMsg = { senderUin: Number((node.data.user_id ?? node.data.uin) ?? parentMeta?.user_id) || +this.core.selfInfo.uin, senderName: (node.data.nickname || node.data.name) ?? parentMeta?.nickname ?? 'QQ用户', - groupId: msgPeer.chatType === ChatType.KCHATTYPEGROUP ? +msgPeer.peerUid : undefined, + groupId: msgPeer.chatType === ChatType.KCHATTYPEGROUP ? +msgPeer.peerUid : 0, time: Number(node.data.time) || Date.now(), msg: sendElements, }; @@ -202,10 +202,12 @@ export class SendMsgBase extends OneBotAction { } const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(nodeMsg.Peer, [nodeMsg.MsgId])).msgList[0]; this.core.context.logger.logDebug(`handleForwardedNodesPacket[PureRaw] 开始转换 ${stringifyWithBigInt(msg)}`); - await this.core.apis.FileApi.downloadRawMsgMedia([msg]); - const transformedMsg = this.core.apis.PacketApi.pkt.msgConverter.rawMsgToPacketMsg(msg, msgPeer); - this.core.context.logger.logDebug(`handleForwardedNodesPacket[PureRaw] 转换为 ${stringifyWithBigInt(transformedMsg)}`); - packetMsg.push(transformedMsg); + if (msg) { + await this.core.apis.FileApi.downloadRawMsgMedia([msg]); + const transformedMsg = this.core.apis.PacketApi.pkt.msgConverter.rawMsgToPacketMsg(msg, msgPeer); + this.core.context.logger.logDebug(`handleForwardedNodesPacket[PureRaw] 转换为 ${stringifyWithBigInt(transformedMsg)}`); + packetMsg.push(transformedMsg); + } } else { this.core.context.logger.logDebug(`handleForwardedNodesPacket 跳过元素 ${stringifyWithBigInt(node)}`); } @@ -238,8 +240,8 @@ export class SendMsgBase extends OneBotAction { const res_id = uploadReturnData?.res_id; const finallySendElements = uploadReturnData?.finallySendElements; if (!finallySendElements) throw Error('转发消息失败,生成节点为空'); - const returnMsg = await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(msgPeer, [finallySendElements], [], true).catch(_ => undefined); - return { message: returnMsg ?? null, res_id }; + const returnMsg = await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(msgPeer, [finallySendElements], []).catch(() => undefined); + return { message: returnMsg ?? null, res_id: res_id! }; } private async handleForwardedNodes(destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<{ @@ -297,7 +299,7 @@ export class SendMsgBase extends OneBotAction { const AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0); const MsgNodeList: Promise[] = []; for (const sendElementsSplitElement of AllElement) { - MsgNodeList.push(this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(selfPeer, sendElementsSplitElement, [], true).catch(_ => undefined)); + MsgNodeList.push(this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(selfPeer, sendElementsSplitElement, []).catch(() => undefined)); } (await Promise.allSettled(MsgNodeList)).map((result) => { if (result.status === 'fulfilled' && result.value) { @@ -305,8 +307,8 @@ export class SendMsgBase extends OneBotAction { MessageUnique.createUniqueMsgId(selfPeer, result.value.msgId); } }); - } catch (e: any) { - this.core.context.logger.logDebug('生成转发消息节点失败', e?.stack); + } catch (e: unknown) { + this.core.context.logger.logDebug('生成转发消息节点失败', (e as Error).stack); } } } @@ -321,11 +323,13 @@ export class SendMsgBase extends OneBotAction { continue; } const nodeMsg = (await this.core.apis.MsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0]; - srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid }; - if (srcPeer.peerUid !== nodeMsg.peerUid) { - needSendSelf = true; + if (nodeMsg) { + srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid }; + if (srcPeer.peerUid !== nodeMsg.peerUid) { + needSendSelf = true; + } + nodeMsgArray.push(nodeMsg); } - nodeMsgArray.push(nodeMsg); } nodeMsgIds = nodeMsgArray.map(msg => msg.msgId); let retMsgIds: string[] = []; @@ -347,8 +351,8 @@ export class SendMsgBase extends OneBotAction { return { message: await this.core.apis.MsgApi.multiForwardMsg(srcPeer!, destPeer, retMsgIds) }; - } catch (e: any) { - this.core.context.logger.logError('forward failed', e?.stack); + } catch (e: unknown) { + this.core.context.logger.logError('forward failed', (e as Error)?.stack); return { message: null }; @@ -371,13 +375,13 @@ export class SendMsgBase extends OneBotAction { this.core.context.logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg); } try { - return await this.core.apis.MsgApi.sendMsg(selfPeer, sendElements, true); - } catch (e: any) { - this.core.context.logger.logError(e?.stack, '克隆转发消息失败,将忽略本条消息', msg); + return await this.core.apis.MsgApi.sendMsg(selfPeer, sendElements); + } catch (e: unknown) { + this.core.context.logger.logError((e as Error)?.stack, '克隆转发消息失败,将忽略本条消息', msg); } + return; } } - export default class SendMsg extends SendMsgBase { - actionName = ActionName.SendMsg; + override actionName = ActionName.SendMsg; } diff --git a/src/onebot/action/msg/SendPrivateMsg.ts b/src/onebot/action/msg/SendPrivateMsg.ts index fa2775a9..cb268f0d 100644 --- a/src/onebot/action/msg/SendPrivateMsg.ts +++ b/src/onebot/action/msg/SendPrivateMsg.ts @@ -4,10 +4,10 @@ import { OB11PostSendMsg } from '@/onebot/types'; // 未检测参数 class SendPrivateMsg extends SendMsgBase { - actionName = ActionName.SendPrivateMsg; - contextMode: ContextMode = ContextMode.Private; + override actionName = ActionName.SendPrivateMsg; + override contextMode: ContextMode = ContextMode.Private; - protected async check(payload: OB11PostSendMsg): Promise { + protected override async check(payload: OB11PostSendMsg): Promise { payload.message_type = 'private'; return super.check(payload); } diff --git a/src/onebot/action/msg/SetMsgEmojiLike.ts b/src/onebot/action/msg/SetMsgEmojiLike.ts index 0ac44b1a..02ce4e01 100644 --- a/src/onebot/action/msg/SetMsgEmojiLike.ts +++ b/src/onebot/action/msg/SetMsgEmojiLike.ts @@ -11,9 +11,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class SetMsgEmojiLike extends OneBotAction { - actionName = ActionName.SetMsgEmojiLike; - payloadSchema = SchemaData; +export class SetMsgEmojiLike extends OneBotAction { + override actionName = ActionName.SetMsgEmojiLike; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id); @@ -26,7 +26,7 @@ export class SetMsgEmojiLike extends OneBotAction { payload.set = payload.set ?? true; const msgData = (await this.core.apis.MsgApi.getMsgsByMsgId(msg.Peer, [msg.MsgId])).msgList; - if (!msgData || msgData.length === 0 || !msgData[0].msgSeq) { + if (!msgData || msgData.length === 0 || !msgData[0]?.msgSeq) { throw new Error('find msg by msgid error'); } diff --git a/src/onebot/action/packet/GetPacketStatus.ts b/src/onebot/action/packet/GetPacketStatus.ts index c0ecf08e..2630163b 100644 --- a/src/onebot/action/packet/GetPacketStatus.ts +++ b/src/onebot/action/packet/GetPacketStatus.ts @@ -3,7 +3,7 @@ import { ActionName, BaseCheckResult } from '@/onebot/action/router'; export abstract class GetPacketStatusDepends extends OneBotAction { - protected async check(payload: PT): Promise{ + protected override async check(payload: PT): Promise{ if (!this.core.apis.PacketApi.available) { return { valid: false, @@ -15,10 +15,10 @@ export abstract class GetPacketStatusDepends extends OneBotAction { - actionName = ActionName.GetPacketStatus; +export class GetPacketStatus extends GetPacketStatusDepends { + override actionName = ActionName.GetPacketStatus; - async _handle(payload: any) { - return null; + async _handle() { + return; } } diff --git a/src/onebot/action/packet/SendPoke.ts b/src/onebot/action/packet/SendPoke.ts index 0e7b0d68..5cdf74c1 100644 --- a/src/onebot/action/packet/SendPoke.ts +++ b/src/onebot/action/packet/SendPoke.ts @@ -9,9 +9,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class SendPoke extends GetPacketStatusDepends { - actionName = ActionName.SendPoke; - payloadSchema = SchemaData; +export class SendPoke extends GetPacketStatusDepends { + override actionName = ActionName.SendPoke; + override payloadSchema = SchemaData; async _handle(payload: Payload) { if (payload.group_id) { diff --git a/src/onebot/action/router.ts b/src/onebot/action/router.ts index f893f9d3..bc6e2dbd 100644 --- a/src/onebot/action/router.ts +++ b/src/onebot/action/router.ts @@ -2,15 +2,11 @@ export type BaseCheckResult = ValidCheckResult | InvalidCheckResult; export interface ValidCheckResult { valid: true; - - [k: string | number]: any; } export interface InvalidCheckResult { valid: false; message: string; - - [k: string | number]: any; } export const ActionName = { diff --git a/src/onebot/action/system/CanSendImage.ts b/src/onebot/action/system/CanSendImage.ts index ecf4fca4..5f105aaa 100644 --- a/src/onebot/action/system/CanSendImage.ts +++ b/src/onebot/action/system/CanSendImage.ts @@ -1,10 +1,6 @@ import { ActionName } from '@/onebot/action/router'; -import CanSendRecord, { CanSend } from './CanSendRecord'; - -interface ReturnType { - yes: boolean; -} +import { CanSend } from './CanSendRecord'; export default class CanSendImage extends CanSend { - actionName = ActionName.CanSendImage; + override actionName = ActionName.CanSendImage; } diff --git a/src/onebot/action/system/CanSendRecord.ts b/src/onebot/action/system/CanSendRecord.ts index d3dfc409..033943ba 100644 --- a/src/onebot/action/system/CanSendRecord.ts +++ b/src/onebot/action/system/CanSendRecord.ts @@ -5,8 +5,8 @@ interface ReturnType { yes: boolean; } -export class CanSend extends OneBotAction { - async _handle(_payload: void): Promise { +export class CanSend extends OneBotAction { + async _handle(): Promise { return { yes: true, }; @@ -15,5 +15,5 @@ export class CanSend extends OneBotAction { export default class CanSendRecord extends CanSend{ - actionName = ActionName.CanSendRecord; + override actionName = ActionName.CanSendRecord; } diff --git a/src/onebot/action/system/GetCSRF.ts b/src/onebot/action/system/GetCSRF.ts index 3d90c726..a1909615 100644 --- a/src/onebot/action/system/GetCSRF.ts +++ b/src/onebot/action/system/GetCSRF.ts @@ -1,10 +1,10 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -export class GetCSRF extends OneBotAction { - actionName = ActionName.GetCSRF; +export class GetCSRF extends OneBotAction { + override actionName = ActionName.GetCSRF; - async _handle(payload: any) { + async _handle() { const sKey = await this.core.apis.UserApi.getSKey(); if (!sKey) { throw new Error('SKey is undefined'); diff --git a/src/onebot/action/system/GetCredentials.ts b/src/onebot/action/system/GetCredentials.ts index 0e918d2a..90ef79ca 100644 --- a/src/onebot/action/system/GetCredentials.ts +++ b/src/onebot/action/system/GetCredentials.ts @@ -15,14 +15,14 @@ type Payload = Static; export class GetCredentials extends OneBotAction { - actionName = ActionName.GetCredentials; - payloadSchema = SchemaData; + override actionName = ActionName.GetCredentials; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain); //把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起 const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; '); - const bkn = cookiesObject?.skey ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : ''; + const bkn = cookiesObject?.['skey'] ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : ''; return { cookies: cookies, token: +bkn }; } } diff --git a/src/onebot/action/system/GetLoginInfo.ts b/src/onebot/action/system/GetLoginInfo.ts index 3b66e393..ca8ba296 100644 --- a/src/onebot/action/system/GetLoginInfo.ts +++ b/src/onebot/action/system/GetLoginInfo.ts @@ -4,9 +4,9 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; class GetLoginInfo extends OneBotAction { - actionName = ActionName.GetLoginInfo; + override actionName = ActionName.GetLoginInfo; - async _handle(payload: null) { + async _handle() { return OB11Construct.selfInfo(this.core.selfInfo); } } diff --git a/src/onebot/action/system/GetStatus.ts b/src/onebot/action/system/GetStatus.ts index 2f70c8d1..c698c085 100644 --- a/src/onebot/action/system/GetStatus.ts +++ b/src/onebot/action/system/GetStatus.ts @@ -1,10 +1,15 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; -export default class GetStatus extends OneBotAction { - actionName = ActionName.GetStatus; +interface ResponseType{ + online: boolean; + good: boolean; + stat: unknown; +} +export default class GetStatus extends OneBotAction { + override actionName = ActionName.GetStatus; - async _handle(payload: any): Promise { + async _handle(): Promise { return { online: !!this.core.selfInfo.online, good: true, diff --git a/src/onebot/action/system/GetSystemMsg.ts b/src/onebot/action/system/GetSystemMsg.ts index 01605869..75853b4e 100644 --- a/src/onebot/action/system/GetSystemMsg.ts +++ b/src/onebot/action/system/GetSystemMsg.ts @@ -9,7 +9,7 @@ interface RetData { } export class GetGroupSystemMsg extends OneBotAction { - actionName = ActionName.GetGroupSystemMsg; + override actionName = ActionName.GetGroupSystemMsg; async _handle(): Promise { const SingleScreenNotifies = await this.core.apis.GroupApi.getSingleScreenNotifies(false, 50); diff --git a/src/onebot/action/system/GetVersionInfo.ts b/src/onebot/action/system/GetVersionInfo.ts index 1b12f127..0d401f6b 100644 --- a/src/onebot/action/system/GetVersionInfo.ts +++ b/src/onebot/action/system/GetVersionInfo.ts @@ -1,12 +1,15 @@ import { OneBotAction } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; - import { napCatVersion } from '@/common/version'; +interface ResponseType { + app_name: string; + protocol_version: string; + app_version: string; +} +export default class GetVersionInfo extends OneBotAction { + override actionName = ActionName.GetVersionInfo; -export default class GetVersionInfo extends OneBotAction { - actionName = ActionName.GetVersionInfo; - - async _handle(payload: any): Promise { + async _handle(): Promise { return { app_name: 'NapCat.Onebot', protocol_version: 'v11', diff --git a/src/onebot/action/user/FriendPoke.ts b/src/onebot/action/user/FriendPoke.ts index 1ed19142..e447a987 100644 --- a/src/onebot/action/user/FriendPoke.ts +++ b/src/onebot/action/user/FriendPoke.ts @@ -8,9 +8,9 @@ const SchemaData = Type.Object({ type Payload = Static; -export class FriendPoke extends GetPacketStatusDepends { - actionName = ActionName.FriendPoke; - payloadSchema = SchemaData; +export class FriendPoke extends GetPacketStatusDepends { + override actionName = ActionName.FriendPoke; + override payloadSchema = SchemaData; async _handle(payload: Payload) { await this.core.apis.PacketApi.pkt.operation.FriendPoke(+payload.user_id); diff --git a/src/onebot/action/user/GetCookies.ts b/src/onebot/action/user/GetCookies.ts index 49269c54..00773fe3 100644 --- a/src/onebot/action/user/GetCookies.ts +++ b/src/onebot/action/user/GetCookies.ts @@ -13,14 +13,14 @@ const SchemaData = Type.Object({ type Payload = Static; export class GetCookies extends OneBotAction { - actionName = ActionName.GetCookies; - payloadSchema = SchemaData; + override actionName = ActionName.GetCookies; + override payloadSchema = SchemaData; async _handle(payload: Payload) { const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain); //把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起 const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; '); - const bkn = cookiesObject?.skey ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : ''; + const bkn = cookiesObject?.['skey'] ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : ''; return { cookies, bkn }; } } diff --git a/src/onebot/action/user/GetFriendList.ts b/src/onebot/action/user/GetFriendList.ts index 48971172..263c189d 100644 --- a/src/onebot/action/user/GetFriendList.ts +++ b/src/onebot/action/user/GetFriendList.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class GetFriendList extends OneBotAction { - actionName = ActionName.GetFriendList; - payloadSchema = SchemaData; + override actionName = ActionName.GetFriendList; + override payloadSchema = SchemaData; async _handle(payload: Payload) { //全新逻辑 diff --git a/src/onebot/action/user/GetRecentContact.ts b/src/onebot/action/user/GetRecentContact.ts index 9b79bac5..91f25484 100644 --- a/src/onebot/action/user/GetRecentContact.ts +++ b/src/onebot/action/user/GetRecentContact.ts @@ -10,16 +10,16 @@ const SchemaData = Type.Object({ type Payload = Static; -export default class GetRecentContact extends OneBotAction { - actionName = ActionName.GetRecentContact; - payloadSchema = SchemaData; +export default class GetRecentContact extends OneBotAction { + override actionName = ActionName.GetRecentContact; + override payloadSchema = SchemaData; - async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig) { + async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) { const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+payload.count); //烘焙消息 return await Promise.all(ret.info.changedList.map(async (t) => { const FastMsg = await this.core.apis.MsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]); - if (FastMsg.msgList.length > 0) { + if (FastMsg.msgList.length > 0 && FastMsg.msgList[0]) { //扩展ret.info.changedList const lastestMsg = await this.obContext.apis.MsgApi.parseMessage(FastMsg.msgList[0], config.messagePostFormat); return { diff --git a/src/onebot/action/user/SendLike.ts b/src/onebot/action/user/SendLike.ts index ee661cdd..828b46a5 100644 --- a/src/onebot/action/user/SendLike.ts +++ b/src/onebot/action/user/SendLike.ts @@ -10,8 +10,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SendLike extends OneBotAction { - actionName = ActionName.SendLike; - payloadSchema = SchemaData; + override actionName = ActionName.SendLike; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const qq = payload.user_id.toString(); diff --git a/src/onebot/action/user/SetFriendAddRequest.ts b/src/onebot/action/user/SetFriendAddRequest.ts index dfe29e6c..bda5964a 100644 --- a/src/onebot/action/user/SetFriendAddRequest.ts +++ b/src/onebot/action/user/SetFriendAddRequest.ts @@ -11,8 +11,8 @@ const SchemaData = Type.Object({ type Payload = Static; export default class SetFriendAddRequest extends OneBotAction { - actionName = ActionName.SetFriendAddRequest; - payloadSchema = SchemaData; + override actionName = ActionName.SetFriendAddRequest; + override payloadSchema = SchemaData; async _handle(payload: Payload): Promise { const approve = payload.approve?.toString() !== 'false'; diff --git a/src/onebot/api/friend.ts b/src/onebot/api/friend.ts index 610c93bf..20438429 100644 --- a/src/onebot/api/friend.ts +++ b/src/onebot/api/friend.ts @@ -5,7 +5,6 @@ import { OB11FriendPokeEvent } from '@/onebot/event/notice/OB11PokeEvent'; export class OneBotFriendApi { obContext: NapCatOneBot11Adapter; core: NapCatCore; - friendList: Map = new Map();//此处作为缓存 uin->info constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { this.obContext = obContext; this.core = core; @@ -17,7 +16,7 @@ export class OneBotFriendApi { const pokedetail: Array<{ uid: string }> = json.items; //筛选item带有uid的元素 const poke_uid = pokedetail.filter(item => item.uid); - if (poke_uid.length == 2) { + if (poke_uid.length == 2 && poke_uid[0]?.uid && poke_uid[1]?.uid) { return new OB11FriendPokeEvent( this.core, uin, diff --git a/src/onebot/api/group.ts b/src/onebot/api/group.ts index fe436559..1051856c 100644 --- a/src/onebot/api/group.ts +++ b/src/onebot/api/group.ts @@ -29,7 +29,6 @@ import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent'; export class OneBotGroupApi { obContext: NapCatOneBot11Adapter; core: NapCatCore; - GroupMemberList: Map = new Map();//此处作为缓存 group_id->memberUin->info constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) { this.obContext = obContext; this.core = core; @@ -130,10 +129,10 @@ export class OneBotGroupApi { //判断业务类型 //Poke事件 - const pokedetail: any[] = json.items; + const pokedetail: Array<{ uid: string }> = json.items; //筛选item带有uid的元素 const poke_uid = pokedetail.filter(item => item.uid); - if (poke_uid.length == 2) { + if (poke_uid.length == 2 && poke_uid[0]?.uid && poke_uid[1]?.uid) { return new OB11GroupPokeEvent( this.core, parseInt(msg.peerUid), @@ -164,6 +163,7 @@ export class OneBotGroupApi { } else { context.logger.logWarn('收到未知的灰条消息', json); } + return; } async parseEssenceMsg(msg: RawMessage, jsonStr: string) { @@ -181,13 +181,16 @@ export class OneBotGroupApi { const msgData = await this.core.apis.MsgApi.getMsgsBySeqAndCount(Peer, msgSeq.toString(), 1, true, true); const msgList = (await this.core.apis.WebApi.getGroupEssenceMsgAll(Group)).flatMap((e) => e.data.msg_list); const realMsg = msgList.find((e) => e.msg_seq.toString() == msgSeq); - return new OB11GroupEssenceEvent( - this.core, - parseInt(msg.peerUid), - MessageUnique.getShortIdByMsgId(msgData.msgList[0].msgId)!, - parseInt(msgData.msgList[0].senderUin), - parseInt(realMsg?.add_digest_uin ?? '0'), - ); + if (msgData.msgList[0]) { + return new OB11GroupEssenceEvent( + this.core, + parseInt(msg.peerUid), + MessageUnique.getShortIdByMsgId(msgData.msgList[0].msgId)!, + parseInt(msgData.msgList[0].senderUin), + parseInt(realMsg?.add_digest_uin ?? '0'), + ); + } + return; // 获取MsgSeq+Peer可获取具体消息 } @@ -233,6 +236,7 @@ export class OneBotGroupApi { ); } } + return; } async parseSelfInviteEvent(msg: RawMessage, inviterUin: string, inviteeUin: string) { diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 563181d5..abce943d 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -44,7 +44,7 @@ type RawToOb11Converters = { msg: RawMessage, elementWrapper: MessageElement, context: RecvMessageContext - ) => PromiseLike + ) => Promise } type Ob11ToRawConverters = { @@ -128,9 +128,9 @@ export class OneBotMsgApi { file_size: element.fileSize, }, }; - } catch (e: any) { - this.core.context.logger.logError('获取图片url失败', e.stack); - return null; + } catch (e) { + this.core.context.logger.logError('获取图片url失败', (e as Error).stack); + return; } }, @@ -296,7 +296,7 @@ export class OneBotMsgApi { peerUid: msg.peerUid, guildId: '0', }, msg.parentMsgIdList[0] ?? msg.msgId, elementWrapper.elementId); - } catch (error) { + } catch { this.core.context.logger.logWarn('合并获取视频 URL 失败'); } } else { @@ -306,7 +306,7 @@ export class OneBotMsgApi { peerUid: msg.peerUid, guildId: '0', }, msg.msgId, elementWrapper.elementId); - } catch (error) { + } catch { this.core.context.logger.logWarn('获取视频 URL 失败'); } } @@ -358,7 +358,7 @@ export class OneBotMsgApi { }; }, - multiForwardMsgElement: async (_, msg, wrapper, context) => { + multiForwardMsgElement: async (_, msg, _wrapper, context) => { const parentMsgPeer = msg.parentMsgPeer ?? { chatType: msg.chatType, guildId: '', @@ -465,7 +465,13 @@ export class OneBotMsgApi { const parsedFaceId = +id; // 从face_config.json中获取表情名称 const sysFaces = faceConfig.sysface; - const face: any = sysFaces.find((systemFace) => systemFace.QSid === parsedFaceId.toString()); + const face: { + QSid?: string, + QDes?: string, + AniStickerId?: string, + AniStickerType?: number, + AniStickerPackId?: string, + } | undefined = sysFaces.find((systemFace) => systemFace.QSid === parsedFaceId.toString()); if (!face) { this.core.context.logger.logError('不支持的ID', id); return undefined; @@ -622,7 +628,7 @@ export class OneBotMsgApi { //throw Error('音乐消息签名地址未配置'); } try { - const musicJson = await RequestUtil.HttpGetJson(signUrl, 'POST', postData); + const musicJson = await RequestUtil.HttpGetJson(signUrl, 'POST', postData); return this.ob11ToRawConverters.json({ data: { data: musicJson }, type: OB11MessageDataType.json @@ -630,6 +636,7 @@ export class OneBotMsgApi { } catch (e) { this.core.context.logger.logError('生成音乐消息失败', e); } + return undefined; }, [OB11MessageDataType.node]: async () => undefined, @@ -671,6 +678,7 @@ export class OneBotMsgApi { type: OB11MessageDataType.json }, context); } + return undefined; } }; @@ -688,6 +696,7 @@ export class OneBotMsgApi { return new OB11FriendAddNoticeEvent(this.core, Number(await this.core.apis.UserApi.getUinByUidV2(msg.peerUid))); } } + return; } private async getMultiMessages(msg: RawMessage, parentMsgPeer: Peer) { @@ -696,11 +705,14 @@ export class OneBotMsgApi { //首次列表不存在则开始创建 msg.parentMsgIdList.push(msg.msgId); //拉取下级消息 - return (await this.core.apis.MsgApi.getMultiMsg( - parentMsgPeer, - msg.parentMsgIdList[0], - msg.msgId - ))?.msgList; + if (msg.parentMsgIdList[0]) { + return (await this.core.apis.MsgApi.getMultiMsg( + parentMsgPeer, + msg.parentMsgIdList[0], + msg.msgId + ))?.msgList; + } + return undefined; } private async parseMultiMessageContent( @@ -831,7 +843,7 @@ export class OneBotMsgApi { msg: RawMessage, elementWrapper: MessageElement, context: RecvMessageContext - ) => PromiseLike; + ) => Promise; const parsedElement = await converters?.( element[key], msg, @@ -844,6 +856,7 @@ export class OneBotMsgApi { return parsedElement; } } + return []; }, )); @@ -897,7 +910,7 @@ export class OneBotMsgApi { return { sendElements, deleteAfterSentFiles }; } - async sendMsgWithOb11UniqueId(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) { + async sendMsgWithOb11UniqueId(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[]) { if (!sendElements.length) { throw new Error('消息体无法解析, 请检查是否发送了不支持的消息类型'); } @@ -928,7 +941,7 @@ export class OneBotMsgApi { const timeout = 10000 + (totalSize / 1024 / 256 * 1000); - const returnMsg = await this.core.apis.MsgApi.sendMsg(peer, sendElements, waitComplete, timeout); + const returnMsg = await this.core.apis.MsgApi.sendMsg(peer, sendElements, timeout); if (!returnMsg) throw new Error('发送消息失败'); returnMsg.id = MessageUnique.createUniqueMsgId({ @@ -1025,7 +1038,7 @@ export class OneBotMsgApi { if (isAdminOrOwner && !operatorUid) { let dataNotify: GroupNotify | undefined; await this.core.eventWrapper.registerListen('NodeIKernelGroupListener/onGroupNotifiesUpdated', - (doubt, notifies) => { + (_doubt, notifies) => { for (const notify of notifies) { if (notify.group.groupCode === groupUin && notify.user1.uid === memberUid) { dataNotify = notify; @@ -1124,7 +1137,7 @@ export class OneBotMsgApi { } return false; }, 1, 1000); - } catch (error) { + } catch { request_seq = ''; } // 未拉取到seq @@ -1173,5 +1186,6 @@ export class OneBotMsgApi { } else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) { return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent); } + return undefined; } } diff --git a/src/onebot/api/quick-action.ts b/src/onebot/api/quick-action.ts index da5484bc..aa81a88d 100644 --- a/src/onebot/api/quick-action.ts +++ b/src/onebot/api/quick-action.ts @@ -46,9 +46,7 @@ export class OneBotQuickActionApi { async handleMsg(msg: OB11Message, quickAction: QuickAction) { const reply = quickAction.reply; const peerContextMode = msg.message_type == 'private' ? ContextMode.Private : ContextMode.Group; - const peer: Peer = await createContext(this.core, { - message_type: undefined, group_id: msg.group_id?.toString(), user_id: msg.user_id?.toString(), }, peerContextMode); @@ -79,7 +77,7 @@ export class OneBotQuickActionApi { sendElements, deleteAfterSentFiles, } = await this.obContext.apis.MsgApi.createSendElements(replyMessage, peer); - this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles, false).then().catch(e => this.core.context.logger.logError(e)); + this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles).then().catch(e => this.core.context.logger.logError(e)); } } async findNotify(flag: string) { @@ -91,7 +89,7 @@ export class OneBotQuickActionApi { } async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) { - + const invite_notify = this.obContext.apis.MsgApi.notifyGroupInvite.get(request.flag); const notify = invite_notify ?? await this.findNotify(request.flag); diff --git a/src/onebot/api/user.ts b/src/onebot/api/user.ts index 769e60bc..6f4d3f85 100644 --- a/src/onebot/api/user.ts +++ b/src/onebot/api/user.ts @@ -1,4 +1,4 @@ -import { GrayTipRovokeElement, NapCatCore, RawMessage } from '@/core'; +import { NapCatCore } from '@/core'; import { NapCatOneBot11Adapter } from '@/onebot'; import { OB11ProfileLikeEvent } from '@/onebot/event/notice/OB11ProfileLikeEvent'; import { decodeProfileLikeTip } from '@/core/helper/adaptDecoder'; diff --git a/src/onebot/event/notice/OB11PokeEvent.ts b/src/onebot/event/notice/OB11PokeEvent.ts index 26f313d3..df0a6c86 100644 --- a/src/onebot/event/notice/OB11PokeEvent.ts +++ b/src/onebot/event/notice/OB11PokeEvent.ts @@ -9,11 +9,11 @@ class OB11PokeEvent extends OB11BaseNoticeEvent { } export class OB11FriendPokeEvent extends OB11PokeEvent { - raw_info: any; + raw_info: unknown; sender_id: number; //raw_message nb等框架标准为string - constructor(core: NapCatCore, user_id: number, sender_id: number, target_id: number, raw_message: any) { + constructor(core: NapCatCore, user_id: number, sender_id: number, target_id: number, raw_message: unknown) { super(core); this.target_id = target_id; this.user_id = user_id; @@ -24,10 +24,10 @@ export class OB11FriendPokeEvent extends OB11PokeEvent { export class OB11GroupPokeEvent extends OB11PokeEvent { group_id: number; - raw_info: any; + raw_info: unknown; //raw_message nb等框架标准为string - constructor(core: NapCatCore, group_id: number, user_id: number, target_id: number, raw_message: any) { + constructor(core: NapCatCore, group_id: number, user_id: number, target_id: number, raw_message: unknown) { super(core); this.group_id = group_id; this.target_id = target_id; diff --git a/src/onebot/event/notice/OB11ProfileLikeEvent.ts b/src/onebot/event/notice/OB11ProfileLikeEvent.ts index 3c790764..4409d4e7 100644 --- a/src/onebot/event/notice/OB11ProfileLikeEvent.ts +++ b/src/onebot/event/notice/OB11ProfileLikeEvent.ts @@ -7,7 +7,7 @@ export class OB11ProfileLikeEvent extends OB11BaseNoticeEvent { operator_id: number; operator_nick: string; times: number; - time: number; + override time: number; constructor(core: NapCatCore, operatorId: number, operatorNick: string, times: number, time: number) { super(core); diff --git a/src/onebot/event/request/OB11FriendRequest.ts b/src/onebot/event/request/OB11FriendRequest.ts index 660d2b1a..e270cb0a 100644 --- a/src/onebot/event/request/OB11FriendRequest.ts +++ b/src/onebot/event/request/OB11FriendRequest.ts @@ -3,7 +3,7 @@ import { EventType } from '@/onebot/event/OneBotEvent'; import { NapCatCore } from '@/core'; export class OB11FriendRequestEvent extends OB11BaseNoticeEvent { - post_type = EventType.REQUEST; + override post_type = EventType.REQUEST; request_type = 'friend'; user_id: number; diff --git a/src/onebot/event/request/OB11GroupRequest.ts b/src/onebot/event/request/OB11GroupRequest.ts index de1ca026..249fa1dc 100644 --- a/src/onebot/event/request/OB11GroupRequest.ts +++ b/src/onebot/event/request/OB11GroupRequest.ts @@ -3,10 +3,10 @@ import { EventType } from '@/onebot/event/OneBotEvent'; import { NapCatCore } from '@/core'; export class OB11GroupRequestEvent extends OB11GroupNoticeEvent { - post_type = EventType.REQUEST; + override post_type = EventType.REQUEST; request_type = 'group'; - user_id: number; + override user_id: number; comment: string; flag: string; sub_type: string; diff --git a/src/onebot/helper/cqcode.ts b/src/onebot/helper/cqcode.ts index 06b7626a..35aaddae 100644 --- a/src/onebot/helper/cqcode.ts +++ b/src/onebot/helper/cqcode.ts @@ -14,7 +14,7 @@ function from(source: string) { const capture = pattern.exec(source); if (!capture) return null; const [, type, attrs] = capture; - const data: Record = {}; + const data: Record = {}; if (attrs) { attrs.slice(1).split(',').forEach((str) => { const index = str.indexOf('='); @@ -24,7 +24,7 @@ function from(source: string) { return { type, data, capture }; } -function convert(type: string, data: any) { +function convert(type: string, data: unknown) { return { type, data, @@ -32,18 +32,21 @@ function convert(type: string, data: any) { } export function decodeCQCode(source: string): OB11MessageData[] { - const elements: any[] = []; + const elements: Array = []; let result: ReturnType; while ((result = from(source))) { const { type, data, capture } = result; - if (capture.index) { - elements.push(convert('text', { text: unescape(source.slice(0, capture.index)) })); + if (type) { + if (capture.index) { + elements.push(convert('text', { text: unescape(source.slice(0, capture.index)) })); + } + elements.push(convert(type, data)); + source = source.slice(capture.index + capture[0].length); } - elements.push(convert(type, data)); - source = source.slice(capture.index + capture[0].length); + } if (source) elements.push(convert('text', { text: unescape(source) })); - return elements; + return elements as OB11MessageData[]; } function CQCodeEscapeText(text: string) { diff --git a/src/onebot/index.ts b/src/onebot/index.ts index fe9d48dc..ff8d7260 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -41,7 +41,6 @@ import { OB11GroupRequestEvent } from '@/onebot/event/request/OB11GroupRequest'; import { OB11FriendRecallNoticeEvent } from '@/onebot/event/notice/OB11FriendRecallNoticeEvent'; import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecallNoticeEvent'; import { LRUCache } from '@/common/lru-cache'; -import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener'; import { BotOfflineEvent } from './event/notice/BotOfflineEvent'; import { NetworkAdapterConfig, @@ -49,7 +48,6 @@ import { OneBotConfig, } from './config/config'; import { OB11Message } from './types'; -import { OB11PluginAdapter } from './network/plugin'; import { IOB11NetworkAdapter } from '@/onebot/network/adapter'; import { OB11HttpSSEServerAdapter } from './network/http-server-sse'; @@ -187,18 +185,6 @@ export class NapCatOneBot11Adapter { }); } - initRecentContactListener() { - const recentContactListener = new NodeIKernelRecentContactListener(); - recentContactListener.onRecentContactNotification = function ( - msgList: any[] /* arg0: { msgListUnreadCnt: string }, arg1: number */ - ) { - msgList.forEach((msg) => { - if (msg.chatType == ChatType.KCHATTYPEGROUP) { - // log("recent contact", msgList, arg0, arg1); - } - }); - }; - } private async reloadNetwork(prev: OneBotConfig, now: OneBotConfig): Promise { const prevLog = await this.creatOneBotLog(prev); @@ -352,6 +338,7 @@ export class NapCatOneBot11Adapter { this.core.apis.FriendApi.clearBuddyReqUnreadCnt(); for (let i = 0; i < reqs.unreadNums; i++) { const req = reqs.buddyReqs[i]; + if (!req) continue; if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) { continue; } @@ -381,6 +368,7 @@ export class NapCatOneBot11Adapter { groupListener.onGroupNotifiesUpdated = async (_, notifies) => { await this.core.apis.GroupApi.clearGroupNotifiesUnreadCount(false); + if (!notifies[0]?.type) return; if ( ![ GroupNotifyMsgType.SET_ADMIN, @@ -506,7 +494,10 @@ export class NapCatOneBot11Adapter { ob11Msg.arrayMsg.user_id.toString() == this.core.selfInfo.uin; } - private createMsgMap(network: Array, ob11Msg: any, isSelfMsg: boolean, message: RawMessage): Map { + private createMsgMap(network: Array, ob11Msg: { + stringMsg: OB11Message; + arrayMsg: OB11Message; + }, isSelfMsg: boolean, message: RawMessage): Map { const msgMap: Map = new Map(); network.filter(e => e.enable).forEach(e => { if (isSelfMsg || message.chatType !== ChatType.KCHATTYPEGROUP) { @@ -566,7 +557,7 @@ export class NapCatOneBot11Adapter { } } else if (message.msgType === NTMsgType.KMSGTYPEGRAYTIPS) { // 灰条为单元素消息 - const grayTipElement = message.elements[0].grayTipElement; + const grayTipElement = message.elements[0]?.grayTipElement; if (grayTipElement) { const event = await this.apis.GroupApi.parseGrayTipElement(message, grayTipElement); if (event) { @@ -583,7 +574,7 @@ export class NapCatOneBot11Adapter { try { if (message.msgType === NTMsgType.KMSGTYPEGRAYTIPS) { // 灰条为单元素消息 - const grayTipElement = message.elements[0].grayTipElement; + const grayTipElement = message.elements[0]?.grayTipElement; if (grayTipElement) { const event = await this.apis.MsgApi.parsePrivateMsgEvent(message, grayTipElement); if (event) { @@ -605,7 +596,7 @@ export class NapCatOneBot11Adapter { } else if (message.chatType == ChatType.KCHATTYPEGROUP) { return await this.emitGroupRecallMsg(message, oriMessageId, element); } - + return; } private async emitFriendRecallMsg(message: RawMessage, oriMessageId: number, element: MessageElement) { diff --git a/src/onebot/network/adapter.ts b/src/onebot/network/adapter.ts index a8a49451..6cb3def3 100644 --- a/src/onebot/network/adapter.ts +++ b/src/onebot/network/adapter.ts @@ -29,5 +29,5 @@ export abstract class IOB11NetworkAdapter { abstract close(): void | Promise; - abstract reload(config: any): OB11NetworkReloadType | Promise; + abstract reload(config: unknown): OB11NetworkReloadType | Promise; } diff --git a/src/onebot/network/http-server-sse.ts b/src/onebot/network/http-server-sse.ts index 6b4839ed..47414871 100644 --- a/src/onebot/network/http-server-sse.ts +++ b/src/onebot/network/http-server-sse.ts @@ -5,9 +5,9 @@ import { OB11HttpServerAdapter } from './http-server'; export class OB11HttpSSEServerAdapter extends OB11HttpServerAdapter { private sseClients: Response[] = []; - override async handleRequest(req: Request, res: Response): Promise { + override async handleRequest(req: Request, res: Response) { if (req.path === '/_events') { - return this.createSseSupport(req, res); + this.createSseSupport(req, res); } else { super.httpApiRequest(req, res); } @@ -18,7 +18,7 @@ export class OB11HttpSSEServerAdapter extends OB11HttpServerAdapter { res.setHeader('Cache-Control', 'no-cache'); res.setHeader('Connection', 'keep-alive'); res.flushHeaders(); - + this.sseClients.push(res); req.on('close', () => { this.sseClients = this.sseClients.filter((client) => client !== res); diff --git a/src/onebot/network/http-server.ts b/src/onebot/network/http-server.ts index c9a125e3..74fb0c26 100644 --- a/src/onebot/network/http-server.ts +++ b/src/onebot/network/http-server.ts @@ -1,5 +1,5 @@ -import { OB11EmitEventContent, OB11NetworkReloadType } from './index'; -import express, { Express, Request, Response } from 'express'; +import { OB11EmitEventContent, OB11NetworkReloadType } from './index'; +import express, { Express, NextFunction, Request, Response } from 'express'; import http from 'http'; import { NapCatCore } from '@/core'; import { OB11Response } from '@/onebot/action/OneBotAction'; @@ -18,7 +18,8 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter super(name, config, core, obContext, actions); } - onEvent(_event: T) { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + override onEvent(_event: T) { // http server is passive, no need to emit event } @@ -61,17 +62,18 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter try { req.body = json5.parse(rawData || '{}'); next(); - } catch (err) { + } catch { return res.status(400).send('Invalid JSON'); } + return; }); - req.on('error', (_err) => { + req.on('error', () => { return res.status(400).send('Invalid JSON'); }); }); - + //@ts-expect-error authorize this.app.use((req, res, next) => this.authorize(this.config.token, req, res, next)); - this.app.use(async (req, res, _) => { + this.app.use(async (req, res) => { await this.handleRequest(req, res); }); this.server.listen(this.config.port, () => { @@ -79,10 +81,10 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter }); } - private authorize(token: string | undefined, req: Request, res: Response, next: any) { + private authorize(token: string | undefined, req: Request, res: Response, next: NextFunction) { if (!token || token.length == 0) return next();//客户端未设置密钥 const HeaderClientToken = req.headers.authorization?.split('Bearer ').pop() || ''; - const QueryClientToken = req.query.access_token; + const QueryClientToken = req.query['access_token']; const ClientToken = typeof (QueryClientToken) === 'string' && QueryClientToken !== '' ? QueryClientToken : HeaderClientToken; if (ClientToken === token) { return next(); @@ -104,13 +106,14 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter return res.json(hello); } const actionName = req.path.split('/')[1]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const action = this.actions.get(actionName as any); if (action) { try { const result = await action.handle(payload, this.name, this.config); return res.json(result); - } catch (error: any) { - return res.json(OB11Response.error(error?.stack?.toString() || error?.message || 'Error Handle', 200)); + } catch (error: unknown) { + return res.json(OB11Response.error((error as Error)?.stack?.toString() || (error as Error)?.message || 'Error Handle', 200)); } } else { return res.json(OB11Response.error('不支持的Api ' + actionName, 200)); @@ -120,10 +123,11 @@ export class OB11HttpServerAdapter extends IOB11NetworkAdapter async handleRequest(req: Request, res: Response) { if (!this.isEnable) { this.core.context.logger.log('[OneBot] [HTTP Server Adapter] Server is closed'); - return res.json(OB11Response.error('Server is closed', 200)); + res.json(OB11Response.error('Server is closed', 200)); + return; } - - return this.httpApiRequest(req, res); + this.httpApiRequest(req, res); + return; } async reload(newConfig: HttpServerConfig) { diff --git a/src/onebot/network/websocket-client.ts b/src/onebot/network/websocket-client.ts index d6e4e1c2..34fd6502 100644 --- a/src/onebot/network/websocket-client.ts +++ b/src/onebot/network/websocket-client.ts @@ -1,5 +1,5 @@ import { OB11EmitEventContent, OB11NetworkReloadType } from '@/onebot/network/index'; -import { WebSocket } from 'ws'; +import { RawData, WebSocket } from 'ws'; import { OB11HeartbeatEvent } from '@/onebot/event/meta/OB11HeartbeatEvent'; import { NapCatCore } from '@/core'; import { ActionName } from '@/onebot/action/router'; @@ -119,13 +119,13 @@ export class OB11WebSocketClientAdapter extends IOB11NetworkAdapter(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT)); + this.checkStateAndReply(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT)); } catch (e) { this.logger.logError('[OneBot] [WebSocket Client] 发送生命周期失败', e); } } - - private async handleMessage(message: any) { + private async handleMessage(message: RawData) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any let receiveData: { action: typeof ActionName[keyof typeof ActionName], params?: any, echo?: any } = { action: ActionName.Unknown, params: {} }; let echo = undefined; @@ -133,19 +133,20 @@ export class OB11WebSocketClientAdapter extends IOB11NetworkAdapter(OB11Response.error('json解析失败,请检查数据格式', 1400, echo)); + } catch { + this.checkStateAndReply(OB11Response.error('json解析失败,请检查数据格式', 1400, echo)); return; } receiveData.params = (receiveData?.params) ? receiveData.params : {};// 兼容类型验证 + // eslint-disable-next-line @typescript-eslint/no-explicit-any const action = this.actions.get(receiveData.action as any); if (!action) { this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的Api ' + receiveData.action); - this.checkStateAndReply(OB11Response.error('不支持的Api ' + receiveData.action, 1404, echo)); + this.checkStateAndReply(OB11Response.error('不支持的Api ' + receiveData.action, 1404, echo)); return; } const retdata = await action.websocketHandle(receiveData.params, echo ?? '', this.name, this.config); - this.checkStateAndReply({ ...retdata }); + this.checkStateAndReply({ ...retdata }); } async reload(newConfig: WebsocketClientConfig) { const wasEnabled = this.isEnable; diff --git a/src/onebot/network/websocket-server.ts b/src/onebot/network/websocket-server.ts index d4ac3dd5..7e92f634 100644 --- a/src/onebot/network/websocket-server.ts +++ b/src/onebot/network/websocket-server.ts @@ -1,6 +1,6 @@ import { OB11EmitEventContent, OB11NetworkReloadType } from './index'; import urlParse from 'url'; -import { WebSocket, WebSocketServer } from 'ws'; +import { RawData, WebSocket, WebSocketServer } from 'ws'; import { Mutex } from 'async-mutex'; import { OB11Response } from '@/onebot/action/OneBotAction'; import { ActionName } from '@/onebot/action/router'; @@ -77,7 +77,7 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT), wsClient); + this.checkStateAndReply(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT), wsClient); } catch (e) { this.logger.logError('[OneBot] [WebSocket Server] 发送生命周期失败', e); } @@ -143,7 +143,7 @@ export class OB11WebSocketServerAdapter extends IOB11NetworkAdapter(OB11Response.error('json解析失败,请检查数据格式', 1400, echo), wsClient); + } catch { + this.checkStateAndReply(OB11Response.error('json解析失败,请检查数据格式', 1400, echo), wsClient); return; } receiveData.params = (receiveData?.params) ? receiveData.params : {};//兼容类型验证 不然类型校验爆炸 + // eslint-disable-next-line @typescript-eslint/no-explicit-any const action = this.actions.get(receiveData.action as any); if (!action) { this.logger.logError('[OneBot] [WebSocket Client] 发生错误', '不支持的API ' + receiveData.action); - this.checkStateAndReply(OB11Response.error('不支持的API ' + receiveData.action, 1404, echo), wsClient); + this.checkStateAndReply(OB11Response.error('不支持的API ' + receiveData.action, 1404, echo), wsClient); return; } const retdata = await action.websocketHandle(receiveData.params, echo ?? '', this.name, this.config); - this.checkStateAndReply({ ...retdata }, wsClient); + this.checkStateAndReply({ ...retdata }, wsClient); } async reload(newConfig: WebsocketServerConfig) { diff --git a/src/onebot/types/data.ts b/src/onebot/types/data.ts index 5a6a972e..52b97436 100644 --- a/src/onebot/types/data.ts +++ b/src/onebot/types/data.ts @@ -1,5 +1,4 @@ export interface OB11User { - [key: string]: any; user_id: number; // 用户ID nickname: string; // 昵称 remark?: string; // 备注 diff --git a/src/onebot/types/message.ts b/src/onebot/types/message.ts index 8f311e87..ff14e8fb 100644 --- a/src/onebot/types/message.ts +++ b/src/onebot/types/message.ts @@ -42,7 +42,7 @@ export interface OB11Return { retcode: number; data: DataType; message: string; - echo?: any; // ws调用api才有此字段 + echo?: unknown; // ws调用api才有此字段 wording?: string; // go-cqhttp字段,错误信息 } diff --git a/src/plugin/index.ts b/src/plugin/index.ts index bf518971..484a58b5 100644 --- a/src/plugin/index.ts +++ b/src/plugin/index.ts @@ -3,7 +3,7 @@ import { NapCatCore } from '@/core'; import { ActionMap } from '@/onebot/action'; import { OB11PluginAdapter } from '@/onebot/network/plugin'; -export const plugin_onmessage = async (adapter: string, core: NapCatCore, obCtx: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap, instance: OB11PluginAdapter) => { +export const plugin_onmessage = async (adapter: string, _core: NapCatCore, _obCtx: NapCatOneBot11Adapter, message: OB11Message, action: ActionMap, instance: OB11PluginAdapter) => { if (message.raw_message === 'ping') { const ret = await action.get('send_group_msg')?.handle({ group_id: String(message.group_id), message: 'pong' }, adapter, instance.config); console.log(ret); diff --git a/src/shell/base.ts b/src/shell/base.ts index 46a380e0..3685dbda 100644 --- a/src/shell/base.ts +++ b/src/shell/base.ts @@ -10,18 +10,19 @@ import { loadQQWrapper, NapCatCore, NapCatCoreWorkingEnv, + NodeIQQNTWrapperEngine, NodeIQQNTWrapperSession, PlatformType, WrapperNodeApi, + WrapperSessionInitConfig, } from '@/core'; import { QQBasicInfoWrapper } from '@/common/qq-basic-info'; import { hostname, systemVersion } from '@/common/system'; import { proxiedListenerOf } from '@/common/proxy-handler'; - import path from 'path'; import fs from 'fs'; import os from 'os'; -import { NodeIKernelLoginService } from '@/core/services'; +import { LoginListItem, NodeIKernelLoginService } from '@/core/services'; import { program } from 'commander'; import qrcode from 'qrcode-terminal'; import { NapCatOneBot11Adapter } from '@/onebot'; @@ -29,13 +30,12 @@ import { InitWebUi } from '@/webui'; import { WebUiDataRuntime } from '@/webui/src/helper/Data'; import { napCatVersion } from '@/common/version'; import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener'; -import { FFmpegService } from '@/common/ffmpeg'; // NapCat Shell App ES 入口文件 async function handleUncaughtExceptions(logger: LogWrapper) { process.on('uncaughtException', (err) => { logger.logError('[NapCat] [Error] Unhandled Exception:', err.message); }); - process.on('unhandledRejection', (reason, promise) => { + process.on('unhandledRejection', (reason) => { logger.logError('[NapCat] [Error] unhandledRejection:', reason); }); } @@ -65,7 +65,7 @@ function getPlatformType(): PlatformType { } async function initializeEngine( - engine: any, + engine: NodeIQQNTWrapperEngine, basicInfoWrapper: QQBasicInfoWrapper, dataPathGlobal: string, systemPlatform: PlatformType, @@ -79,7 +79,7 @@ async function initializeEngine( app_version: basicInfoWrapper.getFullQQVesion(), os_version: systemVersion, use_xlog: false, - qua: basicInfoWrapper.QQVersionQua, + qua: basicInfoWrapper.QQVersionQua ?? '', global_path_config: { desktopGlobalPath: dataPathGlobal, }, @@ -111,7 +111,7 @@ async function handleLogin( logger: LogWrapper, pathWrapper: NapCatPathWrapper, quickLoginUin: string | undefined, - historyLoginList: any[] + historyLoginList: LoginListItem[] ): Promise { return new Promise((resolve) => { const loginListener = new NodeIKernelLoginListener(); @@ -151,7 +151,7 @@ async function handleLogin( }); }; - loginListener.onQRCodeSessionFailed = (errType: number, errCode: number, errMsg: string) => { + loginListener.onQRCodeSessionFailed = (errType: number, errCode: number) => { if (!isLogined) { logger.logError('[Core] [Login] Login Error,ErrType: ', errType, ' ErrCode:', errCode); if (errType == 1 && errCode == 3) { @@ -232,8 +232,7 @@ async function handleLogin( async function initializeSession( session: NodeIQQNTWrapperSession, - sessionConfig: any, - logger: LogWrapper + sessionConfig: WrapperSessionInitConfig ) { return new Promise((resolve, reject) => { const sessionListener = new NodeIKernelSessionListener(); @@ -252,7 +251,7 @@ async function initializeSession( ); try { session.startNT(0); - } catch (_) { + } catch { try { session.startNT(); } catch (e: unknown) { @@ -290,7 +289,7 @@ export async function NCoreInitShell() { program.option('-q, --qq [number]', 'QQ号').parse(process.argv); const cmdOptions = program.opts(); - const quickLoginUin = cmdOptions.qq; + const quickLoginUin = cmdOptions['qq']; const historyLoginList = (await loginService.getLoginList()).LocalLoginInfoList; const dataTimestape = new Date().getTime().toString(); @@ -312,7 +311,7 @@ export async function NCoreInitShell() { dataPath, ); - await initializeSession(session, sessionConfig, logger); + await initializeSession(session, sessionConfig); const accountDataPath = path.resolve(dataPath, './NapCat/data'); fs.mkdirSync(dataPath, { recursive: true }); diff --git a/src/universal/napcat.ts b/src/universal/napcat.ts index a4559d0c..71710c8d 100644 --- a/src/universal/napcat.ts +++ b/src/universal/napcat.ts @@ -2,12 +2,6 @@ import { NCoreInitShell } from '@/shell/base'; export * from '@/framework/napcat'; export * from '@/shell/base'; -interface LiteLoaderGlobal extends Global { - LiteLoader?: unknown; -} - -declare const global: LiteLoaderGlobal; - -if (global.LiteLoader === undefined) { +if ((global as unknown as { LiteLoader: unknown }).LiteLoader === undefined) { NCoreInitShell(); } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index c5c47900..8e2fcaed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -36,10 +36,10 @@ "strictBindCallApply": true, "alwaysStrict": true, "noImplicitThis": true, - "noImplicitReturns": false, // false for now - "noPropertyAccessFromIndexSignature": false, // false for now + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": true, - "exactOptionalPropertyTypes": true, + "exactOptionalPropertyTypes": false,// 精准可选 "forceConsistentCasingInFileNames": true, "useUnknownInCatchVariables": true, "noImplicitOverride": true,