mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
936554cca2 | ||
![]() |
e1d47f55bf | ||
![]() |
cc8e8f108b | ||
![]() |
e6d36dc6c3 | ||
![]() |
aedc8cfc91 | ||
![]() |
00c80bf181 | ||
![]() |
72890a8b59 | ||
![]() |
3b2577bcad |
@@ -92,7 +92,8 @@ wget -O fastboot.sh https://cdn.jsdelivr.net/gh/LLOneBot/llonebot-docker/fastboo
|
||||
{
|
||||
"type": "file",
|
||||
"data": {
|
||||
"file": "file:///D:/1.txt"
|
||||
"file": "file:///D:/1.txt",
|
||||
"name": "自定义显示的文件名" // 此字段不是必须的
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"manifest_version": 4,
|
||||
"type": "extension",
|
||||
"name": "LLOneBot v3.12.0",
|
||||
"name": "LLOneBot v3.13.1",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi",
|
||||
"version": "3.12.0",
|
||||
"version": "3.13.1",
|
||||
"thumbnail": "./icon.png",
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -79,6 +79,7 @@ export async function getGroupMember(groupQQ: string | number, memberQQ: string
|
||||
}
|
||||
return member
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export async function refreshGroupMembers(groupQQ: string) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// import {DATA_DIR} from "./utils";
|
||||
import {Level} from "level";
|
||||
import {RawMessage} from "../ntqqapi/types";
|
||||
import {DATA_DIR} from "./utils";
|
||||
import {DATA_DIR, log} from "./utils";
|
||||
import {selfInfo} from "./data";
|
||||
|
||||
|
||||
@@ -93,14 +93,14 @@ class DBUtil {
|
||||
// 有则更新,无则添加
|
||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
||||
let existMsg = this.cache[longIdKey]
|
||||
if (!existMsg){
|
||||
if (!existMsg) {
|
||||
try {
|
||||
existMsg = await this.getMsgByLongId(msg.msgId)
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
if (existMsg){
|
||||
if (existMsg) {
|
||||
this.updateMsg(msg).then()
|
||||
return existMsg.msgShortId
|
||||
}
|
||||
@@ -108,10 +108,15 @@ class DBUtil {
|
||||
const shortMsgId = await this.genMsgShortId();
|
||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + shortMsgId;
|
||||
const seqIdKey = this.DB_KEY_PREFIX_MSG_SEQ_ID + msg.msgSeq;
|
||||
await this.db.put(shortIdKey, msg.msgId);
|
||||
msg.msgShortId = shortMsgId;
|
||||
await this.db.put(longIdKey, JSON.stringify(msg));
|
||||
await this.db.put(seqIdKey, msg.msgId);
|
||||
try {
|
||||
await this.db.put(shortIdKey, msg.msgId);
|
||||
await this.db.put(longIdKey, JSON.stringify(msg));
|
||||
await this.db.put(seqIdKey, msg.msgId);
|
||||
|
||||
} catch (e) {
|
||||
log("addMsg db error", e.stack.toString());
|
||||
}
|
||||
this.cache[seqIdKey] = this.cache[shortIdKey] = this.cache[longIdKey] = msg;
|
||||
return shortMsgId
|
||||
}
|
||||
|
@@ -177,7 +177,7 @@ function onLoad() {
|
||||
try {
|
||||
await postReceiveMsg(payload.msgList);
|
||||
} catch (e) {
|
||||
log("report message error: ", e.toString());
|
||||
log("report message error: ", e.stack.toString());
|
||||
}
|
||||
})
|
||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => {
|
||||
@@ -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("开始获取变动的管理员")
|
||||
@@ -281,8 +282,9 @@ function onLoad() {
|
||||
log("获取群通知的成员信息失败", notify, getGroup(notify.group.groupCode));
|
||||
}
|
||||
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT) {
|
||||
log("有成员退出通知");
|
||||
let groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin))
|
||||
// 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)) {
|
||||
log("有加群请求");
|
||||
@@ -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) {
|
||||
// 可能有群管理员变动
|
||||
}
|
||||
})
|
||||
|
@@ -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,
|
||||
@@ -104,8 +104,8 @@ export class SendMsgElementConstructor {
|
||||
return element;
|
||||
}
|
||||
|
||||
static video(filePath: string): Promise<SendFileElement> {
|
||||
return SendMsgElementConstructor.file(filePath, true);
|
||||
static video(filePath: string, fileName: string=""): Promise<SendFileElement> {
|
||||
return SendMsgElementConstructor.file(filePath, true, fileName);
|
||||
}
|
||||
|
||||
static async ptt(pttPath: string): Promise<SendPttElement> {
|
||||
|
@@ -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({
|
||||
|
@@ -283,6 +283,30 @@ export interface TipAioOpGrayTipElement{
|
||||
fromGrpCodeOfTmpChat: string,
|
||||
}
|
||||
|
||||
export interface TipGroupElement {
|
||||
"type": 1, // 1是表示有人加入群, 自己加入群也会收到这个
|
||||
"role": 0,
|
||||
"groupName": string, // 暂时获取不到
|
||||
"memberUid": string,
|
||||
"memberNick": string,
|
||||
"memberRemark": string,
|
||||
"adminUid": string, // 同意加群的管理员uid
|
||||
"adminNick": string,
|
||||
"adminRemark": string,
|
||||
"createGroup": null,
|
||||
"memberAdd": {
|
||||
"showType": 1,
|
||||
"otherAdd": null,
|
||||
"otherAddByOtherQRCode": null,
|
||||
"otherAddByYourQRCode": null,
|
||||
"youAddByOtherQRCode": null,
|
||||
"otherInviteOther": null,
|
||||
"otherInviteYou": null,
|
||||
"youInviteOther": null
|
||||
},
|
||||
"shutUp": null
|
||||
}
|
||||
|
||||
|
||||
export interface RawMessage {
|
||||
msgId: string;
|
||||
|
@@ -133,6 +133,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
const returnMsg = await this.send(peer, sendElements, deleteAfterSentFiles)
|
||||
return {message_id: returnMsg.msgShortId}
|
||||
} catch (e) {
|
||||
log("发送消息失败", e.stack.toString())
|
||||
throw (e.toString())
|
||||
}
|
||||
}
|
||||
@@ -297,8 +298,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 +311,15 @@ 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 if (sendMsg.type === OB11MessageDataType.video) {
|
||||
log("发送视频", path, payloadFileName || fileName)
|
||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName));
|
||||
} else {
|
||||
sendElements.push(await constructorMap[sendMsg.type](path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,7 +339,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
throw ("消息体无法解析")
|
||||
}
|
||||
const returnMsg = await NTQQApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||
await dbUtil.addMsg(returnMsg)
|
||||
log("消息发送结果", returnMsg)
|
||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||
}))
|
||||
return returnMsg
|
||||
|
@@ -3,12 +3,12 @@ import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||
export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = "group_increase";
|
||||
sub_type = "approve"; // TODO: 实现其他几种子类型的识别 ("approve" | "invite")
|
||||
operate_id: number;
|
||||
operator_id: number;
|
||||
|
||||
constructor(groupId: number, userId: number) {
|
||||
super();
|
||||
this.group_id = groupId;
|
||||
this.operate_id = userId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被邀请的,还是主动加入的
|
||||
this.operator_id = userId; // 实际上不应该这么实现,但是现在还没有办法识别用户是被邀请的,还是主动加入的
|
||||
this.user_id = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -113,6 +113,7 @@ export interface OB11MessageText {
|
||||
|
||||
interface OB11MessageFileBase {
|
||||
data: {
|
||||
name?: string;
|
||||
file: string,
|
||||
url?: string;
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
@@ -1 +1 @@
|
||||
export const version = "3.12.0"
|
||||
export const version = "3.13.2"
|
Reference in New Issue
Block a user