fix: quick reply friend msg

This commit is contained in:
linyuchen 2024-04-11 18:17:02 +08:00
parent 51602b987e
commit b5e578733f
2 changed files with 289 additions and 272 deletions

View File

@ -24,9 +24,10 @@ import {isNull} from "../common/utils";
export class SendMsgElementConstructor { export class SendMsgElementConstructor {
static poke(groupCode: string, uin: string){ static poke(groupCode: string, uin: string) {
return null return null
} }
static text(content: string): SendTextElement { static text(content: string): SendTextElement {
return { return {
elementType: ElementType.TEXT, elementType: ElementType.TEXT,
@ -68,7 +69,7 @@ export class SendMsgElementConstructor {
} }
} }
static async pic(picPath: string, summary: string = "", subType: 0|1=0): Promise<SendPicElement> { static async pic(picPath: string, summary: string = "", subType: 0 | 1 = 0): Promise<SendPicElement> {
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType); const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType);
if (fileSize === 0) { if (fileSize === 0) {
throw "文件异常大小为0"; throw "文件异常大小为0";
@ -121,8 +122,8 @@ export class SendMsgElementConstructor {
throw "文件异常大小为0"; throw "文件异常大小为0";
} }
const pathLib = require("path"); const pathLib = require("path");
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`) let thumbDir = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
thumb = pathLib.dirname(thumb) thumbDir = pathLib.dirname(thumbDir)
// log("thumb 目录", thumb) // log("thumb 目录", thumb)
let videoInfo = { let videoInfo = {
width: 1920, height: 1080, width: 1920, height: 1080,
@ -139,33 +140,46 @@ export class SendMsgElementConstructor {
} }
const createThumb = new Promise<string>((resolve, reject) => { const createThumb = new Promise<string>((resolve, reject) => {
const thumbFileName = `${md5}_0.png` const thumbFileName = `${md5}_0.png`
const thumbPath = pathLib.join(thumb, thumbFileName) const thumbPath = pathLib.join(thumbDir, thumbFileName)
log("开始生成视频缩略图", filePath);
let completed = false;
function useDefaultThumb() {
if (completed) return;
log("获取视频封面失败,使用默认封面");
fs.writeFile(thumbPath, defaultVideoThumb).then(() => {
resolve(thumbPath);
}).catch(reject)
}
setTimeout(useDefaultThumb, 5000);
ffmpeg(filePath) ffmpeg(filePath)
.on("end", () => { .on("end", () => {
}) })
.on("error", (err) => { .on("error", (err) => {
log("获取视频封面失败,使用默认封面", err)
if (diyThumbPath) { if (diyThumbPath) {
fs.copyFile(diyThumbPath, thumbPath).then(() => { fs.copyFile(diyThumbPath, thumbPath).then(() => {
completed = true;
resolve(thumbPath); resolve(thumbPath);
}).catch(reject) }).catch(reject)
} else { } else {
fs.writeFile(thumbPath, defaultVideoThumb).then(() => { useDefaultThumb()
resolve(thumbPath);
}).catch(reject)
} }
}) })
.screenshots({ .screenshots({
timestamps: [0], timestamps: [0],
filename: thumbFileName, filename: thumbFileName,
folder: thumb, folder: thumbDir,
size: videoInfo.width + "x" + videoInfo.height size: videoInfo.width + "x" + videoInfo.height
}).on("end", () => { }).on("end", () => {
log("生成视频缩略图", thumbPath)
completed = true;
resolve(thumbPath); resolve(thumbPath);
}); })
}) })
let thumbPath = new Map() let thumbPath = new Map()
const _thumbPath = await createThumb; const _thumbPath = await createThumb;
log("生成缩略图", _thumbPath)
const thumbSize = (await fs.stat(_thumbPath)).size; const thumbSize = (await fs.stat(_thumbPath)).size;
// log("生成缩略图", _thumbPath) // log("生成缩略图", _thumbPath)
thumbPath.set(0, _thumbPath) thumbPath.set(0, _thumbPath)
@ -196,6 +210,7 @@ export class SendMsgElementConstructor {
// sourceVideoCodecFormat: 2 // sourceVideoCodecFormat: 2
} }
} }
log("videoElement", element)
return element; return element;
} }
@ -244,7 +259,7 @@ export class SendMsgElementConstructor {
} }
} }
static dice(resultId: number|null): SendFaceElement{ static dice(resultId: number | null): SendFaceElement {
// 实际测试并不能控制结果 // 实际测试并不能控制结果
// 随机1到6 // 随机1到6
@ -268,7 +283,7 @@ export class SendMsgElementConstructor {
} }
// 猜拳(石头剪刀布)表情 // 猜拳(石头剪刀布)表情
static rps(resultId: number | null): SendFaceElement{ static rps(resultId: number | null): SendFaceElement {
// 实际测试并不能控制结果 // 实际测试并不能控制结果
if (isNull(resultId)) resultId = Math.floor(Math.random() * 3) + 1; if (isNull(resultId)) resultId = Math.floor(Math.random() * 3) + 1;
return { return {

View File

@ -1,5 +1,5 @@
import {OB11Message, OB11MessageAt, OB11MessageData} from "../types"; import {OB11Message, OB11MessageAt, OB11MessageData} from "../types";
import {getGroup, selfInfo} from "../../common/data"; import {getFriend, getGroup, getUidByUin, selfInfo} from "../../common/data";
import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent"; import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent";
import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent"; import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent";
import {WebSocket as WebSocketClass} from "ws"; import {WebSocket as WebSocketClass} from "ws";
@ -115,6 +115,7 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
peerUid: msg.user_id.toString() peerUid: msg.user_id.toString()
} }
if (msg.message_type == "private") { if (msg.message_type == "private") {
peer.peerUid = getUidByUin(msg.user_id.toString())
if (msg.sub_type === "group") { if (msg.sub_type === "group") {
peer.chatType = ChatType.temp peer.chatType = ChatType.temp
} }
@ -139,6 +140,7 @@ export function postOB11Event(msg: PostEventType, reportSelf = false) {
} }
replyMessage = replyMessage.concat(convertMessage2List(reply, resJson.auto_escape)) replyMessage = replyMessage.concat(convertMessage2List(reply, resJson.auto_escape))
const {sendElements, deleteAfterSentFiles} = await createSendElements(replyMessage, group) const {sendElements, deleteAfterSentFiles} = await createSendElements(replyMessage, group)
log(`发送消息给`, peer, sendElements)
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then() sendMsg(peer, sendElements, deleteAfterSentFiles, false).then()
} else if (resJson.delete) { } else if (resJson.delete) {
NTQQMsgApi.recallMsg(peer, [rawMessage.msgId]).then() NTQQMsgApi.recallMsg(peer, [rawMessage.msgId]).then()