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,
"type": "extension",
"name": "LLOneBot v3.12.0",
"name": "LLOneBot v3.13.0",
"slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi",
"version": "3.12.0",
"version": "3.13.0",
"thumbnail": "./icon.png",
"authors": [
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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