diff --git a/manifest.json b/manifest.json index 15c46af..de36a2a 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "LLOneBot", "slug": "LLOneBot", "description": "LiteLoaderQQNT的OneBotApi", - "version": "1.2.4", + "version": "1.2.5", "thumbnail": "./icon.png", "author": { "name": "linyuchen", diff --git a/src/common/IPCChannel.ts b/src/common/IPCChannel.ts index 682e41a..1fe71ef 100644 --- a/src/common/IPCChannel.ts +++ b/src/common/IPCChannel.ts @@ -8,4 +8,5 @@ export const CHANNEL_UPDATE_FRIENDS = "llonebot_update_friends" export const CHANNEL_LOG = "llonebot_log" export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data" export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info" -export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file" \ No newline at end of file +export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file" +export const CHANNEL_DELETE_FILE= "llonebot_delete_file" diff --git a/src/global.d.ts b/src/global.d.ts index f647c8a..2dd4577 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -44,6 +44,7 @@ declare var llonebot: { getConfig():Promise; setSelfInfo(selfInfo: SelfInfo):void; downloadFile(arg: {uri: string, localFilePath: string}):Promise; + deleteFile(path: string[]):Promise; }; declare global { diff --git a/src/main/main.ts b/src/main/main.ts index 00c3ceb..28bc98b 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -13,7 +13,7 @@ import { CHANNEL_SET_CONFIG, CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, - CHANNEL_UPDATE_GROUPS + CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE } from "../common/IPCChannel"; import {ConfigUtil} from "./config"; import {startExpress} from "./HttpServer"; @@ -123,6 +123,12 @@ function onLoad(plugin: any) { selfInfo.user_id = arg.user_id; selfInfo.nickname = arg.nickname; }) + + ipcMain.on(CHANNEL_DELETE_FILE, (event: any, arg: string[]) => { + for (const path of arg) { + fs.unlinkSync(path); + } + }) } diff --git a/src/preload.ts b/src/preload.ts index 2ec69ff..12c09b1 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -6,7 +6,7 @@ import { CHANNEL_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA, CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG, CHANNEL_SET_CONFIG, - CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS + CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE } from "./common/IPCChannel"; @@ -50,8 +50,11 @@ contextBridge.exposeInMainWorld("llonebot", { setSelfInfo(selfInfo: SelfInfo){ ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, selfInfo) }, - downloadFile: async (arg: {uri: string, localFilePath: string}) => { + downloadFile: (arg: {uri: string, localFilePath: string}) => { return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg); }, + deleteFile: async (localFilePath: string[]) => { + ipcRenderer.send(CHANNEL_DELETE_FILE, localFilePath); + } // startExpress, }); \ No newline at end of file diff --git a/src/renderer.ts b/src/renderer.ts index 4e19fa9..f3218bb 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -20,7 +20,7 @@ async function getUserInfo(uid: string): Promise { return user } -async function getFriends(){ +async function getFriends() { let _friends = await window.LLAPI.getFriendsList(false) for (let friend of _friends) { let existFriend = friends.find(f => f.uin == friend.uin) @@ -210,6 +210,7 @@ async function listenSendMessage(postData: PostDataSendMsg) { } } if (peer) { + let sendFiles: string[] = []; for (let message of postData.params.message) { if (message.type == "at") { // @ts-ignore @@ -242,6 +243,7 @@ async function listenSendMessage(postData: PostDataSendMsg) { await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath}) } message.file = localFilePath + sendFiles.push(localFilePath); } else if (message.type == "reply") { let msgId = message.data?.id || message.msgId let replyMessage = msgHistory.find(msg => msg.raw.msgId == msgId) @@ -249,9 +251,11 @@ async function listenSendMessage(postData: PostDataSendMsg) { message.msgSeq = replyMessage?.raw.msgSeq || "" } } - // 发送完之后要删除下载的文件 console.log("发送消息", postData) - window.LLAPI.sendMessage(peer, postData.params.message).then(res => console.log("消息发送成功:", peer, postData.params.message), + window.LLAPI.sendMessage(peer, postData.params.message).then(res => { + console.log("消息发送成功:", peer, postData.params.message) + window.llonebot.deleteFile(sendFiles); + }, err => console.log("消息发送失败", postData, err)) } } @@ -305,6 +309,7 @@ function onLoad() { }) console.log("chatListEle", chatListEle) } + getFriends().then(); getGroups().then(() => { getGroupsMembers(groups).then(() => {