fix: send silk

fix: try get group qq from temp msg
This commit is contained in:
linyuchen
2024-03-05 11:22:12 +08:00
parent 276767e8bb
commit f993846230
8 changed files with 45 additions and 12 deletions

View File

@@ -109,3 +109,5 @@ export function getUidByUin(uin: string) {
}
}
}
export let tempGroupCodeMap: Record<string, string> = {} // peerUid => 群号

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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

View File

@@ -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) {

View File

@@ -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

View File

@@ -1 +1 @@
export const version = "3.11.1"
export const version = "3.11.2"