From f9938462309adcc28f4250fa76a4009ad118e393 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Tue, 5 Mar 2024 11:22:12 +0800 Subject: [PATCH] fix: send silk fix: try get group qq from temp msg --- manifest.json | 4 ++-- src/common/data.ts | 2 ++ src/common/utils.ts | 12 +++++++++++- src/ntqqapi/hook.ts | 6 +++++- src/ntqqapi/types.ts | 10 +++++++++- src/onebot11/constructor.ts | 6 +++++- src/onebot11/utils.ts | 15 ++++++++++----- src/version.ts | 2 +- 8 files changed, 45 insertions(+), 12 deletions(-) diff --git a/manifest.json b/manifest.json index 4f19d6f..03f54f0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { "manifest_version": 4, "type": "extension", - "name": "LLOneBot v3.11.1", + "name": "LLOneBot v3.11.2", "slug": "LLOneBot", "description": "LiteLoaderQQNT的OneBotApi", - "version": "3.11.1", + "version": "3.11.2", "thumbnail": "./icon.png", "authors": [ { diff --git a/src/common/data.ts b/src/common/data.ts index d4f771f..df7f921 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -109,3 +109,5 @@ export function getUidByUin(uin: string) { } } } + +export let tempGroupCodeMap: Record = {} // peerUid => 群号 \ No newline at end of file diff --git a/src/common/utils.ts b/src/common/utils.ts index aff7cc4..668727f 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -233,7 +233,17 @@ export async function encodeSilk(filePath: string) { }; } else { const pcm = fs.readFileSync(filePath); - const duration = getDuration(pcm); + let duration = 0; + try{ + duration = getDuration(pcm); + }catch (e) { + log("获取语音文件时长失败", filePath, e.stack) + duration = fs.statSync(filePath).size / 1024 / 3 // 每3kb大约1s + duration = Math.floor(duration) + duration = Math.max(1, duration) + log("使用文件大小估算时长", duration) + } + return { converted: false, path: filePath, diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts index 6351058..8488587 100644 --- a/src/ntqqapi/hook.ts +++ b/src/ntqqapi/hook.ts @@ -2,7 +2,7 @@ import {type BrowserWindow} from 'electron' import {getConfigUtil, log, sleep} from '../common/utils' import {NTQQApi, type NTQQApiClass, sendMessagePool} from './ntcall' import {type Group, type RawMessage, type User} from './types' -import {addHistoryMsg, friends, groups, msgHistory, selfInfo} from '../common/data' +import {addHistoryMsg, friends, groups, msgHistory, selfInfo, tempGroupCodeMap} from '../common/data' import {OB11GroupDecreaseEvent} from '../onebot11/event/notice/OB11GroupDecreaseEvent' import {OB11GroupIncreaseEvent} from '../onebot11/event/notice/OB11GroupIncreaseEvent' import {v4 as uuidv4} from 'uuid' @@ -246,6 +246,10 @@ registerReceiveHook<{ msgList: RawMessage[] }>(ReceiveCmd.NEW_MSG, (payload) => if (msgElement.picElement) { pathList.push(...Object.values(msgElement.picElement.thumbPath)) } + const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement + if (aioOpGrayTipElement){ + tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat; + } // log("需要清理的文件", pathList); for (const path of pathList) { if (path) { diff --git a/src/ntqqapi/types.ts b/src/ntqqapi/types.ts index b8e5a61..edebdc9 100644 --- a/src/ntqqapi/types.ts +++ b/src/ntqqapi/types.ts @@ -95,7 +95,7 @@ export interface SendPttElement { filePath: string, md5HexStr: string, fileSize: number, - duration: number, + duration: number, // 单位是秒 formatType: number, voiceType: number, voiceChangeType: number, @@ -234,6 +234,7 @@ export interface GrayTipElement { operatorMemRemark?: string; wording: string; // 自定义的撤回提示语 } + aioOpGrayTipElement: TipAioOpGrayTipElement } export interface FaceElement { @@ -266,6 +267,13 @@ export interface VideoElement { "sourceVideoCodecFormat": 0 } +export interface TipAioOpGrayTipElement{ + operateType: number, + peerUid: string, + fromGrpCodeOfTmpChat: string, +} + + export interface RawMessage { msgId: string; msgShortId?: number; // 自己维护的消息id diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index 3852591..ff4c614 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -9,7 +9,7 @@ import { OB11UserSex } from "./types"; import {AtType, ChatType, Group, GroupMember, IMAGE_HTTP_HOST, RawMessage, SelfInfo, User} from '../ntqqapi/types'; -import {fileCache, getFriend, getGroupMember, getHistoryMsgBySeq, selfInfo} from '../common/data'; +import {fileCache, getFriend, getGroupMember, getHistoryMsgBySeq, selfInfo, tempGroupCodeMap} from '../common/data'; import {getConfigUtil, log} from "../common/utils"; import {NTQQApi} from "../ntqqapi/ntcall"; import {EventType} from "./event/OB11BaseEvent"; @@ -56,6 +56,10 @@ export class OB11Constructor { } } else if (msg.chatType == ChatType.temp) { resMsg.sub_type = "group" + const tempGroupCode = tempGroupCodeMap[msg.peerUin] + if (tempGroupCode) { + resMsg.group_id = parseInt(tempGroupCode) + } } for (let element of msg.elements) { diff --git a/src/onebot11/utils.ts b/src/onebot11/utils.ts index c42a17b..0eaa083 100644 --- a/src/onebot11/utils.ts +++ b/src/onebot11/utils.ts @@ -1,4 +1,4 @@ -import {CONFIG_DIR, isGIF} from "../common/utils"; +import {CONFIG_DIR, isGIF, log} from "../common/utils"; import {v4 as uuidv4} from "uuid"; import * as path from 'node:path'; import {fileCache} from "../common/data"; @@ -71,16 +71,21 @@ export async function uri2local(uri: string, fileName: string = null) { // res.errMsg = `不支持的file协议,` + url.protocol // return res // } - if (isGIF(filePath) && !res.isLocal) { - await fs.rename(filePath, filePath + ".gif"); - filePath += ".gif"; - } + // if (isGIF(filePath) && !res.isLocal) { + // await fs.rename(filePath, filePath + ".gif"); + // filePath += ".gif"; + // } if (!res.isLocal) { + try{ const {ext} = await fileType.fileTypeFromFile(filePath) if (ext) { + log("获取文件类型", ext, filePath) await fs.rename(filePath, filePath + `.${ext}`) filePath += `.${ext}` } + }catch (e){ + // log("获取文件类型失败", filePath,e.stack) + } } res.success = true res.path = filePath diff --git a/src/version.ts b/src/version.ts index e64f817..1620de1 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = "3.11.1" \ No newline at end of file +export const version = "3.11.2" \ No newline at end of file