From 48f12fc30b573eaca965bb62ab11d48865c2d8c0 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Mon, 25 Mar 2024 18:52:15 +0800 Subject: [PATCH] fix: pic subType --- src/ntqqapi/api/file.ts | 7 ++++--- src/ntqqapi/constructor.ts | 20 ++++++++++---------- src/ntqqapi/types/msg.ts | 14 ++++++++++---- src/onebot11/action/msg/SendMsg.ts | 4 ++-- src/onebot11/types.ts | 6 ++++-- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/ntqqapi/api/file.ts b/src/ntqqapi/api/file.ts index 76016ef..cad1f70 100644 --- a/src/ntqqapi/api/file.ts +++ b/src/ntqqapi/api/file.ts @@ -47,7 +47,7 @@ export class NTQQFileApi { } // 上传文件到QQ的文件夹 - static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) { + static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) { const md5 = await NTQQFileApi.getFileMd5(filePath); let ext = (await NTQQFileApi.getFileType(filePath))?.ext if (ext) { @@ -66,7 +66,7 @@ export class NTQQFileApi { md5HexStr: md5, fileName: fileName, elementType: elementType, - elementSubType: 0, + elementSubType, thumbSize: 0, needCreate: true, downloadType: 1, @@ -81,7 +81,8 @@ export class NTQQFileApi { md5, fileName, path: mediaPath, - fileSize + fileSize, + ext } } diff --git a/src/ntqqapi/constructor.ts b/src/ntqqapi/constructor.ts index 90468a1..8c19c43 100644 --- a/src/ntqqapi/constructor.ts +++ b/src/ntqqapi/constructor.ts @@ -62,32 +62,32 @@ export class SendMsgElementConstructor { } } - static async pic(picPath: string, summary: string = ""): Promise { - const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC); + static async pic(picPath: string, summary: string = "", subType: 0|1=0): Promise { + const {md5, fileName, path, fileSize, ext} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType); if (fileSize === 0) { throw "文件异常,大小为0"; } const imageSize = await NTQQFileApi.getImageSize(picPath); const picElement = { md5HexStr: md5, - fileSize: fileSize, + fileSize: fileSize.toString(), picWidth: imageSize.width, picHeight: imageSize.height, - fileName: fileName, + fileName: md5 + ext, sourcePath: path, original: true, picType: isGIF(picPath) ? PicType.gif : PicType.jpg, - picSubType: 0, + picSubType: subType, fileUuid: "", fileSubId: "", thumbFileSize: 0, - summary, + summary }; - + log("图片信息", picElement) return { elementType: ElementType.PIC, elementId: "", - picElement + picElement, }; } @@ -118,7 +118,7 @@ export class SendMsgElementConstructor { let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`) thumb = pathLib.dirname(thumb) // log("thumb 目录", thumb) - let videoInfo ={ + let videoInfo = { width: 1920, height: 1080, time: 15, format: "mp4", @@ -128,7 +128,7 @@ export class SendMsgElementConstructor { try { videoInfo = await getVideoInfo(path); log("视频信息", videoInfo) - }catch (e) { + } catch (e) { log("获取视频信息失败", e) } const createThumb = new Promise((resolve, reject) => { diff --git a/src/ntqqapi/types/msg.ts b/src/ntqqapi/types/msg.ts index 299bf05..c2be236 100644 --- a/src/ntqqapi/types/msg.ts +++ b/src/ntqqapi/types/msg.ts @@ -49,24 +49,29 @@ export enum PicType { jpg = 1000 } +export enum PicSubType { + normal = 0, // 普通图片,大图 + face = 1 // 表情包小图 +} + export interface SendPicElement { elementType: ElementType.PIC, elementId: "", picElement: { md5HexStr: string, - fileSize: number, + fileSize: number | string, picWidth: number, picHeight: number, fileName: string, sourcePath: string, original: boolean, picType: PicType, - picSubType: number, + picSubType: PicSubType, fileUuid: string, fileSubId: string, thumbFileSize: number, summary: string, - } + }, } export interface SendReplyElement { @@ -200,7 +205,7 @@ export interface GrayTipElement { xmlElement: { content: string; }, - jsonGrayTipElement:{ + jsonGrayTipElement: { jsonStr: string; } } @@ -248,6 +253,7 @@ export interface MarketFaceElement { ], "apngSupportSize": null } + export interface VideoElement { "filePath": string, "fileName": string, diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index a4d796b..9b16d25 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -2,7 +2,7 @@ import { AtType, ChatType, ElementType, - Group, + Group, PicSubType, RawMessage, SendArkElement, SendMessageElement @@ -188,7 +188,7 @@ export async function createSendElements(messageData: OB11MessageData[], group: } else if (sendMsg.type === OB11MessageDataType.voice) { sendElements.push(await SendMsgElementConstructor.ptt(path)); } else if (sendMsg.type === OB11MessageDataType.image) { - sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || "")); + sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || "", parseInt(sendMsg.data?.subType?.toString()) || 0)); } } } diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index 907c84b..bc2d4e8 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -1,4 +1,4 @@ -import {RawMessage} from "../ntqqapi/types"; +import {PicSubType, RawMessage} from "../ntqqapi/types"; import {EventType} from "./event/OB11BaseEvent"; export interface OB11User { @@ -134,11 +134,13 @@ interface OB11MessageFileBase { } } + export interface OB11MessageImage extends OB11MessageFileBase { type: OB11MessageDataType.image data: OB11MessageFileBase['data'] & { summary ? : string; // 图片摘要 - } + subType?: PicSubType + }, } export interface OB11MessageRecord extends OB11MessageFileBase {