Compare commits

..

2 Commits

Author SHA1 Message Date
linyuchen
f8890b309b fix: face msg faceType 2024-04-11 18:57:58 +08:00
linyuchen
b5e578733f fix: quick reply friend msg 2024-04-11 18:17:02 +08:00
6 changed files with 313 additions and 278 deletions

View File

@@ -1,10 +1,10 @@
{
"manifest_version": 4,
"type": "extension",
"name": "LLOneBot v3.22.0",
"name": "LLOneBot v3.22.1",
"slug": "LLOneBot",
"description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新",
"version": "3.22.0",
"version": "3.22.1",
"icon": "./icon.jpg",
"authors": [
{

View File

@@ -1,6 +1,6 @@
import {
AtType,
ElementType,
ElementType, FaceIndex,
FaceType,
PicType,
SendArkElement,
@@ -24,9 +24,10 @@ import {isNull} from "../common/utils";
export class SendMsgElementConstructor {
static poke(groupCode: string, uin: string){
static poke(groupCode: string, uin: string) {
return null
}
static text(content: string): SendTextElement {
return {
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);
if (fileSize === 0) {
throw "文件异常大小为0";
@@ -121,8 +122,8 @@ export class SendMsgElementConstructor {
throw "文件异常大小为0";
}
const pathLib = require("path");
let thumb = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
thumb = pathLib.dirname(thumb)
let thumbDir = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`)
thumbDir = pathLib.dirname(thumbDir)
// log("thumb 目录", thumb)
let videoInfo = {
width: 1920, height: 1080,
@@ -139,33 +140,46 @@ export class SendMsgElementConstructor {
}
const createThumb = new Promise<string>((resolve, reject) => {
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)
.on("end", () => {
})
.on("error", (err) => {
log("获取视频封面失败,使用默认封面", err)
if (diyThumbPath) {
fs.copyFile(diyThumbPath, thumbPath).then(() => {
completed = true;
resolve(thumbPath);
}).catch(reject)
} else {
fs.writeFile(thumbPath, defaultVideoThumb).then(() => {
resolve(thumbPath);
}).catch(reject)
useDefaultThumb()
}
})
.screenshots({
timestamps: [0],
filename: thumbFileName,
folder: thumb,
folder: thumbDir,
size: videoInfo.width + "x" + videoInfo.height
}).on("end", () => {
log("生成视频缩略图", thumbPath)
completed = true;
resolve(thumbPath);
});
})
})
let thumbPath = new Map()
const _thumbPath = await createThumb;
log("生成缩略图", _thumbPath)
const thumbSize = (await fs.stat(_thumbPath)).size;
// log("生成缩略图", _thumbPath)
thumbPath.set(0, _thumbPath)
@@ -196,6 +210,7 @@ export class SendMsgElementConstructor {
// sourceVideoCodecFormat: 2
}
}
log("videoElement", element)
return element;
}
@@ -234,17 +249,18 @@ export class SendMsgElementConstructor {
}
static face(faceId: number): SendFaceElement {
faceId = parseInt(faceId.toString());
return {
elementType: ElementType.FACE,
elementId: "",
faceElement: {
faceIndex: faceId,
faceType: FaceType.normal
faceType: faceId < 222 ? FaceType.normal : FaceType.normal2,
}
}
}
static dice(resultId: number|null): SendFaceElement{
static dice(resultId: number | null): SendFaceElement {
// 实际测试并不能控制结果
// 随机1到6
@@ -253,7 +269,7 @@ export class SendMsgElementConstructor {
elementType: ElementType.FACE,
elementId: "",
faceElement: {
faceIndex: 358,
faceIndex: FaceIndex.dice,
faceType: FaceType.dice,
"faceText": "[骰子]",
"packId": "1",
@@ -268,14 +284,14 @@ 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;
return {
elementType: ElementType.FACE,
elementId: "",
faceElement: {
"faceIndex": 359,
"faceIndex": FaceIndex.RPS,
"faceText": "[包剪锤]",
"faceType": 3,
"packId": "1",

View File

@@ -214,9 +214,15 @@ export interface GrayTipElement {
export enum FaceType {
normal=1, // 小黄脸
normal2=2, // 新小黄脸, 从faceIndex 222开始
dice=3 // 骰子
}
export enum FaceIndex {
dice = 358,
RPS = 359 // 石头剪刀布
}
export interface FaceElement {
faceIndex: number,
faceType: FaceType,

View File

@@ -10,7 +10,7 @@ import {
} from "./types";
import {
AtType,
ChatType,
ChatType, FaceIndex,
GrayTipElementSubType,
Group,
GroupMember,
@@ -227,8 +227,19 @@ export class OB11Constructor {
message_data["type"] = OB11MessageDataType.json;
message_data["data"]["data"] = element.arkElement.bytesData;
} else if (element.faceElement) {
const faceId = element.faceElement.faceIndex;
if (faceId === FaceIndex.dice){
message_data["type"] = OB11MessageDataType.dice
message_data["data"]["result"] = element.faceElement.resultId;
}
else if (faceId === FaceIndex.RPS){
message_data["type"] = OB11MessageDataType.RPS
message_data["data"]["result"] = element.faceElement.resultId;
}
else{
message_data["type"] = OB11MessageDataType.face;
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
}
} else if (element.marketFaceElement) {
message_data["type"] = OB11MessageDataType.mface;
message_data["data"]["text"] = element.marketFaceElement.faceName;

View File

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

View File

@@ -1 +1 @@
export const version = "3.22.0"
export const version = "3.22.1"