diff --git a/manifest.json b/manifest.json index d4b8e15..8fc70f2 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "LLOneBot", "slug": "LLOneBot", "description": "LiteLoaderQQNT的OneBotApi", - "version": "2.0.0", + "version": "2.0.1", "thumbnail": "./icon.png", "authors": [{ "name": "linyuchen", diff --git a/src/main/HttpServer.ts b/src/main/HttpServer.ts index 7e62ef9..7e724d6 100644 --- a/src/main/HttpServer.ts +++ b/src/main/HttpServer.ts @@ -1,3 +1,5 @@ +import {log} from "./utils"; + const express = require("express"); const bodyParser = require('body-parser'); import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend"; @@ -45,9 +47,10 @@ function checkSendMessage(sendMsgList: SendMessage[]) { // ==end== function handlePost(jsonData: any) { + log("API receive post:" + JSON.stringify(jsonData)) if (!jsonData.params) { - jsonData.params = jsonData - + jsonData.params = JSON.parse(JSON.stringify(jsonData)); + delete jsonData.params.params; } let resData = { status: 0, diff --git a/src/main/IPCSend.ts b/src/main/IPCSend.ts index a2b1461..c69b45c 100644 --- a/src/main/IPCSend.ts +++ b/src/main/IPCSend.ts @@ -8,6 +8,7 @@ function sendIPCMsg(channel: string, data: any) { try { content.send(channel, data) } catch (e) { + console.log("llonebot send ipc msg to render error:", e) } } } diff --git a/src/preload.ts b/src/preload.ts index d33a06b7..f19256a 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -34,6 +34,7 @@ contextBridge.exposeInMainWorld("llonebot", { ipcRenderer.send(CHANNEL_UPDATE_FRIENDS, friends); }, listenSendMessage: (handle: (jsonData: PostDataSendMsg) => void) => { + ipcRenderer.send(CHANNEL_LOG, "发送消息API已注册"); ipcRenderer.on(CHANNEL_SEND_MSG, (event: any, args: PostDataSendMsg) => { handle(args) }) diff --git a/src/renderer.ts b/src/renderer.ts index 3f25bce..c8fa65a 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -179,6 +179,7 @@ async function handleNewMessage(messages: MessageElement[]) { } async function listenSendMessage(postData: PostDataSendMsg) { + console.log("收到发送消息请求", postData); if (postData.action == "send_private_msg" || postData.action == "send_group_msg") { let peer: Peer | null = null; if (!postData.params) { @@ -308,7 +309,7 @@ async function initAccountInfo(){ let accountInfo = await window.LLAPI.getAccountInfo(); window.llonebot.log("getAccountInfo " + JSON.stringify(accountInfo)); if (!accountInfo.uid) { - return; + return false; } let selfInfo = await window.LLAPI.getUserInfo(accountInfo.uid); window.llonebot.setSelfInfo({ @@ -316,6 +317,7 @@ async function initAccountInfo(){ nickname: selfInfo.nickName }); window.llonebot.log("selfInfo " + JSON.stringify(selfInfo)); + return true; } function onLoad() { @@ -325,7 +327,10 @@ function onLoad() { return; } initAccountInfo().then( - ()=>{ + (initSuccess)=>{ + if (!initSuccess) { + return; + } if (friends.length == 0) { getFriends().then(()=>{}); } @@ -346,104 +351,104 @@ function onLoad() { recallMessage(arg.message_id) }) window.llonebot.log("llonebot loaded"); - window.LLAPI.add_qmenu((qContextMenu: Node) => { - let btn = document.createElement("a") - btn.className = "q-context-menu-item q-context-menu-item--normal vue-component" - btn.setAttribute("aria-disabled", "false") - btn.setAttribute("role", "menuitem") - btn.setAttribute("tabindex", "-1") - btn.onclick = () => { - // window.LLAPI.getPeer().then(peer => { - // // console.log("current peer", peer) - // if (peer && peer.chatType == "group") { - // getGroupMembers(peer.uid, true).then(()=> { - // console.log("获取群成员列表成功", groups); - // alert("获取群成员列表成功") - // }) - // } - // }) - async function func() { - for (const group of groups) { - await getGroupMembers(group.uid, true) - } - } - - func().then(() => { - console.log("获取群成员列表结果", groups); - // 找到members数量为空的群 - groups.map(group => { - if (group.members.length == 0) { - console.log(`${group.name}群成员为空`) - } - }) - window.llonebot.updateGroups(groups) - }) - } - btn.innerText = "获取群成员列表" - console.log(qContextMenu) - // qContextMenu.appendChild(btn) - }) - - window.LLAPI.on("context-msg-menu", (event, target, msgIds) => { - console.log("msg menu", event, target, msgIds); - }) - - // console.log("getAccountInfo", LLAPI.getAccountInfo()); - function getChatListEle() { - chatListEle = document.getElementsByClassName("viewport-list__inner") - console.log("chatListEle", chatListEle) - if (chatListEle.length == 0) { - setTimeout(getChatListEle, 500) - } else { - try { - // 选择要观察的目标节点 - const targetNode = chatListEle[0]; - - // 创建一个观察器实例并传入回调函数 - const observer = new MutationObserver(function (mutations) { - mutations.forEach(function (mutation) { - // console.log("chat list changed", mutation.type); // 输出 mutation 的类型 - // 获得当前聊天窗口 - window.LLAPI.getPeer().then(peer => { - // console.log("current peer", peer) - if (peer && peer.chatType == "group") { - getGroupMembers(peer.uid, false).then() - } - }) - }); - }); - - // 配置观察选项 - const config = {attributes: true, childList: true, subtree: true}; - - // 传入目标节点和观察选项 - observer.observe(targetNode, config); - - } catch (e) { - window.llonebot.log(e) - } - } - } - - // getChatListEle(); + // window.LLAPI.add_qmenu((qContextMenu: Node) => { + // let btn = document.createElement("a") + // btn.className = "q-context-menu-item q-context-menu-item--normal vue-component" + // btn.setAttribute("aria-disabled", "false") + // btn.setAttribute("role", "menuitem") + // btn.setAttribute("tabindex", "-1") + // btn.onclick = () => { + // // window.LLAPI.getPeer().then(peer => { + // // // console.log("current peer", peer) + // // if (peer && peer.chatType == "group") { + // // getGroupMembers(peer.uid, true).then(()=> { + // // console.log("获取群成员列表成功", groups); + // // alert("获取群成员列表成功") + // // }) + // // } + // // }) + // async function func() { + // for (const group of groups) { + // await getGroupMembers(group.uid, true) + // } + // } + // + // func().then(() => { + // console.log("获取群成员列表结果", groups); + // // 找到members数量为空的群 + // groups.map(group => { + // if (group.members.length == 0) { + // console.log(`${group.name}群成员为空`) + // } + // }) + // window.llonebot.updateGroups(groups) + // }) + // } + // btn.innerText = "获取群成员列表" + // console.log(qContextMenu) + // // qContextMenu.appendChild(btn) + // }) + // + // window.LLAPI.on("context-msg-menu", (event, target, msgIds) => { + // console.log("msg menu", event, target, msgIds); + // }) + // + // // console.log("getAccountInfo", LLAPI.getAccountInfo()); + // function getChatListEle() { + // chatListEle = document.getElementsByClassName("viewport-list__inner") + // console.log("chatListEle", chatListEle) + // if (chatListEle.length == 0) { + // setTimeout(getChatListEle, 500) + // } else { + // try { + // // 选择要观察的目标节点 + // const targetNode = chatListEle[0]; + // + // // 创建一个观察器实例并传入回调函数 + // const observer = new MutationObserver(function (mutations) { + // mutations.forEach(function (mutation) { + // // console.log("chat list changed", mutation.type); // 输出 mutation 的类型 + // // 获得当前聊天窗口 + // window.LLAPI.getPeer().then(peer => { + // // console.log("current peer", peer) + // if (peer && peer.chatType == "group") { + // getGroupMembers(peer.uid, false).then() + // } + // }) + // }); + // }); + // + // // 配置观察选项 + // const config = {attributes: true, childList: true, subtree: true}; + // + // // 传入目标节点和观察选项 + // observer.observe(targetNode, config); + // + // } catch (e) { + // window.llonebot.log(e) + // } + // } + // } + // + // // getChatListEle(); } ); }); } // 打开设置界面时触发 -async function onSettingWindowCreated (view: any) { +async function onSettingWindowCreated (view: Element) { window.llonebot.log("setting window created"); const {port, hosts} = await window.llonebot.getConfig() function creatHostEleStr(host: string) { let eleStr = ` -