fix: get_group_member_list, send_private_msg, send_group_msg.

feat: auto identify qq to read config
This commit is contained in:
linyuchen 2023-12-02 11:58:50 +08:00
parent a802e95d89
commit 0c131ff555
9 changed files with 49 additions and 21 deletions

View File

@ -1,6 +1,6 @@
# LLOneBot API
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API, V12没有完整测试
## 安装方法
@ -38,4 +38,15 @@
- [ ] 转发消息记录
- [ ] xml
支持的api:
- [x] get_login_info
- [x] send_msg
- [x] send_group_msg
- [x] send_private_msg
- [x] delete_msg
- [x] get_group_list
- [x] get_group_member_list
- [x] get_group_member_info
- [x] get_friend_list
**自己发送成功的消息也会上报可以用于获取需要撤回消息的id**

View File

@ -4,7 +4,7 @@
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi",
"version": "1.1.0",
"version": "1.2.1",
"thumbnail": "./icon.png",
"author": {
"name": "linyuchen",

View File

@ -7,5 +7,5 @@ export const CHANNEL_UPDATE_GROUPS = "llonebot_update_groups"
export const CHANNEL_UPDATE_FRIENDS = "llonebot_update_friends"
export const CHANNEL_LOG = "llonebot_log"
export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
export const CHANNEL_GET_SELF_INFO= "llonebot_get_self_info"
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file"

View File

@ -139,7 +139,7 @@ export type SendMessage = {
}
export type PostDataAction = "send_private_msg" | "send_group_msg" | "get_group_list"
| "get_friend_list" | "delete_msg" | "get_login_info"
| "get_friend_list" | "delete_msg" | "get_login_info" | "get_group_member_list" | "get_group_member_info"
export type PostDataSendMsg = {
action: PostDataAction

View File

@ -5,6 +5,7 @@ import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg} from "../common/
import {friends, groups, selfInfo} from "./data";
function handlePost(jsonData: any) {
jsonData.params = jsonData;
let resData = {
status: 0,
retcode: 0,
@ -14,6 +15,12 @@ function handlePost(jsonData: any) {
if (jsonData.action == "get_login_info") {
resData["data"] = selfInfo
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
if (jsonData.action == "send_private_msg") {
jsonData.message_type = "private"
}
else {
jsonData.message_type = "group"
}
sendIPCSendQQMsg(jsonData);
} else if (jsonData.action == "get_group_list") {
resData["data"] = groups.map(group => {
@ -97,8 +104,8 @@ export function startExpress(port: number) {
res.send(resData)
});
}
const actionList = ["get_login_info", "send_private_msg", "send_group_msg",
"get_group_list", "get_friend_list", "delete_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"]
for (const action of actionList) {
parseToOnebot12(action as PostDataAction)

View File

@ -21,4 +21,8 @@ export class ConfigUtil{
return jsonData;
}
}
setConfig(config: Config){
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
}
}

View File

@ -1,16 +1,18 @@
// 运行在 Electron 主进程 下的插件入口
import * as path from "path";
const fs = require('fs');
import {ipcMain} from 'electron';
import {Config, Group, SelfInfo, User} from "../common/types";
import {
CHANNEL_DOWNLOAD_FILE,
CHANNEL_GET_CONFIG, CHANNEL_GET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
CHANNEL_GET_CONFIG,
CHANNEL_SET_SELF_INFO,
CHANNEL_LOG,
CHANNEL_POST_ONEBOT_DATA,
CHANNEL_SET_CONFIG,
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS,
CHANNEL_START_HTTP_SERVER,
CHANNEL_UPDATE_FRIENDS,
CHANNEL_UPDATE_GROUPS
} from "../common/IPCChannel";
import {ConfigUtil} from "./config";
@ -18,19 +20,22 @@ import {startExpress} from "./HttpServer";
import {log} from "./utils";
import {friends, groups, selfInfo} from "./data";
const fs = require('fs');
// 加载插件时触发
function onLoad(plugin: any) {
const configFilePath = path.join(plugin.path.data, "config.json")
let configUtil = new ConfigUtil(configFilePath)
function getConfigUtil() {
const configFilePath = path.join(plugin.path.data, `config_${selfInfo.user_id}.json`)
return new ConfigUtil(configFilePath)
}
if (!fs.existsSync(plugin.path.data)) {
fs.mkdirSync(plugin.path.data, {recursive: true});
}
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
return configUtil.getConfig()
return getConfigUtil().getConfig()
})
ipcMain.handle(CHANNEL_DOWNLOAD_FILE, async (event: any, arg: {uri: string, localFilePath: string}) => {
let url = new URL(arg.uri);
@ -51,11 +56,11 @@ function onLoad(plugin: any) {
return arg.localFilePath;
})
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
fs.writeFileSync(configFilePath, JSON.stringify(arg, null, 2), "utf-8")
getConfigUtil().setConfig(arg)
})
ipcMain.on(CHANNEL_START_HTTP_SERVER, (event: any, arg: any) => {
startExpress(configUtil.getConfig().port)
startExpress(getConfigUtil().getConfig().port)
})
ipcMain.on(CHANNEL_UPDATE_GROUPS, (event: any, arg: Group[]) => {
@ -89,7 +94,7 @@ function onLoad(plugin: any) {
})
ipcMain.on(CHANNEL_POST_ONEBOT_DATA, (event: any, arg: any) => {
for(const host of configUtil.getConfig().hosts) {
for(const host of getConfigUtil().getConfig().hosts) {
try {
fetch(host, {
method: "POST",
@ -113,7 +118,7 @@ function onLoad(plugin: any) {
log(arg)
})
ipcMain.on(CHANNEL_GET_SELF_INFO, (event: any, arg: SelfInfo) => {
ipcMain.handle(CHANNEL_SET_SELF_INFO, (event: any, arg: SelfInfo) => {
selfInfo.user_id = arg.user_id;
selfInfo.nickname = arg.nickname;
})

View File

@ -3,7 +3,7 @@
import {Config, Group, PostDataSendMsg, SelfInfo, User} from "./common/types";
import {
CHANNEL_DOWNLOAD_FILE,
CHANNEL_GET_CONFIG, CHANNEL_GET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
CHANNEL_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG,
CHANNEL_SET_CONFIG,
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS
@ -48,7 +48,7 @@ contextBridge.exposeInMainWorld("llonebot", {
return ipcRenderer.invoke(CHANNEL_GET_CONFIG);
},
setSelfInfo(selfInfo: SelfInfo){
ipcRenderer.send(CHANNEL_GET_SELF_INFO, selfInfo)
ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, selfInfo)
},
downloadFile: async (arg: {uri: string, localFilePath: string}) => {
return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg);

View File

@ -247,7 +247,7 @@ function recallMessage(msgId: string) {
let chatListEle: HTMLCollectionOf<Element>
function onLoad() {
window.llonebot.startExpress();
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
listenSendMessage(postData).then()
});
@ -300,7 +300,8 @@ function onLoad() {
window.llonebot.setSelfInfo({
user_id: accountInfo.uin,
nickname: userInfo.nickName
})
});
window.llonebot.startExpress();
})
})