From c3a48e33449f612f709628a623f2f17dc642b1d9 Mon Sep 17 00:00:00 2001 From: huankong233 Date: Mon, 21 Oct 2024 19:51:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E5=A5=BD=E5=8F=8B/=E7=BE=A4=E8=81=8A=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=B7=B2=E8=AF=BB=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/onebot/action/msg/MarkMsgAsRead.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/onebot/action/msg/MarkMsgAsRead.ts b/src/onebot/action/msg/MarkMsgAsRead.ts index bfbc0e7a..279f4966 100644 --- a/src/onebot/action/msg/MarkMsgAsRead.ts +++ b/src/onebot/action/msg/MarkMsgAsRead.ts @@ -1,7 +1,7 @@ import { ChatType, Peer } from '@/core/entities'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; -import { FromSchema, JSONSchema } from 'json-schema-to-ts'; const SchemaData = { type: 'object', @@ -49,23 +49,14 @@ export class MarkGroupMsgAsRead extends MarkMsgAsRead { actionName = ActionName.MarkGroupMsgAsRead; } - -interface Payload { - message_id: number; -} - -export class GoCQHTTPMarkMsgAsRead extends BaseAction { +export class GoCQHTTPMarkMsgAsRead extends MarkMsgAsRead { actionName = ActionName.GoCQHTTP_MarkMsgAsRead; - - async _handle(payload: Payload): Promise { - return null; - } } -export class MarkAllMsgAsRead extends BaseAction { +export class MarkAllMsgAsRead extends BaseAction { actionName = ActionName._MarkAllMsgAsRead; - async _handle(payload: Payload): Promise { + async _handle(): Promise { await this.core.apis.MsgApi.markAllMsgAsRead(); return null; } From 1aa1f4c21290ffb55b78ce21ec3b7ac5672aad9b Mon Sep 17 00:00:00 2001 From: huankong233 Date: Tue, 22 Oct 2024 09:48:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=20getFile=20=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/onebot/action/file/GetFile.ts | 42 +++++++++++-------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/onebot/action/file/GetFile.ts b/src/onebot/action/file/GetFile.ts index 40f705ca..790459f9 100644 --- a/src/onebot/action/file/GetFile.ts +++ b/src/onebot/action/file/GetFile.ts @@ -5,9 +5,9 @@ import { ActionName } from '../types'; import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import { OB11MessageImage, OB11MessageVideo } from '@/onebot/types'; -export interface GetFilePayload { - file: string; // 文件名或者fileUuid -} +// interface GetFilePayload { +// file: string; // 文件名或者fileUuid +// } export interface GetFileResponse { file?: string; // path @@ -21,14 +21,23 @@ const GetFileBase_PayloadSchema = { type: 'object', properties: { file: { type: 'string' }, - }, - required: ['file'], + file_id: { type: "string" } + } } as const satisfies JSONSchema; +export type GetFilePayload = FromSchema; + export class GetFileBase extends BaseAction { - payloadSchema: any = GetFileBase_PayloadSchema; + payloadSchema = GetFileBase_PayloadSchema; async _handle(payload: GetFilePayload): Promise { + if(!payload.file){ + if(payload.file_id){ + payload.file = payload.file_id; + }else{ + throw new Error('必须传入 file 或 file_id'); + } + } //接收消息标记模式 const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file); if (contextMsgFile) { @@ -115,27 +124,6 @@ export class GetFileBase extends BaseAction { } } -const GetFile_PayloadSchema = { - type: 'object', - properties: { - file_id: { type: 'string' }, - file: { type: 'string' }, - }, - required: ['file_id'], -} as const satisfies JSONSchema; - -type GetFile_Payload_Internal = FromSchema; - -interface GetFile_Payload extends GetFile_Payload_Internal { - file: string; -} - export default class GetFile extends GetFileBase { actionName = ActionName.GetFile; - payloadSchema = GetFile_PayloadSchema; - - async _handle(payload: GetFile_Payload): Promise { - payload.file = payload.file_id; - return super._handle(payload); - } } From 052d17a46fa5c3df56cd6346384f308eb4efd638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 22 Oct 2024 10:15:16 +0800 Subject: [PATCH 3/3] fix: getfile --- src/onebot/action/file/GetFile.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/onebot/action/file/GetFile.ts b/src/onebot/action/file/GetFile.ts index 790459f9..521d82a4 100644 --- a/src/onebot/action/file/GetFile.ts +++ b/src/onebot/action/file/GetFile.ts @@ -16,13 +16,16 @@ export interface GetFileResponse { file_name?: string; base64?: string; } - const GetFileBase_PayloadSchema = { type: 'object', properties: { file: { type: 'string' }, - file_id: { type: "string" } - } + file_id: { type: 'string' } + }, + oneOf: [ + { required: ['file'] }, + { required: ['file_id'] } + ] } as const satisfies JSONSchema; export type GetFilePayload = FromSchema; @@ -31,13 +34,7 @@ export class GetFileBase extends BaseAction { payloadSchema = GetFileBase_PayloadSchema; async _handle(payload: GetFilePayload): Promise { - if(!payload.file){ - if(payload.file_id){ - payload.file = payload.file_id; - }else{ - throw new Error('必须传入 file 或 file_id'); - } - } + payload.file ||= payload.file_id || ''; //接收消息标记模式 const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file); if (contextMsgFile) {