mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: 打开插件设置界面导致插件多次监听
This commit is contained in:
parent
f07f0111cd
commit
600addbf82
@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "1.2.5",
|
"version": "1.2.6",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@ -10,3 +10,4 @@ export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
|
|||||||
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
|
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
|
||||||
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file"
|
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file"
|
||||||
export const CHANNEL_DELETE_FILE= "llonebot_delete_file"
|
export const CHANNEL_DELETE_FILE= "llonebot_delete_file"
|
||||||
|
export const CHANNEL_GET_RUNNING_STATUS= "llonebot_get_running_status"
|
1
src/global.d.ts
vendored
1
src/global.d.ts
vendored
@ -45,6 +45,7 @@ declare var llonebot: {
|
|||||||
setSelfInfo(selfInfo: SelfInfo):void;
|
setSelfInfo(selfInfo: SelfInfo):void;
|
||||||
downloadFile(arg: {uri: string, localFilePath: string}):Promise<string>;
|
downloadFile(arg: {uri: string, localFilePath: string}):Promise<string>;
|
||||||
deleteFile(path: string[]):Promise<void>;
|
deleteFile(path: string[]):Promise<void>;
|
||||||
|
getRunningStatus(): Promise<boolean>;
|
||||||
};
|
};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_START_HTTP_SERVER,
|
CHANNEL_START_HTTP_SERVER,
|
||||||
CHANNEL_UPDATE_FRIENDS,
|
CHANNEL_UPDATE_FRIENDS,
|
||||||
CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE
|
CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE, CHANNEL_GET_RUNNING_STATUS
|
||||||
} from "../common/IPCChannel";
|
} from "../common/IPCChannel";
|
||||||
import {ConfigUtil} from "./config";
|
import {ConfigUtil} from "./config";
|
||||||
import {startExpress} from "./HttpServer";
|
import {startExpress} from "./HttpServer";
|
||||||
@ -22,10 +22,12 @@ import {friends, groups, selfInfo} from "./data";
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
let running = false;
|
||||||
|
|
||||||
|
|
||||||
// 加载插件时触发
|
// 加载插件时触发
|
||||||
function onLoad(plugin: any) {
|
function onLoad(plugin: any) {
|
||||||
|
log("main onLoaded");
|
||||||
function getConfigUtil() {
|
function getConfigUtil() {
|
||||||
const configFilePath = path.join(plugin.path.data, `config_${selfInfo.user_id}.json`)
|
const configFilePath = path.join(plugin.path.data, `config_${selfInfo.user_id}.json`)
|
||||||
return new ConfigUtil(configFilePath)
|
return new ConfigUtil(configFilePath)
|
||||||
@ -122,6 +124,7 @@ function onLoad(plugin: any) {
|
|||||||
ipcMain.handle(CHANNEL_SET_SELF_INFO, (event: any, arg: SelfInfo) => {
|
ipcMain.handle(CHANNEL_SET_SELF_INFO, (event: any, arg: SelfInfo) => {
|
||||||
selfInfo.user_id = arg.user_id;
|
selfInfo.user_id = arg.user_id;
|
||||||
selfInfo.nickname = arg.nickname;
|
selfInfo.nickname = arg.nickname;
|
||||||
|
running = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on(CHANNEL_DELETE_FILE, (event: any, arg: string[]) => {
|
ipcMain.on(CHANNEL_DELETE_FILE, (event: any, arg: string[]) => {
|
||||||
@ -129,6 +132,10 @@ function onLoad(plugin: any) {
|
|||||||
fs.unlinkSync(path);
|
fs.unlinkSync(path);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.handle(CHANNEL_GET_RUNNING_STATUS, (event: any, arg: any) => {
|
||||||
|
return running;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,10 +3,18 @@
|
|||||||
import {Config, Group, PostDataSendMsg, SelfInfo, User} from "./common/types";
|
import {Config, Group, PostDataSendMsg, SelfInfo, User} from "./common/types";
|
||||||
import {
|
import {
|
||||||
CHANNEL_DOWNLOAD_FILE,
|
CHANNEL_DOWNLOAD_FILE,
|
||||||
CHANNEL_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
|
CHANNEL_GET_CONFIG,
|
||||||
CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG,
|
CHANNEL_SET_SELF_INFO,
|
||||||
|
CHANNEL_LOG,
|
||||||
|
CHANNEL_POST_ONEBOT_DATA,
|
||||||
|
CHANNEL_RECALL_MSG,
|
||||||
|
CHANNEL_SEND_MSG,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE
|
CHANNEL_START_HTTP_SERVER,
|
||||||
|
CHANNEL_UPDATE_FRIENDS,
|
||||||
|
CHANNEL_UPDATE_GROUPS,
|
||||||
|
CHANNEL_DELETE_FILE,
|
||||||
|
CHANNEL_GET_RUNNING_STATUS
|
||||||
} from "./common/IPCChannel";
|
} from "./common/IPCChannel";
|
||||||
|
|
||||||
|
|
||||||
@ -55,6 +63,9 @@ contextBridge.exposeInMainWorld("llonebot", {
|
|||||||
},
|
},
|
||||||
deleteFile: async (localFilePath: string[]) => {
|
deleteFile: async (localFilePath: string[]) => {
|
||||||
ipcRenderer.send(CHANNEL_DELETE_FILE, localFilePath);
|
ipcRenderer.send(CHANNEL_DELETE_FILE, localFilePath);
|
||||||
|
},
|
||||||
|
getRunningStatus: () => {
|
||||||
|
return ipcRenderer.invoke(CHANNEL_GET_RUNNING_STATUS);
|
||||||
}
|
}
|
||||||
// startExpress,
|
// startExpress,
|
||||||
});
|
});
|
@ -4,6 +4,7 @@
|
|||||||
// 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";
|
import * as stream from "stream";
|
||||||
|
import {raw} from "express";
|
||||||
|
|
||||||
let self_qq: string = ""
|
let self_qq: string = ""
|
||||||
let groups: Group[] = []
|
let groups: Group[] = []
|
||||||
@ -30,6 +31,8 @@ async function getFriends() {
|
|||||||
}
|
}
|
||||||
window.llonebot.updateFriends(friends)
|
window.llonebot.updateFriends(friends)
|
||||||
return friends
|
return friends
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFriend(qq: string) {
|
async function getFriend(qq: string) {
|
||||||
@ -254,7 +257,9 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
console.log("发送消息", postData)
|
console.log("发送消息", postData)
|
||||||
window.LLAPI.sendMessage(peer, postData.params.message).then(res => {
|
window.LLAPI.sendMessage(peer, postData.params.message).then(res => {
|
||||||
console.log("消息发送成功:", peer, postData.params.message)
|
console.log("消息发送成功:", peer, postData.params.message)
|
||||||
window.llonebot.deleteFile(sendFiles);
|
if (sendFiles.length) {
|
||||||
|
window.llonebot.deleteFile(sendFiles);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
err => console.log("消息发送失败", postData, err))
|
err => console.log("消息发送失败", postData, err))
|
||||||
}
|
}
|
||||||
@ -268,14 +273,11 @@ function recallMessage(msgId: string) {
|
|||||||
|
|
||||||
let chatListEle: HTMLCollectionOf<Element>
|
let chatListEle: HTMLCollectionOf<Element>
|
||||||
|
|
||||||
function onLoad() {
|
async function onLoad(arg: any) {
|
||||||
|
let runningStatus = await window.llonebot.getRunningStatus();
|
||||||
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
|
if (runningStatus) {
|
||||||
listenSendMessage(postData).then().catch(err => console.log("listenSendMessage err", err))
|
return;
|
||||||
})
|
}
|
||||||
window.llonebot.listenRecallMessage((arg: { message_id: string }) => {
|
|
||||||
recallMessage(arg.message_id)
|
|
||||||
})
|
|
||||||
|
|
||||||
async function getGroupsMembers(groupsArg: Group[]) {
|
async function getGroupsMembers(groupsArg: Group[]) {
|
||||||
// 批量获取群成员列表
|
// 批量获取群成员列表
|
||||||
@ -292,9 +294,12 @@ function onLoad() {
|
|||||||
getGroupsMembers(failedGroups).then()
|
getGroupsMembers(failedGroups).then()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
} else {
|
} else {
|
||||||
console.log("全部群成员获取完毕", groups)
|
window.llonebot.log("全部群成员获取完毕")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await getFriends();
|
||||||
|
await getGroups();
|
||||||
|
await getGroupsMembers(groups);
|
||||||
|
|
||||||
function onNewMessages(messages: MessageElement[]) {
|
function onNewMessages(messages: MessageElement[]) {
|
||||||
async function func(messages: MessageElement[]) {
|
async function func(messages: MessageElement[]) {
|
||||||
@ -307,26 +312,31 @@ function onLoad() {
|
|||||||
|
|
||||||
func(messages).then(() => {
|
func(messages).then(() => {
|
||||||
})
|
})
|
||||||
console.log("chatListEle", chatListEle)
|
// console.log("chatListEle", chatListEle)
|
||||||
}
|
}
|
||||||
|
window.LLAPI.on("new-messages", onNewMessages);
|
||||||
|
window.LLAPI.on("new-send-messages", onNewMessages);
|
||||||
|
|
||||||
getFriends().then();
|
let accountInfo = await window.LLAPI.getAccountInfo();
|
||||||
getGroups().then(() => {
|
window.llonebot.log("getAccountInfo " + JSON.stringify(accountInfo));
|
||||||
getGroupsMembers(groups).then(() => {
|
if (!accountInfo.uid) {
|
||||||
window.LLAPI.on("new-messages", onNewMessages);
|
return;
|
||||||
window.LLAPI.on("new-send-messages", onNewMessages);
|
}
|
||||||
})
|
let selfInfo = await window.LLAPI.getUserInfo(accountInfo.uid);
|
||||||
})
|
window.llonebot.setSelfInfo({
|
||||||
|
user_id: accountInfo.uin,
|
||||||
|
nickname: selfInfo.nickName
|
||||||
|
});
|
||||||
|
window.llonebot.log("selfInfo " + JSON.stringify(selfInfo))
|
||||||
|
window.llonebot.startExpress();
|
||||||
|
|
||||||
window.LLAPI.getAccountInfo().then(accountInfo => {
|
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
|
||||||
window.LLAPI.getUserInfo(accountInfo.uid).then(userInfo => {
|
listenSendMessage(postData).then().catch(err => console.log("listenSendMessage err", err))
|
||||||
window.llonebot.setSelfInfo({
|
|
||||||
user_id: accountInfo.uin,
|
|
||||||
nickname: userInfo.nickName
|
|
||||||
});
|
|
||||||
window.llonebot.startExpress();
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
window.llonebot.listenRecallMessage((arg: { message_id: string }) => {
|
||||||
|
recallMessage(arg.message_id)
|
||||||
|
})
|
||||||
|
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user