n8n-nodes-discord-dnd 0.1.81 → 0.1.83
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/dist/transformers/MessageTransformer.js +20 -1
- package/dist/transformers/MessageTransformer.js.map +1 -1
- package/package.json +4 -14
- package/dist/nodes/DiscordAction.node.d.ts +0 -5
- package/dist/nodes/DiscordAction.node.js +0 -153
- package/dist/nodes/DiscordAction.node.js.map +0 -1
- package/dist/nodes/DiscordTrigger2.node.d.ts +0 -5
- package/dist/nodes/DiscordTrigger2.node.js +0 -163
- package/dist/nodes/DiscordTrigger2.node.js.map +0 -1
@@ -4,7 +4,26 @@ exports.messageToJson = void 0;
|
|
4
4
|
async function messageToJson(message) {
|
5
5
|
const repliedMessage = await message.fetchReference().catch(() => null);
|
6
6
|
return {
|
7
|
-
|
7
|
+
channelId: message.channelId,
|
8
|
+
guildId: message.guildId,
|
9
|
+
id: message.id,
|
10
|
+
createdTimestamp: message.createdTimestamp,
|
11
|
+
content: message.content,
|
12
|
+
pinned: message.pinned,
|
13
|
+
embeds: message.embeds.map((embed) => embed.toJSON()),
|
14
|
+
attachments: message.attachments.map((attachment) => ({
|
15
|
+
...attachment,
|
16
|
+
})),
|
17
|
+
stickers: message.stickers.map((sticker) => ({
|
18
|
+
...sticker,
|
19
|
+
})),
|
20
|
+
editedTimestamp: message.editedTimestamp,
|
21
|
+
reactions: message.reactions.cache.map((reaction) => ({
|
22
|
+
...reaction,
|
23
|
+
})),
|
24
|
+
mentions: {
|
25
|
+
...message.mentions,
|
26
|
+
},
|
8
27
|
repliedMessage,
|
9
28
|
};
|
10
29
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MessageTransformer.js","sourceRoot":"","sources":["../../src/transformers/MessageTransformer.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,aAAa,CAAC,OAAgB;IAClD,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACxE,OAAO;QACL,GAAG,OAAO;
|
1
|
+
{"version":3,"file":"MessageTransformer.js","sourceRoot":"","sources":["../../src/transformers/MessageTransformer.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,aAAa,CAAC,OAAgB;IAClD,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACxE,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACrD,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAsB,EAAE,EAAE,CAAC,CAAC;YAChE,GAAG,UAAU;SACd,CAAC,CAAC;QACH,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC3C,GAAG,OAAO;SACX,CAAC,CAAC;QACH,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACpD,GAAG,QAAQ;SACZ,CAAC,CAAC;QACH,QAAQ,EAAE;YACR,GAAG,OAAO,CAAC,QAAQ;SACpB;QAED,cAAc;KACf,CAAC;AACJ,CAAC;AA1BD,sCA0BC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "n8n-nodes-discord-dnd",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.83",
|
4
4
|
"description": "n8n node to create triggers for Discord events",
|
5
5
|
"keywords": [
|
6
6
|
"n8n",
|
@@ -33,9 +33,7 @@
|
|
33
33
|
"dist/credentials/DiscordApi.credentials.js"
|
34
34
|
],
|
35
35
|
"nodes": [
|
36
|
-
"dist/nodes/DiscordTrigger.node.js"
|
37
|
-
"dist/nodes/DiscordAction.node.js",
|
38
|
-
"dist/nodes/DiscordTrigger2.node.js"
|
36
|
+
"dist/nodes/DiscordTrigger.node.js"
|
39
37
|
]
|
40
38
|
},
|
41
39
|
"devDependencies": {
|
@@ -50,15 +48,7 @@
|
|
50
48
|
"typescript": "~5.0.4"
|
51
49
|
},
|
52
50
|
"dependencies": {
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"@google-cloud/speech": "^7.0.1",
|
56
|
-
"axios": "^1.9.0",
|
57
|
-
"discord.js": "^14.19.2",
|
58
|
-
"ffmpeg-static": "^5.2.0",
|
59
|
-
"fluent-ffmpeg": "^2.1.3",
|
60
|
-
"libsodium-wrappers": "^0.7.15",
|
61
|
-
"n8n-core": "~1.5.0",
|
62
|
-
"prism-media": "^1.3.5"
|
51
|
+
"discord.js": "^14.9.0",
|
52
|
+
"n8n-core": "~1.5.0"
|
63
53
|
}
|
64
54
|
}
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from "n8n-workflow";
|
2
|
-
export declare class DiscordAction implements INodeType {
|
3
|
-
description: INodeTypeDescription;
|
4
|
-
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
5
|
-
}
|
@@ -1,153 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DiscordAction = void 0;
|
4
|
-
const discord_js_1 = require("discord.js");
|
5
|
-
const voice_1 = require("@discordjs/voice");
|
6
|
-
const client_1 = require("./client");
|
7
|
-
let discordClient = null; // 🧠 Client được cache
|
8
|
-
async function waitForConnectionReady(connection, timeout = 30000) {
|
9
|
-
await Promise.race([
|
10
|
-
(0, voice_1.entersState)(connection, voice_1.VoiceConnectionStatus.Ready, timeout),
|
11
|
-
new Promise((_, reject) => {
|
12
|
-
connection.once(voice_1.VoiceConnectionStatus.Disconnected, () => reject(new Error("Disconnected")));
|
13
|
-
connection.once("error", reject);
|
14
|
-
}),
|
15
|
-
]);
|
16
|
-
}
|
17
|
-
async function getOrCreateDiscordClient(token, options) {
|
18
|
-
if (discordClient && discordClient.isReady()) {
|
19
|
-
return discordClient;
|
20
|
-
}
|
21
|
-
discordClient = await (0, client_1.initializeDiscordClient)(token, options);
|
22
|
-
return discordClient;
|
23
|
-
}
|
24
|
-
class DiscordAction {
|
25
|
-
constructor() {
|
26
|
-
this.description = {
|
27
|
-
displayName: "Discord Action",
|
28
|
-
name: "discordAction",
|
29
|
-
icon: "file:../assets/icon/discord.svg",
|
30
|
-
group: ["output"],
|
31
|
-
version: 1,
|
32
|
-
description: "Perform Discord voice channel operations",
|
33
|
-
defaults: {
|
34
|
-
name: "Discord Action",
|
35
|
-
},
|
36
|
-
inputs: ["main"],
|
37
|
-
outputs: ["main"],
|
38
|
-
credentials: [
|
39
|
-
{
|
40
|
-
name: "discordApi",
|
41
|
-
required: true,
|
42
|
-
},
|
43
|
-
],
|
44
|
-
properties: [
|
45
|
-
{
|
46
|
-
displayName: "Operation",
|
47
|
-
name: "operation",
|
48
|
-
type: "options",
|
49
|
-
options: [
|
50
|
-
{
|
51
|
-
name: "Join Voice Channel",
|
52
|
-
value: "joinVoiceChannel",
|
53
|
-
},
|
54
|
-
{
|
55
|
-
name: "Leave Voice Channel",
|
56
|
-
value: "leaveVoiceChannel",
|
57
|
-
},
|
58
|
-
],
|
59
|
-
default: "joinVoiceChannel",
|
60
|
-
required: true,
|
61
|
-
},
|
62
|
-
{
|
63
|
-
displayName: "Guild ID",
|
64
|
-
name: "guildId",
|
65
|
-
type: "string",
|
66
|
-
default: "",
|
67
|
-
required: true,
|
68
|
-
},
|
69
|
-
{
|
70
|
-
displayName: "Channel ID",
|
71
|
-
name: "channelId",
|
72
|
-
type: "string",
|
73
|
-
default: "",
|
74
|
-
displayOptions: {
|
75
|
-
show: {
|
76
|
-
operation: ["joinVoiceChannel"],
|
77
|
-
},
|
78
|
-
},
|
79
|
-
required: true,
|
80
|
-
},
|
81
|
-
],
|
82
|
-
};
|
83
|
-
}
|
84
|
-
async execute() {
|
85
|
-
const credentials = await this.getCredentials("discordApi");
|
86
|
-
const operation = this.getNodeParameter("operation", 0);
|
87
|
-
const guildId = this.getNodeParameter("guildId", 0);
|
88
|
-
const channelId = this.getNodeParameter("channelId", 0);
|
89
|
-
const clientOptions = {
|
90
|
-
intents: [discord_js_1.GatewayIntentBits.Guilds, discord_js_1.GatewayIntentBits.GuildVoiceStates],
|
91
|
-
partials: [discord_js_1.Partials.Channel],
|
92
|
-
};
|
93
|
-
const client = await getOrCreateDiscordClient(credentials.botToken, clientOptions);
|
94
|
-
try {
|
95
|
-
const guild = await client.guilds.fetch(guildId);
|
96
|
-
if (!guild)
|
97
|
-
throw new Error(`Could not find guild ${guildId}`);
|
98
|
-
switch (operation) {
|
99
|
-
case "joinVoiceChannel": {
|
100
|
-
const voiceChannel = (await guild.channels.fetch(channelId));
|
101
|
-
// is voice channel
|
102
|
-
if (!voiceChannel || voiceChannel.type !== 2) {
|
103
|
-
throw new Error(`Channel ${channelId} is not a valid voice channel`);
|
104
|
-
}
|
105
|
-
const oldConnection = (0, voice_1.getVoiceConnection)(guildId);
|
106
|
-
if (oldConnection) {
|
107
|
-
oldConnection.destroy();
|
108
|
-
}
|
109
|
-
const connection = (0, voice_1.joinVoiceChannel)({
|
110
|
-
channelId: voiceChannel.id,
|
111
|
-
guildId: voiceChannel.guild.id,
|
112
|
-
adapterCreator: voiceChannel.guild
|
113
|
-
.voiceAdapterCreator,
|
114
|
-
selfDeaf: false,
|
115
|
-
selfMute: false,
|
116
|
-
});
|
117
|
-
const player = (0, voice_1.createAudioPlayer)();
|
118
|
-
connection.subscribe(player);
|
119
|
-
try {
|
120
|
-
await waitForConnectionReady(connection);
|
121
|
-
}
|
122
|
-
catch (error) {
|
123
|
-
connection.destroy();
|
124
|
-
throw new Error(`Failed to join voice channel: ${(error === null || error === void 0 ? void 0 : error.message) || "Unknown error"}`);
|
125
|
-
}
|
126
|
-
break;
|
127
|
-
}
|
128
|
-
case "leaveVoiceChannel": {
|
129
|
-
const connection = (0, voice_1.getVoiceConnection)(guildId);
|
130
|
-
if (connection) {
|
131
|
-
connection.destroy();
|
132
|
-
}
|
133
|
-
break;
|
134
|
-
}
|
135
|
-
default:
|
136
|
-
throw new Error(`Unsupported operation "${operation}"`);
|
137
|
-
}
|
138
|
-
return [
|
139
|
-
this.helpers.returnJsonArray({
|
140
|
-
success: true,
|
141
|
-
operation,
|
142
|
-
guildId,
|
143
|
-
channelId: operation === "joinVoiceChannel" ? channelId : undefined,
|
144
|
-
}),
|
145
|
-
];
|
146
|
-
}
|
147
|
-
catch (error) {
|
148
|
-
throw error;
|
149
|
-
}
|
150
|
-
}
|
151
|
-
}
|
152
|
-
exports.DiscordAction = DiscordAction;
|
153
|
-
//# sourceMappingURL=DiscordAction.node.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"DiscordAction.node.js","sourceRoot":"","sources":["../../src/nodes/DiscordAction.node.ts"],"names":[],"mappings":";;;AAMA,2CAA+E;AAC/E,4CAQ0B;AAC1B,qCAAmD;AAEnD,IAAI,aAAa,GAAkB,IAAI,CAAC,CAAC,uBAAuB;AAEhE,KAAK,UAAU,sBAAsB,CACnC,UAA2B,EAC3B,OAAO,GAAG,KAAM;IAEhB,MAAM,OAAO,CAAC,IAAI,CAAC;QACjB,IAAA,mBAAW,EAAC,UAAU,EAAE,6BAAqB,CAAC,KAAK,EAAE,OAAO,CAAC;QAC7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D,MAAM;iBACP;gBAED;oBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,SAAS,GAAG,CAAC,CAAC;aAC3D;YAED,OAAO;gBACL,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;oBAC3B,OAAO,EAAE,IAAI;oBACb,SAAS;oBACT,OAAO;oBACP,SAAS,EAAE,SAAS,KAAK,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;iBACpE,CAAC;aACH,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF;AAlJD,sCAkJC"}
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { INodeType, ITriggerFunctions, ITriggerResponse, INodeTypeDescription } from "n8n-workflow";
|
2
|
-
export declare class DiscordTriggerWithSpeech implements INodeType {
|
3
|
-
description: INodeTypeDescription;
|
4
|
-
trigger(this: ITriggerFunctions): Promise<ITriggerResponse>;
|
5
|
-
}
|
@@ -1,163 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.DiscordTriggerWithSpeech = void 0;
|
7
|
-
const discord_js_1 = require("discord.js");
|
8
|
-
const voice_1 = require("@discordjs/voice");
|
9
|
-
const speech_1 = require("@google-cloud/speech");
|
10
|
-
const prism_media_1 = __importDefault(require("prism-media"));
|
11
|
-
const stream_1 = require("stream");
|
12
|
-
// ----------- Support Classes -----------
|
13
|
-
class BufferStream extends stream_1.Writable {
|
14
|
-
constructor(onDone) {
|
15
|
-
super();
|
16
|
-
this.onDone = onDone;
|
17
|
-
this.chunks = [];
|
18
|
-
}
|
19
|
-
_write(chunk, _encoding, callback) {
|
20
|
-
this.chunks.push(chunk);
|
21
|
-
callback();
|
22
|
-
}
|
23
|
-
_final(callback) {
|
24
|
-
const buffer = Buffer.concat(this.chunks);
|
25
|
-
this.onDone(buffer);
|
26
|
-
callback();
|
27
|
-
}
|
28
|
-
}
|
29
|
-
// ----------- Main Discord Trigger -----------
|
30
|
-
class DiscordTriggerWithSpeech {
|
31
|
-
constructor() {
|
32
|
-
this.description = {
|
33
|
-
displayName: "Discord Trigger With Speech",
|
34
|
-
name: "discordTriggerWithSpeech",
|
35
|
-
icon: "file:discord.svg",
|
36
|
-
group: ["trigger"],
|
37
|
-
version: 1,
|
38
|
-
description: "Trigger when someone speaks in Discord voice channel",
|
39
|
-
defaults: {
|
40
|
-
name: "Discord Trigger With Speech",
|
41
|
-
},
|
42
|
-
inputs: [],
|
43
|
-
outputs: ["main"],
|
44
|
-
credentials: [
|
45
|
-
{
|
46
|
-
name: "discordApi",
|
47
|
-
required: true,
|
48
|
-
},
|
49
|
-
{
|
50
|
-
name: "googleApi",
|
51
|
-
required: true,
|
52
|
-
},
|
53
|
-
],
|
54
|
-
properties: [
|
55
|
-
{
|
56
|
-
displayName: "Voice Channel ID",
|
57
|
-
name: "voiceChannelId",
|
58
|
-
type: "string",
|
59
|
-
required: true,
|
60
|
-
default: "",
|
61
|
-
},
|
62
|
-
],
|
63
|
-
};
|
64
|
-
}
|
65
|
-
async trigger() {
|
66
|
-
const credentialsDiscord = await this.getCredentials("discordApi");
|
67
|
-
const credentialsGoogle = await this.getCredentials("googleApi");
|
68
|
-
const voiceChannelId = this.getNodeParameter("voiceChannelId");
|
69
|
-
// Init Google Speech Client
|
70
|
-
const speechClient = new speech_1.SpeechClient({
|
71
|
-
credentials: {
|
72
|
-
client_email: credentialsGoogle.client_email,
|
73
|
-
private_key: credentialsGoogle.private_key,
|
74
|
-
},
|
75
|
-
projectId: credentialsGoogle.project_id,
|
76
|
-
});
|
77
|
-
// Init Discord Client
|
78
|
-
const client = new discord_js_1.Client({
|
79
|
-
intents: [discord_js_1.GatewayIntentBits.Guilds, discord_js_1.GatewayIntentBits.GuildVoiceStates],
|
80
|
-
partials: [discord_js_1.Partials.Channel],
|
81
|
-
});
|
82
|
-
client.once("ready", async () => {
|
83
|
-
console.log("Discord bot ready!");
|
84
|
-
const channel = (await client.channels.fetch(voiceChannelId));
|
85
|
-
if (!channel || !channel.isVoiceBased()) {
|
86
|
-
console.error("Channel not found or not a voice channel");
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
const connection = (0, voice_1.joinVoiceChannel)({
|
90
|
-
channelId: channel.id,
|
91
|
-
guildId: channel.guild.id,
|
92
|
-
adapterCreator: channel.guild.voiceAdapterCreator,
|
93
|
-
});
|
94
|
-
client.on("voiceStateUpdate", async (oldState, newState) => {
|
95
|
-
if (newState.channelId !== voiceChannelId)
|
96
|
-
return;
|
97
|
-
const userId = newState.id;
|
98
|
-
const receiver = connection.receiver;
|
99
|
-
const audioStream = receiver.subscribe(userId, {
|
100
|
-
end: {
|
101
|
-
behavior: voice_1.EndBehaviorType.AfterSilence,
|
102
|
-
duration: 1000, // 1s không có tiếng thì kết thúc ghi âm
|
103
|
-
},
|
104
|
-
});
|
105
|
-
const decoder = new prism_media_1.default.opus.Decoder({
|
106
|
-
rate: 48000,
|
107
|
-
channels: 2,
|
108
|
-
frameSize: 960,
|
109
|
-
});
|
110
|
-
const memoryStream = new BufferStream(async (buffer) => {
|
111
|
-
var _a;
|
112
|
-
console.log("Received audio buffer, sending to Google Speech...");
|
113
|
-
const request = {
|
114
|
-
audio: {
|
115
|
-
content: buffer.toString("base64"),
|
116
|
-
},
|
117
|
-
config: {
|
118
|
-
encoding: "LINEAR16",
|
119
|
-
sampleRateHertz: 48000,
|
120
|
-
languageCode: "en-US",
|
121
|
-
audioChannelCount: 2,
|
122
|
-
},
|
123
|
-
};
|
124
|
-
try {
|
125
|
-
const [response] = await speechClient.recognize(request);
|
126
|
-
const transcription = ((_a = response.results) === null || _a === void 0 ? void 0 : _a.map((result) => { var _a; return (_a = result.alternatives) === null || _a === void 0 ? void 0 : _a[0].transcript; }).join("\n")) || "";
|
127
|
-
console.log("Google Speech result:", transcription);
|
128
|
-
// Emit về n8n
|
129
|
-
this.emit([
|
130
|
-
[
|
131
|
-
{
|
132
|
-
json: {
|
133
|
-
text: transcription,
|
134
|
-
userId: userId,
|
135
|
-
},
|
136
|
-
},
|
137
|
-
],
|
138
|
-
]);
|
139
|
-
}
|
140
|
-
catch (err) {
|
141
|
-
console.error("Error recognizing speech:", err);
|
142
|
-
}
|
143
|
-
});
|
144
|
-
audioStream.pipe(decoder).pipe(memoryStream);
|
145
|
-
});
|
146
|
-
});
|
147
|
-
await client.login(credentialsDiscord.botToken);
|
148
|
-
const closeFunction = async () => {
|
149
|
-
const connection = (0, voice_1.getVoiceConnection)(voiceChannelId);
|
150
|
-
if (connection) {
|
151
|
-
connection.destroy();
|
152
|
-
}
|
153
|
-
console.log("Disconnecting bot...");
|
154
|
-
await client.destroy();
|
155
|
-
};
|
156
|
-
return {
|
157
|
-
manualTriggerFunction: async () => { },
|
158
|
-
closeFunction,
|
159
|
-
};
|
160
|
-
}
|
161
|
-
}
|
162
|
-
exports.DiscordTriggerWithSpeech = DiscordTriggerWithSpeech;
|
163
|
-
//# sourceMappingURL=DiscordTrigger2.node.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"DiscordTrigger2.node.js","sourceRoot":"","sources":["../../src/nodes/DiscordTrigger2.node.ts"],"names":[],"mappings":";;;;;;AAOA,2CAA+E;AAC/E,4CAI0B;AAE1B,iDAAoD;AACpD,8DAAgC;AAChC,mCAAkC;AAElC,0CAA0C;AAC1C,MAAM,YAAa,SAAQ,iBAAQ;IAEjC,YAAoB,MAAgC;QAClD,KAAK,EAAE,CAAC;QADU,WAAM,GAAN,MAAM,CAA0B;QAD5C,WAAM,GAAa,EAAE,CAAC;IAG9B,CAAC;IAED,MAAM,CAAC,KAAU,EAAE,SAAyB,EAAE,QAAoB;QAChE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxB,QAAQ,EAAE,CAAC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