Merge branch 'main' into dev

This commit is contained in:
linyuchen 2024-03-06 20:30:59 +08:00
commit aedc8cfc91
9 changed files with 67 additions and 44 deletions

View File

@ -1,10 +1,10 @@
{ {
"manifest_version": 4, "manifest_version": 4,
"type": "extension", "type": "extension",
"name": "LLOneBot v3.12.0", "name": "LLOneBot v3.13.0",
"slug": "LLOneBot", "slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi", "description": "LiteLoaderQQNT的OneBotApi",
"version": "3.12.0", "version": "3.13.0",
"thumbnail": "./icon.png", "thumbnail": "./icon.png",
"authors": [ "authors": [
{ {

View File

@ -79,6 +79,7 @@ export async function getGroupMember(groupQQ: string | number, memberQQ: string
} }
return member return member
} }
return null
} }
export async function refreshGroupMembers(groupQQ: string) { export async function refreshGroupMembers(groupQQ: string) {

View File

@ -245,14 +245,15 @@ function onLoad() {
const notifies = notify.notifies.slice(0, payload.unreadCount) const notifies = notify.notifies.slice(0, payload.unreadCount)
// log("获取群通知详情完成", notifies, payload); // log("获取群通知详情完成", notifies, payload);
try {
for (const notify of notifies) { for (const notify of notifies) {
try {
notify.time = Date.now(); notify.time = Date.now();
const notifyTime = parseInt(notify.seq) / 1000 const notifyTime = parseInt(notify.seq) / 1000
// log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`); // log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`);
if (notifyTime < startTime) { // if (notifyTime < startTime) {
continue; // continue;
} // }
let existNotify = groupNotifies[notify.seq]; let existNotify = groupNotifies[notify.seq];
if (existNotify) { if (existNotify) {
if (Date.now() - existNotify.time < 3000) { if (Date.now() - existNotify.time < 3000) {
@ -261,14 +262,14 @@ function onLoad() {
} }
log("收到群通知", notify); log("收到群通知", notify);
groupNotifies[notify.seq] = notify; groupNotifies[notify.seq] = notify;
const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid); // let member2: GroupMember;
refreshGroupMembers(notify.group.groupCode).then() // if (notify.user2.uid) {
let member2: GroupMember; // member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
if (notify.user2.uid) { // }
member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
}
if ([GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET].includes(notify.type)) { if ([GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET].includes(notify.type)) {
const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid);
log("有管理员变动通知"); log("有管理员变动通知");
refreshGroupMembers(notify.group.groupCode).then()
let groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent() let groupAdminNoticeEvent = new OB11GroupAdminNoticeEvent()
groupAdminNoticeEvent.group_id = parseInt(notify.group.groupCode); groupAdminNoticeEvent.group_id = parseInt(notify.group.groupCode);
log("开始获取变动的管理员") log("开始获取变动的管理员")
@ -282,6 +283,7 @@ function onLoad() {
} }
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT) { } else if (notify.type == GroupNotifyTypes.MEMBER_EXIT) {
log("有成员退出通知"); log("有成员退出通知");
const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid);
let groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin)) let groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin))
// postEvent(groupDecreaseEvent, true); // postEvent(groupDecreaseEvent, true);
} else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) { } else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
@ -300,6 +302,7 @@ function onLoad() {
groupRequestEvent.flag = notify.seq; groupRequestEvent.flag = notify.seq;
postOB11Event(groupRequestEvent); postOB11Event(groupRequestEvent);
} else if (notify.type == GroupNotifyTypes.INVITE_ME) { } else if (notify.type == GroupNotifyTypes.INVITE_ME) {
log("收到邀请我加群通知")
let groupInviteEvent = new OB11GroupRequestEvent(); let groupInviteEvent = new OB11GroupRequestEvent();
groupInviteEvent.group_id = parseInt(notify.group.groupCode); groupInviteEvent.group_id = parseInt(notify.group.groupCode);
let user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin let user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
@ -308,12 +311,12 @@ function onLoad() {
groupInviteEvent.flag = notify.seq; groupInviteEvent.flag = notify.seq;
postOB11Event(groupInviteEvent); postOB11Event(groupInviteEvent);
} }
}
} catch (e) { } catch (e) {
log("解析群通知失败", e.stack); log("解析群通知失败", e.stack.toString());
} }
} }
else if (payload.doubt){
} else if (payload.doubt) {
// 可能有群管理员变动 // 可能有群管理员变动
} }
}) })

View File

