mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
30 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8083ae4091 | ||
![]() |
465b7eaf6e | ||
![]() |
0a6a67738e | ||
![]() |
f9a3b60192 | ||
![]() |
15ea558721 | ||
![]() |
35c9ffc0b0 | ||
![]() |
7dde7cbc2b | ||
![]() |
515fc8afb4 | ||
![]() |
f341e9f6e1 | ||
![]() |
bfdb2835c6 | ||
![]() |
05c4d693e0 | ||
![]() |
5c04f73f89 | ||
![]() |
8f7886e1ee | ||
![]() |
5bbbe77ad0 | ||
![]() |
0a3ae76b89 | ||
![]() |
ddd60a6a79 | ||
![]() |
6364f90b20 | ||
![]() |
e4d8c5e72e | ||
![]() |
907c9053c7 | ||
![]() |
6d33fb8b14 | ||
![]() |
2350e4dc75 | ||
![]() |
600addbf82 | ||
![]() |
f07f0111cd | ||
![]() |
923f72e5d3 | ||
![]() |
5b4001e411 | ||
![]() |
b950f01d51 | ||
![]() |
dc38275660 | ||
![]() |
3d077550cd | ||
![]() |
44fe01f94b | ||
![]() |
5f9679dfbf |
36
.github/workflows/publish.yml
vendored
Normal file
36
.github/workflows/publish.yml
vendored
Normal 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 }}
|
24
README.md
24
README.md
@@ -1,24 +1,25 @@
|
|||||||
# LLOneBot API
|
# LLOneBot API
|
||||||
|
|
||||||
|
|
||||||
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API, V12没有完整测试
|
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API, V12没有完整测试
|
||||||
|
|
||||||
|
*注意:本文档对应的是 LiteLoader 1.0.0及以上版本,如果你使用的是旧版本请切换到本项目v1分支查看文档*
|
||||||
|
|
||||||
## 安装方法
|
## 安装方法
|
||||||
|
|
||||||
1.安装[NTQQLiteLoader](https://github.com/LiteLoaderQQNT/LiteLoaderQQNT)
|
1.安装[NTQQLiteLoader](https://liteloaderqqnt.github.io/guide/install.html)
|
||||||
|
|
||||||
2.安装修改后的[LiteLoaderQQNT-Plugin-LLAPI](https://github.com/linyuchen/LiteLoaderQQNT-Plugin-LLAPI),原版的功能有缺陷
|
2.安装修改后的[LiteLoaderQQNT-Plugin-LLAPI](https://github.com/linyuchen/LiteLoaderQQNT-Plugin-LLAPI),原版的功能有缺陷
|
||||||
|
|
||||||
3.安装本项目插件[OneBotApi](https://github.com/linyuchen/LiteLoaderQQNT-OneBotApi/releases/)
|
3.安装本项目插件[OneBotApi](https://github.com/linyuchen/LiteLoaderQQNT-OneBotApi/releases/), 注意本插件2.0以下的版本不支持LiteLoader 1.0.0及以上版本
|
||||||
|
|
||||||
*关于插件的安装方法: 上述的两个插件都没有上架NTQQLiteLoader插件市场,需要自己下载源码复制到插件目录*
|
*关于插件的安装方法: 上述的两个插件都没有上架NTQQLiteLoader插件市场,需要自己下载复制到插件目录*
|
||||||
|
|
||||||
*Windows插件目录:`%USERPROFILE%/Documents/LiteLoaderQQNT/plugins`*
|
*插件目录:`LiteLoaderQQNT/plugins`*
|
||||||
|
|
||||||
*Mac插件目录:`~/Library/Containers/com.tencent.qq/Data/Documents/LiteLoaderQQNT/plugins`*
|
|
||||||
|
|
||||||
## 支持的API
|
## 支持的API
|
||||||
|
|
||||||
目前只支持http协议,不支持websocket,事件上报也是http协议
|
目前只支持http协议POST方法,不支持websocket,事件上报也是http协议
|
||||||
|
|
||||||
- [x] 获取群列表
|
- [x] 获取群列表
|
||||||
- [x] 获取群成员列表
|
- [x] 获取群成员列表
|
||||||
@@ -50,3 +51,12 @@
|
|||||||
- [x] get_friend_list
|
- [x] get_friend_list
|
||||||
|
|
||||||
**自己发送成功的消息也会上报,可以用于获取需要撤回消息的id**
|
**自己发送成功的消息也会上报,可以用于获取需要撤回消息的id**
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
*暂时不支持`"message": "hello"`这种message为字符串的形式*
|
||||||
|
|
||||||
|
## onebot11文档
|
||||||
|
<https://11.onebot.dev/>
|
||||||
|
BIN
doc/image/example.jpg
Normal file
BIN
doc/image/example.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
@@ -1,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 3,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "1.2.2",
|
"version": "2.0.4",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"author": {
|
"authors": [{
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
"link": "https://github.com/linyuchen"
|
"link": "https://github.com/linyuchen"
|
||||||
},
|
}],
|
||||||
"repository": {
|
"repository": {
|
||||||
"repo": "linyuchen/LLOneBot",
|
"repo": "linyuchen/LiteLoaderQQNT-OneBotApi",
|
||||||
"branch": "main",
|
"branch": "main",
|
||||||
"use_release": {
|
"release": {
|
||||||
"tag": "latest",
|
"tag": "latest",
|
||||||
"name": "LLOneBot.zip"
|
"name": "LLOneBot.zip"
|
||||||
}
|
}
|
||||||
|
@@ -9,3 +9,5 @@ export const CHANNEL_LOG = "llonebot_log"
|
|||||||
export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
|
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_GET_RUNNING_STATUS= "llonebot_get_running_status"
|
@@ -44,7 +44,7 @@ export type Group = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Peer = {
|
export type Peer = {
|
||||||
chatType: "private" | "group"
|
chatType: "private" | "group" | "friend"
|
||||||
name: string
|
name: string
|
||||||
uid: string // qq号
|
uid: string // qq号
|
||||||
}
|
}
|
||||||
@@ -53,6 +53,7 @@ export type MessageElement = {
|
|||||||
raw: {
|
raw: {
|
||||||
msgId: string,
|
msgId: string,
|
||||||
msgSeq: string,
|
msgSeq: string,
|
||||||
|
senderUin: string; // 发送者QQ号
|
||||||
elements: {
|
elements: {
|
||||||
replyElement: {
|
replyElement: {
|
||||||
senderUid: string, // 原消息发送者QQ号
|
senderUid: string, // 原消息发送者QQ号
|
||||||
@@ -98,7 +99,6 @@ export type MessageElement = {
|
|||||||
}
|
}
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
peer: Peer,
|
peer: Peer,
|
||||||
sender: {
|
sender: {
|
||||||
uid: string // 一串加密的字符串
|
uid: string // 一串加密的字符串
|
||||||
@@ -114,7 +114,7 @@ export type SendMessage = {
|
|||||||
text: string, // 纯文本
|
text: string, // 纯文本
|
||||||
}
|
}
|
||||||
} | {
|
} | {
|
||||||
type: "image" | "voice",
|
type: "image" | "voice" | "record",
|
||||||
file: string, // 本地路径
|
file: string, // 本地路径
|
||||||
data?: {
|
data?: {
|
||||||
file: string // 本地路径
|
file: string // 本地路径
|
||||||
|
2
src/global.d.ts
vendored
2
src/global.d.ts
vendored
@@ -44,6 +44,8 @@ declare var llonebot: {
|
|||||||
getConfig():Promise<Config>;
|
getConfig():Promise<Config>;
|
||||||
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>;
|
||||||
|
getRunningStatus(): Promise<boolean>;
|
||||||
};
|
};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,14 +1,55 @@
|
|||||||
import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend";
|
import {log} from "./utils";
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const bodyParser = require('body-parser');
|
import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend";
|
||||||
import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg} from "../common/types";
|
import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg, SendMessage} from "../common/types";
|
||||||
import {friends, groups, selfInfo} from "./data";
|
import {friends, groups, selfInfo} from "./data";
|
||||||
|
|
||||||
function handlePost(jsonData: any) {
|
// @SiberianHusky 2021-08-15
|
||||||
if (!jsonData.params) {
|
function checkSendMessage(sendMsgList: SendMessage[]) {
|
||||||
jsonData.params = jsonData
|
function checkUri(uri: string): boolean {
|
||||||
|
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||||
|
return pattern.test(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let msg of sendMsgList) {
|
||||||
|
if (msg["type"] && msg["data"]) {
|
||||||
|
let type = msg["type"];
|
||||||
|
let data = msg["data"];
|
||||||
|
if (type === "text" && !data["text"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (["image", "voice"].includes(type)) {
|
||||||
|
if (!data["file"]) {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (checkUri(data["file"])) {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (type === "at" && !data["qq"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (type === "reply" && !data["id"]) {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
// ==end==
|
||||||
|
|
||||||
|
function handlePost(jsonData: any) {
|
||||||
|
log("API receive post:" + JSON.stringify(jsonData))
|
||||||
|
if (!jsonData.params) {
|
||||||
|
jsonData.params = JSON.parse(JSON.stringify(jsonData));
|
||||||
|
delete jsonData.params.params;
|
||||||
}
|
}
|
||||||
let resData = {
|
let resData = {
|
||||||
status: 0,
|
status: 0,
|
||||||
@@ -21,11 +62,20 @@ function handlePost(jsonData: any) {
|
|||||||
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
|
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
|
||||||
if (jsonData.action == "send_private_msg") {
|
if (jsonData.action == "send_private_msg") {
|
||||||
jsonData.message_type = "private"
|
jsonData.message_type = "private"
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
jsonData.message_type = "group"
|
jsonData.message_type = "group"
|
||||||
}
|
}
|
||||||
|
// @SiberianHuskY 2021-10-20 22:00:00
|
||||||
|
resData.status = checkSendMessage(jsonData.message);
|
||||||
|
if (resData.status == 200) {
|
||||||
|
resData.message = "发送成功";
|
||||||
|
resData.data = jsonData.message;
|
||||||
sendIPCSendQQMsg(jsonData);
|
sendIPCSendQQMsg(jsonData);
|
||||||
|
} else {
|
||||||
|
resData.message = "发送失败, 请检查消息格式";
|
||||||
|
resData.data = jsonData.message;
|
||||||
|
}
|
||||||
|
// == end ==
|
||||||
} else if (jsonData.action == "get_group_list") {
|
} else if (jsonData.action == "get_group_list") {
|
||||||
resData["data"] = groups.map(group => {
|
resData["data"] = groups.map(group => {
|
||||||
return {
|
return {
|
||||||
@@ -41,8 +91,7 @@ function handlePost(jsonData: any) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
} else if (jsonData.action == "get_group_info") {
|
||||||
else if (jsonData.action == "get_group_info") {
|
|
||||||
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
||||||
if (group) {
|
if (group) {
|
||||||
resData["data"] = {
|
resData["data"] = {
|
||||||
@@ -51,8 +100,7 @@ function handlePost(jsonData: any) {
|
|||||||
member_count: group.members.length,
|
member_count: group.members.length,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (jsonData.action == "get_group_member_info") {
|
||||||
else if (jsonData.action == "get_group_member_info") {
|
|
||||||
let member = groups.find(group => group.uid == jsonData.params.group_id)?.members?.find(member => member.uin == jsonData.params.user_id)
|
let member = groups.find(group => group.uid == jsonData.params.group_id)?.members?.find(member => member.uin == jsonData.params.user_id)
|
||||||
resData["data"] = {
|
resData["data"] = {
|
||||||
user_id: member.uin,
|
user_id: member.uin,
|
||||||
@@ -62,8 +110,7 @@ function handlePost(jsonData: any) {
|
|||||||
card: member.cardName,
|
card: member.cardName,
|
||||||
role: OnebotGroupMemberRole[member.role],
|
role: OnebotGroupMemberRole[member.role],
|
||||||
}
|
}
|
||||||
}
|
} else if (jsonData.action == "get_group_member_list") {
|
||||||
else if (jsonData.action == "get_group_member_list") {
|
|
||||||
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
||||||
if (group) {
|
if (group) {
|
||||||
resData["data"] = group?.members?.map(member => {
|
resData["data"] = group?.members?.map(member => {
|
||||||
@@ -97,9 +144,8 @@ function handlePost(jsonData: any) {
|
|||||||
export function startExpress(port: number) {
|
export function startExpress(port: number) {
|
||||||
const app = express();
|
const app = express();
|
||||||
// 中间件,用于解析POST请求的请求体
|
// 中间件,用于解析POST请求的请求体
|
||||||
app.use(express.urlencoded({extended: true, limit: "50mb"}));
|
app.use(express.urlencoded({extended: true, limit: "500mb"}));
|
||||||
app.use(bodyParser({limit: '50mb'}))
|
app.use(express.json({limit: '500mb'}));
|
||||||
app.use(express.json());
|
|
||||||
|
|
||||||
function parseToOnebot12(action: PostDataAction) {
|
function parseToOnebot12(action: PostDataAction) {
|
||||||
app.post('/' + action, (req: any, res: any) => {
|
app.post('/' + action, (req: any, res: any) => {
|
||||||
@@ -109,6 +155,7 @@ export function startExpress(port: number) {
|
|||||||
res.send(resData)
|
res.send(resData)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionList: PostDataAction[] = ["get_login_info", "send_private_msg", "send_group_msg",
|
const actionList: PostDataAction[] = ["get_login_info", "send_private_msg", "send_group_msg",
|
||||||
"get_group_list", "get_friend_list", "delete_msg", "get_group_member_list", "get_group_member_info"]
|
"get_group_list", "get_friend_list", "delete_msg", "get_group_member_list", "get_group_member_info"]
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,26 +13,31 @@ 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_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";
|
||||||
import {log} from "./utils";
|
import {isGIF, log} from "./utils";
|
||||||
import {friends, groups, selfInfo} from "./data";
|
import {friends, groups, selfInfo} from "./data";
|
||||||
|
import {} from "../global";
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
let running = false;
|
||||||
|
|
||||||
|
|
||||||
// 加载插件时触发
|
// 加载插件时触发
|
||||||
function onLoad(plugin: any) {
|
function onLoad() {
|
||||||
|
log("main onLoaded");
|
||||||
|
// const config_dir = browserWindow.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
|
const config_dir = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
function getConfigUtil() {
|
function getConfigUtil() {
|
||||||
const configFilePath = path.join(plugin.path.data, `config_${selfInfo.user_id}.json`)
|
const configFilePath = path.join(config_dir, `config_${selfInfo.user_id}.json`)
|
||||||
return new ConfigUtil(configFilePath)
|
return new ConfigUtil(configFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(plugin.path.data)) {
|
if (!fs.existsSync(config_dir)) {
|
||||||
fs.mkdirSync(plugin.path.data, {recursive: true});
|
fs.mkdirSync(config_dir, {recursive: true});
|
||||||
}
|
}
|
||||||
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
|
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
|
||||||
return getConfigUtil().getConfig()
|
return getConfigUtil().getConfig()
|
||||||
@@ -53,6 +58,10 @@ function onLoad(plugin: any) {
|
|||||||
let buffer = await blob.arrayBuffer();
|
let buffer = await blob.arrayBuffer();
|
||||||
fs.writeFileSync(arg.localFilePath, Buffer.from(buffer));
|
fs.writeFileSync(arg.localFilePath, Buffer.from(buffer));
|
||||||
}
|
}
|
||||||
|
if (isGIF(arg.localFilePath)) {
|
||||||
|
fs.renameSync(arg.localFilePath, arg.localFilePath + ".gif");
|
||||||
|
arg.localFilePath += ".gif";
|
||||||
|
}
|
||||||
return arg.localFilePath;
|
return arg.localFilePath;
|
||||||
})
|
})
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
|
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
|
||||||
@@ -121,17 +130,33 @@ 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[]) => {
|
||||||
|
for (const path of arg) {
|
||||||
|
fs.unlinkSync(path);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle(CHANNEL_GET_RUNNING_STATUS, (event: any, arg: any) => {
|
||||||
|
return running;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 创建窗口时触发
|
// 创建窗口时触发
|
||||||
function onBrowserWindowCreated(window: any, plugin: any) {
|
function onBrowserWindowCreated(window: any) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
onLoad();
|
||||||
|
} catch (e: any) {
|
||||||
|
console.log(e.toString())
|
||||||
|
}
|
||||||
|
|
||||||
// 这两个函数都是可选的
|
// 这两个函数都是可选的
|
||||||
export {
|
export {
|
||||||
onLoad, onBrowserWindowCreated
|
onBrowserWindowCreated
|
||||||
}
|
}
|
@@ -6,3 +6,11 @@ export function log(msg: any) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isGIF(path: string) {
|
||||||
|
const buffer = Buffer.alloc(4);
|
||||||
|
const fd = fs.openSync(path, 'r');
|
||||||
|
fs.readSync(fd, buffer, 0, 4, 0);
|
||||||
|
fs.closeSync(fd);
|
||||||
|
return buffer.toString() === 'GIF8'
|
||||||
|
}
|
@@ -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_START_HTTP_SERVER,
|
||||||
|
CHANNEL_UPDATE_FRIENDS,
|
||||||
|
CHANNEL_UPDATE_GROUPS,
|
||||||
|
CHANNEL_DELETE_FILE,
|
||||||
|
CHANNEL_GET_RUNNING_STATUS
|
||||||
} from "./common/IPCChannel";
|
} from "./common/IPCChannel";
|
||||||
|
|
||||||
|
|
||||||
@@ -26,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)
|
||||||
})
|
})
|
||||||
@@ -50,8 +59,14 @@ contextBridge.exposeInMainWorld("llonebot", {
|
|||||||
setSelfInfo(selfInfo: SelfInfo){
|
setSelfInfo(selfInfo: SelfInfo){
|
||||||
ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, 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);
|
return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg);
|
||||||
},
|
},
|
||||||
|
deleteFile: async (localFilePath: string[]) => {
|
||||||
|
ipcRenderer.send(CHANNEL_DELETE_FILE, localFilePath);
|
||||||
|
},
|
||||||
|
getRunningStatus: () => {
|
||||||
|
return ipcRenderer.invoke(CHANNEL_GET_RUNNING_STATUS);
|
||||||
|
}
|
||||||
// startExpress,
|
// startExpress,
|
||||||
});
|
});
|
322
src/renderer.ts
322
src/renderer.ts
@@ -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[] = []
|
||||||
@@ -20,8 +21,25 @@ async function getUserInfo(uid: string): Promise<User> {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFriend(qq: string) {
|
async function getFriends() {
|
||||||
return friends.find(friend => friend.uid == qq)
|
let _friends = await window.LLAPI.getFriendsList(false)
|
||||||
|
for (let friend of _friends) {
|
||||||
|
let existFriend = friends.find(f => f.uin == friend.uin)
|
||||||
|
if (!existFriend) {
|
||||||
|
friends.push(friend)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.llonebot.updateFriends(friends)
|
||||||
|
return friends
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getFriend(qq: string) {
|
||||||
|
let friend = friends.find(friend => friend.uin == qq)
|
||||||
|
if (!friend) {
|
||||||
|
await getFriends();
|
||||||
|
friend = friends.find(friend => friend.uin == qq);
|
||||||
|
}
|
||||||
|
return friend;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGroup(qq: string) {
|
async function getGroup(qq: string) {
|
||||||
@@ -39,11 +57,11 @@ async function getGroups() {
|
|||||||
group.members = [];
|
group.members = [];
|
||||||
let existGroup = groups.find(g => g.uid == group.uid)
|
let existGroup = groups.find(g => g.uid == group.uid)
|
||||||
if (!existGroup) {
|
if (!existGroup) {
|
||||||
console.log("更新群列表", groups)
|
// console.log("更新群列表", groups)
|
||||||
groups.push(group)
|
groups.push(group)
|
||||||
|
}
|
||||||
|
}
|
||||||
window.llonebot.updateGroups(groups)
|
window.llonebot.updateGroups(groups)
|
||||||
}
|
|
||||||
}
|
|
||||||
return groups
|
return groups
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +102,7 @@ async function getGroupMember(group_qq: string, member_uid: string) {
|
|||||||
|
|
||||||
|
|
||||||
async function handleNewMessage(messages: MessageElement[]) {
|
async function handleNewMessage(messages: MessageElement[]) {
|
||||||
|
// console.log("llonebot 收到消息:", messages);
|
||||||
for (let message of messages) {
|
for (let message of messages) {
|
||||||
let onebot_message_data: any = {
|
let onebot_message_data: any = {
|
||||||
self: {
|
self: {
|
||||||
@@ -98,7 +117,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
|
||||||
@@ -112,10 +133,10 @@ async function handleNewMessage(messages: MessageElement[]) {
|
|||||||
card: groupMember!.cardName,
|
card: groupMember!.cardName,
|
||||||
role: OnebotGroupMemberRole[groupMember!.role]
|
role: OnebotGroupMemberRole[groupMember!.role]
|
||||||
}
|
}
|
||||||
console.log("收到群消息", onebot_message_data)
|
// console.log("收到群消息", onebot_message_data)
|
||||||
} else if (message.peer.chatType == "private") {
|
} else if (message.peer.chatType == "private" || message.peer.chatType == "friend") {
|
||||||
onebot_message_data["user_id"] = message.peer.uid
|
onebot_message_data["user_id"] = message.raw.senderUin;
|
||||||
let friend = getFriend(message.sender.uid)
|
let friend = await getFriend(message.raw.senderUin)
|
||||||
onebot_message_data.sender = {
|
onebot_message_data.sender = {
|
||||||
user_id: friend!.uin,
|
user_id: friend!.uin,
|
||||||
nickname: friend!.nickName
|
nickname: friend!.nickName
|
||||||
@@ -161,6 +182,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) {
|
||||||
@@ -171,12 +193,12 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (postData.action == "send_private_msg") {
|
if (postData.action == "send_private_msg") {
|
||||||
let friend = getFriend(postData.params.user_id)
|
let friend = await getFriend(postData.params.user_id)
|
||||||
if (friend) {
|
if (friend) {
|
||||||
peer = {
|
peer = {
|
||||||
chatType: "private",
|
chatType: "private",
|
||||||
name: friend.nickName,
|
name: friend.nickName,
|
||||||
uid: friend.uin
|
uid: friend.uid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (postData.action == "send_group_msg") {
|
} else if (postData.action == "send_group_msg") {
|
||||||
@@ -193,6 +215,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (peer) {
|
if (peer) {
|
||||||
|
let sendFiles: string[] = [];
|
||||||
for (let message of postData.params.message) {
|
for (let message of postData.params.message) {
|
||||||
if (message.type == "at") {
|
if (message.type == "at") {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -206,22 +229,24 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
message.content = `@${atMember.cardName || atMember.nick}`
|
message.content = `@${atMember.cardName || atMember.nick}`
|
||||||
} else if (message.type == "text") {
|
} else if (message.type == "text") {
|
||||||
message.content = message.data?.text || message.content
|
message.content = message.data?.text || message.content
|
||||||
} else if (message.type == "image" || message.type == "voice") {
|
} else if (message.type == "image" || message.type == "voice" || message.type == "record") {
|
||||||
// todo: 收到的应该是uri格式的,需要转成本地的, uri格式有三种,http, file, base64
|
// 收到的是uri格式的,需要转成本地的, uri格式有三种,http, file, base64
|
||||||
let url = message.data?.file || message.file
|
let url = message.data?.file || message.file
|
||||||
let uri = new URL(url);
|
let uri = new URL(url);
|
||||||
let ext: string;
|
let ext: string;
|
||||||
if (message.type == "image") {
|
if (message.type == "image") {
|
||||||
ext = ".png"
|
ext = ".png"
|
||||||
}
|
}
|
||||||
if (message.type == "voice") {
|
if (message.type == "voice" || message.type == "record") {
|
||||||
|
message.type = "voice"
|
||||||
ext = ".amr"
|
ext = ".amr"
|
||||||
}
|
}
|
||||||
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})
|
localFilePath = await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
|
||||||
|
sendFiles.push(localFilePath);
|
||||||
}
|
}
|
||||||
message.file = localFilePath
|
message.file = localFilePath
|
||||||
} else if (message.type == "reply") {
|
} else if (message.type == "reply") {
|
||||||
@@ -231,9 +256,13 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
message.msgSeq = replyMessage?.raw.msgSeq || ""
|
message.msgSeq = replyMessage?.raw.msgSeq || ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 发送完之后要删除下载的文件
|
|
||||||
console.log("发送消息", postData)
|
console.log("发送消息", postData)
|
||||||
window.LLAPI.sendMessage(peer, postData.params.message).then(res => console.log("消息发送成功:", res),
|
window.LLAPI.sendMessage(peer, postData.params.message).then(res => {
|
||||||
|
console.log("消息发送成功:", peer, postData.params.message)
|
||||||
|
if (sendFiles.length) {
|
||||||
|
window.llonebot.deleteFile(sendFiles);
|
||||||
|
}
|
||||||
|
},
|
||||||
err => console.log("消息发送失败", postData, err))
|
err => console.log("消息发送失败", postData, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,15 +275,6 @@ function recallMessage(msgId: string) {
|
|||||||
|
|
||||||
let chatListEle: HTMLCollectionOf<Element>
|
let chatListEle: HTMLCollectionOf<Element>
|
||||||
|
|
||||||
function onLoad() {
|
|
||||||
|
|
||||||
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
|
|
||||||
listenSendMessage(postData).then()
|
|
||||||
});
|
|
||||||
window.llonebot.listenRecallMessage((arg: { message_id: string }) => {
|
|
||||||
recallMessage(arg.message_id)
|
|
||||||
})
|
|
||||||
|
|
||||||
async function getGroupsMembers(groupsArg: Group[]) {
|
async function getGroupsMembers(groupsArg: Group[]) {
|
||||||
// 批量获取群成员列表
|
// 批量获取群成员列表
|
||||||
let failedGroups: Group[] = []
|
let failedGroups: Group[] = []
|
||||||
@@ -270,7 +290,7 @@ function onLoad() {
|
|||||||
getGroupsMembers(failedGroups).then()
|
getGroupsMembers(failedGroups).then()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
} else {
|
} else {
|
||||||
console.log("全部群成员获取完毕", groups)
|
window.llonebot.log("全部群成员获取完毕")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,120 +305,153 @@ function onLoad() {
|
|||||||
|
|
||||||
func(messages).then(() => {
|
func(messages).then(() => {
|
||||||
})
|
})
|
||||||
console.log("chatListEle", chatListEle)
|
// console.log("chatListEle", chatListEle)
|
||||||
}
|
}
|
||||||
|
|
||||||
getGroups().then(() => {
|
async function initAccountInfo(){
|
||||||
getGroupsMembers(groups).then(() => {
|
let accountInfo = await window.LLAPI.getAccountInfo();
|
||||||
window.LLAPI.on("new-messages", onNewMessages);
|
window.llonebot.log("getAccountInfo " + JSON.stringify(accountInfo));
|
||||||
window.LLAPI.on("new-send-messages", onNewMessages);
|
if (!accountInfo.uid) {
|
||||||
})
|
return false;
|
||||||
})
|
}
|
||||||
|
let selfInfo = await window.LLAPI.getUserInfo(accountInfo.uid);
|
||||||
window.LLAPI.getAccountInfo().then(accountInfo => {
|
|
||||||
window.LLAPI.getUserInfo(accountInfo.uid).then(userInfo => {
|
|
||||||
window.llonebot.setSelfInfo({
|
window.llonebot.setSelfInfo({
|
||||||
user_id: accountInfo.uin,
|
user_id: accountInfo.uin,
|
||||||
nickname: userInfo.nickName
|
nickname: selfInfo.nickName
|
||||||
});
|
});
|
||||||
window.llonebot.startExpress();
|
window.llonebot.log("selfInfo " + JSON.stringify(selfInfo));
|
||||||
})
|
return true;
|
||||||
})
|
}
|
||||||
|
|
||||||
window.LLAPI.add_qmenu((qContextMenu: Node) => {
|
function onLoad() {
|
||||||
let btn = document.createElement("a")
|
window.llonebot.log("llonebot render onLoad");
|
||||||
btn.className = "q-context-menu-item q-context-menu-item--normal vue-component"
|
window.llonebot.getRunningStatus().then(running=>{
|
||||||
btn.setAttribute("aria-disabled", "false")
|
if (running) {
|
||||||
btn.setAttribute("role", "menuitem")
|
return;
|
||||||
btn.setAttribute("tabindex", "-1")
|
}
|
||||||
btn.onclick = () => {
|
initAccountInfo().then(
|
||||||
|
(initSuccess)=>{
|
||||||
|
if (!initSuccess) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (friends.length == 0) {
|
||||||
|
getFriends().then(()=>{});
|
||||||
|
}
|
||||||
|
if (groups.length == 0) {
|
||||||
|
getGroups().then(()=>{
|
||||||
|
getGroupsMembers(groups).then(()=>{});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.LLAPI.on("new-messages", onNewMessages);
|
||||||
|
window.LLAPI.on("new-send-messages", onNewMessages);
|
||||||
|
window.llonebot.log("llonebot render start");
|
||||||
|
window.llonebot.startExpress();
|
||||||
|
|
||||||
|
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
|
||||||
|
listenSendMessage(postData).then().catch(err => console.log("listenSendMessage err", err))
|
||||||
|
})
|
||||||
|
window.llonebot.listenRecallMessage((arg: { message_id: string }) => {
|
||||||
|
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 => {
|
// 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};
|
||||||
|
//
|
||||||
|
// // 传入目标节点和观察选项
|
||||||
|
// observer.observe(targetNode, config);
|
||||||
|
//
|
||||||
|
// } catch (e) {
|
||||||
|
// window.llonebot.log(e)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // getChatListEle();
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
|
|
||||||
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 onConfigView(view: any) {
|
async function onSettingWindowCreated (view: Element) {
|
||||||
|
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
|
||||||
}
|
}
|
||||||
@@ -407,12 +460,15 @@ async function onConfigView(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>
|
||||||
@@ -420,7 +476,10 @@ async function onConfigView(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();
|
||||||
@@ -429,7 +488,7 @@ async function onConfigView(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);
|
||||||
}
|
}
|
||||||
@@ -457,12 +516,15 @@ async function onConfigView(view: any) {
|
|||||||
})
|
})
|
||||||
alert("保存成功");
|
alert("保存成功");
|
||||||
})
|
})
|
||||||
doc.querySelectorAll("section").forEach((node) => view.appendChild(node));
|
doc.body.childNodes.forEach(node => {
|
||||||
|
view.appendChild(node);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeout(onLoad, 2000)
|
||||||
|
|
||||||
export {
|
export {
|
||||||
onLoad,
|
onSettingWindowCreated
|
||||||
onConfigView
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user