From 075047d790e873e3fa4ad95271a5d5702dd97e33 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, 25 Jan 2026 15:07:43 +0800 Subject: [PATCH] Refactor payload schemas to use string IDs Replaced Type.Union([Type.Number(), Type.String()]) with Type.String for group_id, user_id, and similar fields across all action payload schemas to standardize input types. Also made minor improvements to error handling, return types, and removed unused imports for better code clarity and consistency. --- .../extends/ClickInlineKeyboardButton.ts | 2 +- .../action/extends/GetAiCharacters.ts | 2 +- .../action/extends/GetCollectionList.ts | 5 ++-- .../action/extends/GetGroupInfoEx.ts | 2 +- .../action/extends/GetMiniAppArk.ts | 28 +++++++++++-------- .../action/extends/GetQunAlbumList.ts | 1 - .../action/extends/GetUserStatus.ts | 19 +++++++------ .../action/extends/MoveGroupFile.ts | 2 +- .../action/extends/RenameGroupFile.ts | 2 +- .../action/extends/SendPacket.ts | 2 +- .../action/extends/SetGroupSign.ts | 2 +- .../action/extends/SetInputStatus.ts | 2 +- .../action/extends/SetSpecialTitle.ts | 4 +-- .../action/extends/ShareContact.ts | 7 ++--- .../action/extends/TransGroupFile.ts | 2 +- .../action/extends/TranslateEnWordToZn.ts | 2 +- .../action/file/GetGroupFileUrl.ts | 2 +- .../action/file/flash/SendFlashMsg.ts | 4 +-- .../action/file/online/CancelOnlineFile.ts | 2 +- .../file/online/GetOnlineFileMessages.ts | 2 +- .../action/file/online/ReceiveOnlineFile.ts | 2 +- .../action/file/online/RefuseOnlineFile.ts | 2 +- .../action/file/online/SendOnlineFile.ts | 2 +- .../action/file/online/SendOnlineFolder.ts | 2 +- .../action/go-cqhttp/CreateGroupFileFolder.ts | 2 +- .../action/go-cqhttp/DeleteGroupFile.ts | 3 +- .../action/go-cqhttp/DeleteGroupFileFolder.ts | 3 +- .../action/go-cqhttp/DownloadFile.ts | 2 +- .../action/go-cqhttp/GetGroupAtAllRemain.ts | 2 +- .../go-cqhttp/GetGroupFileSystemInfo.ts | 2 +- .../action/go-cqhttp/GetGroupFilesByFolder.ts | 2 +- .../action/go-cqhttp/GetGroupHonorInfo.ts | 2 +- .../action/go-cqhttp/GetGroupRootFiles.ts | 2 +- .../action/go-cqhttp/GetOnlineClient.ts | 1 + .../action/go-cqhttp/GetStrangerInfo.ts | 14 +++++----- .../action/go-cqhttp/QuickAction.ts | 6 ++-- .../action/go-cqhttp/SendGroupNotice.ts | 3 +- .../action/go-cqhttp/SetGroupPortrait.ts | 3 +- .../action/go-cqhttp/SetQQProfile.ts | 1 - .../action/go-cqhttp/UploadGroupFile.ts | 2 +- .../action/go-cqhttp/UploadPrivateFile.ts | 4 +-- .../action/group/DelGroupNotice.ts | 2 +- .../napcat-onebot/action/group/GetAiRecord.ts | 2 +- .../action/group/GetGroupDetailInfo.ts | 2 +- .../action/group/GetGroupEssence.ts | 15 ++++++++-- .../action/group/GetGroupIgnoredNotifies.ts | 2 +- .../action/group/GetGroupMemberList.ts | 1 - .../action/group/GetGroupNotice.ts | 2 +- .../action/group/GetGroupShutList.ts | 1 - .../action/msg/ForwardSingleMsg.ts | 4 +-- .../action/packet/GetPacketStatus.ts | 1 + packages/napcat-onebot/action/schemas.ts | 12 ++++++++ .../action/stream/UploadFileStream.ts | 4 +-- .../action/user/GetRecentContact.ts | 16 +++++------ 54 files changed, 119 insertions(+), 101 deletions(-) diff --git a/packages/napcat-onebot/action/extends/ClickInlineKeyboardButton.ts b/packages/napcat-onebot/action/extends/ClickInlineKeyboardButton.ts index acafa29c..a2fd84b8 100644 --- a/packages/napcat-onebot/action/extends/ClickInlineKeyboardButton.ts +++ b/packages/napcat-onebot/action/extends/ClickInlineKeyboardButton.ts @@ -3,7 +3,7 @@ import { OneBotAction } from '../OneBotAction'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), bot_appid: Type.String({ description: '机器人AppID' }), button_id: Type.String({ default: '', description: '按钮ID' }), callback_data: Type.String({ default: '', description: '回调数据' }), diff --git a/packages/napcat-onebot/action/extends/GetAiCharacters.ts b/packages/napcat-onebot/action/extends/GetAiCharacters.ts index 8eb5dabf..14476c2d 100644 --- a/packages/napcat-onebot/action/extends/GetAiCharacters.ts +++ b/packages/napcat-onebot/action/extends/GetAiCharacters.ts @@ -4,7 +4,7 @@ import { AIVoiceChatType } from 'napcat-core/packet/entities/aiChat'; import { Type, Static } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), chat_type: Type.Union([Type.Number(), Type.String()], { default: 1, description: '聊天类型' }), }); diff --git a/packages/napcat-onebot/action/extends/GetCollectionList.ts b/packages/napcat-onebot/action/extends/GetCollectionList.ts index 2954498f..d98b2100 100644 --- a/packages/napcat-onebot/action/extends/GetCollectionList.ts +++ b/packages/napcat-onebot/action/extends/GetCollectionList.ts @@ -1,11 +1,10 @@ -import { type NTQQCollectionApi } from 'napcat-core/apis/collection'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { Type, Static } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - category: Type.Union([Type.Number(), Type.String()], { description: '分类ID' }), - count: Type.Union([Type.Number(), Type.String()], { default: 1, description: '获取数量' }), + category: Type.String({ description: '分类ID' }), + count: Type.String({ default: '1', description: '获取数量' }), }); type PayloadType = Static; diff --git a/packages/napcat-onebot/action/extends/GetGroupInfoEx.ts b/packages/napcat-onebot/action/extends/GetGroupInfoEx.ts index edb38918..7f5e697a 100644 --- a/packages/napcat-onebot/action/extends/GetGroupInfoEx.ts +++ b/packages/napcat-onebot/action/extends/GetGroupInfoEx.ts @@ -2,7 +2,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { Type, Static } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); type PayloadType = Static; diff --git a/packages/napcat-onebot/action/extends/GetMiniAppArk.ts b/packages/napcat-onebot/action/extends/GetMiniAppArk.ts index 81c206b0..8140608a 100644 --- a/packages/napcat-onebot/action/extends/GetMiniAppArk.ts +++ b/packages/napcat-onebot/action/extends/GetMiniAppArk.ts @@ -1,7 +1,7 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus'; import { MiniAppInfo, MiniAppInfoHelper } from 'napcat-core/packet/utils/helper/miniAppHelper'; -import { MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams } from 'napcat-core/packet/entities/miniApp'; +import { MiniAppReqCustomParams, MiniAppReqParams } from 'napcat-core/packet/entities/miniApp'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Union([ @@ -22,15 +22,15 @@ const PayloadSchema = Type.Union([ iconUrl: Type.String({ description: '图标URL' }), webUrl: Type.Optional(Type.String({ description: '网页URL' })), appId: Type.String({ description: '小程序AppID' }), - scene: Type.Union([Type.Number(), Type.String()], { description: '场景ID' }), - templateType: Type.Union([Type.Number(), Type.String()], { description: '模板类型' }), - businessType: Type.Union([Type.Number(), Type.String()], { description: '业务类型' }), - verType: Type.Union([Type.Number(), Type.String()], { description: '版本类型' }), - shareType: Type.Union([Type.Number(), Type.String()], { description: '分享类型' }), + scene: Type.String({ description: '场景ID' }), + templateType: Type.String({ description: '模板类型' }), + businessType: Type.String({ description: '业务类型' }), + verType: Type.String({ description: '版本类型' }), + shareType: Type.String({ description: '分享类型' }), versionId: Type.String({ description: '版本ID' }), sdkId: Type.String({ description: 'SDK ID' }), - withShareTicket: Type.Union([Type.Number(), Type.String()], { description: '是否携带分享票据' }), - rawArkData: Type.Optional(Type.Union([Type.String()], { description: '是否返回原始Ark数据' })), + withShareTicket: Type.String({ description: '是否携带分享票据' }), + rawArkData: Type.Optional(Type.String({ description: '是否返回原始Ark数据' })), }), ], { description: '小程序Ark参数' }); @@ -49,15 +49,19 @@ export class GetMiniAppArk extends GetPacketStatusDepends; -const ReturnSchema = Type.Optional( - Type.Object({ - status: Type.Number({ description: '在线状态' }), - ext_status: Type.Number({ description: '扩展状态' }), - }), - { description: '用户状态' } -); +const ReturnSchema = Type.Object({ + status: Type.Number({ description: '在线状态' }), + ext_status: Type.Number({ description: '扩展状态' }), +}, { description: '用户状态' }); type ReturnType = Static; @@ -24,6 +21,10 @@ export class GetUserStatus extends GetPacketStatusDepends; -const ReturnSchema = Type.Optional(Type.String({ description: '响应十六进制数据' }), { description: '发包结果' }); +const ReturnSchema = Type.Union([Type.String({ description: '响应十六进制数据' }), Type.Undefined()], { description: '发包结果' }); type ReturnType = Static; diff --git a/packages/napcat-onebot/action/extends/SetGroupSign.ts b/packages/napcat-onebot/action/extends/SetGroupSign.ts index 2a7cd012..95c9b223 100644 --- a/packages/napcat-onebot/action/extends/SetGroupSign.ts +++ b/packages/napcat-onebot/action/extends/SetGroupSign.ts @@ -3,7 +3,7 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); type PayloadType = Static; diff --git a/packages/napcat-onebot/action/extends/SetInputStatus.ts b/packages/napcat-onebot/action/extends/SetInputStatus.ts index 22da88a2..d1d2ad67 100644 --- a/packages/napcat-onebot/action/extends/SetInputStatus.ts +++ b/packages/napcat-onebot/action/extends/SetInputStatus.ts @@ -4,7 +4,7 @@ import { ChatType } from 'napcat-core'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: 'QQ号' }), + user_id: Type.String({ description: 'QQ号' }), event_type: Type.Number({ description: '事件类型' }), }); diff --git a/packages/napcat-onebot/action/extends/SetSpecialTitle.ts b/packages/napcat-onebot/action/extends/SetSpecialTitle.ts index a1cbfc8f..7d926413 100644 --- a/packages/napcat-onebot/action/extends/SetSpecialTitle.ts +++ b/packages/napcat-onebot/action/extends/SetSpecialTitle.ts @@ -3,8 +3,8 @@ import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketS import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), - user_id: Type.Union([Type.Number(), Type.String()], { description: 'QQ号' }), + group_id: Type.String({ description: '群号' }), + user_id: Type.String({ description: 'QQ号' }), special_title: Type.String({ default: '', description: '专属头衔' }), }); diff --git a/packages/napcat-onebot/action/extends/ShareContact.ts b/packages/napcat-onebot/action/extends/ShareContact.ts index e21d4a13..f9f8d827 100644 --- a/packages/napcat-onebot/action/extends/ShareContact.ts +++ b/packages/napcat-onebot/action/extends/ShareContact.ts @@ -1,11 +1,10 @@ -import { GeneralCallResult } from 'napcat-core'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - user_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: 'QQ号' })), - group_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: '群号' })), + user_id: Type.Optional(Type.String({ description: 'QQ号' })), + group_id: Type.Optional(Type.String({ description: '群号' })), phone_number: Type.String({ default: '', description: '手机号' }), }); @@ -31,7 +30,7 @@ export class SharePeerBase extends OneBotAction { } const PayloadSchemaGroupEx = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); export class SharePeer extends SharePeerBase { override actionName = ActionName.SharePeer; diff --git a/packages/napcat-onebot/action/extends/TransGroupFile.ts b/packages/napcat-onebot/action/extends/TransGroupFile.ts index 11338f9f..9263d4a0 100644 --- a/packages/napcat-onebot/action/extends/TransGroupFile.ts +++ b/packages/napcat-onebot/action/extends/TransGroupFile.ts @@ -4,7 +4,7 @@ import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketS import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), file_id: Type.String({ description: '文件ID' }), }); diff --git a/packages/napcat-onebot/action/extends/TranslateEnWordToZn.ts b/packages/napcat-onebot/action/extends/TranslateEnWordToZn.ts index b1b285f7..00514207 100644 --- a/packages/napcat-onebot/action/extends/TranslateEnWordToZn.ts +++ b/packages/napcat-onebot/action/extends/TranslateEnWordToZn.ts @@ -8,7 +8,7 @@ const PayloadSchema = Type.Object({ type PayloadType = Static; -const ReturnSchema = Type.Optional(Type.Array(Type.Any()), { description: '翻译结果列表' }); +const ReturnSchema = Type.Union([Type.Array(Type.Any()), Type.Undefined()], { description: '翻译结果列表' }); type ReturnType = Static; diff --git a/packages/napcat-onebot/action/file/GetGroupFileUrl.ts b/packages/napcat-onebot/action/file/GetGroupFileUrl.ts index ba857551..a6cb677b 100644 --- a/packages/napcat-onebot/action/file/GetGroupFileUrl.ts +++ b/packages/napcat-onebot/action/file/GetGroupFileUrl.ts @@ -4,7 +4,7 @@ import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketS import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), file_id: Type.String({ description: '文件ID' }), }); diff --git a/packages/napcat-onebot/action/file/flash/SendFlashMsg.ts b/packages/napcat-onebot/action/file/flash/SendFlashMsg.ts index e350564d..dd088b75 100644 --- a/packages/napcat-onebot/action/file/flash/SendFlashMsg.ts +++ b/packages/napcat-onebot/action/file/flash/SendFlashMsg.ts @@ -5,8 +5,8 @@ import { ChatType, Peer } from 'napcat-core/types'; export const SendFlashMsgPayloadSchema = Type.Object({ fileset_id: Type.String({ description: '文件集 ID' }), - user_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' })), - group_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: '群号' })), + user_id: Type.Optional(Type.String({ description: '用户 QQ' })), + group_id: Type.Optional(Type.String({ description: '群号' })), }); export type SendFlashMsgPayload = Static; diff --git a/packages/napcat-onebot/action/file/online/CancelOnlineFile.ts b/packages/napcat-onebot/action/file/online/CancelOnlineFile.ts index f11a79fe..05015049 100644 --- a/packages/napcat-onebot/action/file/online/CancelOnlineFile.ts +++ b/packages/napcat-onebot/action/file/online/CancelOnlineFile.ts @@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox'; import { ChatType } from 'napcat-core/types'; export const CancelOnlineFilePayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }), + user_id: Type.String({ description: '用户 QQ' }), msg_id: Type.String({ description: '消息 ID' }), }); diff --git a/packages/napcat-onebot/action/file/online/GetOnlineFileMessages.ts b/packages/napcat-onebot/action/file/online/GetOnlineFileMessages.ts index e62eff13..bc122260 100644 --- a/packages/napcat-onebot/action/file/online/GetOnlineFileMessages.ts +++ b/packages/napcat-onebot/action/file/online/GetOnlineFileMessages.ts @@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox'; import { ChatType } from 'napcat-core/types'; export const GetOnlineFileMessagesPayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }), + user_id: Type.String({ description: '用户 QQ' }), }); export type GetOnlineFileMessagesPayload = Static; diff --git a/packages/napcat-onebot/action/file/online/ReceiveOnlineFile.ts b/packages/napcat-onebot/action/file/online/ReceiveOnlineFile.ts index c8dbf849..07fc5788 100644 --- a/packages/napcat-onebot/action/file/online/ReceiveOnlineFile.ts +++ b/packages/napcat-onebot/action/file/online/ReceiveOnlineFile.ts @@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox'; import { ChatType } from 'napcat-core/types'; export const ReceiveOnlineFilePayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }), + user_id: Type.String({ description: '用户 QQ' }), msg_id: Type.String({ description: '消息 ID' }), element_id: Type.String({ description: '元素 ID' }), }); diff --git a/packages/napcat-onebot/action/file/online/RefuseOnlineFile.ts b/packages/napcat-onebot/action/file/online/RefuseOnlineFile.ts index af87a002..094000dd 100644 --- a/packages/napcat-onebot/action/file/online/RefuseOnlineFile.ts +++ b/packages/napcat-onebot/action/file/online/RefuseOnlineFile.ts @@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox'; import { ChatType } from 'napcat-core/types'; export const RefuseOnlineFilePayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }), + user_id: Type.String({ description: '用户 QQ' }), msg_id: Type.String({ description: '消息 ID' }), element_id: Type.String({ description: '元素 ID' }), }); diff --git a/packages/napcat-onebot/action/file/online/SendOnlineFile.ts b/packages/napcat-onebot/action/file/online/SendOnlineFile.ts index 12d1e0d3..35cbc32a 100644 --- a/packages/napcat-onebot/action/file/online/SendOnlineFile.ts +++ b/packages/napcat-onebot/action/file/online/SendOnlineFile.ts @@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox'; import { ChatType } from 'napcat-core/types'; export const SendOnlineFilePayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }), + user_id: Type.String({ description: '用户 QQ' }), file_path: Type.String({ description: '本地文件路径' }), file_name: Type.Optional(Type.String({ description: '文件名 (可选)' })), }); diff --git a/packages/napcat-onebot/action/file/online/SendOnlineFolder.ts b/packages/napcat-onebot/action/file/online/SendOnlineFolder.ts index 7ab8e3ac..6bced1e0 100644 --- a/packages/napcat-onebot/action/file/online/SendOnlineFolder.ts +++ b/packages/napcat-onebot/action/file/online/SendOnlineFolder.ts @@ -4,7 +4,7 @@ import { Static, Type } from '@sinclair/typebox'; import { ChatType } from 'napcat-core/types'; export const SendOnlineFolderPayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }), + user_id: Type.String({ description: '用户 QQ' }), folder_path: Type.String({ description: '本地文件夹路径' }), folder_name: Type.Optional(Type.String({ description: '文件夹名称 (可选)' })), }); diff --git a/packages/napcat-onebot/action/go-cqhttp/CreateGroupFileFolder.ts b/packages/napcat-onebot/action/go-cqhttp/CreateGroupFileFolder.ts index a3d1f370..8652d7e8 100644 --- a/packages/napcat-onebot/action/go-cqhttp/CreateGroupFileFolder.ts +++ b/packages/napcat-onebot/action/go-cqhttp/CreateGroupFileFolder.ts @@ -3,7 +3,7 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), // 兼容gocq 与name二选一 folder_name: Type.Optional(Type.String({ description: '文件夹名称' })), // 兼容gocq 与folder_name二选一 diff --git a/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFile.ts b/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFile.ts index 6947713a..f397d0e9 100644 --- a/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFile.ts +++ b/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFile.ts @@ -2,10 +2,9 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { FileNapCatOneBotUUID } from 'napcat-common/src/file-uuid'; import { Static, Type } from '@sinclair/typebox'; -import { NTQQGroupApi } from 'napcat-core/apis'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), file_id: Type.String({ description: '文件ID' }), }); diff --git a/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFileFolder.ts b/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFileFolder.ts index 5f15125b..03242e33 100644 --- a/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFileFolder.ts +++ b/packages/napcat-onebot/action/go-cqhttp/DeleteGroupFileFolder.ts @@ -1,10 +1,9 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { Static, Type } from '@sinclair/typebox'; -import { NTQQGroupApi } from 'napcat-core/apis'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), folder_id: Type.Optional(Type.String({ description: '文件夹ID' })), folder: Type.Optional(Type.String({ description: '文件夹ID' })), }); diff --git a/packages/napcat-onebot/action/go-cqhttp/DownloadFile.ts b/packages/napcat-onebot/action/go-cqhttp/DownloadFile.ts index d5a8509f..830bf7b8 100644 --- a/packages/napcat-onebot/action/go-cqhttp/DownloadFile.ts +++ b/packages/napcat-onebot/action/go-cqhttp/DownloadFile.ts @@ -29,7 +29,7 @@ export default class GoCQHTTPDownloadFile extends OneBotAction { const isRandomName = !payload.name; const name = payload.name || randomUUID(); - let result: Awaited>; + let result: Awaited>; if (payload.base64) { result = await uriToLocalFile(this.core.NapCatTempPath, `base64://${payload.base64}`, name); diff --git a/packages/napcat-onebot/action/go-cqhttp/GetGroupAtAllRemain.ts b/packages/napcat-onebot/action/go-cqhttp/GetGroupAtAllRemain.ts index 2fcced56..8bb7db29 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetGroupAtAllRemain.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetGroupAtAllRemain.ts @@ -3,7 +3,7 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); type PayloadType = Static; diff --git a/packages/napcat-onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts b/packages/napcat-onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts index 59bbe7cb..94a9eca6 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetGroupFileSystemInfo.ts @@ -3,7 +3,7 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); type PayloadType = Static; diff --git a/packages/napcat-onebot/action/go-cqhttp/GetGroupFilesByFolder.ts b/packages/napcat-onebot/action/go-cqhttp/GetGroupFilesByFolder.ts index 34e52c81..cf63bfa4 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetGroupFilesByFolder.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetGroupFilesByFolder.ts @@ -4,7 +4,7 @@ import { OB11Construct } from '@/napcat-onebot/helper/data'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), folder_id: Type.Optional(Type.String({ description: '文件夹ID' })), folder: Type.Optional(Type.String({ description: '文件夹ID' })), file_count: Type.Union([Type.Number(), Type.String()], { default: 50, description: '文件数量' }), diff --git a/packages/napcat-onebot/action/go-cqhttp/GetGroupHonorInfo.ts b/packages/napcat-onebot/action/go-cqhttp/GetGroupHonorInfo.ts index 46157b10..af64949a 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetGroupHonorInfo.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetGroupHonorInfo.ts @@ -4,7 +4,7 @@ import { WebHonorType } from 'napcat-core/types'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), type: Type.Optional(Type.Enum(WebHonorType, { description: '荣誉类型' })), }); diff --git a/packages/napcat-onebot/action/go-cqhttp/GetGroupRootFiles.ts b/packages/napcat-onebot/action/go-cqhttp/GetGroupRootFiles.ts index f5e53b48..0e5db1fb 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetGroupRootFiles.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetGroupRootFiles.ts @@ -4,7 +4,7 @@ import { OB11Construct } from '@/napcat-onebot/helper/data'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), file_count: Type.Union([Type.Number(), Type.String()], { default: 50, description: '文件数量' }), }); diff --git a/packages/napcat-onebot/action/go-cqhttp/GetOnlineClient.ts b/packages/napcat-onebot/action/go-cqhttp/GetOnlineClient.ts index 5790d3a9..70928cd4 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetOnlineClient.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetOnlineClient.ts @@ -1,6 +1,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { sleep } from 'napcat-common/src/helper'; +import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({}, { description: '在线客户端负载' }); diff --git a/packages/napcat-onebot/action/go-cqhttp/GetStrangerInfo.ts b/packages/napcat-onebot/action/go-cqhttp/GetStrangerInfo.ts index 6b47ce49..45e747cf 100644 --- a/packages/napcat-onebot/action/go-cqhttp/GetStrangerInfo.ts +++ b/packages/napcat-onebot/action/go-cqhttp/GetStrangerInfo.ts @@ -1,12 +1,12 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; -import { OB11User, OB11UserSex } from '@/napcat-onebot/index'; +import { OB11UserSex } from '@/napcat-onebot/index'; import { OB11Construct } from '@/napcat-onebot/helper/data'; import { ActionName } from '@/napcat-onebot/action/router'; import { calcQQLevel } from 'napcat-common/src/helper'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户QQ' }), + user_id: Type.String({ description: '用户QQ' }), no_cache: Type.Union([Type.Boolean(), Type.String()], { default: false, description: '是否不使用缓存' }), }); @@ -58,11 +58,11 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction if (!publishGroupBulletinResult || publishGroupBulletinResult.ec !== 0) { throw new Error(`设置群公告失败,错误信息:${publishGroupBulletinResult?.em}`); } - return null; } } diff --git a/packages/napcat-onebot/action/go-cqhttp/SetGroupPortrait.ts b/packages/napcat-onebot/action/go-cqhttp/SetGroupPortrait.ts index 45e1401a..0c68893d 100644 --- a/packages/napcat-onebot/action/go-cqhttp/SetGroupPortrait.ts +++ b/packages/napcat-onebot/action/go-cqhttp/SetGroupPortrait.ts @@ -3,10 +3,9 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { checkFileExistV2, uriToLocalFile } from 'napcat-common/src/file'; import { Static, Type } from '@sinclair/typebox'; import fs from 'node:fs/promises'; -import { GeneralCallResult } from 'napcat-core'; export const SetGroupPortraitPayloadSchema = Type.Object({ file: Type.String({ description: '头像文件路径或 URL' }), - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); export type SetGroupPortraitPayload = Static; diff --git a/packages/napcat-onebot/action/go-cqhttp/SetQQProfile.ts b/packages/napcat-onebot/action/go-cqhttp/SetQQProfile.ts index d8364f8f..f869b132 100644 --- a/packages/napcat-onebot/action/go-cqhttp/SetQQProfile.ts +++ b/packages/napcat-onebot/action/go-cqhttp/SetQQProfile.ts @@ -1,4 +1,3 @@ -import { NTQQUserApi } from 'napcat-core/apis'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; diff --git a/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts b/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts index c5379700..cde3b633 100644 --- a/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts +++ b/packages/napcat-onebot/action/go-cqhttp/UploadGroupFile.ts @@ -7,7 +7,7 @@ import { SendMessageContext } from '@/napcat-onebot/api'; import { Static, Type } from '@sinclair/typebox'; export const GoCQHTTPUploadGroupFilePayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), file: Type.String({ description: '本地文件路径' }), name: Type.String({ description: '文件名' }), folder: Type.Optional(Type.String({ description: '父目录 ID' })), diff --git a/packages/napcat-onebot/action/go-cqhttp/UploadPrivateFile.ts b/packages/napcat-onebot/action/go-cqhttp/UploadPrivateFile.ts index 50848820..9123f613 100644 --- a/packages/napcat-onebot/action/go-cqhttp/UploadPrivateFile.ts +++ b/packages/napcat-onebot/action/go-cqhttp/UploadPrivateFile.ts @@ -8,7 +8,7 @@ import { ContextMode, createContext } from '@/napcat-onebot/action/msg/SendMsg'; import { Static, Type } from '@sinclair/typebox'; export const GoCQHTTPUploadPrivateFilePayloadSchema = Type.Object({ - user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }), + user_id: Type.String({ description: '用户 QQ' }), file: Type.String({ description: '本地文件路径' }), name: Type.String({ description: '文件名' }), upload_file: Type.Boolean({ default: true, description: '是否执行上传' }), @@ -39,7 +39,7 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction { + async _handle (payload: GoCQHTTPUploadPrivateFilePayload): Promise { let file = payload.file; if (fs.existsSync(file)) { file = `file://${file}`; diff --git a/packages/napcat-onebot/action/group/DelGroupNotice.ts b/packages/napcat-onebot/action/group/DelGroupNotice.ts index 948a0498..57a0aca4 100644 --- a/packages/napcat-onebot/action/group/DelGroupNotice.ts +++ b/packages/napcat-onebot/action/group/DelGroupNotice.ts @@ -3,7 +3,7 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), notice_id: Type.String({ description: '公告ID' }), }); diff --git a/packages/napcat-onebot/action/group/GetAiRecord.ts b/packages/napcat-onebot/action/group/GetAiRecord.ts index 567c54d3..15d09dcb 100644 --- a/packages/napcat-onebot/action/group/GetAiRecord.ts +++ b/packages/napcat-onebot/action/group/GetAiRecord.ts @@ -5,7 +5,7 @@ import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ character: Type.String({ description: '角色ID' }), - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), text: Type.String({ description: '语音文本内容' }), }); diff --git a/packages/napcat-onebot/action/group/GetGroupDetailInfo.ts b/packages/napcat-onebot/action/group/GetGroupDetailInfo.ts index 2195b4da..b1edbe0a 100644 --- a/packages/napcat-onebot/action/group/GetGroupDetailInfo.ts +++ b/packages/napcat-onebot/action/group/GetGroupDetailInfo.ts @@ -3,7 +3,7 @@ import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); type PayloadType = Static; diff --git a/packages/napcat-onebot/action/group/GetGroupEssence.ts b/packages/napcat-onebot/action/group/GetGroupEssence.ts index ac5c6a7c..27d87bd5 100644 --- a/packages/napcat-onebot/action/group/GetGroupEssence.ts +++ b/packages/napcat-onebot/action/group/GetGroupEssence.ts @@ -7,7 +7,7 @@ import { Static, Type } from '@sinclair/typebox'; import { NetworkAdapterConfig } from '@/napcat-onebot/config/config'; const PayloadSchema = Type.Object({ - group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }), + group_id: Type.String({ description: '群号' }), }); type PayloadType = Static; @@ -57,6 +57,15 @@ export class GetGroupEssence extends OneBotAction { }, msg.msg_seq.toString(), msg.msg_random.toString()); if (msgOriginData) { const { id: message_id, msg: rawMessage } = msgOriginData; + const parsed = await this.obContext.apis.MsgApi.parseMessage(rawMessage, config.messagePostFormat); + let content: any[] = []; + if (parsed) { + if (Array.isArray(parsed.message)) { + content = parsed.message; + } else { + content = [{ type: 'text', data: { text: parsed.message } }]; + } + } return { msg_seq: msg.msg_seq, msg_random: msg.msg_random, @@ -66,7 +75,7 @@ export class GetGroupEssence extends OneBotAction { operator_nick: msg.add_digest_nick, message_id, operator_time: msg.add_digest_time, - content: (await this.obContext.apis.MsgApi.parseMessage(rawMessage, config.messagePostFormat))?.message, + content, }; } const msgTempData = JSON.stringify({ @@ -107,7 +116,7 @@ export class GetGroupEssence extends OneBotAction { }; } return undefined; - }).filter(e => e !== undefined), + }).filter((e): e is any => e !== undefined), }; })); } diff --git a/packages/napcat-onebot/action/group/GetGroupIgnoredNotifies.ts b/packages/napcat-onebot/action/group/GetGroupIgnoredNotifies.ts index 1db5f6c1..23c1d95c 100644 --- a/packages/napcat-onebot/action/group/GetGroupIgnoredNotifies.ts +++ b/packages/napcat-onebot/action/group/GetGroupIgnoredNotifies.ts @@ -1,7 +1,7 @@ import { GroupNotifyMsgStatus } from 'napcat-core'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; -import { Notify } from '@/napcat-onebot/types'; +import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({}, { description: '群忽略通知负载' }); diff --git a/packages/napcat-onebot/action/group/GetGroupMemberList.ts b/packages/napcat-onebot/action/group/GetGroupMemberList.ts index 8a142b65..49c3d2b0 100644 --- a/packages/napcat-onebot/action/group/GetGroupMemberList.ts +++ b/packages/napcat-onebot/action/group/GetGroupMemberList.ts @@ -1,4 +1,3 @@ -import { OB11GroupMember } from '@/napcat-onebot/index'; import { OB11Construct } from '@/napcat-onebot/helper/data'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; diff --git a/packages/napcat-onebot/action/group/GetGroupNotice.ts b/packages/napcat-onebot/action/group/GetGroupNotice.ts index 8d5439da..91123552 100644 --- a/packages/napcat-onebot/action/group/GetGroupNotice.ts +++ b/packages/napcat-onebot/action/group/GetGroupNotice.ts @@ -23,7 +23,7 @@ const ReturnSchema = Type.Array(Type.Object({ type ReturnType = Static; -type ApiGroupNotice = ReturnType[number] & WebApiGroupNoticeFeed; +export type ApiGroupNotice = ReturnType[number] & WebApiGroupNoticeFeed; export class GetGroupNotice extends OneBotAction { override actionName = ActionName.GoCQHTTP_GetGroupNotice; diff --git a/packages/napcat-onebot/action/group/GetGroupShutList.ts b/packages/napcat-onebot/action/group/GetGroupShutList.ts index d665ea89..d81835af 100644 --- a/packages/napcat-onebot/action/group/GetGroupShutList.ts +++ b/packages/napcat-onebot/action/group/GetGroupShutList.ts @@ -1,4 +1,3 @@ -import { ShutUpGroupMember } from 'napcat-core'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName } from '@/napcat-onebot/action/router'; import { Static, Type } from '@sinclair/typebox'; diff --git a/packages/napcat-onebot/action/msg/ForwardSingleMsg.ts b/packages/napcat-onebot/action/msg/ForwardSingleMsg.ts index 4a580910..efd96091 100644 --- a/packages/napcat-onebot/action/msg/ForwardSingleMsg.ts +++ b/packages/napcat-onebot/action/msg/ForwardSingleMsg.ts @@ -6,8 +6,8 @@ import { Static, Type } from '@sinclair/typebox'; const PayloadSchema = Type.Object({ message_id: Type.Union([Type.Number(), Type.String()], { description: '消息ID' }), - group_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: '目标群号' })), - user_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: '目标用户QQ' })), + group_id: Type.Optional(Type.String({ description: '目标群号' })), + user_id: Type.Optional(Type.String({ description: '目标用户QQ' })), }); type PayloadType = Static; diff --git a/packages/napcat-onebot/action/packet/GetPacketStatus.ts b/packages/napcat-onebot/action/packet/GetPacketStatus.ts index 122139be..e38cfc88 100644 --- a/packages/napcat-onebot/action/packet/GetPacketStatus.ts +++ b/packages/napcat-onebot/action/packet/GetPacketStatus.ts @@ -1,5 +1,6 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { ActionName, BaseCheckResult } from '@/napcat-onebot/action/router'; +import { Type } from '@sinclair/typebox'; export abstract class GetPacketStatusDepends extends OneBotAction { protected override async check (payload: PT): Promise { diff --git a/packages/napcat-onebot/action/schemas.ts b/packages/napcat-onebot/action/schemas.ts index 6c56df2b..5f91d7a0 100644 --- a/packages/napcat-onebot/action/schemas.ts +++ b/packages/napcat-onebot/action/schemas.ts @@ -49,3 +49,15 @@ export const OB11GroupMemberSchema = Type.Object({ is_robot: Type.Optional(Type.Boolean({ description: '是否为机器人' })), qage: Type.Optional(Type.Number({ description: 'Q龄' })), }, { description: 'OneBot 11 群成员信息' }); + +export const OB11NotifySchema = Type.Object({ + request_id: Type.Number({ description: '请求ID' }), + invitor_uin: Type.Number({ description: '邀请者QQ' }), + invitor_nick: Type.String({ description: '邀请者昵称' }), + group_id: Type.Number({ description: '群号' }), + group_name: Type.String({ description: '群名称' }), + message: Type.String({ description: '附言' }), + checked: Type.Boolean({ description: '是否已处理' }), + actor: Type.Number({ description: '操作者QQ' }), + requester_nick: Type.String({ description: '申请者昵称' }), +}, { description: 'OneBot 11 通知信息' }); diff --git a/packages/napcat-onebot/action/stream/UploadFileStream.ts b/packages/napcat-onebot/action/stream/UploadFileStream.ts index 4072db5c..92ed67b4 100644 --- a/packages/napcat-onebot/action/stream/UploadFileStream.ts +++ b/packages/napcat-onebot/action/stream/UploadFileStream.ts @@ -102,7 +102,7 @@ export class UploadFileStream extends OneBotAction