@ -81,19 +81,19 @@ export class SendMsgElementConstructor {
}; };
} }
static async file(filePath: string, isVideo: boolean = false): Promise<SendFileElement> { static async file(filePath: string, showPreview: boolean = false, fileName: string = ""): Promise<SendFileElement> {
let picHeight = 0; let picHeight = 0;
let picWidth = 0; let picWidth = 0;
if (isVideo) { if (showPreview) {
picHeight = 1024; picHeight = 1024;
picWidth = 768; picWidth = 768;
} }
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE); const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
let element: SendFileElement = { let element: SendFileElement = {
elementType: ElementType.FILE, elementType: ElementType.FILE,
elementId: "", elementId: "",
fileElement: { fileElement: {
fileName, fileName: fileName || _fileName,
"filePath": path, "filePath": path,
"fileSize": (fileSize).toString(), "fileSize": (fileSize).toString(),
picHeight, picHeight,

View File

@ -455,13 +455,13 @@ export class NTQQApi {
if (waitComplete) { if (waitComplete) {
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) { if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
return sentMessage return sentMessage
} else {
return await checkSendComplete()
} }
} }
else{
return sentMessage
}
// log(`给${peerUid}发送消息成功`) // log(`给${peerUid}发送消息成功`)
return sentMessage }
} else {
checkSendCompleteUsingTime += 500 checkSendCompleteUsingTime += 500
if (checkSendCompleteUsingTime > timeout) { if (checkSendCompleteUsingTime > timeout) {
throw ('发送超时') throw ('发送超时')
@ -469,7 +469,6 @@ export class NTQQApi {
await sleep(500) await sleep(500)
return await checkSendComplete() return await checkSendComplete()
} }
}
callNTQQApi({ callNTQQApi({
methodName: NTQQApiMethod.SEND_MSG, methodName: NTQQApiMethod.SEND_MSG,

View File

@ -297,8 +297,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
case OB11MessageDataType.video: case OB11MessageDataType.video:
case OB11MessageDataType.voice: { case OB11MessageDataType.voice: {
const file = sendMsg.data?.file const file = sendMsg.data?.file
const payloadFileName = sendMsg.data?.name
if (file) { if (file) {
const {path, isLocal} = (await uri2local(file)) const {path, isLocal, fileName} = (await uri2local(file))
if (path) { if (path) {
if (!isLocal) { // 只删除http和base64转过来的文件 if (!isLocal) { // 只删除http和base64转过来的文件
deleteAfterSentFiles.push(path) deleteAfterSentFiles.push(path)
@ -309,10 +310,15 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
[OB11MessageDataType.video]: SendMsgElementConstructor.video, [OB11MessageDataType.video]: SendMsgElementConstructor.video,
[OB11MessageDataType.file]: SendMsgElementConstructor.file, [OB11MessageDataType.file]: SendMsgElementConstructor.file,
} }
if (sendMsg.type === OB11MessageDataType.file) {
log("发送文件", path, payloadFileName || fileName)
sendElements.push(await SendMsgElementConstructor.file(path, false, payloadFileName || fileName));
} else {
sendElements.push(await constructorMap[sendMsg.type](path)); sendElements.push(await constructorMap[sendMsg.type](path));
} }
} }
} }
}
break; break;
} }
@ -329,6 +335,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
throw ("消息体无法解析") throw ("消息体无法解析")
} }
const returnMsg = await NTQQApi.sendMsg(peer, sendElements, waitComplete, 20000); const returnMsg = await NTQQApi.sendMsg(peer, sendElements, waitComplete, 20000);
log("消息发送结果", returnMsg)
await dbUtil.addMsg(returnMsg) await dbUtil.addMsg(returnMsg)
deleteAfterSentFiles.map(f => fs.unlink(f, () => { deleteAfterSentFiles.map(f => fs.unlink(f, () => {
})) }))

View File

@ -113,6 +113,7 @@ export interface OB11MessageText {
interface OB11MessageFileBase { interface OB11MessageFileBase {
data: { data: {
name?: string;
file: string, file: string,
url?: string; url?: string;
} }

View File

@ -15,6 +15,8 @@ export async function uri2local(uri: string, fileName: string = null) {
let res = { let res = {
success: false, success: false,
errMsg: "", errMsg: "",
fileName: "",
ext: "",
path: "", path: "",
isLocal: false isLocal: false
} }
@ -39,7 +41,15 @@ export async function uri2local(uri: string, fileName: string = null) {
let blob = await fetchRes.blob(); let blob = await fetchRes.blob();
let buffer = await blob.arrayBuffer(); let buffer = await blob.arrayBuffer();
try { try {
fileName = path.parse(url.pathname).name || fileName const pathInfo = path.parse(decodeURIComponent(url.pathname))
if (pathInfo.name){
fileName = pathInfo.name
if (pathInfo.ext){
fileName += pathInfo.ext
res.ext = pathInfo.ext
}
}
res.fileName = fileName
filePath = path.join(DATA_DIR, uuidv4() + fileName) filePath = path.join(DATA_DIR, uuidv4() + fileName)
await fs.writeFile(filePath, Buffer.from(buffer)); await fs.writeFile(filePath, Buffer.from(buffer));
} catch (e: any) { } catch (e: any) {
@ -75,15 +85,17 @@ export async function uri2local(uri: string, fileName: string = null) {
// await fs.rename(filePath, filePath + ".gif"); // await fs.rename(filePath, filePath + ".gif");
// filePath += ".gif"; // filePath += ".gif";
// } // }
if (!res.isLocal) { if (!res.isLocal && !res.ext) {
try{ try {
const {ext} = await fileType.fileTypeFromFile(filePath) let ext: string = (await fileType.fileTypeFromFile(filePath)).ext
if (ext) { if (ext) {
log("获取文件类型", ext, filePath) log("获取文件类型", ext, filePath)
await fs.rename(filePath, filePath + `.${ext}`) await fs.rename(filePath, filePath + `.${ext}`)
filePath += `.${ext}` filePath += `.${ext}`
res.fileName += `.${ext}`
res.ext = ext
} }
}catch (e){ } catch (e) {
// log("获取文件类型失败", filePath,e.stack) // log("获取文件类型失败", filePath,e.stack)
} }
} }

View File

@ -1 +1 @@
export const version = "3.12.0" export const version = "3.13.0"