Skip to content

Commit 0c131ff

Browse files
author
linyuchen
committed
fix: get_group_member_list, send_private_msg, send_group_msg.
feat: auto identify qq to read config
1 parent a802e95 commit 0c131ff

9 files changed

Lines changed: 49 additions & 21 deletions

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LLOneBot API
22

3-
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API
3+
将NTQQLiteLoaderAPI封装成OneBot11/12标准的API, V12没有完整测试
44

55
## 安装方法
66

@@ -38,4 +38,15 @@
3838
- [ ] 转发消息记录
3939
- [ ] xml
4040

41+
支持的api:
42+
- [x] get_login_info
43+
- [x] send_msg
44+
- [x] send_group_msg
45+
- [x] send_private_msg
46+
- [x] delete_msg
47+
- [x] get_group_list
48+
- [x] get_group_member_list
49+
- [x] get_group_member_info
50+
- [x] get_friend_list
51+
4152
**自己发送成功的消息也会上报,可以用于获取需要撤回消息的id**

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "LLOneBot",
55
"slug": "LLOneBot",
66
"description": "LiteLoaderQQNT的OneBotApi",
7-
"version": "1.1.0",
7+
"version": "1.2.1",
88
"thumbnail": "./icon.png",
99
"author": {
1010
"name": "linyuchen",

src/common/IPCChannel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export const CHANNEL_UPDATE_GROUPS = "llonebot_update_groups"
77
export const CHANNEL_UPDATE_FRIENDS = "llonebot_update_friends"
88
export const CHANNEL_LOG = "llonebot_log"
99
export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
10-
export const CHANNEL_GET_SELF_INFO= "llonebot_get_self_info"
10+
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
1111
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file"

src/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export type SendMessage = {
139139
}
140140

141141
export type PostDataAction = "send_private_msg" | "send_group_msg" | "get_group_list"
142-
| "get_friend_list" | "delete_msg" | "get_login_info"
142+
| "get_friend_list" | "delete_msg" | "get_login_info" | "get_group_member_list" | "get_group_member_info"
143143

144144
export type PostDataSendMsg = {
145145
action: PostDataAction

src/main/HttpServer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg} from "../common/
55
import {friends, groups, selfInfo} from "./data";
66

77
function handlePost(jsonData: any) {
8+
jsonData.params = jsonData;
89
let resData = {
910
status: 0,
1011
retcode: 0,
@@ -14,6 +15,12 @@ function handlePost(jsonData: any) {
1415
if (jsonData.action == "get_login_info") {
1516
resData["data"] = selfInfo
1617
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
18+
if (jsonData.action == "send_private_msg") {
19+
jsonData.message_type = "private"
20+
}
21+
else {
22+
jsonData.message_type = "group"
23+
}
1724
sendIPCSendQQMsg(jsonData);
1825
} else if (jsonData.action == "get_group_list") {
1926
resData["data"] = groups.map(group => {
@@ -97,8 +104,8 @@ export function startExpress(port: number) {
97104
res.send(resData)
98105
});
99106
}
100-
const actionList = ["get_login_info", "send_private_msg", "send_group_msg",
101-
"get_group_list", "get_friend_list", "delete_msg"]
107+
const actionList: PostDataAction[] = ["get_login_info", "send_private_msg", "send_group_msg",
108+
"get_group_list", "get_friend_list", "delete_msg", "get_group_member_list", "get_group_member_info"]
102109

103110
for (const action of actionList) {
104111
parseToOnebot12(action as PostDataAction)

src/main/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ export class ConfigUtil{
2121
return jsonData;
2222
}
2323
}
24+
25+
setConfig(config: Config){
26+
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2), "utf-8")
27+
}
2428
}

src/main/main.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
// 运行在 Electron 主进程 下的插件入口
22

33
import * as path from "path";
4-
5-
const fs = require('fs');
64
import {ipcMain} from 'electron';
75

86
import {Config, Group, SelfInfo, User} from "../common/types";
97
import {
108
CHANNEL_DOWNLOAD_FILE,
11-
CHANNEL_GET_CONFIG, CHANNEL_GET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
9+
CHANNEL_GET_CONFIG,
10+
CHANNEL_SET_SELF_INFO,
11+
CHANNEL_LOG,
12+
CHANNEL_POST_ONEBOT_DATA,
1213
CHANNEL_SET_CONFIG,
13-
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS,
14+
CHANNEL_START_HTTP_SERVER,
15+
CHANNEL_UPDATE_FRIENDS,
1416
CHANNEL_UPDATE_GROUPS
1517
} from "../common/IPCChannel";
1618
import {ConfigUtil} from "./config";
1719
import {startExpress} from "./HttpServer";
1820
import {log} from "./utils";
1921
import {friends, groups, selfInfo} from "./data";
2022

23+
const fs = require('fs');
2124

2225

2326
// 加载插件时触发
2427
function onLoad(plugin: any) {
2528

26-
const configFilePath = path.join(plugin.path.data, "config.json")
27-
let configUtil = new ConfigUtil(configFilePath)
29+
function getConfigUtil() {
30+
const configFilePath = path.join(plugin.path.data, `config_${selfInfo.user_id}.json`)
31+
return new ConfigUtil(configFilePath)
32+
}
2833

2934
if (!fs.existsSync(plugin.path.data)) {
3035
fs.mkdirSync(plugin.path.data, {recursive: true});
3136
}
3237
ipcMain.handle(CHANNEL_GET_CONFIG, (event: any, arg: any) => {
33-
return configUtil.getConfig()
38+
return getConfigUtil().getConfig()
3439
})
3540
ipcMain.handle(CHANNEL_DOWNLOAD_FILE, async (event: any, arg: {uri: string, localFilePath: string}) => {
3641
let url = new URL(arg.uri);
@@ -51,11 +56,11 @@ function onLoad(plugin: any) {
5156
return arg.localFilePath;
5257
})
5358
ipcMain.on(CHANNEL_SET_CONFIG, (event: any, arg: Config) => {
54-
fs.writeFileSync(configFilePath, JSON.stringify(arg, null, 2), "utf-8")
59+
getConfigUtil().setConfig(arg)
5560
})
5661

5762
ipcMain.on(CHANNEL_START_HTTP_SERVER, (event: any, arg: any) => {
58-
startExpress(configUtil.getConfig().port)
63+
startExpress(getConfigUtil().getConfig().port)
5964
})
6065

6166
ipcMain.on(CHANNEL_UPDATE_GROUPS, (event: any, arg: Group[]) => {
@@ -89,7 +94,7 @@ function onLoad(plugin: any) {
8994
})
9095

9196
ipcMain.on(CHANNEL_POST_ONEBOT_DATA, (event: any, arg: any) => {
92-
for(const host of configUtil.getConfig().hosts) {
97+
for(const host of getConfigUtil().getConfig().hosts) {
9398
try {
9499
fetch(host, {
95100
method: "POST",
@@ -113,7 +118,7 @@ function onLoad(plugin: any) {
113118
log(arg)
114119
})
115120

116-
ipcMain.on(CHANNEL_GET_SELF_INFO, (event: any, arg: SelfInfo) => {
121+
ipcMain.handle(CHANNEL_SET_SELF_INFO, (event: any, arg: SelfInfo) => {
117122
selfInfo.user_id = arg.user_id;
118123
selfInfo.nickname = arg.nickname;
119124
})

src/preload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {Config, Group, PostDataSendMsg, SelfInfo, User} from "./common/types";
44
import {
55
CHANNEL_DOWNLOAD_FILE,
6-
CHANNEL_GET_CONFIG, CHANNEL_GET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
6+
CHANNEL_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
77
CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG,
88
CHANNEL_SET_CONFIG,
99
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS
@@ -48,7 +48,7 @@ contextBridge.exposeInMainWorld("llonebot", {
4848
return ipcRenderer.invoke(CHANNEL_GET_CONFIG);
4949
},
5050
setSelfInfo(selfInfo: SelfInfo){
51-
ipcRenderer.send(CHANNEL_GET_SELF_INFO, selfInfo)
51+
ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, selfInfo)
5252
},
5353
downloadFile: async (arg: {uri: string, localFilePath: string}) => {
5454
return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg);

src/renderer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function recallMessage(msgId: string) {
247247
let chatListEle: HTMLCollectionOf<Element>
248248

249249
function onLoad() {
250-
window.llonebot.startExpress();
250+
251251
window.llonebot.listenSendMessage((postData: PostDataSendMsg) => {
252252
listenSendMessage(postData).then()
253253
});
@@ -300,7 +300,8 @@ function onLoad() {
300300
window.llonebot.setSelfInfo({
301301
user_id: accountInfo.uin,
302302
nickname: userInfo.nickName
303-
})
303+
});
304+
window.llonebot.startExpress();
304305
})
305306
})
306307

0 commit comments

Comments
 (0)