mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-05 07:01:16 +00:00
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.
This commit is contained in:
parent
b69352f6a1
commit
075047d790
@ -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: '回调数据' }),
|
||||
|
||||
@ -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: '聊天类型' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
|
||||
@ -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<PayloadType, ReturnTyp
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
let reqParam: MiniAppReqParams;
|
||||
const customParams = {
|
||||
const customParams: MiniAppReqCustomParams = {
|
||||
title: payload.title,
|
||||
desc: payload.desc,
|
||||
picUrl: payload.picUrl,
|
||||
jumpUrl: payload.jumpUrl,
|
||||
webUrl: payload.webUrl,
|
||||
} as MiniAppReqCustomParams;
|
||||
webUrl: payload.webUrl ?? '',
|
||||
};
|
||||
if ('type' in payload) {
|
||||
reqParam = MiniAppInfoHelper.generateReq(customParams, MiniAppInfo.get(payload.type)!.template);
|
||||
const template = MiniAppInfo.get(payload.type)?.template;
|
||||
if (!template) {
|
||||
throw new Error('未知的模板类型');
|
||||
}
|
||||
reqParam = MiniAppInfoHelper.generateReq(customParams, template);
|
||||
} else {
|
||||
const { appId, scene, iconUrl, templateType, businessType, verType, shareType, versionId, withShareTicket } = payload;
|
||||
reqParam = MiniAppInfoHelper.generateReq(
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import { NTQQWebApi } from 'napcat-core/apis';
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
@ -3,18 +3,15 @@ import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketS
|
||||
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号' }),
|
||||
});
|
||||
|
||||
type PayloadType = Static<typeof PayloadSchema>;
|
||||
|
||||
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<typeof ReturnSchema>;
|
||||
|
||||
@ -24,6 +21,10 @@ export class GetUserStatus extends GetPacketStatusDepends<PayloadType, ReturnTyp
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
return await this.core.apis.PacketApi.pkt.operation.GetStrangerStatus(+payload.user_id);
|
||||
const res = await this.core.apis.PacketApi.pkt.operation.GetStrangerStatus(+payload.user_id);
|
||||
if (!res) {
|
||||
throw new Error('无法获取用户状态');
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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' }),
|
||||
current_parent_directory: Type.String({ description: '当前父目录' }),
|
||||
target_parent_directory: Type.String({ description: '目标父目录' }),
|
||||
|
||||
@ -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' }),
|
||||
current_parent_directory: Type.String({ description: '当前父目录' }),
|
||||
new_name: Type.String({ description: '新文件名' }),
|
||||
|
||||
@ -11,7 +11,7 @@ const PayloadSchema = Type.Object({
|
||||
|
||||
type PayloadType = Static<typeof PayloadSchema>;
|
||||
|
||||
const ReturnSchema = Type.Optional(Type.String({ description: '响应十六进制数据' }), { description: '发包结果' });
|
||||
const ReturnSchema = Type.Union([Type.String({ description: '响应十六进制数据' }), Type.Undefined()], { description: '发包结果' });
|
||||
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
|
||||
@ -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: '事件类型' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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: '专属头衔' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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<PayloadType, ReturnType> {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -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' }),
|
||||
});
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ const PayloadSchema = Type.Object({
|
||||
|
||||
type PayloadType = Static<typeof PayloadSchema>;
|
||||
|
||||
const ReturnSchema = Type.Optional(Type.Array(Type.Any()), { description: '翻译结果列表' });
|
||||
const ReturnSchema = Type.Union([Type.Array(Type.Any()), Type.Undefined()], { description: '翻译结果列表' });
|
||||
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
|
||||
@ -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' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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<typeof SendFlashMsgPayloadSchema>;
|
||||
|
||||
@ -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' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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<typeof GetOnlineFileMessagesPayloadSchema>;
|
||||
|
||||
@ -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' }),
|
||||
});
|
||||
|
||||
@ -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' }),
|
||||
});
|
||||
|
||||
@ -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: '文件名 (可选)' })),
|
||||
});
|
||||
|
||||
@ -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: '文件夹名称 (可选)' })),
|
||||
});
|
||||
|
||||
@ -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二选一
|
||||
|
||||
@ -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' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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' })),
|
||||
});
|
||||
|
||||
@ -29,7 +29,7 @@ export default class GoCQHTTPDownloadFile extends OneBotAction<PayloadType, Retu
|
||||
async _handle (payload: PayloadType): Promise<ReturnType> {
|
||||
const isRandomName = !payload.name;
|
||||
const name = payload.name || randomUUID();
|
||||
let result: Awaited<ReturnType<typeof uriToLocalFile>>;
|
||||
let result: Awaited<globalThis.ReturnType<typeof uriToLocalFile>>;
|
||||
|
||||
if (payload.base64) {
|
||||
result = await uriToLocalFile(this.core.NapCatTempPath, `base64://${payload.base64}`, name);
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
|
||||
@ -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: '文件数量' }),
|
||||
|
||||
@ -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: '荣誉类型' })),
|
||||
});
|
||||
|
||||
|
||||
@ -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: '文件数量' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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: '在线客户端负载' });
|
||||
|
||||
|
||||
@ -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<PayloadType, R
|
||||
sex: OB11Construct.sex(extendData.detail.simpleInfo.baseInfo.sex) ?? OB11UserSex.unknown,
|
||||
long_nick: extendData.detail.simpleInfo.baseInfo.longNick ?? info.longNick,
|
||||
reg_time: extendData.detail.commonExt?.regTime ?? info.regTime,
|
||||
is_vip: extendData.detail.simpleInfo.vasInfo?.svipFlag,
|
||||
is_years_vip: extendData.detail.simpleInfo.vasInfo?.yearVipFlag,
|
||||
vip_level: extendData.detail.simpleInfo.vasInfo?.vipLevel,
|
||||
remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.remark,
|
||||
status: extendData.detail.simpleInfo.status?.status ?? info.status,
|
||||
is_vip: extendData.detail.simpleInfo.vasInfo?.svipFlag ?? false,
|
||||
is_years_vip: extendData.detail.simpleInfo.vasInfo?.yearVipFlag ?? false,
|
||||
vip_level: extendData.detail.simpleInfo.vasInfo?.vipLevel ?? 0,
|
||||
remark: extendData.detail.simpleInfo.coreInfo.remark ?? info.remark ?? '',
|
||||
status: extendData.detail.simpleInfo.status?.status ?? info.status ?? 0,
|
||||
login_days: 0, // 失效
|
||||
};
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import { QuickAction, QuickActionEvent } from '@/napcat-onebot/types';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
const SenderSchema = Type.Object({
|
||||
user_id: Type.Number({ description: '用户ID' }),
|
||||
user_id: Type.String({ description: '用户ID' }),
|
||||
nickname: Type.String({ description: '昵称' }),
|
||||
sex: Type.Optional(Type.String({ description: '性别' })),
|
||||
age: Type.Optional(Type.Number({ description: '年龄' })),
|
||||
@ -34,8 +34,8 @@ const QuickActionEventSchema = Type.Object({
|
||||
post_type: Type.String({ description: '上报类型' }),
|
||||
message_type: Type.Optional(Type.String({ description: '消息类型' })),
|
||||
sub_type: Type.Optional(Type.String({ description: '消息子类型' })),
|
||||
user_id: Type.Union([Type.Number(), Type.String()], { description: '发送者 QQ 号' }),
|
||||
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: '群号' })),
|
||||
user_id: Type.String({ description: '发送者 QQ 号' }),
|
||||
group_id: Type.Optional(Type.String({ description: '群号' })),
|
||||
message_id: Type.Optional(Type.Number({ description: '消息 ID' })),
|
||||
message_seq: Type.Optional(Type.Number({ description: '消息序列号' })),
|
||||
real_id: Type.Optional(Type.Number({ description: '真实消息 ID' })),
|
||||
|
||||
@ -5,7 +5,7 @@ import { unlink } from 'node:fs/promises';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
export const SendGroupNoticePayloadSchema = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }),
|
||||
group_id: Type.String({ description: '群号' }),
|
||||
content: Type.String({ description: '公告内容' }),
|
||||
image: Type.Optional(Type.String({ description: '公告图片路径或 URL' })),
|
||||
pinned: Type.Union([Type.Number(), Type.String()], { default: 0, description: '是否置顶 (0/1)' }),
|
||||
@ -60,6 +60,5 @@ export class SendGroupNotice extends OneBotAction<SendGroupNoticePayload, void>
|
||||
if (!publishGroupBulletinResult || publishGroupBulletinResult.ec !== 0) {
|
||||
throw new Error(`设置群公告失败,错误信息:${publishGroupBulletinResult?.em}`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<typeof SetGroupPortraitPayloadSchema>;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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' })),
|
||||
|
||||
@ -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<GoCQHTTPUplo
|
||||
throw new Error('缺少参数 user_id');
|
||||
}
|
||||
|
||||
async _handle (payload: Payload): Promise<UploadPrivateFileResponse> {
|
||||
async _handle (payload: GoCQHTTPUploadPrivateFilePayload): Promise<GoCQHTTPUploadPrivateFileResponse> {
|
||||
let file = payload.file;
|
||||
if (fs.existsSync(file)) {
|
||||
file = `file://${file}`;
|
||||
|
||||
@ -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' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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: '语音文本内容' }),
|
||||
});
|
||||
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
@ -57,6 +57,15 @@ export class GetGroupEssence extends OneBotAction<PayloadType, ReturnType> {
|
||||
}, 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<PayloadType, ReturnType> {
|
||||
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<PayloadType, ReturnType> {
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}).filter(e => e !== undefined),
|
||||
}).filter((e): e is any => e !== undefined),
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
@ -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: '群忽略通知负载' });
|
||||
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -23,7 +23,7 @@ const ReturnSchema = Type.Array(Type.Object({
|
||||
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
type ApiGroupNotice = ReturnType[number] & WebApiGroupNoticeFeed;
|
||||
export type ApiGroupNotice = ReturnType[number] & WebApiGroupNoticeFeed;
|
||||
|
||||
export class GetGroupNotice extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupNotice;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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<typeof PayloadSchema>;
|
||||
|
||||
@ -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<PT, RT> extends OneBotAction<PT, RT> {
|
||||
protected override async check (payload: PT): Promise<BaseCheckResult> {
|
||||
|
||||
@ -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 通知信息' });
|
||||
|
||||
@ -102,7 +102,7 @@ export class UploadFileStream extends OneBotAction<UploadFileStreamPayload, Stre
|
||||
return this.getStreamStatus(stream);
|
||||
}
|
||||
|
||||
private getOrCreateStream (payload: Payload): StreamState {
|
||||
private getOrCreateStream (payload: UploadFileStreamPayload): StreamState {
|
||||
let stream = UploadFileStream.streams.get(payload.stream_id);
|
||||
|
||||
if (!stream) {
|
||||
@ -115,7 +115,7 @@ export class UploadFileStream extends OneBotAction<UploadFileStreamPayload, Stre
|
||||
return stream;
|
||||
}
|
||||
|
||||
private createStream (payload: Payload): StreamState {
|
||||
private createStream (payload: UploadFileStreamPayload): StreamState {
|
||||
const { stream_id, total_chunks, file_size, filename, expected_sha256 } = payload;
|
||||
|
||||
const useMemory = this.shouldUseMemory(file_size);
|
||||
|
||||
@ -39,25 +39,25 @@ export default class GetRecentContact extends OneBotAction<GetRecentContactPaylo
|
||||
return {
|
||||
lastestMsg,
|
||||
peerUin: t.peerUin,
|
||||
remark: t.remark,
|
||||
remark: String(t.remark ?? ''),
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName,
|
||||
sendNickName: String(t.sendNickName ?? ''),
|
||||
sendMemberName: String(t.sendMemberName ?? ''),
|
||||
peerName: String(t.peerName ?? ''),
|
||||
};
|
||||
}
|
||||
return {
|
||||
lastestMsg: undefined,
|
||||
peerUin: t.peerUin,
|
||||
remark: t.remark,
|
||||
remark: String(t.remark ?? ''),
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: t.sendNickName,
|
||||
sendMemberName: t.sendMemberName,
|
||||
peerName: t.peerName,
|
||||
sendNickName: String(t.sendNickName ?? ''),
|
||||
sendMemberName: String(t.sendMemberName ?? ''),
|
||||
peerName: String(t.peerName ?? ''),
|
||||
};
|
||||
}));
|
||||
return results;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user