@zhin.js/adapter-icqq 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/lib/adapter.d.ts +7 -2
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +78 -33
- package/lib/adapter.js.map +1 -1
- package/lib/bot.d.ts +29 -29
- package/lib/bot.d.ts.map +1 -1
- package/lib/bot.js +226 -405
- package/lib/bot.js.map +1 -1
- package/lib/commands/index.d.ts +7 -0
- package/lib/commands/index.d.ts.map +1 -0
- package/lib/commands/index.js +30 -0
- package/lib/commands/index.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -297
- package/lib/index.js.map +1 -1
- package/lib/ipc-client.d.ts +60 -0
- package/lib/ipc-client.d.ts.map +1 -0
- package/lib/ipc-client.js +272 -0
- package/lib/ipc-client.js.map +1 -0
- package/lib/protocol.d.ts +174 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +162 -0
- package/lib/protocol.js.map +1 -0
- package/lib/routes.d.ts +8 -0
- package/lib/routes.d.ts.map +1 -0
- package/lib/routes.js +67 -0
- package/lib/routes.js.map +1 -0
- package/lib/tools/index.d.ts +10 -0
- package/lib/tools/index.d.ts.map +1 -0
- package/lib/tools/index.js +336 -0
- package/lib/tools/index.js.map +1 -0
- package/lib/types.d.ts +45 -7
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +5 -0
- package/lib/types.js.map +1 -1
- package/package.json +11 -12
- package/plugin.yml +3 -0
- package/skills/icqq/SKILL.md +31 -64
- package/skills/icqq/references/friends.md +54 -0
- package/skills/icqq/references/general.md +145 -0
- package/skills/icqq/references/gfs.md +49 -0
- package/skills/icqq/references/groups.md +71 -0
- package/skills/icqq/references/messaging.md +66 -0
- package/skills/icqq/references/requests.md +27 -0
- package/skills/icqq/references/settings.md +38 -0
- package/src/adapter.ts +73 -35
- package/src/bot.ts +272 -443
- package/src/commands/index.ts +32 -0
- package/src/index.ts +14 -305
- package/src/ipc-client.ts +326 -0
- package/src/protocol.ts +242 -0
- package/src/routes.ts +83 -0
- package/src/tools/index.ts +407 -0
- package/src/types.ts +47 -7
package/src/adapter.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ICQQ 适配器
|
|
2
|
+
* ICQQ 适配器 — 通过 @icqqjs/cli 守护进程 IPC 管理 Bot 实例
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
Adapter,
|
|
7
|
-
Plugin,
|
|
8
|
-
} from "zhin.js";
|
|
4
|
+
import { Adapter, Plugin } from "zhin.js";
|
|
9
5
|
import { IcqqBot } from "./bot.js";
|
|
10
|
-
import type { IcqqBotConfig } from "./types.js";
|
|
6
|
+
import type { IcqqBotConfig, IpcMemberInfo } from "./types.js";
|
|
7
|
+
import { Actions } from "./protocol.js";
|
|
11
8
|
|
|
12
9
|
export class IcqqAdapter extends Adapter<IcqqBot> {
|
|
13
10
|
constructor(plugin: Plugin) {
|
|
@@ -18,12 +15,33 @@ export class IcqqAdapter extends Adapter<IcqqBot> {
|
|
|
18
15
|
return new IcqqBot(this, config);
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
async start(): Promise<void> {
|
|
19
|
+
await super.start();
|
|
20
|
+
this.logger.info("ICQQ 适配器已启动");
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
async
|
|
23
|
+
async stop(): Promise<void> {
|
|
24
|
+
await super.stop();
|
|
25
|
+
this.logger.info("ICQQ 适配器已停止");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ── IGroupManagement 标准群管方法(通过 IPC) ─────────────────────
|
|
29
|
+
|
|
30
|
+
private getBot(botId: string): IcqqBot {
|
|
24
31
|
const bot = this.bots.get(botId);
|
|
25
32
|
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
26
|
-
return bot
|
|
33
|
+
return bot;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async kickMember(botId: string, sceneId: string, userId: string) {
|
|
37
|
+
const bot = this.getBot(botId);
|
|
38
|
+
const resp = await bot.ipc.request(Actions.GROUP_KICK, {
|
|
39
|
+
group_id: Number(sceneId),
|
|
40
|
+
user_id: Number(userId),
|
|
41
|
+
reject_add_request: false,
|
|
42
|
+
});
|
|
43
|
+
if (!resp.ok) throw new Error(resp.error ?? "踢人失败");
|
|
44
|
+
return true;
|
|
27
45
|
}
|
|
28
46
|
|
|
29
47
|
async muteMember(
|
|
@@ -32,15 +50,24 @@ export class IcqqAdapter extends Adapter<IcqqBot> {
|
|
|
32
50
|
userId: string,
|
|
33
51
|
duration = 600,
|
|
34
52
|
) {
|
|
35
|
-
const bot = this.
|
|
36
|
-
|
|
37
|
-
|
|
53
|
+
const bot = this.getBot(botId);
|
|
54
|
+
const resp = await bot.ipc.request(Actions.GROUP_MUTE, {
|
|
55
|
+
group_id: Number(sceneId),
|
|
56
|
+
user_id: Number(userId),
|
|
57
|
+
duration,
|
|
58
|
+
});
|
|
59
|
+
if (!resp.ok) throw new Error(resp.error ?? "禁言失败");
|
|
60
|
+
return true;
|
|
38
61
|
}
|
|
39
62
|
|
|
40
63
|
async muteAll(botId: string, sceneId: string, enable = true) {
|
|
41
|
-
const bot = this.
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
const bot = this.getBot(botId);
|
|
65
|
+
const resp = await bot.ipc.request(Actions.GROUP_MUTE_ALL, {
|
|
66
|
+
group_id: Number(sceneId),
|
|
67
|
+
enable,
|
|
68
|
+
});
|
|
69
|
+
if (!resp.ok) throw new Error(resp.error ?? "全员禁言失败");
|
|
70
|
+
return true;
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
async setAdmin(
|
|
@@ -49,9 +76,14 @@ export class IcqqAdapter extends Adapter<IcqqBot> {
|
|
|
49
76
|
userId: string,
|
|
50
77
|
enable = true,
|
|
51
78
|
) {
|
|
52
|
-
const bot = this.
|
|
53
|
-
|
|
54
|
-
|
|
79
|
+
const bot = this.getBot(botId);
|
|
80
|
+
const resp = await bot.ipc.request(Actions.SET_GROUP_ADMIN, {
|
|
81
|
+
group_id: Number(sceneId),
|
|
82
|
+
user_id: Number(userId),
|
|
83
|
+
enable,
|
|
84
|
+
});
|
|
85
|
+
if (!resp.ok) throw new Error(resp.error ?? "设置管理员失败");
|
|
86
|
+
return true;
|
|
55
87
|
}
|
|
56
88
|
|
|
57
89
|
async setMemberNickname(
|
|
@@ -60,22 +92,34 @@ export class IcqqAdapter extends Adapter<IcqqBot> {
|
|
|
60
92
|
userId: string,
|
|
61
93
|
nickname: string,
|
|
62
94
|
) {
|
|
63
|
-
const bot = this.
|
|
64
|
-
|
|
65
|
-
|
|
95
|
+
const bot = this.getBot(botId);
|
|
96
|
+
const resp = await bot.ipc.request(Actions.SET_GROUP_CARD, {
|
|
97
|
+
group_id: Number(sceneId),
|
|
98
|
+
user_id: Number(userId),
|
|
99
|
+
card: nickname,
|
|
100
|
+
});
|
|
101
|
+
if (!resp.ok) throw new Error(resp.error ?? "设置群名片失败");
|
|
102
|
+
return true;
|
|
66
103
|
}
|
|
67
104
|
|
|
68
105
|
async setGroupName(botId: string, sceneId: string, name: string) {
|
|
69
|
-
const bot = this.
|
|
70
|
-
|
|
71
|
-
|
|
106
|
+
const bot = this.getBot(botId);
|
|
107
|
+
const resp = await bot.ipc.request(Actions.SET_GROUP_NAME, {
|
|
108
|
+
group_id: Number(sceneId),
|
|
109
|
+
name,
|
|
110
|
+
});
|
|
111
|
+
if (!resp.ok) throw new Error(resp.error ?? "设置群名失败");
|
|
112
|
+
return true;
|
|
72
113
|
}
|
|
73
114
|
|
|
74
115
|
async listMembers(botId: string, sceneId: string) {
|
|
75
|
-
const bot = this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
116
|
+
const bot = this.getBot(botId);
|
|
117
|
+
const resp = await bot.ipc.request(Actions.LIST_GROUP_MEMBERS, {
|
|
118
|
+
group_id: Number(sceneId),
|
|
119
|
+
});
|
|
120
|
+
if (!resp.ok) throw new Error(resp.error ?? "获取成员列表失败");
|
|
121
|
+
const raw = resp.data as IpcMemberInfo[];
|
|
122
|
+
const members = raw.map((m) => ({
|
|
79
123
|
user_id: m.user_id,
|
|
80
124
|
nickname: m.nickname,
|
|
81
125
|
card: m.card,
|
|
@@ -85,10 +129,4 @@ export class IcqqAdapter extends Adapter<IcqqBot> {
|
|
|
85
129
|
return { members, count: members.length };
|
|
86
130
|
}
|
|
87
131
|
|
|
88
|
-
// ── 生命周期 ───────────────────────────────────────────────────────
|
|
89
|
-
|
|
90
|
-
async start(): Promise<void> {
|
|
91
|
-
await super.start();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
132
|
}
|