From 6be0c11ca2005eac28483938791af6acfc73e2bf Mon Sep 17 00:00:00 2001 From: idranme Date: Fri, 13 Sep 2024 22:58:21 +0800 Subject: [PATCH 1/6] refactor --- src/common/utils/audio.ts | 4 +- src/ntqqapi/api/group.ts | 4 +- src/onebot11/action/BaseAction.ts | 39 +++++++------- src/onebot11/action/file/GetFile.ts | 24 +++++---- src/onebot11/action/file/GetImage.ts | 7 --- src/onebot11/action/file/GetRecord.ts | 13 +++-- .../action/go-cqhttp/CreateGroupFileFolder.ts | 8 ++- .../action/go-cqhttp/DelEssenceMsg.ts | 8 +-- src/onebot11/action/go-cqhttp/DelGroupFile.ts | 13 +++-- .../action/go-cqhttp/DelGroupFolder.ts | 8 ++- src/onebot11/action/go-cqhttp/DownloadFile.ts | 7 ++- .../action/go-cqhttp/GetForwardMsg.ts | 2 +- .../action/go-cqhttp/GetGroupAtAllRemain.ts | 4 +- .../action/go-cqhttp/GetGroupMsgHistory.ts | 2 +- .../action/go-cqhttp/GetGroupRootFiles.ts | 4 +- .../action/go-cqhttp/GetGroupSystemMsg.ts | 4 +- .../action/go-cqhttp/GetStrangerInfo.ts | 2 +- .../action/go-cqhttp/MarkMsgAsRead.ts | 2 +- .../action/go-cqhttp/QuickOperation.ts | 4 +- .../action/go-cqhttp/SendForwardMsg.ts | 7 ++- .../action/go-cqhttp/SendGroupNotice.ts | 6 +-- .../action/go-cqhttp/SetEssenceMsg.ts | 2 +- src/onebot11/action/go-cqhttp/UploadFile.ts | 2 +- src/onebot11/action/group/GetGroupEssence.ts | 2 +- .../action/group/GetGroupHonorInfo.ts | 2 +- src/onebot11/action/group/GetGroupInfo.ts | 2 +- src/onebot11/action/group/GetGroupList.ts | 2 +- .../action/group/GetGroupMemberInfo.ts | 2 +- .../action/group/GetGroupMemberList.ts | 2 +- src/onebot11/action/group/GetGuildList.ts | 2 +- src/onebot11/action/group/SendGroupMsg.ts | 6 +-- .../action/group/SetGroupAddRequest.ts | 2 +- src/onebot11/action/group/SetGroupAdmin.ts | 2 +- src/onebot11/action/group/SetGroupBan.ts | 2 +- src/onebot11/action/group/SetGroupCard.ts | 2 +- src/onebot11/action/group/SetGroupKick.ts | 2 +- src/onebot11/action/group/SetGroupLeave.ts | 2 +- src/onebot11/action/group/SetGroupName.ts | 2 +- src/onebot11/action/group/SetGroupWholeBan.ts | 2 +- src/onebot11/action/index.ts | 4 +- src/onebot11/action/llonebot/Config.ts | 4 +- src/onebot11/action/llonebot/Debug.ts | 2 +- src/onebot11/action/llonebot/GetEvent.ts | 2 +- .../action/llonebot/GetGroupAddRequest.ts | 2 +- .../action/llonebot/GetProfileLike.ts | 4 +- .../action/llonebot/SetOnlineStatus.ts | 4 +- src/onebot11/action/llonebot/SetQQAvatar.ts | 4 +- src/onebot11/action/msg/DeleteMsg.ts | 2 +- src/onebot11/action/msg/ForwardSingleMsg.ts | 2 +- src/onebot11/action/msg/GetMsg.ts | 2 +- src/onebot11/action/msg/SendMsg.ts | 25 +-------- src/onebot11/action/msg/SendPrivateMsg.ts | 6 +-- src/onebot11/action/msg/SetMsgEmojiLike.ts | 2 +- src/onebot11/action/system/CanSendRecord.ts | 2 +- src/onebot11/action/system/CleanCache.ts | 4 +- src/onebot11/action/system/GetLoginInfo.ts | 2 +- src/onebot11/action/system/GetStatus.ts | 2 +- src/onebot11/action/system/GetVersionInfo.ts | 2 +- src/onebot11/action/user/GetCookie.ts | 52 +++++++++---------- src/onebot11/action/user/GetFriendList.ts | 4 +- src/onebot11/action/user/SendLike.ts | 2 +- .../action/user/SetFriendAddRequest.ts | 3 +- src/onebot11/connect/http.ts | 4 +- src/onebot11/connect/ws.ts | 4 +- 64 files changed, 176 insertions(+), 182 deletions(-) diff --git a/src/common/utils/audio.ts b/src/common/utils/audio.ts index 919766b..fce6ad0 100644 --- a/src/common/utils/audio.ts +++ b/src/common/utils/audio.ts @@ -101,7 +101,7 @@ export async function encodeSilk(ctx: Context, filePath: string) { type OutFormat = 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac' -export async function decodeSilk(ctx: Context, inputFilePath: string, outFormat: OutFormat = 'mp3') { +export async function decodeSilk(ctx: Context, inputFilePath: string, outFormat: OutFormat) { const silk = await fsPromise.readFile(inputFilePath) const { data } = await decode(silk, 24000) const tmpPath = path.join(TEMP_DIR, path.basename(inputFilePath)) @@ -115,4 +115,4 @@ export async function decodeSilk(ctx: Context, inputFilePath: string, outFormat: '-ac 1' ] }, outFilePath) -} \ No newline at end of file +} diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index 546c2ba..fc4b50c 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -265,8 +265,8 @@ export class NTQQGroupApi extends Service { return await invoke('nodeIKernelRichMediaService/deleteGroupFolder', [{ groupId, folderId }, null]) } - async deleteGroupFile(groupId: string, fileIdList: string[]) { - return await invoke('nodeIKernelRichMediaService/deleteGroupFile', [{ groupId, busIdList: [102], fileIdList }, null]) + async deleteGroupFile(groupId: string, fileIdList: string[], busIdList: number[]) { + return await invoke('nodeIKernelRichMediaService/deleteGroupFile', [{ groupId, busIdList, fileIdList }, null]) } async getGroupFileList(groupId: string, fileListForm: GetFileListParam) { diff --git a/src/onebot11/action/BaseAction.ts b/src/onebot11/action/BaseAction.ts index 86e2a71..7eb0b82 100644 --- a/src/onebot11/action/BaseAction.ts +++ b/src/onebot11/action/BaseAction.ts @@ -1,44 +1,43 @@ -import { ActionName, BaseCheckResult } from './types' +import { ActionName } from './types' import { OB11Response } from './OB11Response' import { OB11Return } from '../types' -import { Context } from 'cordis' +import { Context, Schema } from 'cordis' import type Adapter from '../adapter' abstract class BaseAction { abstract actionName: ActionName protected ctx: Context + payloadSchema?: Schema constructor(protected adapter: Adapter) { this.ctx = adapter.ctx } - protected async check(payload: PayloadType): Promise { - return { - valid: true, - } - } - public async handle(payload: PayloadType): Promise> { - const result = await this.check(payload) - if (!result.valid) { - return OB11Response.error(result.message, 400) + let params: PayloadType + try { + params = this.payloadSchema ? new this.payloadSchema(payload) : payload + } catch (e) { + return OB11Response.error((e as Error).message, 400) } try { - const resData = await this._handle(payload) + const resData = await this._handle(params) return OB11Response.ok(resData) } catch (e) { this.ctx.logger.error('发生错误', e) - return OB11Response.error(e?.toString() || (e as Error)?.stack?.toString() || '未知错误,可能操作超时', 200) + return OB11Response.error((e as Error)?.toString() || (e as Error)?.stack?.toString() || '未知错误,可能操作超时', 200) } } public async websocketHandle(payload: PayloadType, echo: unknown): Promise> { - const result = await this.check(payload) - if (!result.valid) { - return OB11Response.error(result.message, 1400) + let params: PayloadType + try { + params = this.payloadSchema ? new this.payloadSchema(payload) : payload + } catch (e) { + return OB11Response.error((e as Error).message, 1400) } try { - const resData = await this._handle(payload) + const resData = await this._handle(params) return OB11Response.ok(resData, echo) } catch (e) { this.ctx.logger.error('发生错误', e) @@ -46,9 +45,7 @@ abstract class BaseAction { } } - protected async _handle(payload: PayloadType): Promise { - throw `pleas override ${this.actionName} _handle` - } + protected abstract _handle(payload: PayloadType): Promise } -export default BaseAction +export { BaseAction, Schema } diff --git a/src/onebot11/action/file/GetFile.ts b/src/onebot11/action/file/GetFile.ts index 24fd776..07c37e8 100644 --- a/src/onebot11/action/file/GetFile.ts +++ b/src/onebot11/action/file/GetFile.ts @@ -1,5 +1,5 @@ -import BaseAction from '../BaseAction' -import fsPromise from 'node:fs/promises' +import { BaseAction, Schema } from '../BaseAction' +import { readFile } from 'node:fs/promises' import { ActionName } from '../types' import { Peer, ElementType } from '@/ntqqapi/types' import { MessageUnique } from '@/common/utils/messageUnique' @@ -17,13 +17,16 @@ export interface GetFileResponse { } export abstract class GetFileBase extends BaseAction { - // forked from https://github.com/NapNeko/NapCatQQ/blob/6f6b258f22d7563f15d84e7172c4d4cbb547f47e/src/onebot11/action/file/GetFile.ts#L44 + payloadSchema = Schema.object({ + file: Schema.string().required() + }) + protected async _handle(payload: GetFilePayload): Promise { const { enableLocalFile2Url } = this.adapter.config - let fileCache = await MessageUnique.getFileCacheById(String(payload.file)) + let fileCache = await MessageUnique.getFileCacheById(payload.file) if (!fileCache?.length) { - fileCache = await MessageUnique.getFileCacheByName(String(payload.file)) + fileCache = await MessageUnique.getFileCacheByName(payload.file) } if (fileCache?.length) { @@ -62,7 +65,7 @@ export abstract class GetFileBase extends BaseAction { - if (!payload.file_id) { - throw new Error('file_id 不能为空') - } + protected async _handle(payload: { file_id: string, file: string }): Promise { payload.file = payload.file_id return super._handle(payload) } diff --git a/src/onebot11/action/file/GetImage.ts b/src/onebot11/action/file/GetImage.ts index 56f0288..d51ba67 100644 --- a/src/onebot11/action/file/GetImage.ts +++ b/src/onebot11/action/file/GetImage.ts @@ -3,11 +3,4 @@ import { ActionName } from '../types' export default class GetImage extends GetFileBase { actionName = ActionName.GetImage - - protected async _handle(payload: { file: string }) { - if (!payload.file) { - throw new Error('参数 file 不能为空') - } - return super._handle(payload) - } } diff --git a/src/onebot11/action/file/GetRecord.ts b/src/onebot11/action/file/GetRecord.ts index 48e765f..27efbbc 100644 --- a/src/onebot11/action/file/GetRecord.ts +++ b/src/onebot11/action/file/GetRecord.ts @@ -1,8 +1,9 @@ +import path from 'node:path' import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile' import { ActionName } from '../types' import { decodeSilk } from '@/common/utils/audio' -import path from 'node:path' -import fs from 'node:fs' +import { Schema } from '../BaseAction' +import { stat, readFile } from 'node:fs/promises' interface Payload extends GetFilePayload { out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac' @@ -10,14 +11,18 @@ interface Payload extends GetFilePayload { export default class GetRecord extends GetFileBase { actionName = ActionName.GetRecord + payloadSchema = Schema.object({ + file: Schema.string().required(), + out_format: Schema.string().default('mp3') + }) protected async _handle(payload: Payload): Promise { const res = await super._handle(payload) res.file = await decodeSilk(this.ctx, res.file!, payload.out_format) res.file_name = path.basename(res.file) - res.file_size = fs.statSync(res.file).size.toString() + res.file_size = (await stat(res.file)).size.toString() if (this.adapter.config.enableLocalFile2Url) { - res.base64 = fs.readFileSync(res.file, 'base64') + res.base64 = await readFile(res.file, 'base64') } return res } diff --git a/src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts b/src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts index ef81d33..b7d3eca 100644 --- a/src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts +++ b/src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' interface Payload { @@ -9,9 +9,13 @@ interface Payload { export class CreateGroupFileFolder extends BaseAction { actionName = ActionName.GoCQHTTP_CreateGroupFileFolder + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required(), + name: Schema.string().required(), + }) async _handle(payload: Payload) { await this.ctx.ntGroupApi.createGroupFileFolder(payload.group_id.toString(), payload.name) return null } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts b/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts index 711689b..f96c09a 100644 --- a/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts +++ b/src/onebot11/action/go-cqhttp/DelEssenceMsg.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { MessageUnique } from '@/common/utils/messageUnique' @@ -8,11 +8,11 @@ interface Payload { export class DelEssenceMsg extends BaseAction { actionName = ActionName.GoCQHTTP_DelEssenceMsg + payloadSchema = Schema.object({ + message_id: Schema.union([Number, String]).required() + }) protected async _handle(payload: Payload) { - if (!payload.message_id) { - throw Error('message_id不能为空') - } const msg = await MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id) if (!msg) { throw new Error('msg not found') diff --git a/src/onebot11/action/go-cqhttp/DelGroupFile.ts b/src/onebot11/action/go-cqhttp/DelGroupFile.ts index e883390..b9a4a25 100644 --- a/src/onebot11/action/go-cqhttp/DelGroupFile.ts +++ b/src/onebot11/action/go-cqhttp/DelGroupFile.ts @@ -1,17 +1,22 @@ -import BaseAction from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' interface Payload { group_id: string | number file_id: string - busid?: 102 + busid: number } export class DelGroupFile extends BaseAction { actionName = ActionName.GoCQHTTP_DelGroupFile + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required(), + file_id: Schema.string().required(), + busid: Schema.number().default(102) + }) async _handle(payload: Payload) { - await this.ctx.ntGroupApi.deleteGroupFile(payload.group_id.toString(), [payload.file_id]) + await this.ctx.ntGroupApi.deleteGroupFile(payload.group_id.toString(), [payload.file_id], [payload.busid]) return null } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/DelGroupFolder.ts b/src/onebot11/action/go-cqhttp/DelGroupFolder.ts index 2cb3984..33b30f6 100644 --- a/src/onebot11/action/go-cqhttp/DelGroupFolder.ts +++ b/src/onebot11/action/go-cqhttp/DelGroupFolder.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' interface Payload { @@ -8,9 +8,13 @@ interface Payload { export class DelGroupFolder extends BaseAction { actionName = ActionName.GoCQHTTP_DelGroupFolder + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required(), + folder_id: Schema.string().required() + }) async _handle(payload: Payload) { await this.ctx.ntGroupApi.deleteGroupFileFolder(payload.group_id.toString(), payload.folder_id) return null } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/DownloadFile.ts b/src/onebot11/action/go-cqhttp/DownloadFile.ts index d8a5a9e..d94a866 100644 --- a/src/onebot11/action/go-cqhttp/DownloadFile.ts +++ b/src/onebot11/action/go-cqhttp/DownloadFile.ts @@ -1,7 +1,7 @@ -import BaseAction from '../BaseAction' import fs from 'fs' import fsPromise from 'fs/promises' import path from 'node:path' +import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { calculateFileMD5, fetchFile } from '@/common/utils' import { TEMP_DIR } from '@/common/globalVars' @@ -22,6 +22,11 @@ interface FileResponse { export class DownloadFile extends BaseAction { actionName = ActionName.GoCQHTTP_DownloadFile + payloadSchema = Schema.object({ + url: String, + base64: String, + headers: Schema.union([String, Schema.array(String)]) + }) protected async _handle(payload: Payload): Promise { const isRandomName = !payload.name diff --git a/src/onebot11/action/go-cqhttp/GetForwardMsg.ts b/src/onebot11/action/go-cqhttp/GetForwardMsg.ts index 39eac8b..4e16cff 100644 --- a/src/onebot11/action/go-cqhttp/GetForwardMsg.ts +++ b/src/onebot11/action/go-cqhttp/GetForwardMsg.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11ForwardMessage } from '../../types' import { OB11Entities } from '../../entities' import { ActionName } from '../types' diff --git a/src/onebot11/action/go-cqhttp/GetGroupAtAllRemain.ts b/src/onebot11/action/go-cqhttp/GetGroupAtAllRemain.ts index 840d725..d39032a 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupAtAllRemain.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupAtAllRemain.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { @@ -22,4 +22,4 @@ export class GetGroupAtAllRemain extends BaseAction { remain_at_all_count_for_uin: data.atInfo.RemainAtAllCountForUin } } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts index 74cf1f6..5227976 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11Message } from '../../types' import { ActionName } from '../types' import { ChatType } from '@/ntqqapi/types' diff --git a/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts b/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts index 3617088..65952f9 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { OB11GroupFile, OB11GroupFileFolder } from '../../types' @@ -59,4 +59,4 @@ export class GetGroupRootFiles extends BaseAction { }) } } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts b/src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts index ecf8c2c..6ccf040 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { GroupNotifyStatus } from '@/ntqqapi/types' import { ActionName } from '../types' @@ -56,4 +56,4 @@ export class GetGroupSystemMsg extends BaseAction { } return data } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts b/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts index 03f9c34..4980bb7 100644 --- a/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts +++ b/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11User } from '../../types' import { OB11Entities } from '../../entities' import { ActionName } from '../types' diff --git a/src/onebot11/action/go-cqhttp/MarkMsgAsRead.ts b/src/onebot11/action/go-cqhttp/MarkMsgAsRead.ts index 6fd9490..faaeb64 100644 --- a/src/onebot11/action/go-cqhttp/MarkMsgAsRead.ts +++ b/src/onebot11/action/go-cqhttp/MarkMsgAsRead.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { MessageUnique } from '@/common/utils/messageUnique' diff --git a/src/onebot11/action/go-cqhttp/QuickOperation.ts b/src/onebot11/action/go-cqhttp/QuickOperation.ts index a416444..fc2c080 100644 --- a/src/onebot11/action/go-cqhttp/QuickOperation.ts +++ b/src/onebot11/action/go-cqhttp/QuickOperation.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { handleQuickOperation, QuickOperation, QuickOperationEvent } from '../../helper/quickOperation' import { ActionName } from '../types' @@ -13,4 +13,4 @@ export class HandleQuickOperation extends BaseAction { handleQuickOperation(this.ctx, payload.context, payload.operation).catch(e => this.ctx.logger.error(e)) return null } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/SendForwardMsg.ts b/src/onebot11/action/go-cqhttp/SendForwardMsg.ts index 4e7b73d..d9476f4 100644 --- a/src/onebot11/action/go-cqhttp/SendForwardMsg.ts +++ b/src/onebot11/action/go-cqhttp/SendForwardMsg.ts @@ -1,14 +1,13 @@ import SendMsg from '../msg/SendMsg' import { OB11PostSendMsg } from '../../types' import { ActionName } from '../types' -import { convertMessage2List } from '../../helper/createMessage' export class SendForwardMsg extends SendMsg { actionName = ActionName.GoCQHTTP_SendForwardMsg - protected async check(payload: OB11PostSendMsg) { - if (payload.messages) payload.message = convertMessage2List(payload.messages) - return super.check(payload) + protected async _handle(payload: OB11PostSendMsg) { + if (payload.messages) payload.message = payload.messages + return super._handle(payload) } } diff --git a/src/onebot11/action/go-cqhttp/SendGroupNotice.ts b/src/onebot11/action/go-cqhttp/SendGroupNotice.ts index 9fe8995..9bac373 100644 --- a/src/onebot11/action/go-cqhttp/SendGroupNotice.ts +++ b/src/onebot11/action/go-cqhttp/SendGroupNotice.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { unlink } from 'fs/promises' import { checkFileReceived, uri2local } from '@/common/utils/file' @@ -15,7 +15,7 @@ export class SendGroupNotice extends BaseAction { actionName = ActionName.GoCQHTTP_SendGroupNotice async _handle(payload: Payload) { - if(!payload.content){ + if (!payload.content) { throw new Error('参数 content 不能为空') } const groupCode = payload.group_id.toString() @@ -51,4 +51,4 @@ export class SendGroupNotice extends BaseAction { } return null } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts b/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts index bfe562b..db11d7a 100644 --- a/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts +++ b/src/onebot11/action/go-cqhttp/SetEssenceMsg.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { MessageUnique } from '@/common/utils/messageUnique' diff --git a/src/onebot11/action/go-cqhttp/UploadFile.ts b/src/onebot11/action/go-cqhttp/UploadFile.ts index e612019..c52b36f 100644 --- a/src/onebot11/action/go-cqhttp/UploadFile.ts +++ b/src/onebot11/action/go-cqhttp/UploadFile.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { SendElementEntities } from '@/ntqqapi/entities' import { uri2local } from '@/common/utils' diff --git a/src/onebot11/action/group/GetGroupEssence.ts b/src/onebot11/action/group/GetGroupEssence.ts index 8953e97..13363e1 100644 --- a/src/onebot11/action/group/GetGroupEssence.ts +++ b/src/onebot11/action/group/GetGroupEssence.ts @@ -1,5 +1,5 @@ import { GroupEssenceMsgRet } from '@/ntqqapi/api' -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface PayloadType { diff --git a/src/onebot11/action/group/GetGroupHonorInfo.ts b/src/onebot11/action/group/GetGroupHonorInfo.ts index 4fd781e..867c06a 100644 --- a/src/onebot11/action/group/GetGroupHonorInfo.ts +++ b/src/onebot11/action/group/GetGroupHonorInfo.ts @@ -1,6 +1,6 @@ import { WebHonorType } from '@/ntqqapi/api' import { ActionName } from '../types' -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' interface Payload { group_id: number diff --git a/src/onebot11/action/group/GetGroupInfo.ts b/src/onebot11/action/group/GetGroupInfo.ts index 3d8f8b6..30d0357 100644 --- a/src/onebot11/action/group/GetGroupInfo.ts +++ b/src/onebot11/action/group/GetGroupInfo.ts @@ -1,6 +1,6 @@ import { OB11Group } from '../../types' import { OB11Entities } from '../../entities' -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/group/GetGroupList.ts b/src/onebot11/action/group/GetGroupList.ts index d931247..7bacbef 100644 --- a/src/onebot11/action/group/GetGroupList.ts +++ b/src/onebot11/action/group/GetGroupList.ts @@ -1,6 +1,6 @@ import { OB11Group } from '../../types' import { OB11Entities } from '../../entities' -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/group/GetGroupMemberInfo.ts b/src/onebot11/action/group/GetGroupMemberInfo.ts index b4d153d..e47b1be 100644 --- a/src/onebot11/action/group/GetGroupMemberInfo.ts +++ b/src/onebot11/action/group/GetGroupMemberInfo.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11GroupMember } from '../../types' import { OB11Entities } from '../../entities' import { ActionName } from '../types' diff --git a/src/onebot11/action/group/GetGroupMemberList.ts b/src/onebot11/action/group/GetGroupMemberList.ts index 9ffc178..3bf2127 100644 --- a/src/onebot11/action/group/GetGroupMemberList.ts +++ b/src/onebot11/action/group/GetGroupMemberList.ts @@ -1,6 +1,6 @@ import { OB11GroupMember } from '../../types' import { OB11Entities } from '../../entities' -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { selfInfo } from '@/common/globalVars' diff --git a/src/onebot11/action/group/GetGuildList.ts b/src/onebot11/action/group/GetGuildList.ts index 8ef385e..0693e91 100644 --- a/src/onebot11/action/group/GetGuildList.ts +++ b/src/onebot11/action/group/GetGuildList.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' export default class GetGuildList extends BaseAction { diff --git a/src/onebot11/action/group/SendGroupMsg.ts b/src/onebot11/action/group/SendGroupMsg.ts index 6da8813..bd363bf 100644 --- a/src/onebot11/action/group/SendGroupMsg.ts +++ b/src/onebot11/action/group/SendGroupMsg.ts @@ -1,14 +1,14 @@ import SendMsg from '../msg/SendMsg' -import { ActionName, BaseCheckResult } from '../types' +import { ActionName } from '../types' import { OB11PostSendMsg } from '../../types' class SendGroupMsg extends SendMsg { actionName = ActionName.SendGroupMsg - protected async check(payload: OB11PostSendMsg): Promise { + protected _handle(payload: OB11PostSendMsg) { delete (payload as Partial).user_id payload.message_type = 'group' - return super.check(payload) + return super._handle(payload) } } diff --git a/src/onebot11/action/group/SetGroupAddRequest.ts b/src/onebot11/action/group/SetGroupAddRequest.ts index 6834c11..c20526b 100644 --- a/src/onebot11/action/group/SetGroupAddRequest.ts +++ b/src/onebot11/action/group/SetGroupAddRequest.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { GroupRequestOperateTypes } from '@/ntqqapi/types' import { ActionName } from '../types' diff --git a/src/onebot11/action/group/SetGroupAdmin.ts b/src/onebot11/action/group/SetGroupAdmin.ts index d110b80..30596d4 100644 --- a/src/onebot11/action/group/SetGroupAdmin.ts +++ b/src/onebot11/action/group/SetGroupAdmin.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { GroupMemberRole } from '@/ntqqapi/types' import { ActionName } from '../types' diff --git a/src/onebot11/action/group/SetGroupBan.ts b/src/onebot11/action/group/SetGroupBan.ts index e393163..e8e4cf7 100644 --- a/src/onebot11/action/group/SetGroupBan.ts +++ b/src/onebot11/action/group/SetGroupBan.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/group/SetGroupCard.ts b/src/onebot11/action/group/SetGroupCard.ts index c8af245..980c443 100644 --- a/src/onebot11/action/group/SetGroupCard.ts +++ b/src/onebot11/action/group/SetGroupCard.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/group/SetGroupKick.ts b/src/onebot11/action/group/SetGroupKick.ts index f678da6..421ed6c 100644 --- a/src/onebot11/action/group/SetGroupKick.ts +++ b/src/onebot11/action/group/SetGroupKick.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/group/SetGroupLeave.ts b/src/onebot11/action/group/SetGroupLeave.ts index cf0b7be..bd1d977 100644 --- a/src/onebot11/action/group/SetGroupLeave.ts +++ b/src/onebot11/action/group/SetGroupLeave.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/group/SetGroupName.ts b/src/onebot11/action/group/SetGroupName.ts index 827d9a8..ea460de 100644 --- a/src/onebot11/action/group/SetGroupName.ts +++ b/src/onebot11/action/group/SetGroupName.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/group/SetGroupWholeBan.ts b/src/onebot11/action/group/SetGroupWholeBan.ts index 2da92e9..52fbd80 100644 --- a/src/onebot11/action/group/SetGroupWholeBan.ts +++ b/src/onebot11/action/group/SetGroupWholeBan.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 756246b..c5ddccf 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -10,7 +10,7 @@ import SendGroupMsg from './group/SendGroupMsg' import SendPrivateMsg from './msg/SendPrivateMsg' import SendMsg from './msg/SendMsg' import DeleteMsg from './msg/DeleteMsg' -import BaseAction from './BaseAction' +import { BaseAction } from './BaseAction' import GetVersionInfo from './system/GetVersionInfo' import CanSendRecord from './system/CanSendRecord' import CanSendImage from './system/CanSendImage' @@ -134,7 +134,7 @@ export function initActionMap(adapter: Adapter) { new GetGroupRootFiles(adapter), new SendGroupNotice(adapter) ] - const actionMap = new Map>() + const actionMap = new Map>() for (const action of actionHandlers) { actionMap.set(action.actionName, action) actionMap.set(action.actionName + '_async', action) diff --git a/src/onebot11/action/llonebot/Config.ts b/src/onebot11/action/llonebot/Config.ts index ce663a6..23fd8b6 100644 --- a/src/onebot11/action/llonebot/Config.ts +++ b/src/onebot11/action/llonebot/Config.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { Config } from '@/common/types' import { ActionName } from '../types' import { getConfigUtil } from '@/common/config' @@ -13,7 +13,7 @@ export class GetConfigAction extends BaseAction { export class SetConfigAction extends BaseAction { actionName = ActionName.SetConfig - + protected async _handle(payload: Config): Promise { getConfigUtil().setConfig(payload) } diff --git a/src/onebot11/action/llonebot/Debug.ts b/src/onebot11/action/llonebot/Debug.ts index 0bca979..35ab94e 100644 --- a/src/onebot11/action/llonebot/Debug.ts +++ b/src/onebot11/action/llonebot/Debug.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/llonebot/GetEvent.ts b/src/onebot11/action/llonebot/GetEvent.ts index 808d8cd..8cb3aed 100644 --- a/src/onebot11/action/llonebot/GetEvent.ts +++ b/src/onebot11/action/llonebot/GetEvent.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { getHttpEvent } from '../../helper/eventForHttp' import { OB11Message } from '../../types' diff --git a/src/onebot11/action/llonebot/GetGroupAddRequest.ts b/src/onebot11/action/llonebot/GetGroupAddRequest.ts index 33b9988..147b074 100644 --- a/src/onebot11/action/llonebot/GetGroupAddRequest.ts +++ b/src/onebot11/action/llonebot/GetGroupAddRequest.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { GroupNotify, GroupNotifyStatus } from '@/ntqqapi/types' import { ActionName } from '../types' diff --git a/src/onebot11/action/llonebot/GetProfileLike.ts b/src/onebot11/action/llonebot/GetProfileLike.ts index af08e02..5f6a3e7 100644 --- a/src/onebot11/action/llonebot/GetProfileLike.ts +++ b/src/onebot11/action/llonebot/GetProfileLike.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import { selfInfo } from '@/common/globalVars' import { Dict } from 'cosmokit' @@ -14,4 +14,4 @@ export class GetProfileLike extends BaseAction { } return listdata } -} \ No newline at end of file +} diff --git a/src/onebot11/action/llonebot/SetOnlineStatus.ts b/src/onebot11/action/llonebot/SetOnlineStatus.ts index 98e67e2..e6015b0 100644 --- a/src/onebot11/action/llonebot/SetOnlineStatus.ts +++ b/src/onebot11/action/llonebot/SetOnlineStatus.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { @@ -22,4 +22,4 @@ export class SetOnlineStatus extends BaseAction { } return null } -} \ No newline at end of file +} diff --git a/src/onebot11/action/llonebot/SetQQAvatar.ts b/src/onebot11/action/llonebot/SetQQAvatar.ts index ac10163..b79b391 100644 --- a/src/onebot11/action/llonebot/SetQQAvatar.ts +++ b/src/onebot11/action/llonebot/SetQQAvatar.ts @@ -1,6 +1,6 @@ -import BaseAction from '../BaseAction' +import fs from 'node:fs' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' -import * as fs from 'node:fs' import { checkFileReceived, uri2local } from '../../../common/utils/file' interface Payload { diff --git a/src/onebot11/action/msg/DeleteMsg.ts b/src/onebot11/action/msg/DeleteMsg.ts index df01185..693d6aa 100644 --- a/src/onebot11/action/msg/DeleteMsg.ts +++ b/src/onebot11/action/msg/DeleteMsg.ts @@ -1,5 +1,5 @@ import { ActionName } from '../types' -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { MessageUnique } from '@/common/utils/messageUnique' interface Payload { diff --git a/src/onebot11/action/msg/ForwardSingleMsg.ts b/src/onebot11/action/msg/ForwardSingleMsg.ts index d58c15b..8ec616b 100644 --- a/src/onebot11/action/msg/ForwardSingleMsg.ts +++ b/src/onebot11/action/msg/ForwardSingleMsg.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ChatType } from '@/ntqqapi/types' import { ActionName } from '../types' import { Peer } from '@/ntqqapi/types' diff --git a/src/onebot11/action/msg/GetMsg.ts b/src/onebot11/action/msg/GetMsg.ts index 02171c6..365ea04 100644 --- a/src/onebot11/action/msg/GetMsg.ts +++ b/src/onebot11/action/msg/GetMsg.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11Message } from '../../types' import { OB11Entities } from '../../entities' import { ActionName } from '../types' diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index cf73588..e44e5ae 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -14,8 +14,8 @@ import { OB11PostSendMsg, } from '../../types' import fs from 'node:fs' -import BaseAction from '../BaseAction' -import { ActionName, BaseCheckResult } from '../types' +import { BaseAction } from '../BaseAction' +import { ActionName } from '../types' import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '@/common/utils/sign' import { Peer } from '@/ntqqapi/types/msg' import { MessageUnique } from '@/common/utils/messageUnique' @@ -29,27 +29,6 @@ interface ReturnData { export class SendMsg extends BaseAction { actionName = ActionName.SendMsg - protected async check(payload: OB11PostSendMsg): Promise { - const messages = convertMessage2List(payload.message) - const fmNum = this.getSpecialMsgNum(messages, OB11MessageDataType.node) - if (fmNum && fmNum != messages.length) { - return { - valid: false, - message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素', - } - } - const musicNum = this.getSpecialMsgNum(messages, OB11MessageDataType.music) - if (musicNum && messages.length > 1) { - return { - valid: false, - message: '音乐消息不可以和其他消息混在一起发送', - } - } - return { - valid: true, - } - } - protected async _handle(payload: OB11PostSendMsg) { let contextMode = CreatePeerMode.Normal if (payload.message_type === 'group') { diff --git a/src/onebot11/action/msg/SendPrivateMsg.ts b/src/onebot11/action/msg/SendPrivateMsg.ts index e24aa53..682f7f9 100644 --- a/src/onebot11/action/msg/SendPrivateMsg.ts +++ b/src/onebot11/action/msg/SendPrivateMsg.ts @@ -1,13 +1,13 @@ import SendMsg from './SendMsg' -import { ActionName, BaseCheckResult } from '../types' +import { ActionName } from '../types' import { OB11PostSendMsg } from '../../types' class SendPrivateMsg extends SendMsg { actionName = ActionName.SendPrivateMsg - protected async check(payload: OB11PostSendMsg): Promise { + protected _handle(payload: OB11PostSendMsg) { payload.message_type = 'private' - return super.check(payload) + return super._handle(payload) } } diff --git a/src/onebot11/action/msg/SetMsgEmojiLike.ts b/src/onebot11/action/msg/SetMsgEmojiLike.ts index 3693d29..2f8c694 100644 --- a/src/onebot11/action/msg/SetMsgEmojiLike.ts +++ b/src/onebot11/action/msg/SetMsgEmojiLike.ts @@ -1,5 +1,5 @@ import { ActionName } from '../types' -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { MessageUnique } from '@/common/utils/messageUnique' interface Payload { diff --git a/src/onebot11/action/system/CanSendRecord.ts b/src/onebot11/action/system/CanSendRecord.ts index 665d5fb..daeb110 100644 --- a/src/onebot11/action/system/CanSendRecord.ts +++ b/src/onebot11/action/system/CanSendRecord.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface ReturnType { diff --git a/src/onebot11/action/system/CleanCache.ts b/src/onebot11/action/system/CleanCache.ts index 8614d24..081ec17 100644 --- a/src/onebot11/action/system/CleanCache.ts +++ b/src/onebot11/action/system/CleanCache.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' import fs from 'node:fs' import Path from 'node:path' @@ -82,4 +82,4 @@ function deleteCachePath(pathList: string[]) { for (const path of pathList) { emptyPath(path) } -} \ No newline at end of file +} diff --git a/src/onebot11/action/system/GetLoginInfo.ts b/src/onebot11/action/system/GetLoginInfo.ts index 5255222..f47c904 100644 --- a/src/onebot11/action/system/GetLoginInfo.ts +++ b/src/onebot11/action/system/GetLoginInfo.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11User } from '../../types' import { ActionName } from '../types' import { selfInfo } from '@/common/globalVars' diff --git a/src/onebot11/action/system/GetStatus.ts b/src/onebot11/action/system/GetStatus.ts index 1a3962c..9590d3a 100644 --- a/src/onebot11/action/system/GetStatus.ts +++ b/src/onebot11/action/system/GetStatus.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11Status } from '../../types' import { ActionName } from '../types' import { selfInfo } from '@/common/globalVars' diff --git a/src/onebot11/action/system/GetVersionInfo.ts b/src/onebot11/action/system/GetVersionInfo.ts index cc818b0..6769d00 100644 --- a/src/onebot11/action/system/GetVersionInfo.ts +++ b/src/onebot11/action/system/GetVersionInfo.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11Version } from '../../types' import { ActionName } from '../types' import { version } from '../../../version' diff --git a/src/onebot11/action/user/GetCookie.ts b/src/onebot11/action/user/GetCookie.ts index e0bd672..e23cf5b 100644 --- a/src/onebot11/action/user/GetCookie.ts +++ b/src/onebot11/action/user/GetCookie.ts @@ -1,26 +1,26 @@ -import BaseAction from '../BaseAction' -import { ActionName } from '../types' - -interface Response { - cookies: string - bkn: string -} - -interface Payload { - domain: string -} - -export class GetCookies extends BaseAction { - actionName = ActionName.GetCookies - - protected async _handle(payload: Payload) { - if (!payload.domain) { - throw '缺少参数 domain' - } - const cookiesObject = await this.ctx.ntUserApi.getCookies(payload.domain) - //把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起 - const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ') - const bkn = cookiesObject.skey ? this.ctx.ntWebApi.genBkn(cookiesObject.skey) : '' - return { cookies, bkn } - } -} +import { BaseAction } from '../BaseAction' +import { ActionName } from '../types' + +interface Response { + cookies: string + bkn: string +} + +interface Payload { + domain: string +} + +export class GetCookies extends BaseAction { + actionName = ActionName.GetCookies + + protected async _handle(payload: Payload) { + if (!payload.domain) { + throw '缺少参数 domain' + } + const cookiesObject = await this.ctx.ntUserApi.getCookies(payload.domain) + //把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起 + const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ') + const bkn = cookiesObject.skey ? this.ctx.ntWebApi.genBkn(cookiesObject.skey) : '' + return { cookies, bkn } + } +} diff --git a/src/onebot11/action/user/GetFriendList.ts b/src/onebot11/action/user/GetFriendList.ts index 7bbead3..a2fd1e8 100644 --- a/src/onebot11/action/user/GetFriendList.ts +++ b/src/onebot11/action/user/GetFriendList.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { OB11User } from '../../types' import { OB11Entities } from '../../entities' import { ActionName } from '../types' @@ -32,4 +32,4 @@ export class GetFriendWithCategory extends BaseAction { throw new Error('this ntqq version not support, must be 26702 or later') } } -} \ No newline at end of file +} diff --git a/src/onebot11/action/user/SendLike.ts b/src/onebot11/action/user/SendLike.ts index d63ff4f..2eb8551 100644 --- a/src/onebot11/action/user/SendLike.ts +++ b/src/onebot11/action/user/SendLike.ts @@ -1,4 +1,4 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' interface Payload { diff --git a/src/onebot11/action/user/SetFriendAddRequest.ts b/src/onebot11/action/user/SetFriendAddRequest.ts index 80116e8..65330a5 100644 --- a/src/onebot11/action/user/SetFriendAddRequest.ts +++ b/src/onebot11/action/user/SetFriendAddRequest.ts @@ -1,6 +1,5 @@ -import BaseAction from '../BaseAction' +import { BaseAction } from '../BaseAction' import { ActionName } from '../types' -import { NTQQFriendApi } from '../../../ntqqapi/api/friend' interface Payload { flag: string diff --git a/src/onebot11/connect/http.ts b/src/onebot11/connect/http.ts index 433f136..9f20763 100644 --- a/src/onebot11/connect/http.ts +++ b/src/onebot11/connect/http.ts @@ -1,8 +1,8 @@ -import BaseAction from '../action/BaseAction' import http from 'node:http' import cors from 'cors' import crypto from 'node:crypto' import express, { Express, Request, Response } from 'express' +import { BaseAction } from '../action/BaseAction' import { Context } from 'cordis' import { llonebotError, selfInfo } from '@/common/globalVars' import { OB11Response } from '../action/OB11Response' @@ -211,4 +211,4 @@ namespace OB11HttpPost { } } -export { OB11Http, OB11HttpPost } \ No newline at end of file +export { OB11Http, OB11HttpPost } diff --git a/src/onebot11/connect/ws.ts b/src/onebot11/connect/ws.ts index cc81331..9ea9e82 100644 --- a/src/onebot11/connect/ws.ts +++ b/src/onebot11/connect/ws.ts @@ -1,4 +1,4 @@ -import BaseAction from '../action/BaseAction' +import { BaseAction } from '../action/BaseAction' import { Context } from 'cordis' import { WebSocket, WebSocketServer } from 'ws' import { llonebotError } from '@/common/globalVars' @@ -339,4 +339,4 @@ namespace OB11WebSocketReverseManager { } } -export { OB11WebSocket, OB11WebSocketReverseManager } \ No newline at end of file +export { OB11WebSocket, OB11WebSocketReverseManager } From cad09b2ed1c481ac7a204bca493e7613199edac7 Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 14 Sep 2024 19:56:46 +0800 Subject: [PATCH 2/6] fix --- src/ntqqapi/proto/compiled.d.ts | 66 +++++++++++- src/ntqqapi/proto/compiled.js | 134 +++++++++++++++++++++++-- src/ntqqapi/proto/profileLikeTip.proto | 22 ++-- src/onebot11/adapter.ts | 5 +- 4 files changed, 207 insertions(+), 20 deletions(-) diff --git a/src/ntqqapi/proto/compiled.d.ts b/src/ntqqapi/proto/compiled.d.ts index f2a9951..ee5b5f7 100644 --- a/src/ntqqapi/proto/compiled.d.ts +++ b/src/ntqqapi/proto/compiled.d.ts @@ -363,11 +363,63 @@ export namespace SysMsg { public static getTypeUrl(typeUrlPrefix?: string): string; } + /** Properties of a ProfileLikeSubTip. */ + interface IProfileLikeSubTip { + + /** ProfileLikeSubTip msg */ + msg?: (SysMsg.ILikeMsg|null); + } + + /** Represents a ProfileLikeSubTip. */ + class ProfileLikeSubTip implements IProfileLikeSubTip { + + /** + * Constructs a new ProfileLikeSubTip. + * @param [properties] Properties to set + */ + constructor(properties?: SysMsg.IProfileLikeSubTip); + + /** ProfileLikeSubTip msg. */ + public msg?: (SysMsg.ILikeMsg|null); + + /** + * Decodes a ProfileLikeSubTip message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns ProfileLikeSubTip + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): SysMsg.ProfileLikeSubTip; + + /** + * Decodes a ProfileLikeSubTip message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns ProfileLikeSubTip + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): SysMsg.ProfileLikeSubTip; + + /** + * Gets the default type url for ProfileLikeSubTip + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + /** Properties of a ProfileLikeTip. */ interface IProfileLikeTip { - /** ProfileLikeTip msg */ - msg?: (SysMsg.ILikeMsg|null); + /** ProfileLikeTip msgType */ + msgType?: (number|null); + + /** ProfileLikeTip subType */ + subType?: (number|null); + + /** ProfileLikeTip content */ + content?: (SysMsg.IProfileLikeSubTip|null); } /** Represents a ProfileLikeTip. */ @@ -379,8 +431,14 @@ export namespace SysMsg { */ constructor(properties?: SysMsg.IProfileLikeTip); - /** ProfileLikeTip msg. */ - public msg?: (SysMsg.ILikeMsg|null); + /** ProfileLikeTip msgType. */ + public msgType: number; + + /** ProfileLikeTip subType. */ + public subType: number; + + /** ProfileLikeTip content. */ + public content?: (SysMsg.IProfileLikeSubTip|null); /** * Decodes a ProfileLikeTip message from the specified reader or buffer. diff --git a/src/ntqqapi/proto/compiled.js b/src/ntqqapi/proto/compiled.js index 13f53e8..6cbe19c 100644 --- a/src/ntqqapi/proto/compiled.js +++ b/src/ntqqapi/proto/compiled.js @@ -789,13 +789,111 @@ export const SysMsg = $root.SysMsg = (() => { return LikeMsg; })(); + SysMsg.ProfileLikeSubTip = (function() { + + /** + * Properties of a ProfileLikeSubTip. + * @memberof SysMsg + * @interface IProfileLikeSubTip + * @property {SysMsg.ILikeMsg|null} [msg] ProfileLikeSubTip msg + */ + + /** + * Constructs a new ProfileLikeSubTip. + * @memberof SysMsg + * @classdesc Represents a ProfileLikeSubTip. + * @implements IProfileLikeSubTip + * @constructor + * @param {SysMsg.IProfileLikeSubTip=} [properties] Properties to set + */ + function ProfileLikeSubTip(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ProfileLikeSubTip msg. + * @member {SysMsg.ILikeMsg|null|undefined} msg + * @memberof SysMsg.ProfileLikeSubTip + * @instance + */ + ProfileLikeSubTip.prototype.msg = null; + + /** + * Decodes a ProfileLikeSubTip message from the specified reader or buffer. + * @function decode + * @memberof SysMsg.ProfileLikeSubTip + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {SysMsg.ProfileLikeSubTip} ProfileLikeSubTip + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ProfileLikeSubTip.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.SysMsg.ProfileLikeSubTip(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 14: { + message.msg = $root.SysMsg.LikeMsg.decode(reader, reader.uint32()); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ProfileLikeSubTip message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof SysMsg.ProfileLikeSubTip + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {SysMsg.ProfileLikeSubTip} ProfileLikeSubTip + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ProfileLikeSubTip.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Gets the default type url for ProfileLikeSubTip + * @function getTypeUrl + * @memberof SysMsg.ProfileLikeSubTip + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ProfileLikeSubTip.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/SysMsg.ProfileLikeSubTip"; + }; + + return ProfileLikeSubTip; + })(); + SysMsg.ProfileLikeTip = (function() { /** * Properties of a ProfileLikeTip. * @memberof SysMsg * @interface IProfileLikeTip - * @property {SysMsg.ILikeMsg|null} [msg] ProfileLikeTip msg + * @property {number|null} [msgType] ProfileLikeTip msgType + * @property {number|null} [subType] ProfileLikeTip subType + * @property {SysMsg.IProfileLikeSubTip|null} [content] ProfileLikeTip content */ /** @@ -814,12 +912,28 @@ export const SysMsg = $root.SysMsg = (() => { } /** - * ProfileLikeTip msg. - * @member {SysMsg.ILikeMsg|null|undefined} msg + * ProfileLikeTip msgType. + * @member {number} msgType * @memberof SysMsg.ProfileLikeTip * @instance */ - ProfileLikeTip.prototype.msg = null; + ProfileLikeTip.prototype.msgType = 0; + + /** + * ProfileLikeTip subType. + * @member {number} subType + * @memberof SysMsg.ProfileLikeTip + * @instance + */ + ProfileLikeTip.prototype.subType = 0; + + /** + * ProfileLikeTip content. + * @member {SysMsg.IProfileLikeSubTip|null|undefined} content + * @memberof SysMsg.ProfileLikeTip + * @instance + */ + ProfileLikeTip.prototype.content = null; /** * Decodes a ProfileLikeTip message from the specified reader or buffer. @@ -839,8 +953,16 @@ export const SysMsg = $root.SysMsg = (() => { while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { - case 14: { - message.msg = $root.SysMsg.LikeMsg.decode(reader, reader.uint32()); + case 1: { + message.msgType = reader.uint32(); + break; + } + case 2: { + message.subType = reader.uint32(); + break; + } + case 203: { + message.content = $root.SysMsg.ProfileLikeSubTip.decode(reader, reader.uint32()); break; } default: diff --git a/src/ntqqapi/proto/profileLikeTip.proto b/src/ntqqapi/proto/profileLikeTip.proto index 7043c30..b478f6c 100644 --- a/src/ntqqapi/proto/profileLikeTip.proto +++ b/src/ntqqapi/proto/profileLikeTip.proto @@ -2,17 +2,23 @@ syntax = "proto3"; package SysMsg; message LikeDetail { - string txt = 1; - uint32 uin = 3; - string nickname = 5; + string txt = 1; + uint32 uin = 3; + string nickname = 5; } message LikeMsg { - uint32 count = 1; - uint32 time = 2; - LikeDetail detail = 3; + uint32 count = 1; + uint32 time = 2; + LikeDetail detail = 3; +} + +message ProfileLikeSubTip { + LikeMsg msg = 14; } message ProfileLikeTip { - LikeMsg msg = 14; -} \ No newline at end of file + uint32 msgType = 1; + uint32 subType = 2; + ProfileLikeSubTip content = 203; +} diff --git a/src/onebot11/adapter.ts b/src/onebot11/adapter.ts index d95ed0d..396a779 100644 --- a/src/onebot11/adapter.ts +++ b/src/onebot11/adapter.ts @@ -419,8 +419,9 @@ class OneBot11Adapter extends Service { const sysMsg = SysMsg.SystemMessage.decode(input) const { msgType, subType, subSubType } = sysMsg.msgSpec[0] ?? {} if (msgType === 528 && subType === 39 && subSubType === 39) { - const tip = SysMsg.ProfileLikeTip.decode(sysMsg.bodyWrapper!.body!.slice(12)) - const detail = tip.msg?.detail + const tip = SysMsg.ProfileLikeTip.decode(sysMsg.bodyWrapper!.body!) + if (tip.msgType !== 0 || tip.subType !== 203) return + const detail = tip.content?.msg?.detail if (!detail) return const [times] = detail.txt?.match(/\d+/) ?? ['0'] const profileLikeEvent = new OB11ProfileLikeEvent(detail.uin!, detail.nickname!, +times) From 536999f2963dbf0c37cb2b3515c344f263bfa82c Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 14 Sep 2024 20:13:45 +0800 Subject: [PATCH 3/6] feat: support for sending `contact` message segment --- package.json | 2 +- src/ntqqapi/api/friend.ts | 5 +++++ src/ntqqapi/api/group.ts | 5 +++++ src/ntqqapi/api/user.ts | 11 ----------- src/ntqqapi/services/NodeIKernelBuddyService.ts | 4 ++-- src/ntqqapi/services/NodeIKernelGroupService.ts | 7 ++++--- src/onebot11/helper/createMessage.ts | 8 +++++++- src/onebot11/types.ts | 10 ++++++++++ 8 files changed, 34 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 41563bf..e0fef99 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "electron-vite": "^2.3.0", "protobufjs-cli": "^1.1.3", "typescript": "^5.6.2", - "vite": "^5.4.4", + "vite": "^5.4.5", "vite-plugin-cp": "^4.0.8" }, "packageManager": "yarn@4.4.1" diff --git a/src/ntqqapi/api/friend.ts b/src/ntqqapi/api/friend.ts index 8eb3004..27595f8 100644 --- a/src/ntqqapi/api/friend.ts +++ b/src/ntqqapi/api/friend.ts @@ -189,4 +189,9 @@ export class NTQQFriendApi extends Service { return await invoke('nodeIKernelBuddyService/isBuddy', [{ uid }, null]) } } + + async getBuddyRecommendContact(uin: string) { + const ret = await invoke('nodeIKernelBuddyService/getBuddyRecommendContactArkJson', [{ uin }, null]) + return ret.arkMsg + } } diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index fc4b50c..3899218 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -300,4 +300,9 @@ export class NTQQGroupApi extends Service { const psKey = (await ntUserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')! return await invoke('nodeIKernelGroupService/uploadGroupBulletinPic', [{ groupCode, psKey, path }, null]) } + + async getGroupRecommendContact(groupCode: string) { + const ret = await invoke('nodeIKernelGroupService/getGroupRecommendContactArkJson', [{ groupCode }, null]) + return ret.arkJson + } } diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index f6836af..9884fdb 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -87,17 +87,6 @@ export class NTQQUserApi extends Service { return result.info } - async getSkey(): Promise { - const clientKeyData = await this.forceFetchClientKey() - if (clientKeyData?.result !== 0) { - throw new Error('获取clientKey失败') - } - const url = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin - + '&clientkey=' + clientKeyData.clientKey - + '&u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=' + clientKeyData.keyIndex - return (await RequestUtil.HttpsGetCookies(url))?.skey - } - async getCookies(domain: string) { const clientKeyData = await this.forceFetchClientKey() if (clientKeyData?.result !== 0) { diff --git a/src/ntqqapi/services/NodeIKernelBuddyService.ts b/src/ntqqapi/services/NodeIKernelBuddyService.ts index eb596e4..674a6dd 100644 --- a/src/ntqqapi/services/NodeIKernelBuddyService.ts +++ b/src/ntqqapi/services/NodeIKernelBuddyService.ts @@ -119,7 +119,7 @@ export interface NodeIKernelBuddyService { reportDoubtBuddyReqUnread(): void - getBuddyRecommendContactArkJson(uid: string, phoneNumber: string): Promise + getBuddyRecommendContactArkJson(uid: string, phoneNumber: string): Promise isNull(): boolean -} \ No newline at end of file +} diff --git a/src/ntqqapi/services/NodeIKernelGroupService.ts b/src/ntqqapi/services/NodeIKernelGroupService.ts index 0f8ef1e..c3ec6a2 100644 --- a/src/ntqqapi/services/NodeIKernelGroupService.ts +++ b/src/ntqqapi/services/NodeIKernelGroupService.ts @@ -52,7 +52,7 @@ export interface NodeIKernelGroupService { //26702(其实更早 但是我不知道) getGroupLatestEssenceList(groupCode: string): Promise - //26702(其实更早 但是我不知道) + //26702(其实更早 但是我不知道) shareDigest(Req: { appId: string, appType: number, @@ -232,7 +232,7 @@ export interface NodeIKernelGroupService { setMemberShutUp(groupCode: string, memberTimes: { uid: string, timeStamp: number }[]): Promise - getGroupRecommendContactArkJson(groupCode: string): unknown + getGroupRecommendContactArkJson(groupCode: string): Promise getJoinGroupLink(groupCode: string): unknown @@ -244,6 +244,7 @@ export interface NodeIKernelGroupService { msgRandom: number, msgSeq: number }): Promise + //需要提前判断是否存在 高版本新增 removeGroupEssence(param: { groupCode: string @@ -252,4 +253,4 @@ export interface NodeIKernelGroupService { }): Promise isNull(): boolean -} \ No newline at end of file +} diff --git a/src/onebot11/helper/createMessage.ts b/src/onebot11/helper/createMessage.ts index 6ec850f..e2aec4d 100644 --- a/src/onebot11/helper/createMessage.ts +++ b/src/onebot11/helper/createMessage.ts @@ -174,6 +174,12 @@ export async function createSendElements( sendElements.push(SendElementEntities.rps(resultId)) } break + case OB11MessageDataType.contact: { + const { type, id } = sendMsg.data + const data = type === 'qq' ? ctx.ntFriendApi.getBuddyRecommendContact(id) : ctx.ntGroupApi.getGroupRecommendContact(id) + sendElements.push(SendElementEntities.ark(await data)) + } + break } } @@ -301,4 +307,4 @@ export async function createPeer(ctx: Context, payload: CreatePeerPayload, mode: } } throw new Error('请指定 group_id 或 user_id') -} \ No newline at end of file +} diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index 56c6685..91eb137 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -130,6 +130,7 @@ export enum OB11MessageDataType { poke = 'poke', dice = 'dice', RPS = 'rps', + contact = 'contact', } export interface OB11MessageMFace { @@ -276,6 +277,14 @@ export interface OB11MessageForward { } } +export interface OB11MessageContact { + type: OB11MessageDataType.contact + data: { + type: 'qq' | 'group' + id: string + } +} + export type OB11MessageData = | OB11MessageText | OB11MessageFace @@ -295,6 +304,7 @@ export type OB11MessageData = | OB11MessageRPS | OB11MessageMarkdown | OB11MessageForward + | OB11MessageContact export interface OB11PostSendMsg { message_type?: 'private' | 'group' From 2d354c5eda47177641b9d61db7d0e3415b715d9d Mon Sep 17 00:00:00 2001 From: idranme Date: Sun, 15 Sep 2024 14:08:02 +0800 Subject: [PATCH 4/6] optimize --- src/common/config.ts | 1 - src/common/types.ts | 6 ++++- src/ntqqapi/api/group.ts | 20 +++++++--------- .../action/group/SetGroupAddRequest.ts | 5 ++-- src/onebot11/entities.ts | 2 +- src/onebot11/helper/quickOperation.ts | 24 ++++++++----------- src/renderer/index.ts | 5 ---- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/common/config.ts b/src/common/config.ts index 1408b20..8539af0 100644 --- a/src/common/config.ts +++ b/src/common/config.ts @@ -33,7 +33,6 @@ export class ConfigUtil { enableWsReverse: false, messagePostFormat: 'array', enableHttpHeart: false, - enableQOAutoQuote: false, listenLocalhost: false } const defaultConfig: Config = { diff --git a/src/common/types.ts b/src/common/types.ts index 9439806..14baf48 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -10,7 +10,11 @@ export interface OB11Config { enableWsReverse?: boolean messagePostFormat?: 'array' | 'string' enableHttpHeart?: boolean - enableQOAutoQuote: boolean // 快速操作回复自动引用原消息 + /** + * 快速操作回复自动引用原消息 + * @deprecated + */ + enableQOAutoQuote?: boolean listenLocalhost: boolean } diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index 3899218..1158fe8 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -117,17 +117,15 @@ export class NTQQGroupApi extends Service { const type = parseInt(flagitem[2]) const session = getSession() if (session) { - return session.getGroupService().operateSysNotify( - false, - { - 'operateType': operateType, // 2 拒绝 - 'targetMsg': { - 'seq': seq, // 通知序列号 - 'type': type, - 'groupCode': groupCode, - 'postscript': reason || ' ' // 仅传空值可能导致处理失败,故默认给个空格 - } - }) + return session.getGroupService().operateSysNotify(false, { + operateType, // 2 拒绝 + targetMsg: { + seq, // 通知序列号 + type, + groupCode, + postscript: reason || ' ' // 仅传空值可能导致处理失败,故默认给个空格 + } + }) } else { return await invoke(NTMethod.HANDLE_GROUP_REQUEST, [{ doubt: false, diff --git a/src/onebot11/action/group/SetGroupAddRequest.ts b/src/onebot11/action/group/SetGroupAddRequest.ts index c20526b..5364a72 100644 --- a/src/onebot11/action/group/SetGroupAddRequest.ts +++ b/src/onebot11/action/group/SetGroupAddRequest.ts @@ -14,9 +14,10 @@ export default class SetGroupAddRequest extends BaseAction { protected async _handle(payload: Payload): Promise { const flag = payload.flag.toString() const approve = payload.approve?.toString() !== 'false' - await this.ctx.ntGroupApi.handleGroupRequest(flag, + await this.ctx.ntGroupApi.handleGroupRequest( + flag, approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject, - payload.reason || '' + payload.reason ) return null } diff --git a/src/onebot11/entities.ts b/src/onebot11/entities.ts index 271b32c..ab77f9f 100644 --- a/src/onebot11/entities.ts +++ b/src/onebot11/entities.ts @@ -165,7 +165,7 @@ export namespace OB11Entities { // 284840486: 合并消息内侧 消息具体定位不到 if (!replyMsg && msg.peerUin !== '284840486') { - ctx.logger.info('queryMsgs', msgList.map(e => pick(e, ['msgSeq', 'msgRandom']))) + ctx.logger.info('queryMsgs', msgList.map(e => pick(e, ['msgSeq', 'msgRandom'])), records.msgRandom) throw new Error('回复消息验证失败') } messageSegment = { diff --git a/src/onebot11/helper/quickOperation.ts b/src/onebot11/helper/quickOperation.ts index 8127015..cf0214e 100644 --- a/src/onebot11/helper/quickOperation.ts +++ b/src/onebot11/helper/quickOperation.ts @@ -1,4 +1,4 @@ -import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from '../types' +import { OB11Message, OB11MessageData, OB11MessageDataType } from '../types' import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest' import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest' import { GroupRequestOperateTypes } from '@/ntqqapi/types' @@ -6,7 +6,6 @@ import { convertMessage2List, createSendElements, sendMsg, createPeer, CreatePee import { MessageUnique } from '@/common/utils/messageUnique' import { isNullable } from 'cosmokit' import { Context } from 'cordis' -import { OB11Config } from '@/common/types' interface QuickOperationPrivateMessage { reply?: string @@ -57,7 +56,6 @@ export async function handleQuickOperation(ctx: Context, event: QuickOperationEv async function handleMsg(ctx: Context, msg: OB11Message, quickAction: QuickOperationPrivateMessage | QuickOperationGroupMessage) { const reply = quickAction.reply - const ob11Config: OB11Config = ctx.config let contextMode = CreatePeerMode.Normal if (msg.message_type === 'group') { contextMode = CreatePeerMode.Group @@ -67,23 +65,21 @@ async function handleMsg(ctx: Context, msg: OB11Message, quickAction: QuickOpera const peer = await createPeer(ctx, msg, contextMode) if (reply) { let replyMessage: OB11MessageData[] = [] - if (ob11Config.enableQOAutoQuote) { - replyMessage.push({ - type: OB11MessageDataType.reply, - data: { - id: msg.message_id.toString(), - }, - }) - } + replyMessage.push({ + type: OB11MessageDataType.reply, + data: { + id: msg.message_id.toString(), + }, + }) if (msg.message_type == 'group') { if ((quickAction as QuickOperationGroupMessage).at_sender) { replyMessage.push({ - type: 'at', + type: OB11MessageDataType.at, data: { qq: msg.user_id.toString(), }, - } as OB11MessageAt) + }) } } replyMessage = replyMessage.concat(convertMessage2List(reply, quickAction.auto_escape)) @@ -130,4 +126,4 @@ async function handleGroupRequest(ctx: Context, request: OB11GroupRequestEvent, quickAction.reason, ).catch(e => ctx.logger.error(e)) } -} \ No newline at end of file +} diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 17d16ac..660e703 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -160,11 +160,6 @@ async function onSettingWindowCreated(view: Element) { `
`, 'config-musicSignUrl', ), - SettingItem( - '快速操作回复自动引用原消息', - null, - SettingSwitch('ob11.enableQOAutoQuote', config.ob11.enableQOAutoQuote), - ), SettingItem( 'HTTP、正向 WebSocket 服务仅监听 127.0.0.1', '而不是 0.0.0.0', From b965f50653216ba031d4bf6674da49bcb7ca4037 Mon Sep 17 00:00:00 2001 From: idranme Date: Sun, 15 Sep 2024 16:14:36 +0800 Subject: [PATCH 5/6] fix: `friend_add` event --- src/onebot11/entities.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/onebot11/entities.ts b/src/onebot11/entities.ts index ab77f9f..421e74f 100644 --- a/src/onebot11/entities.ts +++ b/src/onebot11/entities.ts @@ -394,7 +394,8 @@ export namespace OB11Entities { } // 好友增加事件 if (msg.msgType === 5 && msg.subMsgType === 12) { - const event = new OB11FriendAddNoticeEvent(parseInt(msg.peerUin)) + const uin = +msg.peerUin || +(await ctx.ntUserApi.getUinByUid(msg.peerUid)) + const event = new OB11FriendAddNoticeEvent(uin) return event } } From 55446538de52cae90d7b33afe89884c16da0ae26 Mon Sep 17 00:00:00 2001 From: idranme Date: Sun, 15 Sep 2024 17:43:10 +0800 Subject: [PATCH 6/6] chore: v3.32.6 --- manifest.json | 2 +- src/version.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index bd6a3e1..6529520 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "LLOneBot", "slug": "LLOneBot", "description": "实现 OneBot 11 协议,用于 QQ 机器人开发", - "version": "3.32.5", + "version": "3.32.6", "icon": "./icon.webp", "authors": [ { diff --git a/src/version.ts b/src/version.ts index 5631c27..52292a9 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = '3.32.5' +export const version = '3.32.6'