Merge pull request #7 from Rotten-LKZ/dev

feat: github actions for automatically publishing releases
This commit is contained in:
linyuchen 2024-01-28 10:37:06 +08:00 committed by GitHub
commit 515fc8afb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 164 additions and 111 deletions

36
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: "publish"
on:
push:
tags:
- "v*"
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup node
uses: actions/setup-node@v2
with:
node-version: 18
- name: install dependenies
run: npm install
- name: build
run: npm run build
- name: zip
run: |
sudo apt install zip -y
cp manifest.json ./dist/manifest.json
zip LLOneBot.zip ./dist/* -j
- name: publish
uses: ncipollo/release-action@v1
with:
artifacts: "LLOneBot.zip"
draft: true
token: ${{ secrets.RELEASE_TOKEN }}

View File

@ -4,7 +4,7 @@
"name": "LLOneBot", "name": "LLOneBot",
"slug": "LLOneBot", "slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi", "description": "LiteLoaderQQNT的OneBotApi",
"version": "2.0.0", "version": "2.0.2",
"thumbnail": "./icon.png", "thumbnail": "./icon.png",
"authors": [{ "authors": [{
"name": "linyuchen", "name": "linyuchen",

View File

@ -1,3 +1,5 @@
import {log} from "./utils";
const express = require("express"); const express = require("express");
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend"; import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend";
@ -45,9 +47,10 @@ function checkSendMessage(sendMsgList: SendMessage[]) {
// ==end== // ==end==
function handlePost(jsonData: any) { function handlePost(jsonData: any) {
log("API receive post:" + JSON.stringify(jsonData))
if (!jsonData.params) { if (!jsonData.params) {
jsonData.params = jsonData jsonData.params = JSON.parse(JSON.stringify(jsonData));
delete jsonData.params.params;
} }
let resData = { let resData = {
status: 0, status: 0,

View File

@ -8,6 +8,7 @@ function sendIPCMsg(channel: string, data: any) {
try { try {
content.send(channel, data) content.send(channel, data)
} catch (e) { } catch (e) {
console.log("llonebot send ipc msg to render error:", e)
} }
} }
} }

View File

@ -34,6 +34,7 @@ contextBridge.exposeInMainWorld("llonebot", {
ipcRenderer.send(CHANNEL_UPDATE_FRIENDS, friends); ipcRenderer.send(CHANNEL_UPDATE_FRIENDS, friends);
}, },
listenSendMessage: (handle: (jsonData: PostDataSendMsg) => void) => { listenSendMessage: (handle: (jsonData: PostDataSendMsg) => void) => {
ipcRenderer.send(CHANNEL_LOG, "发送消息API已注册");
ipcRenderer.on(CHANNEL_SEND_MSG, (event: any, args: PostDataSendMsg) => { ipcRenderer.on(CHANNEL_SEND_MSG, (event: any, args: PostDataSendMsg) => {
handle(args) handle(args)
}) })

View File

@ -116,7 +116,9 @@ async function handleNewMessage(messages: MessageElement[]) {
detail_type: message.peer.chatType, detail_type: message.peer.chatType,
message_id: message.raw.msgId, message_id: message.raw.msgId,
sub_type: "", sub_type: "",
message: [] message: [],
raw_message: "",
font: 14
} }
if (message.peer.chatType == "group") { if (message.peer.chatType == "group") {
let group_id = message.peer.uid let group_id = message.peer.uid
@ -179,6 +181,7 @@ async function handleNewMessage(messages: MessageElement[]) {
} }
async function listenSendMessage(postData: PostDataSendMsg) { async function listenSendMessage(postData: PostDataSendMsg) {
console.log("收到发送消息请求", postData);
if (postData.action == "send_private_msg" || postData.action == "send_group_msg") { if (postData.action == "send_private_msg" || postData.action == "send_group_msg") {
let peer: Peer | null = null; let peer: Peer | null = null;
if (!postData.params) { if (!postData.params) {
@ -308,7 +311,7 @@ async function initAccountInfo(){
let accountInfo = await window.LLAPI.getAccountInfo(); let accountInfo = await window.LLAPI.getAccountInfo();
window.llonebot.log("getAccountInfo " + JSON.stringify(accountInfo)); window.llonebot.log("getAccountInfo " + JSON.stringify(accountInfo));
if (!accountInfo.uid) { if (!accountInfo.uid) {
return; return false;
} }
let selfInfo = await window.LLAPI.getUserInfo(accountInfo.uid); let selfInfo = await window.LLAPI.getUserInfo(accountInfo.uid);
window.llonebot.setSelfInfo({ window.llonebot.setSelfInfo({
@ -316,6 +319,7 @@ async function initAccountInfo(){
nickname: selfInfo.nickName nickname: selfInfo.nickName
}); });
window.llonebot.log("selfInfo " + JSON.stringify(selfInfo)); window.llonebot.log("selfInfo " + JSON.stringify(selfInfo));
return true;
} }
function onLoad() { function onLoad() {
@ -325,7 +329,10 @@ function onLoad() {
return; return;
} }
initAccountInfo().then( initAccountInfo().then(
()=>{ (initSuccess)=>{
if (!initSuccess) {
return;
}
if (friends.length == 0) { if (friends.length == 0) {
getFriends().then(()=>{}); getFriends().then(()=>{});
} }
@ -346,104 +353,104 @@ function onLoad() {
recallMessage(arg.message_id) recallMessage(arg.message_id)
}) })
window.llonebot.log("llonebot loaded"); window.llonebot.log("llonebot loaded");
window.LLAPI.add_qmenu((qContextMenu: Node) => { // window.LLAPI.add_qmenu((qContextMenu: Node) => {
let btn = document.createElement("a") // let btn = document.createElement("a")
btn.className = "q-context-menu-item q-context-menu-item--normal vue-component" // btn.className = "q-context-menu-item q-context-menu-item--normal vue-component"
btn.setAttribute("aria-disabled", "false") // btn.setAttribute("aria-disabled", "false")
btn.setAttribute("role", "menuitem") // btn.setAttribute("role", "menuitem")
btn.setAttribute("tabindex", "-1") // btn.setAttribute("tabindex", "-1")
btn.onclick = () => { // 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 => { // window.LLAPI.getPeer().then(peer => {
// // console.log("current peer", peer) // // console.log("current peer", peer)
// if (peer && peer.chatType == "group") { // if (peer && peer.chatType == "group") {
// getGroupMembers(peer.uid, true).then(()=> { // getGroupMembers(peer.uid, false).then()
// console.log("获取群成员列表成功", groups);
// alert("获取群成员列表成功")
// })
// } // }
// }) // })
async function func() { // });
for (const group of groups) { // });
await getGroupMembers(group.uid, true) //
} // // 配置观察选项
} // const config = {attributes: true, childList: true, subtree: true};
//
func().then(() => { // // 传入目标节点和观察选项
console.log("获取群成员列表结果", groups); // observer.observe(targetNode, config);
// 找到members数量为空的群 //
groups.map(group => { // } catch (e) {
if (group.members.length == 0) { // window.llonebot.log(e)
console.log(`${group.name}群成员为空`) // }
} // }
}) // }
window.llonebot.updateGroups(groups) //
}) // // getChatListEle();
}
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"); window.llonebot.log("setting window created");
const {port, hosts} = await window.llonebot.getConfig() const {port, hosts} = await window.llonebot.getConfig()
function creatHostEleStr(host: string) { function creatHostEleStr(host: string) {
let eleStr = ` let eleStr = `
<div class="hostItem vertical-list-item"> <setting-item data-direction="row" class="hostItem vertical-list-item">
<h2>(http)</h2> <h2>(http)</h2>
<input class="host" type="text" value="${host}" <input class="host input-text" type="text" value="${host}"
style="width:60%;padding: 5px" style="width:60%;padding: 5px"
placeholder="不支持localhost,如果是本机请填写局域网ip"/> placeholder="如果localhost上报失败试试局域网ip"/>
</div> </setting-item>
` `
return eleStr return eleStr
} }
@ -452,12 +459,15 @@ async function onSettingWindowCreated (view: any) {
for (const host of hosts) { for (const host of hosts) {
hostsEleStr += creatHostEleStr(host); hostsEleStr += creatHostEleStr(host);
} }
const html = ` let html = `
<section class="wrap"> <div class="config_view">
<div class="vertical-list-item"> <setting-section>
<h2></h2> <setting-panel style="padding: 10px">
<setting-list class="wrap">
<setting-item class="vertical-list-item" data-direction="row">
<setting-text></setting-text>
<input id="port" type="number" value="${port}"/> <input id="port" type="number" value="${port}"/>
</div> </setting-item>
<div> <div>
<button id="addHost" class="q-button"></button> <button id="addHost" class="q-button"></button>
</div> </div>
@ -465,7 +475,10 @@ async function onSettingWindowCreated (view: any) {
${hostsEleStr} ${hostsEleStr}
</div> </div>
<button id="save" class="q-button">(QQ后生效)</button> <button id="save" class="q-button">(QQ后生效)</button>
</section> </setting-list>
</setting-panel>
</setting-section>
</div>
` `
const parser = new DOMParser(); const parser = new DOMParser();
@ -474,7 +487,7 @@ async function onSettingWindowCreated (view: any) {
function addHostEle(initValue: string = "") { function addHostEle(initValue: string = "") {
let addressDoc = parser.parseFromString(creatHostEleStr(initValue), "text/html"); let addressDoc = parser.parseFromString(creatHostEleStr(initValue), "text/html");
let addressEle = addressDoc.querySelector("div") let addressEle = addressDoc.querySelector("setting-item")
let hostItemsEle = document.getElementById("hostItems"); let hostItemsEle = document.getElementById("hostItems");
hostItemsEle.appendChild(addressEle); hostItemsEle.appendChild(addressEle);
} }
@ -502,15 +515,14 @@ async function onSettingWindowCreated (view: any) {
}) })
alert("保存成功"); alert("保存成功");
}) })
doc.querySelectorAll("section").forEach((node) => view.appendChild(node)); doc.body.childNodes.forEach(node => {
view.appendChild(node);
});
} }
setTimeout(onLoad, 2000)
onLoad()
export { export {
onSettingWindowCreated onSettingWindowCreated