mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
@@ -27,7 +27,6 @@
|
||||
"@napneko/nap-proto-core": "^0.0.4",
|
||||
"@rollup/plugin-node-resolve": "^16.0.0",
|
||||
"@rollup/plugin-typescript": "^12.1.2",
|
||||
"@sinclair/typebox": "^0.34.9",
|
||||
"@types/cors": "^2.8.17",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/multer": "^1.4.12",
|
||||
@@ -39,9 +38,9 @@
|
||||
"@types/ws": "^8.5.12",
|
||||
"@typescript-eslint/eslint-plugin": "^8.3.0",
|
||||
"@typescript-eslint/parser": "^8.3.0",
|
||||
"ajv": "^8.13.0",
|
||||
"async-mutex": "^0.5.0",
|
||||
"commander": "^13.0.0",
|
||||
"compressing": "^1.10.1",
|
||||
"cors": "^2.8.5",
|
||||
"esbuild": "0.25.0",
|
||||
"eslint": "^9.14.0",
|
||||
@@ -54,14 +53,14 @@
|
||||
"image-size": "^1.1.1",
|
||||
"json5": "^2.2.3",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"napcat.protobuf": "^1.1.4",
|
||||
"typescript": "^5.3.3",
|
||||
"typescript-eslint": "^8.13.0",
|
||||
"vite": "^6.0.1",
|
||||
"vite-plugin-cp": "^6.0.0",
|
||||
"vite-tsconfig-paths": "^5.1.0",
|
||||
"napcat.protobuf": "^1.1.4",
|
||||
"winston": "^3.17.0",
|
||||
"compressing": "^1.10.1"
|
||||
"zod": "^3.24.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ffmpeg.wasm/core-mt": "^0.13.2",
|
||||
@@ -69,4 +68,4 @@
|
||||
"silk-wasm": "^3.6.1",
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,22 +2,20 @@ import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import type { NapCatCore } from '@/core';
|
||||
import json5 from 'json5';
|
||||
import Ajv, { AnySchema, ValidateFunction } from 'ajv';
|
||||
import { z } from 'zod';
|
||||
|
||||
export abstract class ConfigBase<T> {
|
||||
name: string;
|
||||
core: NapCatCore;
|
||||
configPath: string;
|
||||
configData: T = {} as T;
|
||||
ajv: Ajv;
|
||||
validate: ValidateFunction<T>;
|
||||
schema: z.ZodType<T>;
|
||||
|
||||
protected constructor(name: string, core: NapCatCore, configPath: string, ConfigSchema: AnySchema) {
|
||||
protected constructor(name: string, core: NapCatCore, configPath: string, schema: z.ZodType<T>) {
|
||||
this.name = name;
|
||||
this.core = core;
|
||||
this.configPath = configPath;
|
||||
this.ajv = new Ajv({ useDefaults: true, coerceTypes: true });
|
||||
this.validate = this.ajv.compile<T>(ConfigSchema);
|
||||
this.schema = schema;
|
||||
fs.mkdirSync(this.configPath, { recursive: true });
|
||||
this.read();
|
||||
}
|
||||
@@ -42,11 +40,16 @@ export abstract class ConfigBase<T> {
|
||||
|
||||
private loadConfig(configPath: string): T {
|
||||
try {
|
||||
let newConfigData = json5.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||
this.validate(newConfigData);
|
||||
this.configData = newConfigData;
|
||||
this.core.context.logger.logDebug(`[Core] [Config] 配置文件${configPath}加载`, this.configData);
|
||||
return this.configData;
|
||||
let configData = json5.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||
const result = this.schema.safeParse(configData);
|
||||
|
||||
if (result.success) {
|
||||
this.configData = result.data;
|
||||
this.core.context.logger.logDebug(`[Core] [Config] 配置文件${configPath}加载`, this.configData);
|
||||
return this.configData;
|
||||
} else {
|
||||
throw new Error(`配置文件验证失败: ${result.error.message}`);
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
this.handleError(e, '读取配置文件时发生错误');
|
||||
return {} as T;
|
||||
@@ -55,10 +58,14 @@ export abstract class ConfigBase<T> {
|
||||
|
||||
save(newConfigData: T = this.configData): void {
|
||||
const configPath = this.getConfigPath(this.core.selfInfo.uin);
|
||||
this.validate(newConfigData);
|
||||
this.configData = newConfigData;
|
||||
try {
|
||||
fs.writeFileSync(configPath, JSON.stringify(this.configData, null, 2));
|
||||
const result = this.schema.safeParse(newConfigData);
|
||||
if (result.success) {
|
||||
this.configData = result.data;
|
||||
fs.writeFileSync(configPath, JSON.stringify(this.configData, null, 2));
|
||||
} else {
|
||||
throw new Error(`配置文件验证失败: ${result.error.message}`);
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
this.handleError(e, `保存配置文件 ${configPath} 时发生错误:`);
|
||||
}
|
||||
@@ -67,6 +74,8 @@ export abstract class ConfigBase<T> {
|
||||
private handleError(e: unknown, message: string): void {
|
||||
if (e instanceof SyntaxError) {
|
||||
this.core.context.logger.logError('[Core] [Config] 操作配置文件格式错误,请检查配置文件:', e.message);
|
||||
} else if (e instanceof z.ZodError) {
|
||||
this.core.context.logger.logError('[Core] [Config] 配置文件验证错误:', e.message);
|
||||
} else {
|
||||
this.core.context.logger.logError(`[Core] [Config] ${message}:`, (e as Error).message);
|
||||
}
|
||||
|
@@ -128,7 +128,7 @@ class FFmpegService {
|
||||
const [fileInfo, durationInfo] = await Promise.all([
|
||||
// 任务1: 获取文件信息和提取缩略图
|
||||
(async () => {
|
||||
sendLog(`开始任务1: 获取文件信息和提取缩略图`);
|
||||
sendLog('开始任务1: 获取文件信息和提取缩略图');
|
||||
|
||||
// 获取文件信息 (并行)
|
||||
const fileInfoStartTime = Date.now();
|
||||
@@ -147,7 +147,7 @@ class FFmpegService {
|
||||
|
||||
// 直接实现缩略图提取 (不调用extractThumbnail方法)
|
||||
const thumbStartTime = Date.now();
|
||||
sendLog(`开始提取缩略图`);
|
||||
sendLog('开始提取缩略图');
|
||||
|
||||
const ffmpegInstance = await withTimeout(
|
||||
FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' }),
|
||||
@@ -215,7 +215,7 @@ class FFmpegService {
|
||||
// 任务2: 获取视频时长
|
||||
(async () => {
|
||||
const task2StartTime = Date.now();
|
||||
sendLog(`开始任务2: 获取视频时长`);
|
||||
sendLog('开始任务2: 获取视频时长');
|
||||
|
||||
// 创建FFmpeg实例
|
||||
const ffmpegCreateStartTime = Date.now();
|
||||
@@ -291,16 +291,16 @@ interface FFmpegTask {
|
||||
}
|
||||
export default async function handleFFmpegTask({ method, args }: FFmpegTask): Promise<any> {
|
||||
switch (method) {
|
||||
case 'extractThumbnail':
|
||||
return await FFmpegService.extractThumbnail(...args as [string, string]);
|
||||
case 'convertFile':
|
||||
return await FFmpegService.convertFile(...args as [string, string, string]);
|
||||
case 'convert':
|
||||
return await FFmpegService.convert(...args as [string, string]);
|
||||
case 'getVideoInfo':
|
||||
return await FFmpegService.getVideoInfo(...args as [string, string]);
|
||||
default:
|
||||
throw new Error(`Unknown method: ${method}`);
|
||||
case 'extractThumbnail':
|
||||
return await FFmpegService.extractThumbnail(...args as [string, string]);
|
||||
case 'convertFile':
|
||||
return await FFmpegService.convertFile(...args as [string, string, string]);
|
||||
case 'convert':
|
||||
return await FFmpegService.convert(...args as [string, string]);
|
||||
case 'getVideoInfo':
|
||||
return await FFmpegService.getVideoInfo(...args as [string, string]);
|
||||
default:
|
||||
throw new Error(`Unknown method: ${method}`);
|
||||
}
|
||||
}
|
||||
recvTask<FFmpegTask>(async ({ method, args }: FFmpegTask) => {
|
||||
|
@@ -182,28 +182,28 @@ export async function uriToLocalFile(dir: string, uri: string, filename: string
|
||||
const filePath = path.join(dir, filename);
|
||||
|
||||
switch (UriType) {
|
||||
case FileUriType.Local: {
|
||||
const fileExt = path.extname(HandledUri);
|
||||
const localFileName = path.basename(HandledUri, fileExt) + fileExt;
|
||||
const tempFilePath = path.join(dir, filename + fileExt);
|
||||
fs.copyFileSync(HandledUri, tempFilePath);
|
||||
return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath };
|
||||
}
|
||||
case FileUriType.Local: {
|
||||
const fileExt = path.extname(HandledUri);
|
||||
const localFileName = path.basename(HandledUri, fileExt) + fileExt;
|
||||
const tempFilePath = path.join(dir, filename + fileExt);
|
||||
fs.copyFileSync(HandledUri, tempFilePath);
|
||||
return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath };
|
||||
}
|
||||
|
||||
case FileUriType.Remote: {
|
||||
const buffer = await httpDownload({ url: HandledUri, headers: headers ?? {} });
|
||||
fs.writeFileSync(filePath, buffer);
|
||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||
}
|
||||
case FileUriType.Remote: {
|
||||
const buffer = await httpDownload({ url: HandledUri, headers: headers ?? {} });
|
||||
fs.writeFileSync(filePath, buffer);
|
||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||
}
|
||||
|
||||
case FileUriType.Base64: {
|
||||
const base64 = HandledUri.replace(/^base64:\/\//, '');
|
||||
const base64Buffer = Buffer.from(base64, 'base64');
|
||||
fs.writeFileSync(filePath, base64Buffer);
|
||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||
}
|
||||
case FileUriType.Base64: {
|
||||
const base64 = HandledUri.replace(/^base64:\/\//, '');
|
||||
const base64Buffer = Buffer.from(base64, 'base64');
|
||||
fs.writeFileSync(filePath, base64Buffer);
|
||||
return { success: true, errMsg: '', fileName: filename, path: filePath };
|
||||
}
|
||||
|
||||
default:
|
||||
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
||||
default:
|
||||
return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' };
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ export async function runTask<T, R>(workerScript: string, taskData: T): Promise<
|
||||
console.error('Worker Log--->:', (result as { log: string }).log);
|
||||
}
|
||||
if ((result as any)?.error) {
|
||||
reject(new Error("Worker error: " + (result as { error: string }).error));
|
||||
reject(new Error('Worker error: ' + (result as { error: string }).error));
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
|
@@ -44,7 +44,7 @@ export class NTQQFileApi {
|
||||
'https://secret-service.bietiaop.com/rkeys',
|
||||
'http://ss.xingzhige.com/music_card/rkey',
|
||||
],
|
||||
this.context.logger
|
||||
this.context.logger
|
||||
);
|
||||
}
|
||||
|
||||
@@ -308,18 +308,18 @@ export class NTQQFileApi {
|
||||
element.elementType === ElementType.FILE
|
||||
) {
|
||||
switch (element.elementType) {
|
||||
case ElementType.PIC:
|
||||
case ElementType.PIC:
|
||||
element.picElement!.sourcePath = elementResults?.[elementIndex] ?? '';
|
||||
break;
|
||||
case ElementType.VIDEO:
|
||||
break;
|
||||
case ElementType.VIDEO:
|
||||
element.videoElement!.filePath = elementResults?.[elementIndex] ?? '';
|
||||
break;
|
||||
case ElementType.PTT:
|
||||
break;
|
||||
case ElementType.PTT:
|
||||
element.pttElement!.filePath = elementResults?.[elementIndex] ?? '';
|
||||
break;
|
||||
case ElementType.FILE:
|
||||
break;
|
||||
case ElementType.FILE:
|
||||
element.fileElement!.filePath = elementResults?.[elementIndex] ?? '';
|
||||
break;
|
||||
break;
|
||||
}
|
||||
elementIndex++;
|
||||
}
|
||||
|
@@ -1,22 +1,21 @@
|
||||
import { ConfigBase } from '@/common/config-base';
|
||||
import { NapCatCore } from '@/core';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { AnySchema } from 'ajv';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const NapcatConfigSchema = Type.Object({
|
||||
fileLog: Type.Boolean({ default: false }),
|
||||
consoleLog: Type.Boolean({ default: true }),
|
||||
fileLogLevel: Type.String({ default: 'debug' }),
|
||||
consoleLogLevel: Type.String({ default: 'info' }),
|
||||
packetBackend: Type.String({ default: 'auto' }),
|
||||
packetServer: Type.String({ default: '' }),
|
||||
o3HookMode: Type.Number({ default: 0 }),
|
||||
export const NapcatConfigSchema = z.object({
|
||||
fileLog: z.boolean().default(false),
|
||||
consoleLog: z.boolean().default(true),
|
||||
fileLogLevel: z.string().default('debug'),
|
||||
consoleLogLevel: z.string().default('info'),
|
||||
packetBackend: z.string().default('auto'),
|
||||
packetServer: z.string().default(''),
|
||||
o3HookMode: z.number().default(0),
|
||||
});
|
||||
|
||||
export type NapcatConfig = Static<typeof NapcatConfigSchema>;
|
||||
export type NapcatConfig = z.infer<typeof NapcatConfigSchema>;
|
||||
|
||||
export class NapCatConfigLoader extends ConfigBase<NapcatConfig> {
|
||||
constructor(core: NapCatCore, configPath: string, schema: AnySchema) {
|
||||
constructor(core: NapCatCore, configPath: string, schema: z.ZodType<any>) {
|
||||
super('napcat', core, configPath, schema);
|
||||
}
|
||||
}
|
||||
}
|
@@ -115,7 +115,7 @@ export interface GroupEssenceMsg {
|
||||
add_digest_uin: string;
|
||||
add_digest_nick: string;
|
||||
add_digest_time: number;
|
||||
msg_content: unknown[];
|
||||
msg_content: { msg_type: number, text?: string, image_url?: string }[];
|
||||
can_be_removed: true;
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { ActionName, BaseCheckResult } from './router';
|
||||
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
||||
import { NapCatCore } from '@/core';
|
||||
import { NapCatOneBot11Adapter, OB11Return } from '@/onebot';
|
||||
import { NetworkAdapterConfig } from '../config/config';
|
||||
import { TSchema } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
export class OB11Response {
|
||||
private static createResponse<T>(data: T, status: string, retcode: number, message: string = '', echo: unknown = null): OB11Return<T> {
|
||||
@@ -33,8 +32,7 @@ export class OB11Response {
|
||||
export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
||||
actionName: typeof ActionName[keyof typeof ActionName] = ActionName.Unknown;
|
||||
core: NapCatCore;
|
||||
private validate?: ValidateFunction<unknown> = undefined;
|
||||
payloadSchema?: TSchema = undefined;
|
||||
payloadSchema?: z.ZodType<unknown> = undefined;
|
||||
obContext: NapCatOneBot11Adapter;
|
||||
|
||||
constructor(obContext: NapCatOneBot11Adapter, core: NapCatCore) {
|
||||
@@ -42,19 +40,30 @@ export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||
if (this.payloadSchema) {
|
||||
this.validate = new Ajv({ allowUnionTypes: true, useDefaults: true, coerceTypes: true }).compile(this.payloadSchema);
|
||||
protected async check(payload: unknown): Promise<BaseCheckResult> {
|
||||
if (!this.payloadSchema) {
|
||||
return { valid: true };
|
||||
}
|
||||
if (this.validate && !this.validate(payload)) {
|
||||
const errors = this.validate.errors as ErrorObject[];
|
||||
const errorMessages = errors.map(e => `Key: ${e.instancePath.split('/').slice(1).join('.')}, Message: ${e.message}`);
|
||||
|
||||
try {
|
||||
// 使用 zod 验证并转换数据
|
||||
this.payloadSchema.parse(payload);
|
||||
return { valid: true };
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
const errorMessages = error.errors.map(e =>
|
||||
`Key: ${e.path.join('.')}, Message: ${e.message}`
|
||||
);
|
||||
return {
|
||||
valid: false,
|
||||
message: errorMessages.join('\n') || '未知错误',
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: false,
|
||||
message: errorMessages.join('\n') ?? '未知错误',
|
||||
message: '验证过程中发生未知错误'
|
||||
};
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
public async handle(payload: PayloadType, adaptername: string, config: NetworkAdapterConfig): Promise<OB11Return<ReturnDataType | null>> {
|
||||
@@ -86,4 +95,4 @@ export abstract class OneBotAction<PayloadType, ReturnDataType> {
|
||||
}
|
||||
|
||||
abstract _handle(payload: PayloadType, adaptername: string, config: NetworkAdapterConfig): Promise<ReturnDataType>;
|
||||
}
|
||||
}
|
@@ -1,16 +1,15 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '../OneBotAction';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
bot_appid: Type.String(),
|
||||
button_id: Type.String({ default: '' }),
|
||||
callback_data: Type.String({ default: '' }),
|
||||
msg_seq: Type.String({ default: '10086' }),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.string(),
|
||||
bot_appid: z.string(),
|
||||
button_id: z.string().default(''),
|
||||
callback_data: z.string().default(''),
|
||||
msg_seq: z.string().default('10086'),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class ClickInlineKeyboardButton extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.ClickInlineKeyboardButton;
|
||||
@@ -25,6 +24,6 @@ export class ClickInlineKeyboardButton extends OneBotAction<Payload, unknown> {
|
||||
callback_data: payload.callback_data,
|
||||
dmFlag: 0,
|
||||
chatType: 2
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
rawData: Type.String(),
|
||||
brief: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
rawData: z.string(),
|
||||
brief: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class CreateCollection extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.CreateCollection;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 48 }),
|
||||
const SchemaData = z.object({
|
||||
count: z.number().default(48),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class FetchCustomFace extends OneBotAction<Payload, string[]> {
|
||||
override actionName = ActionName.FetchCustomFace;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { type NTQQMsgApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
emojiId: Type.Union([Type.Number(), Type.String()]),
|
||||
emojiType: Type.Union([Type.Number(), Type.String()]),
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 20 }),
|
||||
const SchemaData = z.object({
|
||||
message_id: z.string(),
|
||||
emojiId: z.string(),
|
||||
emojiType: z.string(),
|
||||
count: z.number().default(20),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class FetchEmojiLike extends OneBotAction<Payload, Awaited<ReturnType<NTQQMsgApi['getMsgEmojiLikesList']>>> {
|
||||
override actionName = ActionName.FetchEmojiLike;
|
||||
@@ -23,7 +23,7 @@ export class FetchEmojiLike extends OneBotAction<Payload, Awaited<ReturnType<NTQ
|
||||
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||
if (!msg) throw new Error('消息不存在');
|
||||
return await this.core.apis.MsgApi.getMsgEmojiLikesList(
|
||||
msgIdPeer.Peer, msg.msgSeq, payload.emojiId.toString(), payload.emojiType.toString(), +payload.count
|
||||
msgIdPeer.Peer, msg.msgSeq, payload.emojiId, payload.emojiType, +payload.count
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { AIVoiceChatType } from '@/core/packet/entities/aiChat';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
chat_type: Type.Union([Type.Union([Type.Number(), Type.String()])], { default: 1 }),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.string(),
|
||||
chat_type: z.number().default(1),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
interface GetAiCharactersResponse {
|
||||
type: string;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { type NTQQCollectionApi } from '@/core/apis/collection';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
category: Type.Union([Type.Number(), Type.String()]),
|
||||
count: Type.Union([Type.Union([Type.Number(), Type.String()])], { default: 1 }),
|
||||
const SchemaData = z.object({
|
||||
category: z.number(),
|
||||
count: z.number().default(1),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetCollectionList extends OneBotAction<Payload, Awaited<ReturnType<NTQQCollectionApi['getAllCollection']>>> {
|
||||
override actionName = ActionName.GetCollectionList;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
import { z } from 'zod';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupInfoEx extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GetGroupInfoEx;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return (await this.core.apis.GroupApi.getGroupExtFE0Info([payload.group_id.toString()])).result.groupExtInfos.get(payload.group_id.toString());
|
||||
return (await this.core.apis.GroupApi.getGroupExtFE0Info([payload.group_id])).result.groupExtInfos.get(payload.group_id);
|
||||
}
|
||||
}
|
||||
|
@@ -2,38 +2,38 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { MiniAppInfo, MiniAppInfoHelper } from '@/core/packet/utils/helper/miniAppHelper';
|
||||
import { MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams } from '@/core/packet/entities/miniApp';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Union([
|
||||
Type.Object({
|
||||
type: Type.Union([Type.Literal('bili'), Type.Literal('weibo')]),
|
||||
title: Type.String(),
|
||||
desc: Type.String(),
|
||||
picUrl: Type.String(),
|
||||
jumpUrl: Type.String(),
|
||||
webUrl: Type.Optional(Type.String()),
|
||||
rawArkData: Type.Optional(Type.Union([Type.String()]))
|
||||
const SchemaData = z.union([
|
||||
z.object({
|
||||
type: z.union([z.literal('bili'), z.literal('weibo')]),
|
||||
title: z.string(),
|
||||
desc: z.string(),
|
||||
picUrl: z.string(),
|
||||
jumpUrl: z.string(),
|
||||
webUrl: z.string().optional(),
|
||||
rawArkData: z.string().optional()
|
||||
}),
|
||||
Type.Object({
|
||||
title: Type.String(),
|
||||
desc: Type.String(),
|
||||
picUrl: Type.String(),
|
||||
jumpUrl: Type.String(),
|
||||
iconUrl: Type.String(),
|
||||
webUrl: Type.Optional(Type.String()),
|
||||
appId: Type.String(),
|
||||
scene: Type.Union([Type.Number(), Type.String()]),
|
||||
templateType: Type.Union([Type.Number(), Type.String()]),
|
||||
businessType: Type.Union([Type.Number(), Type.String()]),
|
||||
verType: Type.Union([Type.Number(), Type.String()]),
|
||||
shareType: Type.Union([Type.Number(), Type.String()]),
|
||||
versionId: Type.String(),
|
||||
sdkId: Type.String(),
|
||||
withShareTicket: Type.Union([Type.Number(), Type.String()]),
|
||||
rawArkData: Type.Optional(Type.Union([Type.String()]))
|
||||
z.object({
|
||||
title: z.string(),
|
||||
desc: z.string(),
|
||||
picUrl: z.string(),
|
||||
jumpUrl: z.string(),
|
||||
iconUrl: z.string(),
|
||||
webUrl: z.string().optional(),
|
||||
appId: z.string(),
|
||||
scene: z.union([z.number(), z.string()]),
|
||||
templateType: z.union([z.number(), z.string()]),
|
||||
businessType: z.union([z.number(), z.string()]),
|
||||
verType: z.union([z.number(), z.string()]),
|
||||
shareType: z.union([z.number(), z.string()]),
|
||||
versionId: z.string(),
|
||||
sdkId: z.string(),
|
||||
withShareTicket: z.union([z.number(), z.string()]),
|
||||
rawArkData: z.string().optional()
|
||||
})
|
||||
]);
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetMiniAppArk extends GetPacketStatusDepends<Payload, {
|
||||
data: MiniAppData | MiniAppRawData
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { NTVoteInfo } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
start: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 10 })
|
||||
const SchemaData = z.object({
|
||||
user_id: z.string().optional(),
|
||||
start: z.number().default(0),
|
||||
count: z.number().default(10),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetProfileLike extends OneBotAction<Payload, {
|
||||
uid: string;
|
||||
|
@@ -36,7 +36,7 @@ export class GetUnidirectionalFriendList extends OneBotAction<void, Friend[]> {
|
||||
uint64_uin: self_id,
|
||||
uint64_top: 0,
|
||||
uint32_req_num: 99,
|
||||
bytes_cookies: ""
|
||||
bytes_cookies: ''
|
||||
};
|
||||
const packed_data = await this.pack_data(JSON.stringify(req_json));
|
||||
const data = Buffer.from(packed_data).toString('hex');
|
||||
|
@@ -1,18 +1,18 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
user_id: z.number(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetUserStatus extends GetPacketStatusDepends<Payload, { status: number; ext_status: number; } | undefined> {
|
||||
override actionName = ActionName.GetUserStatus;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
return await this.core.apis.PacketApi.pkt.operation.GetStrangerStatus(+payload.user_id);
|
||||
return await this.core.apis.PacketApi.pkt.operation.GetStrangerStatus(payload.user_id);
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file_id: Type.String(),
|
||||
current_parent_directory: Type.String(),
|
||||
target_parent_directory: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
file_id: z.string(),
|
||||
current_parent_directory: z.string(),
|
||||
target_parent_directory: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
interface MoveGroupFileResponse {
|
||||
ok: boolean;
|
||||
|
@@ -2,14 +2,14 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { checkFileExist, uriToLocalFile } from '@/common/file';
|
||||
import fs from 'fs';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { GeneralCallResultStatus } from '@/core';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
image: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
image: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class OCRImageBase extends OneBotAction<Payload, GeneralCallResultStatus> {
|
||||
override payloadSchema = SchemaData;
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file_id: Type.String(),
|
||||
current_parent_directory: Type.String(),
|
||||
new_name: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
file_id: z.string(),
|
||||
current_parent_directory: z.string(),
|
||||
new_name: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
interface RenameGroupFileResponse {
|
||||
ok: boolean;
|
||||
|
@@ -1,22 +1,21 @@
|
||||
import { PacketHexStr } from '@/core/packet/transformer/base';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
cmd: Type.String(),
|
||||
data: Type.String(),
|
||||
rsp: Type.Union([Type.String(), Type.Boolean()], { default: true }),
|
||||
const SchemaData = z.object({
|
||||
cmd: z.string(),
|
||||
data: z.string(),
|
||||
rsp: z.boolean().default(true),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SendPacket extends GetPacketStatusDepends<Payload, string | undefined> {
|
||||
override payloadSchema = SchemaData;
|
||||
override actionName = ActionName.SendPacket;
|
||||
async _handle(payload: Payload) {
|
||||
const rsp = typeof payload.rsp === 'boolean' ? payload.rsp : payload.rsp === 'true';
|
||||
const data = await this.core.apis.PacketApi.pkt.operation.sendPacket({ cmd: payload.cmd, data: payload.data as PacketHexStr }, rsp);
|
||||
const data = await this.core.apis.PacketApi.pkt.operation.sendPacket({ cmd: payload.cmd, data: payload.data as PacketHexStr }, payload.rsp);
|
||||
return typeof data === 'object' ? data.toString('hex') : undefined;
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
face_id: Type.Union([Type.Number(), Type.String()]),// 参考 face_config.json 的 QSid
|
||||
face_type: Type.Union([Type.Number(), Type.String()], { default: '1' }),
|
||||
wording: Type.String({ default: ' ' }),
|
||||
const SchemaData = z.object({
|
||||
face_id: z.union([z.number(), z.string()]),// 参考 face_config.json 的 QSid
|
||||
face_type: z.union([z.number(), z.string()]).default('1'),
|
||||
wording: z.string().default(' '),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SetDiyOnlineStatus extends OneBotAction<Payload, string> {
|
||||
override actionName = ActionName.SetDiyOnlineStatus;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.String(),
|
||||
remark: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.string(),
|
||||
remark: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupRemark extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupRemark;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class SetGroupSignBase extends GetPacketStatusDepends<Payload, void> {
|
||||
override payloadSchema = SchemaData;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { ChatType } from '@/core';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
event_type: Type.Number(),
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
event_type: z.number(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SetInputStatus extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.SetInputStatus;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
longNick: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
longNick: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SetLongNick extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.SetLongNick;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
status: Type.Union([Type.Number(), Type.String()]),
|
||||
ext_status: Type.Union([Type.Number(), Type.String()]),
|
||||
battery_status: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
status: z.union([z.number(), z.string()]),
|
||||
ext_status: z.union([z.number(), z.string()]),
|
||||
battery_status: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SetOnlineStatus extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetOnlineStatus;
|
||||
|
@@ -2,13 +2,13 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import fs from 'node:fs/promises';
|
||||
import { checkFileExist, uriToLocalFile } from '@/common/file';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
file: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
file: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetAvatar extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetQQAvatar;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
special_title: Type.String({ default: '' }),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
special_title: z.string({ default: '' }),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SetSpecialTitle extends GetPacketStatusDepends<Payload, void> {
|
||||
override actionName = ActionName.SetSpecialTitle;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { GeneralCallResult } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
phoneNumber: Type.String({ default: '' }),
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.number(), z.string()]).optional(),
|
||||
group_id: z.union([z.number(), z.string()]).optional(),
|
||||
phoneNumber: z.string().default(''),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SharePeer extends OneBotAction<Payload, GeneralCallResult & {
|
||||
arkMsg?: string;
|
||||
@@ -28,11 +28,11 @@ export class SharePeer extends OneBotAction<Payload, GeneralCallResult & {
|
||||
}
|
||||
}
|
||||
|
||||
const SchemaDataGroupEx = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaDataGroupEx = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type PayloadGroupEx = Static<typeof SchemaDataGroupEx>;
|
||||
type PayloadGroupEx = z.infer<typeof SchemaDataGroupEx>;
|
||||
|
||||
export class ShareGroupEx extends OneBotAction<PayloadGroupEx, string> {
|
||||
override actionName = ActionName.ShareGroupEx;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file_id: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
file_id: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
interface TransGroupFileResponse {
|
||||
ok: boolean;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
words: Type.Array(Type.String()),
|
||||
const SchemaData = z.object({
|
||||
words: Type.Array(z.string()),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class TranslateEnWordToZn extends OneBotAction<Payload, Array<unknown> | null> {
|
||||
override actionName = ActionName.TranslateEnWordToZn;
|
||||
|
@@ -3,7 +3,7 @@ import fs from 'fs/promises';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OB11MessageImage, OB11MessageVideo } from '@/onebot/types';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
export interface GetFileResponse {
|
||||
file?: string; // path
|
||||
@@ -13,13 +13,13 @@ export interface GetFileResponse {
|
||||
base64?: string;
|
||||
}
|
||||
|
||||
const GetFileBase_PayloadSchema = Type.Object({
|
||||
file: Type.Optional(Type.String()),
|
||||
file_id: Type.Optional(Type.String())
|
||||
const GetFileBase_PayloadSchema = z.object({
|
||||
file: z.string().optional(),
|
||||
file_id: z.string().optional(),
|
||||
});
|
||||
|
||||
|
||||
export type GetFilePayload = Static<typeof GetFileBase_PayloadSchema>;
|
||||
export type GetFilePayload = z.infer<typeof GetFileBase_PayloadSchema>;
|
||||
|
||||
export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
|
||||
override payloadSchema = GetFileBase_PayloadSchema;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file_id: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
file_id: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
interface GetGroupFileUrlResponse {
|
||||
url?: string;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
file_id: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
file_id: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
interface GetPrivateFileUrlResponse {
|
||||
url?: string;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
folder_name: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
folder_name: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
interface ResponseType{
|
||||
result:unknown;
|
||||
groupItem:unknown;
|
||||
|
@@ -2,15 +2,15 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { NTQQGroupApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file_id: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
file_id: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class DeleteGroupFile extends OneBotAction<Payload, Awaited<ReturnType<NTQQGroupApi['delGroupFile']>>> {
|
||||
override actionName = ActionName.GOCQHTTP_DeleteGroupFile;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { NTQQGroupApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
folder_id: Type.Optional(Type.String()),
|
||||
folder: Type.Optional(Type.String()),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
folder_id: z.string().optional(),
|
||||
folder: z.string().optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class DeleteGroupFileFolder extends OneBotAction<Payload, Awaited<ReturnType<NTQQGroupApi['delGroupFileFolder']>>['groupFileCommonResult']> {
|
||||
override actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder;
|
||||
|
@@ -4,20 +4,20 @@ import fs from 'fs';
|
||||
import { join as joinPath } from 'node:path';
|
||||
import { calculateFileMD5, uriToLocalFile } from '@/common/file';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
interface FileResponse {
|
||||
file: string;
|
||||
}
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
url: Type.Optional(Type.String()),
|
||||
base64: Type.Optional(Type.String()),
|
||||
name: Type.Optional(Type.String()),
|
||||
headers: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())])),
|
||||
const SchemaData = z.object({
|
||||
url: z.string().optional(),
|
||||
base64: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
headers: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPDownloadFile extends OneBotAction<Payload, FileResponse> {
|
||||
override actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||
|
@@ -2,15 +2,14 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageForward, OB11MessageNodePlain as OB11MessageNode } from '@/onebot';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { ChatType, ElementType, MsgSourceType, NTMsgType, RawMessage } from '@/core';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.number(), z.string()]).optional(),
|
||||
id: z.union([z.number(), z.string()]).optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, {
|
||||
messages: OB11Message[] | undefined;
|
||||
|
@@ -3,22 +3,21 @@ import { OB11Message } from '@/onebot';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { ChatType } from '@/core/types';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
}
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
message_seq: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 20 }),
|
||||
reverseOrder: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
message_seq: z.union([z.number(), z.string()]).optional(),
|
||||
count: z.union([z.number(), z.string()]).default(20),
|
||||
reverseOrder: z.union([z.boolean(), z.string()]).optional()
|
||||
});
|
||||
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class GetFriendMsgHistory extends OneBotAction<Payload, Response> {
|
||||
override actionName = ActionName.GetFriendMsgHistory;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()])
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()])
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
interface ResponseType {
|
||||
can_at_all: boolean;
|
||||
remain_at_all_count_for_group: number;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()])
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()])
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupFileSystemInfo extends OneBotAction<Payload, {
|
||||
file_count: number,
|
||||
|
@@ -2,16 +2,16 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
folder_id: Type.Optional(Type.String()),
|
||||
folder: Type.Optional(Type.String()),
|
||||
file_count: Type.Union([Type.Number(), Type.String()], { default: 50 }),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
folder_id: z.string().optional(),
|
||||
folder: z.string().optional(),
|
||||
file_count: z.union([z.number(), z.string()]).default(50),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupFilesByFolder extends OneBotAction<Payload, {
|
||||
files: ReturnType<typeof OB11Construct.file>[],
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { WebHonorType } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { WebHonorType } from '@/core/types';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
type: Type.Optional(Type.Enum(WebHonorType))
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
type: z.nativeEnum(WebHonorType).optional()
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupHonorInfo extends OneBotAction<Payload, Array<unknown>> {
|
||||
export class GetGroupHonorInfo extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GetGroupHonorInfo;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
|
@@ -3,22 +3,22 @@ import { OB11Message } from '@/onebot';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { ChatType, Peer } from '@/core/types';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
}
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
message_seq: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 20 }),
|
||||
reverseOrder: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
message_seq: z.union([z.number(), z.string()]).optional(),
|
||||
count: z.union([z.number(), z.string()]).default(20),
|
||||
reverseOrder: z.union([z.boolean(), z.string()]).optional()
|
||||
});
|
||||
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
|
||||
export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<Payload, Response> {
|
||||
|
@@ -3,14 +3,14 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OB11GroupFile, OB11GroupFileFolder } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file_count: Type.Union([Type.Number(), Type.String()], { default: 50 }),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
file_count: z.union([z.number(), z.string()]).default(50),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupRootFiles extends OneBotAction<Payload, {
|
||||
files: OB11GroupFile[],
|
||||
|
@@ -3,14 +3,14 @@ import { OB11User, OB11UserSex } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { calcQQLevel } from '@/common/helper';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
no_cache: Type.Union([Type.Boolean(), Type.String()], { default: false }),
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
no_cache: z.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User & { uid: string }> {
|
||||
override actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
url: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
url: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPCheckUrlSafely extends OneBotAction<Payload, { level: number }> {
|
||||
override actionName = ActionName.GoCQHTTP_CheckUrlSafely;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
friend_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||
user_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||
temp_block: Type.Optional(Type.Boolean()),
|
||||
temp_both_del: Type.Optional(Type.Boolean()),
|
||||
const SchemaData = z.object({
|
||||
friend_id: z.union([z.string(), z.number()]).optional(),
|
||||
user_id: z.union([z.string(), z.number()]).optional(),
|
||||
temp_block: z.boolean().optional(),
|
||||
temp_both_del: z.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPDeleteFriend extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GoCQHTTP_DeleteFriend;
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
model: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
model: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPGetModelShow extends OneBotAction<Payload, Array<{
|
||||
variants: {
|
||||
|
@@ -2,20 +2,20 @@ import { checkFileExist, uriToLocalFile } from '@/common/file';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { unlink } from 'node:fs/promises';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
content: Type.String(),
|
||||
image: Type.Optional(Type.String()),
|
||||
pinned: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||
type: Type.Union([Type.Number(), Type.String()], { default: 1 }),
|
||||
confirm_required: Type.Union([Type.Number(), Type.String()], { default: 1 }),
|
||||
is_show_edit_card: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||
tip_window_type: Type.Union([Type.Number(), Type.String()], { default: 0 })
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
content: z.string(),
|
||||
image: z.string().optional(),
|
||||
pinned: z.union([z.number(), z.string()]).default(0),
|
||||
type: z.union([z.number(), z.string()]).default(1),
|
||||
confirm_required: z.union([z.number(), z.string()]).default(1),
|
||||
is_show_edit_card: z.union([z.number(), z.string()]).default(0),
|
||||
tip_window_type: z.union([z.number(), z.string()]).default(0),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SendGroupNotice extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { checkFileExistV2, uriToLocalFile } from '@/common/file';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import fs from 'node:fs/promises';
|
||||
import { GeneralCallResult } from '@/core';
|
||||
const SchemaData = Type.Object({
|
||||
file: Type.String(),
|
||||
group_id: Type.Union([Type.Number(), Type.String()])
|
||||
const SchemaData = z.object({
|
||||
file: z.string(),
|
||||
group_id: z.union([z.number(), z.string()])
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupPortrait extends OneBotAction<Payload, GeneralCallResult> {
|
||||
override actionName = ActionName.SetGroupPortrait;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
nickname: Type.String(),
|
||||
personal_note: Type.Optional(Type.String()),
|
||||
sex: Type.Optional(Type.Union([Type.Number(), Type.String()])), // 传Sex值?建议传0
|
||||
const SchemaData = z.object({
|
||||
nickname: z.string(),
|
||||
personal_note: z.string().optional(),
|
||||
sex: z.union([z.number(), z.string()]).optional(), // 传Sex值?建议传0
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
export class SetQQProfile extends OneBotAction<Payload, Awaited<ReturnType<NTQQUserApi['modifySelfProfile']>> | null> {
|
||||
override actionName = ActionName.SetQQProfile;
|
||||
override payloadSchema = SchemaData;
|
||||
|
@@ -4,17 +4,17 @@ import { ChatType, Peer } from '@/core/types';
|
||||
import fs from 'fs';
|
||||
import { uriToLocalFile } from '@/common/file';
|
||||
import { SendMessageContext } from '@/onebot/api';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file: Type.String(),
|
||||
name: Type.String(),
|
||||
folder: Type.Optional(Type.String()),
|
||||
folder_id: Type.Optional(Type.String()),//临时扩展
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
file: z.string(),
|
||||
name: z.string(),
|
||||
folder: z.string().optional(),
|
||||
folder_id: z.string().optional(),//临时扩展
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||
|
@@ -5,15 +5,15 @@ import fs from 'fs';
|
||||
import { uriToLocalFile } from '@/common/file';
|
||||
import { SendMessageContext } from '@/onebot/api';
|
||||
import { ContextMode, createContext } from '@/onebot/action/msg/SendMsg';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
file: Type.String(),
|
||||
name: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
file: z.string(),
|
||||
name: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPUploadPrivateFile extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
export default class DelEssenceMsg extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.DelEssenceMsg;
|
||||
override payloadSchema = SchemaData;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
notice_id: Type.String()
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
notice_id: z.string()
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class DelGroupNotice extends OneBotAction<Payload, void> {
|
||||
override actionName = ActionName.DelGroupNotice;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { AIVoiceChatType } from '@/core/packet/entities/aiChat';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
character: Type.String(),
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
text: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
character: z.string(),
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
text: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetAiRecord extends GetPacketStatusDepends<Payload, string> {
|
||||
override actionName = ActionName.GetAiRecord;
|
||||
|
@@ -3,14 +3,14 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import crypto from 'crypto';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupEssence extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||
|
@@ -2,13 +2,13 @@ import { OB11Group } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class GetGroupInfo extends OneBotAction<Payload, OB11Group> {
|
||||
override actionName = ActionName.GetGroupInfo;
|
||||
|
@@ -2,13 +2,13 @@ import { OB11Group } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
no_cache: z.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class GetGroupList extends OneBotAction<Payload, OB11Group[]> {
|
||||
override actionName = ActionName.GetGroupList;
|
||||
|
@@ -2,15 +2,15 @@ import { OB11GroupMember } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
no_cache: z.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class GetGroupMemberInfo extends OneBotAction<Payload, OB11GroupMember> {
|
||||
override actionName = ActionName.GetGroupMemberInfo;
|
||||
|
@@ -2,15 +2,15 @@ import { OB11GroupMember } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { GroupMember } from '@/core';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
no_cache: z.boolean().default(false)
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupMemberList extends OneBotAction<Payload, OB11GroupMember[]> {
|
||||
override actionName = ActionName.GetGroupMemberList;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { WebApiGroupNoticeFeed } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
interface GroupNotice {
|
||||
sender_id: number;
|
||||
publish_time: number;
|
||||
@@ -16,11 +16,11 @@ interface GroupNotice {
|
||||
};
|
||||
}
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed;
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { ShutUpGroupMember } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetGroupShutList extends OneBotAction<Payload, ShutUpGroupMember[]> {
|
||||
override actionName = ActionName.GetGroupShutList;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GroupPoke extends GetPacketStatusDepends<Payload, void> {
|
||||
override actionName = ActionName.GroupPoke;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { AIVoiceChatType } from '@/core/packet/entities/aiChat';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
character: Type.String(),
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
text: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
character: z.string(),
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
text: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
|
||||
export class SendGroupAiRecord extends GetPacketStatusDepends<Payload, {
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetEssenceMsg extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.SetEssenceMsg;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { NTGroupRequestOperateTypes } from '@/core/types';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
flag: Type.Union([Type.String(), Type.Number()]),
|
||||
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
reason: Type.Optional(Type.Union([Type.String({ default: ' ' }), Type.Null()])),
|
||||
const SchemaData = z.object({
|
||||
flag: z.union([z.string(), z.number()]),
|
||||
approve: z.boolean().default(true),
|
||||
reason: z.union([z.string(), z.null()]).default(' '),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupAddRequest;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { NTGroupMemberRole } from '@/core/types';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
enable: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
enable: z.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupAdmin extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupAdmin;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
duration: Type.Union([Type.Number(), Type.String()], { default: 0 }),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
duration: z.union([z.number(), z.string()]).default(0),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupBan extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupBan;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
card: Type.Optional(Type.String())
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
card: z.string().optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupCard extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupCard;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
reject_add_request: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
reject_add_request: z.union([z.boolean(), z.string()]).optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupKick extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupKick;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
is_dismiss: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
is_dismiss: z.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupLeave extends OneBotAction<Payload, void> {
|
||||
override actionName = ActionName.SetGroupLeave;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
group_name: Type.String(),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
group_name: z.string(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupName extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupName;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
enable: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]),
|
||||
enable: z.union([z.boolean(), z.string()]).optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupWholeBan extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetGroupWholeBan;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class DeleteMsg extends OneBotAction<Payload, void> {
|
||||
override actionName = ActionName.DeleteMsg;
|
||||
|
@@ -2,15 +2,15 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ChatType, Peer } from '@/core/types';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.number(), z.string()]),
|
||||
group_id: z.string().optional(),
|
||||
user_id: z.string().optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class ForwardSingleMsg extends OneBotAction<Payload, null> {
|
||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||
|
@@ -3,16 +3,16 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { RawMessage } from '@/core';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
|
||||
export type ReturnDataType = OB11Message
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
class GetMsg extends OneBotAction<Payload, OB11Message> {
|
||||
override actionName = ActionName.GetMsg;
|
||||
|
@@ -2,15 +2,15 @@ import { ChatType, Peer } from '@/core/types';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||
group_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||
message_id: Type.Optional(Type.Union([Type.String(), Type.Number()])),
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.string(), z.number()]).optional(),
|
||||
group_id: z.union([z.string(), z.number()]).optional(),
|
||||
message_id: z.union([z.string(), z.number()]).optional(),
|
||||
});
|
||||
|
||||
type PlayloadType = Static<typeof SchemaData>;
|
||||
type PlayloadType = z.infer<typeof SchemaData>;
|
||||
|
||||
class MarkMsgAsRead extends OneBotAction<PlayloadType, null> {
|
||||
async getPeer(payload: PlayloadType): Promise<Peer> {
|
||||
|
@@ -1,15 +1,15 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
message_id: Type.Union([Type.Number(), Type.String()]),
|
||||
emoji_id: Type.Union([Type.Number(), Type.String()]),
|
||||
set: Type.Optional(Type.Union([Type.Boolean(), Type.String()]))
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.number(), z.string()]),
|
||||
emoji_id: z.union([z.number(), z.string()]),
|
||||
set: z.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SetMsgEmojiLike extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.SetMsgEmojiLike;
|
||||
|
@@ -8,7 +8,7 @@ export class GetRkeyEx extends GetPacketStatusDepends<void, unknown> {
|
||||
let rkeys = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||
return rkeys.map(rkey => {
|
||||
return {
|
||||
type: rkey.type === 10 ? "private" : "group",
|
||||
type: rkey.type === 10 ? 'private' : 'group',
|
||||
rkey: rkey.rkey,
|
||||
created_at: rkey.time,
|
||||
ttl: rkey.ttl,
|
||||
|
@@ -30,7 +30,7 @@ export class GetRkeyServer extends GetPacketStatusDepends<void, { private_rkey?:
|
||||
private_rkey: privateRkeyItem ? privateRkeyItem.rkey : undefined,
|
||||
group_rkey: groupRkeyItem ? groupRkeyItem.rkey : undefined,
|
||||
expired_time: this.expiryTime,
|
||||
name: "NapCat 4"
|
||||
name: 'NapCat 4'
|
||||
};
|
||||
|
||||
return this.rkeyCache;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
|
||||
user_id: Type.Union([Type.Number(), Type.String()]),
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.number(), z.string()]).optional(),
|
||||
user_id: z.union([z.number(), z.string()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class SendPoke extends GetPacketStatusDepends<Payload, void> {
|
||||
override actionName = ActionName.SendPoke;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
interface Response {
|
||||
cookies: string,
|
||||
token: number
|
||||
}
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
domain: Type.String()
|
||||
const SchemaData = z.object({
|
||||
domain: z.string()
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
|
||||
export class GetCredentials extends OneBotAction<Payload, Response> {
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
user_id: Type.Union([Type.Number(), Type.String()])
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.number(), z.string()])
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class FriendPoke extends GetPacketStatusDepends<Payload, void> {
|
||||
override actionName = ActionName.FriendPoke;
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
interface Response {
|
||||
cookies: string,
|
||||
bkn: string
|
||||
}
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
domain: Type.String()
|
||||
const SchemaData = z.object({
|
||||
domain: z.string()
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export class GetCookies extends OneBotAction<Payload, Response> {
|
||||
override actionName = ActionName.GetCookies;
|
||||
|
@@ -2,13 +2,13 @@ import { OB11User } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
const SchemaData = z.object({
|
||||
no_cache: z.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class GetFriendList extends OneBotAction<Payload, OB11User[]> {
|
||||
override actionName = ActionName.GetFriendList;
|
||||
|
@@ -2,13 +2,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 10 }),
|
||||
const SchemaData = z.object({
|
||||
count: z.number().default(10),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class GetRecentContact extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GetRecentContact;
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
times: Type.Union([Type.Number(), Type.String()], { default: 1 }),
|
||||
user_id: Type.Union([Type.Number(), Type.String()])
|
||||
const SchemaData = z.object({
|
||||
times: z.union([z.number(), z.string()]).default(1),
|
||||
user_id: z.union([z.number(), z.string()])
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SendLike extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SendLike;
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { z } from 'zod';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
flag: Type.Union([Type.String(), Type.Number()]),
|
||||
approve: Type.Optional(Type.Union([Type.String(), Type.Boolean()])),
|
||||
remark: Type.Optional(Type.String())
|
||||
const SchemaData = z.object({
|
||||
flag: z.union([z.string(), z.number()]),
|
||||
approve: z.union([z.string(), z.boolean()]).default(true),
|
||||
remark: z.union([z.string(), z.null()]).nullable().optional()
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
export default class SetFriendAddRequest extends OneBotAction<Payload, null> {
|
||||
override actionName = ActionName.SetFriendAddRequest;
|
||||
|
@@ -1000,16 +1000,16 @@ export class OneBotMsgApi {
|
||||
const calculateTotalSize = async (elements: SendMessageElement[]): Promise<number> => {
|
||||
const sizePromises = elements.map(async element => {
|
||||
switch (element.elementType) {
|
||||
case ElementType.PTT:
|
||||
return (await fsPromise.stat(element.pttElement.filePath)).size;
|
||||
case ElementType.FILE:
|
||||
return (await fsPromise.stat(element.fileElement.filePath)).size;
|
||||
case ElementType.VIDEO:
|
||||
return (await fsPromise.stat(element.videoElement.filePath)).size;
|
||||
case ElementType.PIC:
|
||||
return (await fsPromise.stat(element.picElement.sourcePath)).size;
|
||||
default:
|
||||
return 0;
|
||||
case ElementType.PTT:
|
||||
return (await fsPromise.stat(element.pttElement.filePath)).size;
|
||||
case ElementType.FILE:
|
||||
return (await fsPromise.stat(element.fileElement.filePath)).size;
|
||||
case ElementType.VIDEO:
|
||||
return (await fsPromise.stat(element.videoElement.filePath)).size;
|
||||
case ElementType.PIC:
|
||||
return (await fsPromise.stat(element.picElement.sourcePath)).size;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
const sizes = await Promise.all(sizePromises);
|
||||
@@ -1099,14 +1099,14 @@ export class OneBotMsgApi {
|
||||
|
||||
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
||||
switch (type) {
|
||||
case 130:
|
||||
return 'leave';
|
||||
case 131:
|
||||
return 'kick';
|
||||
case 3:
|
||||
return 'kick_me';
|
||||
default:
|
||||
return 'kick';
|
||||
case 130:
|
||||
return 'leave';
|
||||
case 131:
|
||||
return 'kick';
|
||||
case 3:
|
||||
return 'kick_me';
|
||||
default:
|
||||
return 'kick';
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,108 +1,107 @@
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import Ajv from 'ajv';
|
||||
import { z } from 'zod';
|
||||
|
||||
const HttpServerConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'http-server' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
port: Type.Number({ default: 3000 }),
|
||||
host: Type.String({ default: '0.0.0.0' }),
|
||||
enableCors: Type.Boolean({ default: true }),
|
||||
enableWebsocket: Type.Boolean({ default: true }),
|
||||
messagePostFormat: Type.String({ default: 'array' }),
|
||||
token: Type.String({ default: '' }),
|
||||
debug: Type.Boolean({ default: false })
|
||||
const HttpServerConfigSchema = z.object({
|
||||
name: z.string().default('http-server'),
|
||||
enable: z.boolean().default(false),
|
||||
port: z.number().default(3000),
|
||||
host: z.string().default('0.0.0.0'),
|
||||
enableCors: z.boolean().default(true),
|
||||
enableWebsocket: z.boolean().default(true),
|
||||
messagePostFormat: z.string().default('array'),
|
||||
token: z.string().default(''),
|
||||
debug: z.boolean().default(false)
|
||||
});
|
||||
|
||||
const HttpSseServerConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'http-sse-server' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
port: Type.Number({ default: 3000 }),
|
||||
host: Type.String({ default: '0.0.0.0' }),
|
||||
enableCors: Type.Boolean({ default: true }),
|
||||
enableWebsocket: Type.Boolean({ default: true }),
|
||||
messagePostFormat: Type.String({ default: 'array' }),
|
||||
token: Type.String({ default: '' }),
|
||||
debug: Type.Boolean({ default: false }),
|
||||
reportSelfMessage: Type.Boolean({ default: false })
|
||||
const HttpSseServerConfigSchema = z.object({
|
||||
name: z.string().default('http-sse-server'),
|
||||
enable: z.boolean().default(false),
|
||||
port: z.number().default(3000),
|
||||
host: z.string().default('0.0.0.0'),
|
||||
enableCors: z.boolean().default(true),
|
||||
enableWebsocket: z.boolean().default(true),
|
||||
messagePostFormat: z.string().default('array'),
|
||||
token: z.string().default(''),
|
||||
debug: z.boolean().default(false),
|
||||
reportSelfMessage: z.boolean().default(false)
|
||||
});
|
||||
|
||||
const HttpClientConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'http-client' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
url: Type.String({ default: 'http://localhost:8080' }),
|
||||
messagePostFormat: Type.String({ default: 'array' }),
|
||||
reportSelfMessage: Type.Boolean({ default: false }),
|
||||
token: Type.String({ default: '' }),
|
||||
debug: Type.Boolean({ default: false })
|
||||
const HttpClientConfigSchema = z.object({
|
||||
name: z.string().default('http-client'),
|
||||
enable: z.boolean().default(false),
|
||||
url: z.string().default('http://localhost:8080'),
|
||||
messagePostFormat: z.string().default('array'),
|
||||
reportSelfMessage: z.boolean().default(false),
|
||||
token: z.string().default(''),
|
||||
debug: z.boolean().default(false)
|
||||
});
|
||||
|
||||
const WebsocketServerConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'websocket-server' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
host: Type.String({ default: '0.0.0.0' }),
|
||||
port: Type.Number({ default: 3001 }),
|
||||
messagePostFormat: Type.String({ default: 'array' }),
|
||||
reportSelfMessage: Type.Boolean({ default: false }),
|
||||
token: Type.String({ default: '' }),
|
||||
enableForcePushEvent: Type.Boolean({ default: true }),
|
||||
debug: Type.Boolean({ default: false }),
|
||||
heartInterval: Type.Number({ default: 30000 })
|
||||
const WebsocketServerConfigSchema = z.object({
|
||||
name: z.string().default('websocket-server'),
|
||||
enable: z.boolean().default(false),
|
||||
host: z.string().default('0.0.0.0'),
|
||||
port: z.number().default(3001),
|
||||
messagePostFormat: z.string().default('array'),
|
||||
reportSelfMessage: z.boolean().default(false),
|
||||
token: z.string().default(''),
|
||||
enableForcePushEvent: z.boolean().default(true),
|
||||
debug: z.boolean().default(false),
|
||||
heartInterval: z.number().default(30000)
|
||||
});
|
||||
|
||||
const WebsocketClientConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'websocket-client' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
url: Type.String({ default: 'ws://localhost:8082' }),
|
||||
messagePostFormat: Type.String({ default: 'array' }),
|
||||
reportSelfMessage: Type.Boolean({ default: false }),
|
||||
reconnectInterval: Type.Number({ default: 5000 }),
|
||||
token: Type.String({ default: '' }),
|
||||
debug: Type.Boolean({ default: false }),
|
||||
heartInterval: Type.Number({ default: 30000 })
|
||||
const WebsocketClientConfigSchema = z.object({
|
||||
name: z.string().default('websocket-client'),
|
||||
enable: z.boolean().default(false),
|
||||
url: z.string().default('ws://localhost:8082'),
|
||||
messagePostFormat: z.string().default('array'),
|
||||
reportSelfMessage: z.boolean().default(false),
|
||||
reconnectInterval: z.number().default(5000),
|
||||
token: z.string().default(''),
|
||||
debug: z.boolean().default(false),
|
||||
heartInterval: z.number().default(30000)
|
||||
});
|
||||
|
||||
const PluginConfigSchema = Type.Object({
|
||||
name: Type.String({ default: 'plugin' }),
|
||||
enable: Type.Boolean({ default: false }),
|
||||
messagePostFormat: Type.String({ default: 'array' }),
|
||||
reportSelfMessage: Type.Boolean({ default: false }),
|
||||
debug: Type.Boolean({ default: false }),
|
||||
const PluginConfigSchema = z.object({
|
||||
name: z.string().default('plugin'),
|
||||
enable: z.boolean().default(false),
|
||||
messagePostFormat: z.string().default('array'),
|
||||
reportSelfMessage: z.boolean().default(false),
|
||||
debug: z.boolean().default(false),
|
||||
});
|
||||
|
||||
const NetworkConfigSchema = Type.Object({
|
||||
httpServers: Type.Array(HttpServerConfigSchema, { default: [] }),
|
||||
httpSseServers: Type.Array(HttpSseServerConfigSchema, { default: [] }),
|
||||
httpClients: Type.Array(HttpClientConfigSchema, { default: [] }),
|
||||
websocketServers: Type.Array(WebsocketServerConfigSchema, { default: [] }),
|
||||
websocketClients: Type.Array(WebsocketClientConfigSchema, { default: [] }),
|
||||
plugins: Type.Array(PluginConfigSchema, { default: [] })
|
||||
}, { default: {} });
|
||||
const NetworkConfigSchema = z.object({
|
||||
httpServers: z.array(HttpServerConfigSchema).default([]),
|
||||
httpSseServers: z.array(HttpSseServerConfigSchema).default([]),
|
||||
httpClients: z.array(HttpClientConfigSchema).default([]),
|
||||
websocketServers: z.array(WebsocketServerConfigSchema).default([]),
|
||||
websocketClients: z.array(WebsocketClientConfigSchema).default([]),
|
||||
plugins: z.array(PluginConfigSchema).default([])
|
||||
}).default({});
|
||||
|
||||
export const OneBotConfigSchema = Type.Object({
|
||||
export const OneBotConfigSchema = z.object({
|
||||
network: NetworkConfigSchema,
|
||||
musicSignUrl: Type.String({ default: '' }),
|
||||
enableLocalFile2Url: Type.Boolean({ default: false }),
|
||||
parseMultMsg: Type.Boolean({ default: false })
|
||||
musicSignUrl: z.string().default(''),
|
||||
enableLocalFile2Url: z.boolean().default(false),
|
||||
parseMultMsg: z.boolean().default(false)
|
||||
});
|
||||
|
||||
export type OneBotConfig = Static<typeof OneBotConfigSchema>;
|
||||
export type HttpServerConfig = Static<typeof HttpServerConfigSchema>;
|
||||
export type HttpSseServerConfig = Static<typeof HttpSseServerConfigSchema>;
|
||||
export type HttpClientConfig = Static<typeof HttpClientConfigSchema>;
|
||||
export type WebsocketServerConfig = Static<typeof WebsocketServerConfigSchema>;
|
||||
export type WebsocketClientConfig = Static<typeof WebsocketClientConfigSchema>;
|
||||
export type PluginConfig = Static<typeof PluginConfigSchema>;
|
||||
export type OneBotConfig = z.infer<typeof OneBotConfigSchema>;
|
||||
export type HttpServerConfig = z.infer<typeof HttpServerConfigSchema>;
|
||||
export type HttpSseServerConfig = z.infer<typeof HttpSseServerConfigSchema>;
|
||||
export type HttpClientConfig = z.infer<typeof HttpClientConfigSchema>;
|
||||
export type WebsocketServerConfig = z.infer<typeof WebsocketServerConfigSchema>;
|
||||
export type WebsocketClientConfig = z.infer<typeof WebsocketClientConfigSchema>;
|
||||
export type PluginConfig = z.infer<typeof PluginConfigSchema>;
|
||||
|
||||
export type NetworkAdapterConfig = HttpServerConfig | HttpSseServerConfig | HttpClientConfig | WebsocketServerConfig | WebsocketClientConfig | PluginConfig;
|
||||
export type NetworkConfigKey = keyof OneBotConfig['network'];
|
||||
|
||||
|
||||
export function loadConfig(config: Partial<OneBotConfig>): OneBotConfig {
|
||||
const ajv = new Ajv({ useDefaults: true, coerceTypes: true });
|
||||
const validate = ajv.compile(OneBotConfigSchema);
|
||||
const valid = validate(config);
|
||||
if (!valid) {
|
||||
throw new Error(ajv.errorsText(validate.errors));
|
||||
try {
|
||||
return OneBotConfigSchema.parse(config);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
throw new Error(error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', '));
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return config as OneBotConfig;
|
||||
}
|
@@ -1,10 +1,11 @@
|
||||
import { ConfigBase } from '@/common/config-base';
|
||||
import type { NapCatCore } from '@/core';
|
||||
import { OneBotConfig } from './config';
|
||||
import { AnySchema } from 'ajv';
|
||||
import { z } from 'zod';
|
||||
|
||||
|
||||
export class OB11ConfigLoader extends ConfigBase<OneBotConfig> {
|
||||
constructor(core: NapCatCore, configPath: string, schema: AnySchema) {
|
||||
constructor(core: NapCatCore, configPath: string, schema: z.ZodType<OneBotConfig>) {
|
||||
super('onebot11', core, configPath, schema);
|
||||
}
|
||||
}
|
||||
|
@@ -141,7 +141,7 @@ async function handleLogin(
|
||||
handleLoginInner(context, logger, loginService, quickLoginUin, historyLoginList).then().catch(e => logger.logError(e));
|
||||
loginListener.onLoginConnected = () => { };
|
||||
});
|
||||
}
|
||||
};
|
||||
loginListener.onQRCodeGetPicture = ({ pngBase64QrcodeData, qrcodeUrl }) => {
|
||||
WebUiDataRuntime.setQQLoginQrcodeURL(qrcodeUrl);
|
||||
|
||||
@@ -220,7 +220,7 @@ async function handleLoginInner(context: { isLogined: boolean }, logger: LogWrap
|
||||
logger.log(`可用于快速登录的 QQ:\n${historyLoginList
|
||||
.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
||||
.join('\n')
|
||||
}`);
|
||||
}`);
|
||||
}
|
||||
loginService.getQRCodePicture();
|
||||
try {
|
||||
|
@@ -1,33 +1,27 @@
|
||||
import { webUiPathWrapper } from '@/webui';
|
||||
import { Type, Static } from '@sinclair/typebox';
|
||||
import Ajv from 'ajv';
|
||||
import fs, { constants } from 'node:fs/promises';
|
||||
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { deepMerge } from '../utils/object';
|
||||
import { themeType } from '../types/theme';
|
||||
|
||||
// 限制尝试端口的次数,避免死循环
|
||||
|
||||
import { z } from 'zod';
|
||||
// 定义配置的类型
|
||||
const WebUiConfigSchema = Type.Object({
|
||||
host: Type.String({ default: '0.0.0.0' }),
|
||||
port: Type.Number({ default: 6099 }),
|
||||
token: Type.String({ default: 'napcat' }),
|
||||
loginRate: Type.Number({ default: 10 }),
|
||||
autoLoginAccount: Type.String({ default: '' }),
|
||||
const WebUiConfigSchema = z.object({
|
||||
host: z.string().default('0.0.0.0'),
|
||||
port: z.number().default(6099),
|
||||
token: z.string().default('napcat'),
|
||||
loginRate: z.number().default(10),
|
||||
autoLoginAccount: z.string().default(''),
|
||||
theme: themeType,
|
||||
});
|
||||
|
||||
export type WebUiConfigType = Static<typeof WebUiConfigSchema>;
|
||||
export type WebUiConfigType = z.infer<typeof WebUiConfigSchema>;
|
||||
|
||||
// 读取当前目录下名为 webui.json 的配置文件,如果不存在则创建初始化配置文件
|
||||
export class WebUiConfigWrapper {
|
||||
WebUiConfigData: WebUiConfigType | undefined = undefined;
|
||||
|
||||
private validateAndApplyDefaults(config: Partial<WebUiConfigType>): WebUiConfigType {
|
||||
new Ajv({ coerceTypes: true, useDefaults: true }).compile(WebUiConfigSchema)(config);
|
||||
config = WebUiConfigSchema.parse(config);
|
||||
return config as WebUiConfigType;
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user