@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/lib/adapter.d.ts +7 -2
  3. package/lib/adapter.d.ts.map +1 -1
  4. package/lib/adapter.js +78 -33
  5. package/lib/adapter.js.map +1 -1
  6. package/lib/bot.d.ts +29 -29
  7. package/lib/bot.d.ts.map +1 -1
  8. package/lib/bot.js +226 -405
  9. package/lib/bot.js.map +1 -1
  10. package/lib/commands/index.d.ts +7 -0
  11. package/lib/commands/index.d.ts.map +1 -0
  12. package/lib/commands/index.js +30 -0
  13. package/lib/commands/index.js.map +1 -0
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +13 -297
  17. package/lib/index.js.map +1 -1
  18. package/lib/ipc-client.d.ts +60 -0
  19. package/lib/ipc-client.d.ts.map +1 -0
  20. package/lib/ipc-client.js +272 -0
  21. package/lib/ipc-client.js.map +1 -0
  22. package/lib/protocol.d.ts +174 -0
  23. package/lib/protocol.d.ts.map +1 -0
  24. package/lib/protocol.js +162 -0
  25. package/lib/protocol.js.map +1 -0
  26. package/lib/routes.d.ts +8 -0
  27. package/lib/routes.d.ts.map +1 -0
  28. package/lib/routes.js +67 -0
  29. package/lib/routes.js.map +1 -0
  30. package/lib/tools/index.d.ts +10 -0
  31. package/lib/tools/index.d.ts.map +1 -0
  32. package/lib/tools/index.js +336 -0
  33. package/lib/tools/index.js.map +1 -0
  34. package/lib/types.d.ts +45 -7
  35. package/lib/types.d.ts.map +1 -1
  36. package/lib/types.js +5 -0
  37. package/lib/types.js.map +1 -1
  38. package/package.json +11 -12
  39. package/plugin.yml +3 -0
  40. package/skills/icqq/SKILL.md +31 -64
  41. package/skills/icqq/references/friends.md +54 -0
  42. package/skills/icqq/references/general.md +145 -0
  43. package/skills/icqq/references/gfs.md +49 -0
  44. package/skills/icqq/references/groups.md +71 -0
  45. package/skills/icqq/references/messaging.md +66 -0
  46. package/skills/icqq/references/requests.md +27 -0
  47. package/skills/icqq/references/settings.md +38 -0
  48. package/src/adapter.ts +73 -35
  49. package/src/bot.ts +272 -443
  50. package/src/commands/index.ts +32 -0
  51. package/src/index.ts +14 -305
  52. package/src/ipc-client.ts +326 -0
  53. package/src/protocol.ts +242 -0
  54. package/src/routes.ts +83 -0
  55. package/src/tools/index.ts +407 -0
  56. 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 type { MemberInfo } from "@icqqjs/icqq";
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
- // ── IGroupManagement 标准群管方法 ──────────────────────────────────
18
+ async start(): Promise<void> {
19
+ await super.start();
20
+ this.logger.info("ICQQ 适配器已启动");
21
+ }
22
22
 
23
- async kickMember(botId: string, sceneId: string, userId: string) {
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.kickMember(Number(sceneId), Number(userId), false);
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.bots.get(botId);
36
- if (!bot) throw new Error(`Bot ${botId} 不存在`);
37
- return bot.muteMember(Number(sceneId), Number(userId), duration);
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.bots.get(botId);
42
- if (!bot) throw new Error(`Bot ${botId} 不存在`);
43
- return bot.muteAll(Number(sceneId), enable);
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.bots.get(botId);
53
- if (!bot) throw new Error(`Bot ${botId} 不存在`);
54
- return bot.setAdmin(Number(sceneId), Number(userId), enable);
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.bots.get(botId);
64
- if (!bot) throw new Error(`Bot ${botId} 不存在`);
65
- return bot.setCard(Number(sceneId), Number(userId), nickname);
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.bots.get(botId);
70
- if (!bot) throw new Error(`Bot ${botId} 不存在`);
71
- return bot.setGroupName(Number(sceneId), name);
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.bots.get(botId);
76
- if (!bot) throw new Error(`Bot ${botId} 不存在`);
77
- const memberMap = await bot.getMemberList(Number(sceneId));
78
- const members = Array.from(memberMap.values()).map((m: MemberInfo) => ({
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
  }