@zhin.js/adapter-onebot11 1.0.55 → 1.0.56
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 +7 -0
- package/README.md +35 -40
- package/lib/adapter.d.ts +30 -0
- package/lib/adapter.d.ts.map +1 -0
- package/lib/adapter.js +125 -0
- package/lib/adapter.js.map +1 -0
- package/lib/bot-ws-client.d.ts +39 -0
- package/lib/bot-ws-client.d.ts.map +1 -0
- package/lib/bot-ws-client.js +370 -0
- package/lib/bot-ws-client.js.map +1 -0
- package/lib/bot-ws-server.d.ts +41 -0
- package/lib/bot-ws-server.d.ts.map +1 -0
- package/lib/bot-ws-server.js +308 -0
- package/lib/bot-ws-server.js.map +1 -0
- package/lib/index.d.ts +11 -172
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +12 -827
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +54 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +5 -0
- package/lib/types.js.map +1 -0
- package/package.json +4 -4
- package/src/adapter.ts +147 -0
- package/src/bot-ws-client.ts +399 -0
- package/src/bot-ws-server.ts +350 -0
- package/src/index.ts +21 -968
- package/src/types.ts +58 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -5,7 +5,9 @@ Zhin.js OneBot v11 协议适配器,通过 WebSocket 连接各种支持 OneBot
|
|
|
5
5
|
## 功能特性
|
|
6
6
|
|
|
7
7
|
- 🔌 完整 OneBot v11 协议兼容
|
|
8
|
-
-
|
|
8
|
+
- 📦 **单一适配器**:`context: onebot11`,通过 `connection` 选择连接方式
|
|
9
|
+
- 🌐 **正向 WebSocket**(`connection: ws`):应用连 OneBot 实现的 WS
|
|
10
|
+
- 🔄 **反向 WebSocket**(`connection: wss`):应用开 WS 服务端,实现连上来
|
|
9
11
|
- 🔐 Access Token 认证支持
|
|
10
12
|
- 🔄 自动重连机制
|
|
11
13
|
- 💓 心跳检测
|
|
@@ -19,53 +21,46 @@ Zhin.js OneBot v11 协议适配器,通过 WebSocket 连接各种支持 OneBot
|
|
|
19
21
|
pnpm add @zhin.js/adapter-onebot11 ws
|
|
20
22
|
```
|
|
21
23
|
|
|
24
|
+
反向 WS 需同时启用 `@zhin.js/http`。
|
|
25
|
+
|
|
22
26
|
## 配置
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
所有 Bot 使用 **同一 context:`onebot11`**,通过 **`connection`** 区分连接方式。
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
plugins: [
|
|
43
|
-
'adapter-onebot11'
|
|
44
|
-
]
|
|
45
|
-
})
|
|
30
|
+
### 正向 WebSocket(connection: ws)
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
plugins:
|
|
34
|
+
- "@zhin.js/adapter-onebot11"
|
|
35
|
+
|
|
36
|
+
bots:
|
|
37
|
+
- context: onebot11
|
|
38
|
+
connection: ws
|
|
39
|
+
name: my-bot
|
|
40
|
+
url: "ws://localhost:8080"
|
|
41
|
+
access_token: "${ONEBOT_TOKEN}"
|
|
42
|
+
reconnect_interval: 5000
|
|
43
|
+
heartbeat_interval: 30000
|
|
46
44
|
```
|
|
47
45
|
|
|
48
|
-
### WebSocket
|
|
46
|
+
### 反向 WebSocket(connection: wss)
|
|
49
47
|
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
plugins: [
|
|
63
|
-
'http', // 需要 HTTP 服务
|
|
64
|
-
'adapter-onebot11'
|
|
65
|
-
]
|
|
66
|
-
})
|
|
48
|
+
```yaml
|
|
49
|
+
plugins:
|
|
50
|
+
- "@zhin.js/http"
|
|
51
|
+
- "@zhin.js/adapter-onebot11"
|
|
52
|
+
|
|
53
|
+
bots:
|
|
54
|
+
- context: onebot11
|
|
55
|
+
connection: wss
|
|
56
|
+
name: my-bot
|
|
57
|
+
path: "/onebot/ws"
|
|
58
|
+
access_token: "${ONEBOT_TOKEN}"
|
|
59
|
+
heartbeat_interval: 30000
|
|
67
60
|
```
|
|
68
61
|
|
|
62
|
+
兼容旧配置:若使用 `type: 'ws'` / `type: 'ws_reverse'` 而未写 `connection`,适配器会自动映射为 `ws` / `wss`。
|
|
63
|
+
|
|
69
64
|
## 支持的 OneBot 实现
|
|
70
65
|
|
|
71
66
|
### 推荐实现
|
package/lib/adapter.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Adapter, Plugin } from 'zhin.js';
|
|
2
|
+
import { OneBot11WsClient } from './bot-ws-client.js';
|
|
3
|
+
import { OneBot11WsServer } from './bot-ws-server.js';
|
|
4
|
+
import type { OneBot11BotConfig } from './types.js';
|
|
5
|
+
export type OneBot11Bot = OneBot11WsClient | OneBot11WsServer;
|
|
6
|
+
export declare class OneBot11Adapter extends Adapter<OneBot11Bot> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(plugin: Plugin);
|
|
9
|
+
createBot(config: OneBot11BotConfig): OneBot11Bot;
|
|
10
|
+
kickMember(botId: string, sceneId: string, userId: string): Promise<boolean>;
|
|
11
|
+
muteMember(botId: string, sceneId: string, userId: string, duration?: number): Promise<boolean>;
|
|
12
|
+
muteAll(botId: string, sceneId: string, enable?: boolean): Promise<boolean>;
|
|
13
|
+
setAdmin(botId: string, sceneId: string, userId: string, enable?: boolean): Promise<boolean>;
|
|
14
|
+
setMemberNickname(botId: string, sceneId: string, userId: string, nickname: string): Promise<boolean>;
|
|
15
|
+
setGroupName(botId: string, sceneId: string, name: string): Promise<boolean>;
|
|
16
|
+
listMembers(botId: string, sceneId: string): Promise<{
|
|
17
|
+
members: {
|
|
18
|
+
user_id: any;
|
|
19
|
+
nickname: any;
|
|
20
|
+
card: any;
|
|
21
|
+
role: any;
|
|
22
|
+
title: any;
|
|
23
|
+
}[];
|
|
24
|
+
count: number;
|
|
25
|
+
}>;
|
|
26
|
+
getGroupInfo(botId: string, sceneId: string): Promise<any>;
|
|
27
|
+
start(): Promise<void>;
|
|
28
|
+
private registerOneBot11PlatformTools;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,EACP,MAAM,EAKP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAGV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AAE9D,qBAAa,eAAgB,SAAQ,OAAO,CAAC,WAAW,CAAC;;gBAG3C,MAAM,EAAE,MAAM;IAI1B,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW;IAe3C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMzD,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,SAAM;IAMzE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAO;IAMrD,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAO;IAMtE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAMlF,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAMzD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;;;;;;;;IAgB1C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5B,OAAO,CAAC,6BAA6B;CA0BtC"}
|
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Adapter, createGroupManagementTools, GROUP_MANAGEMENT_SKILL_KEYWORDS, GROUP_MANAGEMENT_SKILL_TAGS, } from 'zhin.js';
|
|
2
|
+
import { OneBot11WsClient } from './bot-ws-client.js';
|
|
3
|
+
import { OneBot11WsServer } from './bot-ws-server.js';
|
|
4
|
+
export class OneBot11Adapter extends Adapter {
|
|
5
|
+
#router;
|
|
6
|
+
constructor(plugin) {
|
|
7
|
+
super(plugin, 'onebot11', []);
|
|
8
|
+
}
|
|
9
|
+
createBot(config) {
|
|
10
|
+
const connection = config.connection ?? (config.type === 'ws_reverse' ? 'wss' : 'ws');
|
|
11
|
+
switch (connection) {
|
|
12
|
+
case 'ws':
|
|
13
|
+
return new OneBot11WsClient(this, config);
|
|
14
|
+
case 'wss':
|
|
15
|
+
if (!this.#router) {
|
|
16
|
+
throw new Error('OneBot11 connection: wss 需要 router,请安装并在配置中启用 @zhin.js/http');
|
|
17
|
+
}
|
|
18
|
+
return new OneBot11WsServer(this, this.#router, config);
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`Unknown OneBot11 connection: ${connection}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async kickMember(botId, sceneId, userId) {
|
|
24
|
+
const bot = this.bots.get(botId);
|
|
25
|
+
if (!bot)
|
|
26
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
27
|
+
return bot.kickMember(Number(sceneId), Number(userId), false);
|
|
28
|
+
}
|
|
29
|
+
async muteMember(botId, sceneId, userId, duration = 600) {
|
|
30
|
+
const bot = this.bots.get(botId);
|
|
31
|
+
if (!bot)
|
|
32
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
33
|
+
return bot.muteMember(Number(sceneId), Number(userId), duration);
|
|
34
|
+
}
|
|
35
|
+
async muteAll(botId, sceneId, enable = true) {
|
|
36
|
+
const bot = this.bots.get(botId);
|
|
37
|
+
if (!bot)
|
|
38
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
39
|
+
return bot.muteAll(Number(sceneId), enable);
|
|
40
|
+
}
|
|
41
|
+
async setAdmin(botId, sceneId, userId, enable = true) {
|
|
42
|
+
const bot = this.bots.get(botId);
|
|
43
|
+
if (!bot)
|
|
44
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
45
|
+
return bot.setAdmin(Number(sceneId), Number(userId), enable);
|
|
46
|
+
}
|
|
47
|
+
async setMemberNickname(botId, sceneId, userId, nickname) {
|
|
48
|
+
const bot = this.bots.get(botId);
|
|
49
|
+
if (!bot)
|
|
50
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
51
|
+
return bot.setCard(Number(sceneId), Number(userId), nickname);
|
|
52
|
+
}
|
|
53
|
+
async setGroupName(botId, sceneId, name) {
|
|
54
|
+
const bot = this.bots.get(botId);
|
|
55
|
+
if (!bot)
|
|
56
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
57
|
+
return bot.setGroupName(Number(sceneId), name);
|
|
58
|
+
}
|
|
59
|
+
async listMembers(botId, sceneId) {
|
|
60
|
+
const bot = this.bots.get(botId);
|
|
61
|
+
if (!bot)
|
|
62
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
63
|
+
const members = await bot.getMemberList(Number(sceneId));
|
|
64
|
+
return {
|
|
65
|
+
members: members.map((m) => ({
|
|
66
|
+
user_id: m.user_id,
|
|
67
|
+
nickname: m.nickname,
|
|
68
|
+
card: m.card,
|
|
69
|
+
role: m.role,
|
|
70
|
+
title: m.title,
|
|
71
|
+
})),
|
|
72
|
+
count: members.length,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async getGroupInfo(botId, sceneId) {
|
|
76
|
+
const bot = this.bots.get(botId);
|
|
77
|
+
if (!bot)
|
|
78
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
79
|
+
return bot.getGroupInfo(Number(sceneId));
|
|
80
|
+
}
|
|
81
|
+
async start() {
|
|
82
|
+
this.#router = this.plugin.inject('router');
|
|
83
|
+
this.plugin.useContext('router', (router) => {
|
|
84
|
+
this.#router = router;
|
|
85
|
+
});
|
|
86
|
+
this.registerOneBot11PlatformTools();
|
|
87
|
+
const groupTools = createGroupManagementTools(this, this.name);
|
|
88
|
+
groupTools.forEach((t) => this.addTool(t));
|
|
89
|
+
this.declareSkill({
|
|
90
|
+
description: 'OneBot11 协议群管理:踢人、禁言、封禁、设管理员、改群名、查成员等。仅有昵称时请先 list_members 获取 user_id 再执行操作。',
|
|
91
|
+
keywords: GROUP_MANAGEMENT_SKILL_KEYWORDS,
|
|
92
|
+
tags: GROUP_MANAGEMENT_SKILL_TAGS,
|
|
93
|
+
});
|
|
94
|
+
await super.start();
|
|
95
|
+
this.plugin.logger.info('OneBot11 适配器已启动');
|
|
96
|
+
}
|
|
97
|
+
registerOneBot11PlatformTools() {
|
|
98
|
+
this.addTool({
|
|
99
|
+
name: 'onebot11_set_title',
|
|
100
|
+
description: '设置群成员的专属头衔(需要群主权限)',
|
|
101
|
+
parameters: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
properties: {
|
|
104
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
105
|
+
group_id: { type: 'number', description: '群号' },
|
|
106
|
+
user_id: { type: 'number', description: '成员 QQ 号' },
|
|
107
|
+
title: { type: 'string', description: '头衔名称' },
|
|
108
|
+
},
|
|
109
|
+
required: ['bot', 'group_id', 'user_id', 'title'],
|
|
110
|
+
},
|
|
111
|
+
platforms: ['onebot11'],
|
|
112
|
+
scopes: ['group'],
|
|
113
|
+
permissionLevel: 'group_owner',
|
|
114
|
+
execute: async (args) => {
|
|
115
|
+
const { bot: botId, group_id, user_id, title } = args;
|
|
116
|
+
const bot = this.bots.get(botId);
|
|
117
|
+
if (!bot)
|
|
118
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
119
|
+
const success = await bot.setTitle(group_id, user_id, title);
|
|
120
|
+
return { success, message: success ? `已将 ${user_id} 的头衔设为 "${title}"` : '操作失败' };
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,EAEP,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,GAE5B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,MAAM,OAAO,eAAgB,SAAQ,OAAoB;IACvD,OAAO,CAAU;IAEjB,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,SAAS,CAAC,MAAyB;QACjC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,CAAE,MAA4B,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC7G,QAAQ,UAAU,EAAE,CAAC;YACnB,KAAK,IAAI;gBACP,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,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AAI,CAAC;gBACtD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACjC,IAAI,CAAC,GAAG;oBAAE,MAAM,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;gBAC9C,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC7D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,OAAO,WAAW,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YACnF,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { Bot, Message, SendOptions } from 'zhin.js';
|
|
3
|
+
import type { OneBot11WsClientConfig, OneBot11Message } from './types.js';
|
|
4
|
+
import type { OneBot11Adapter } from './adapter.js';
|
|
5
|
+
export declare class OneBot11WsClient extends EventEmitter implements Bot<OneBot11WsClientConfig, OneBot11Message> {
|
|
6
|
+
adapter: OneBot11Adapter;
|
|
7
|
+
$config: OneBot11WsClientConfig;
|
|
8
|
+
$connected: boolean;
|
|
9
|
+
private ws?;
|
|
10
|
+
private reconnectTimer?;
|
|
11
|
+
private heartbeatTimer?;
|
|
12
|
+
private requestId;
|
|
13
|
+
private pendingRequests;
|
|
14
|
+
get logger(): import("zhin.js").Logger;
|
|
15
|
+
constructor(adapter: OneBot11Adapter, $config: OneBot11WsClientConfig);
|
|
16
|
+
get $id(): string;
|
|
17
|
+
$connect(): Promise<void>;
|
|
18
|
+
$disconnect(): Promise<void>;
|
|
19
|
+
$formatMessage(onebotMsg: OneBot11Message): Message<OneBot11Message>;
|
|
20
|
+
$sendMessage(options: SendOptions): Promise<string>;
|
|
21
|
+
$recallMessage(id: string): Promise<void>;
|
|
22
|
+
kickMember(groupId: number, userId: number, rejectAddRequest?: boolean): Promise<boolean>;
|
|
23
|
+
muteMember(groupId: number, userId: number, duration?: number): Promise<boolean>;
|
|
24
|
+
muteAll(groupId: number, enable?: boolean): Promise<boolean>;
|
|
25
|
+
setAdmin(groupId: number, userId: number, enable?: boolean): Promise<boolean>;
|
|
26
|
+
setCard(groupId: number, userId: number, card: string): Promise<boolean>;
|
|
27
|
+
setTitle(groupId: number, userId: number, title: string, duration?: number): Promise<boolean>;
|
|
28
|
+
setGroupName(groupId: number, name: string): Promise<boolean>;
|
|
29
|
+
getMemberList(groupId: number): Promise<any[]>;
|
|
30
|
+
getGroupInfo(groupId: number): Promise<any>;
|
|
31
|
+
private callApi;
|
|
32
|
+
private handleWebSocketMessage;
|
|
33
|
+
private handleOneBot11Notice;
|
|
34
|
+
private handleOneBot11Request;
|
|
35
|
+
private handleOneBot11Message;
|
|
36
|
+
private startHeartbeat;
|
|
37
|
+
private scheduleReconnect;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=bot-ws-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-ws-client.d.ts","sourceRoot":"","sources":["../src/bot-ws-client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EACL,GAAG,EACH,OAAO,EACP,WAAW,EAIZ,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,qBAAa,gBAAiB,SAAQ,YAAa,YAAW,GAAG,CAAC,sBAAsB,EAAE,eAAe,CAAC;IAerF,OAAO,EAAE,eAAe;IAAS,OAAO,EAAE,sBAAsB;IAdnF,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,CAAY;IACvB,OAAO,CAAC,cAAc,CAAC,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