mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a802e95d89 | ||
![]() |
5ae65e1cf8 | ||
![]() |
a826232e96 |
@@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "0.1.0",
|
"version": "1.1.0",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@@ -9,9 +9,9 @@
|
|||||||
"build-main": "webpack --config webpack.main.config.js",
|
"build-main": "webpack --config webpack.main.config.js",
|
||||||
"build-preload": "webpack --config webpack.preload.config.js",
|
"build-preload": "webpack --config webpack.preload.config.js",
|
||||||
"build-renderer": "webpack --config webpack.renderer.config.js",
|
"build-renderer": "webpack --config webpack.renderer.config.js",
|
||||||
"build-mac": "npm run build && npm run deploy-mac",
|
"build-mac": "npm run build && cp manifest.json dist/ && npm run deploy-mac",
|
||||||
"deploy-mac": "cp dist/* ~/Library/Containers/com.tencent.qq/Data/Documents/LiteLoaderQQNT/plugins/LLOnebot/",
|
"deploy-mac": "cp dist/* ~/Library/Containers/com.tencent.qq/Data/Documents/LiteLoaderQQNT/plugins/LLOnebot/",
|
||||||
"build-win": "npm run build && npm run deploy-win",
|
"build-win": "npm run build && cp manifest.json dist/ && npm run deploy-win",
|
||||||
"deploy-win": "cmd /c \"copy dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOnebot\\\""
|
"deploy-win": "cmd /c \"copy dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOnebot\\\""
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
|
@@ -156,5 +156,5 @@ export type PostDataSendMsg = {
|
|||||||
|
|
||||||
export type Config = {
|
export type Config = {
|
||||||
port: number,
|
port: number,
|
||||||
host: string,
|
hosts: string[],
|
||||||
}
|
}
|
||||||
|
@@ -11,10 +11,14 @@ export class ConfigUtil{
|
|||||||
|
|
||||||
getConfig(): Config{
|
getConfig(): Config{
|
||||||
if (!fs.existsSync(this.configPath)) {
|
if (!fs.existsSync(this.configPath)) {
|
||||||
return {"port":3000, "host": "http://localhost:5000/"}
|
return {port:3000, hosts: ["http://192.168.1.2:5000/"]}
|
||||||
} else {
|
} else {
|
||||||
const data = fs.readFileSync(this.configPath, "utf-8");
|
const data = fs.readFileSync(this.configPath, "utf-8");
|
||||||
return JSON.parse(data);
|
let jsonData =JSON.parse(data);
|
||||||
|
if (!jsonData.hosts){
|
||||||
|
jsonData.hosts = []
|
||||||
|
}
|
||||||
|
return jsonData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -89,21 +89,23 @@ function onLoad(plugin: any) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on(CHANNEL_POST_ONEBOT_DATA, (event: any, arg: any) => {
|
ipcMain.on(CHANNEL_POST_ONEBOT_DATA, (event: any, arg: any) => {
|
||||||
try {
|
for(const host of configUtil.getConfig().hosts) {
|
||||||
fetch(configUtil.getConfig().host, {
|
try {
|
||||||
method: "POST",
|
fetch(host, {
|
||||||
headers: {
|
method: "POST",
|
||||||
"Content-Type": "application/json",
|
headers: {
|
||||||
"x-self-id": selfInfo.user_id
|
"Content-Type": "application/json",
|
||||||
},
|
"x-self-id": selfInfo.user_id
|
||||||
body: JSON.stringify(arg)
|
},
|
||||||
}).then((res: any) => {
|
body: JSON.stringify(arg)
|
||||||
log("新消息事件上传");
|
}).then((res: any) => {
|
||||||
}, (err: any) => {
|
log("新消息事件上传");
|
||||||
log("新消息事件上传失败:" + err + JSON.stringify(arg));
|
}, (err: any) => {
|
||||||
});
|
log("新消息事件上传失败:" + err + JSON.stringify(arg));
|
||||||
} catch (e: any) {
|
});
|
||||||
log(e.toString())
|
} catch (e: any) {
|
||||||
|
log(e.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
// import express from "express";
|
// import express from "express";
|
||||||
// const { ipcRenderer } = require('electron');
|
// const { ipcRenderer } = require('electron');
|
||||||
import {AtType, Group, MessageElement, OnebotGroupMemberRole, Peer, PostDataSendMsg, User} from "./common/types";
|
import {AtType, Group, MessageElement, OnebotGroupMemberRole, Peer, PostDataSendMsg, User} from "./common/types";
|
||||||
|
import * as stream from "stream";
|
||||||
|
|
||||||
let self_qq: string = ""
|
let self_qq: string = ""
|
||||||
let groups: Group[] = []
|
let groups: Group[] = []
|
||||||
@@ -219,8 +220,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
let localFilePath = `${Date.now()}${ext}`
|
let localFilePath = `${Date.now()}${ext}`
|
||||||
if (uri.protocol == "file:") {
|
if (uri.protocol == "file:") {
|
||||||
localFilePath = url.split("file://")[1]
|
localFilePath = url.split("file://")[1]
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
|
await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
|
||||||
}
|
}
|
||||||
message.file = localFilePath
|
message.file = localFilePath
|
||||||
@@ -388,41 +388,77 @@ function onLoad() {
|
|||||||
|
|
||||||
// 打开设置界面时触发
|
// 打开设置界面时触发
|
||||||
async function onConfigView(view: any) {
|
async function onConfigView(view: any) {
|
||||||
// 插件本体的路径
|
const {port, hosts} = await window.llonebot.getConfig()
|
||||||
// const plugin_path = (window as any).LiteLoader.plugins.LLOneBot.path;
|
|
||||||
const {port, host} = await window.llonebot.getConfig()
|
function creatHostEleStr(host: string) {
|
||||||
|
let eleStr = `
|
||||||
|
<div class="hostItem vertical-list-item">
|
||||||
|
<h2>事件上报地址(http)</h2>
|
||||||
|
<input class="host" type="text" value="${host}"
|
||||||
|
style="width:60%;padding: 5px"
|
||||||
|
placeholder="不支持localhost,如果是本机请填写局域网ip"/>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
return eleStr
|
||||||
|
}
|
||||||
|
|
||||||
|
let hostsEleStr = ""
|
||||||
|
for (const host of hosts) {
|
||||||
|
hostsEleStr += creatHostEleStr(host);
|
||||||
|
}
|
||||||
const html = `
|
const html = `
|
||||||
<section>
|
<section class="wrap">
|
||||||
<div>
|
<div class="vertical-list-item">
|
||||||
<label>监听端口</label>
|
<h2>监听端口</h2>
|
||||||
<input id="port" type="number" value="${port}"/>
|
<input id="port" type="number" value="${port}"/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label>事件上报地址(http)</label>
|
<button id="addHost" class="q-button">添加上报地址</button>
|
||||||
<input id="host" type="text" value="${host}"/>
|
|
||||||
</div>
|
</div>
|
||||||
<button id="save">保存(重启QQ后生效)</button>
|
<div id="hostItems">
|
||||||
|
${hostsEleStr}
|
||||||
|
</div>
|
||||||
|
<button id="save" class="q-button">保存(监听端口重启QQ后生效)</button>
|
||||||
</section>
|
</section>
|
||||||
`
|
`
|
||||||
|
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(html, "text/html");
|
const doc = parser.parseFromString(html, "text/html");
|
||||||
|
|
||||||
|
|
||||||
|
function addHostEle(initValue: string = "") {
|
||||||
|
let addressDoc = parser.parseFromString(creatHostEleStr(initValue), "text/html");
|
||||||
|
let addressEle = addressDoc.querySelector("div")
|
||||||
|
let hostItemsEle = document.getElementById("hostItems");
|
||||||
|
hostItemsEle.appendChild(addressEle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
doc.getElementById("addHost").addEventListener("click", () => addHostEle())
|
||||||
|
|
||||||
doc.getElementById("save")?.addEventListener("click",
|
doc.getElementById("save")?.addEventListener("click",
|
||||||
() => {
|
() => {
|
||||||
const portEle: HTMLInputElement = document.getElementById("port") as HTMLInputElement
|
const portEle: HTMLInputElement = document.getElementById("port") as HTMLInputElement
|
||||||
const hostEle: HTMLInputElement = document.getElementById("host") as HTMLInputElement
|
const hostEles: HTMLCollectionOf<HTMLInputElement> = document.getElementsByClassName("host") as HTMLCollectionOf<HTMLInputElement>;
|
||||||
// const port = doc.querySelector("input[type=number]")?.value
|
// const port = doc.querySelector("input[type=number]")?.value
|
||||||
// const host = doc.querySelector("input[type=text]")?.value
|
// const host = doc.querySelector("input[type=text]")?.value
|
||||||
// 获取端口和host
|
// 获取端口和host
|
||||||
const port = portEle.value
|
const port = portEle.value
|
||||||
const host = hostEle.value
|
let hosts: string[] = [];
|
||||||
if (port && host) {
|
for (const hostEle of hostEles) {
|
||||||
window.llonebot.setConfig({
|
if (hostEle.value) {
|
||||||
port: parseInt(port),
|
hosts.push(hostEle.value);
|
||||||
host: host
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
window.llonebot.setConfig({
|
||||||
|
port: parseInt(port),
|
||||||
|
hosts: hosts
|
||||||
|
})
|
||||||
|
alert("保存成功");
|
||||||
})
|
})
|
||||||
doc.querySelectorAll("section").forEach((node) => view.appendChild(node));
|
doc.querySelectorAll("section").forEach((node) => view.appendChild(node));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Reference in New Issue
Block a user