shardwire 1.3.0 → 1.4.0
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/README.md +16 -2
- package/dist/index.d.mts +113 -1
- package/dist/index.d.ts +113 -1
- package/dist/index.js +438 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +439 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ var BOT_EVENT_NAMES = [
|
|
|
34
34
|
"messageCreate",
|
|
35
35
|
"messageUpdate",
|
|
36
36
|
"messageDelete",
|
|
37
|
+
"messageBulkDelete",
|
|
37
38
|
"messageReactionAdd",
|
|
38
39
|
"messageReactionRemove",
|
|
39
40
|
"guildCreate",
|
|
@@ -43,7 +44,10 @@ var BOT_EVENT_NAMES = [
|
|
|
43
44
|
"guildMemberUpdate",
|
|
44
45
|
"threadCreate",
|
|
45
46
|
"threadUpdate",
|
|
46
|
-
"threadDelete"
|
|
47
|
+
"threadDelete",
|
|
48
|
+
"channelCreate",
|
|
49
|
+
"channelUpdate",
|
|
50
|
+
"channelDelete"
|
|
47
51
|
];
|
|
48
52
|
var BOT_ACTION_NAMES = [
|
|
49
53
|
"sendMessage",
|
|
@@ -64,7 +68,14 @@ var BOT_ACTION_NAMES = [
|
|
|
64
68
|
"addMemberRole",
|
|
65
69
|
"removeMemberRole",
|
|
66
70
|
"addMessageReaction",
|
|
67
|
-
"removeOwnMessageReaction"
|
|
71
|
+
"removeOwnMessageReaction",
|
|
72
|
+
"timeoutMember",
|
|
73
|
+
"removeMemberTimeout",
|
|
74
|
+
"createChannel",
|
|
75
|
+
"editChannel",
|
|
76
|
+
"deleteChannel",
|
|
77
|
+
"createThread",
|
|
78
|
+
"archiveThread"
|
|
68
79
|
];
|
|
69
80
|
var DISCORD_GATEWAY_INTENT_ENTRIES = Object.entries(import_discord.GatewayIntentBits).filter(
|
|
70
81
|
(entry) => typeof entry[1] === "number"
|
|
@@ -78,6 +89,7 @@ var EVENT_REQUIRED_INTENTS = {
|
|
|
78
89
|
messageCreate: ["GuildMessages"],
|
|
79
90
|
messageUpdate: ["GuildMessages"],
|
|
80
91
|
messageDelete: ["GuildMessages"],
|
|
92
|
+
messageBulkDelete: ["GuildMessages"],
|
|
81
93
|
messageReactionAdd: ["GuildMessageReactions"],
|
|
82
94
|
messageReactionRemove: ["GuildMessageReactions"],
|
|
83
95
|
guildCreate: ["Guilds"],
|
|
@@ -87,7 +99,10 @@ var EVENT_REQUIRED_INTENTS = {
|
|
|
87
99
|
guildMemberUpdate: ["GuildMembers"],
|
|
88
100
|
threadCreate: ["Guilds"],
|
|
89
101
|
threadUpdate: ["Guilds"],
|
|
90
|
-
threadDelete: ["Guilds"]
|
|
102
|
+
threadDelete: ["Guilds"],
|
|
103
|
+
channelCreate: ["Guilds"],
|
|
104
|
+
channelUpdate: ["Guilds"],
|
|
105
|
+
channelDelete: ["Guilds"]
|
|
91
106
|
};
|
|
92
107
|
function getAvailableEvents(intents) {
|
|
93
108
|
const enabled = new Set(intents);
|
|
@@ -180,6 +195,20 @@ function serializeMessage(message) {
|
|
|
180
195
|
...message.reference.guildId ? { guildId: message.reference.guildId } : {}
|
|
181
196
|
} : void 0;
|
|
182
197
|
const components = "components" in message && message.components && message.components.length > 0 ? message.components.map((row) => row.toJSON()) : void 0;
|
|
198
|
+
const channelMeta = (() => {
|
|
199
|
+
if (!("channel" in message) || !message.channel) {
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
const ch = message.channel;
|
|
203
|
+
const meta = {};
|
|
204
|
+
if (typeof ch.type === "number") {
|
|
205
|
+
meta.channelType = ch.type;
|
|
206
|
+
}
|
|
207
|
+
if ("parentId" in ch && typeof ch.parentId === "string") {
|
|
208
|
+
meta.parentChannelId = ch.parentId;
|
|
209
|
+
}
|
|
210
|
+
return meta;
|
|
211
|
+
})();
|
|
183
212
|
return {
|
|
184
213
|
id: message.id,
|
|
185
214
|
channelId: message.channelId,
|
|
@@ -198,7 +227,8 @@ function serializeMessage(message) {
|
|
|
198
227
|
})) : [],
|
|
199
228
|
embeds: serializeEmbeds(message),
|
|
200
229
|
...components ? { components } : {},
|
|
201
|
-
...reference ? { reference } : {}
|
|
230
|
+
...reference ? { reference } : {},
|
|
231
|
+
...channelMeta
|
|
202
232
|
};
|
|
203
233
|
}
|
|
204
234
|
function serializeGuild(guild) {
|
|
@@ -220,12 +250,43 @@ function serializeThread(thread) {
|
|
|
220
250
|
...typeof thread.locked === "boolean" ? { locked: thread.locked } : {}
|
|
221
251
|
};
|
|
222
252
|
}
|
|
253
|
+
function serializeChannel(channel) {
|
|
254
|
+
const base = {
|
|
255
|
+
id: channel.id,
|
|
256
|
+
type: channel.type
|
|
257
|
+
};
|
|
258
|
+
if ("name" in channel) {
|
|
259
|
+
base.name = channel.name ?? null;
|
|
260
|
+
}
|
|
261
|
+
if ("guildId" in channel && typeof channel.guildId === "string") {
|
|
262
|
+
base.guildId = channel.guildId;
|
|
263
|
+
}
|
|
264
|
+
if ("parentId" in channel) {
|
|
265
|
+
base.parentId = channel.parentId;
|
|
266
|
+
}
|
|
267
|
+
return base;
|
|
268
|
+
}
|
|
223
269
|
function serializeDeletedMessage(message) {
|
|
270
|
+
const channelMeta = (() => {
|
|
271
|
+
if (!("channel" in message) || !message.channel) {
|
|
272
|
+
return {};
|
|
273
|
+
}
|
|
274
|
+
const ch = message.channel;
|
|
275
|
+
const meta = {};
|
|
276
|
+
if (typeof ch.type === "number") {
|
|
277
|
+
meta.channelType = ch.type;
|
|
278
|
+
}
|
|
279
|
+
if ("parentId" in ch && typeof ch.parentId === "string") {
|
|
280
|
+
meta.parentChannelId = ch.parentId;
|
|
281
|
+
}
|
|
282
|
+
return meta;
|
|
283
|
+
})();
|
|
224
284
|
return {
|
|
225
285
|
id: message.id,
|
|
226
286
|
channelId: message.channelId,
|
|
227
287
|
...message.guildId ? { guildId: message.guildId } : {},
|
|
228
|
-
deletedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
288
|
+
deletedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
289
|
+
...channelMeta
|
|
229
290
|
};
|
|
230
291
|
}
|
|
231
292
|
function serializeReactionEmoji(reaction) {
|
|
@@ -291,83 +352,124 @@ function serializeInteraction(interaction) {
|
|
|
291
352
|
...interaction.member && "guild" in interaction.member ? { member: serializeGuildMember(interaction.member) } : {}
|
|
292
353
|
};
|
|
293
354
|
if (interaction.isChatInputCommand()) {
|
|
294
|
-
return
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
355
|
+
return enrichInteractionChannel(
|
|
356
|
+
{
|
|
357
|
+
...base,
|
|
358
|
+
kind: "chatInput",
|
|
359
|
+
commandName: interaction.commandName,
|
|
360
|
+
options: serializeChatInputOptions(interaction)
|
|
361
|
+
},
|
|
362
|
+
interaction
|
|
363
|
+
);
|
|
300
364
|
}
|
|
301
365
|
if (interaction.isContextMenuCommand()) {
|
|
302
|
-
return
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
366
|
+
return enrichInteractionChannel(
|
|
367
|
+
{
|
|
368
|
+
...base,
|
|
369
|
+
kind: "contextMenu",
|
|
370
|
+
commandName: interaction.commandName
|
|
371
|
+
},
|
|
372
|
+
interaction
|
|
373
|
+
);
|
|
307
374
|
}
|
|
308
375
|
if (interaction.isButton()) {
|
|
309
376
|
const message = serializeInteractionMessage(interaction);
|
|
310
|
-
return
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
377
|
+
return enrichInteractionChannel(
|
|
378
|
+
{
|
|
379
|
+
...base,
|
|
380
|
+
kind: "button",
|
|
381
|
+
customId: interaction.customId,
|
|
382
|
+
...message ? { message } : {}
|
|
383
|
+
},
|
|
384
|
+
interaction
|
|
385
|
+
);
|
|
316
386
|
}
|
|
317
387
|
if (interaction.isStringSelectMenu()) {
|
|
318
388
|
const message = serializeInteractionMessage(interaction);
|
|
319
|
-
return
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
389
|
+
return enrichInteractionChannel(
|
|
390
|
+
{
|
|
391
|
+
...base,
|
|
392
|
+
kind: "stringSelect",
|
|
393
|
+
...serializeSelectMenu(interaction),
|
|
394
|
+
...message ? { message } : {}
|
|
395
|
+
},
|
|
396
|
+
interaction
|
|
397
|
+
);
|
|
325
398
|
}
|
|
326
399
|
if (interaction.isUserSelectMenu()) {
|
|
327
400
|
const message = serializeInteractionMessage(interaction);
|
|
328
|
-
return
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
401
|
+
return enrichInteractionChannel(
|
|
402
|
+
{
|
|
403
|
+
...base,
|
|
404
|
+
kind: "userSelect",
|
|
405
|
+
...serializeSelectMenu(interaction),
|
|
406
|
+
...message ? { message } : {}
|
|
407
|
+
},
|
|
408
|
+
interaction
|
|
409
|
+
);
|
|
334
410
|
}
|
|
335
411
|
if (interaction.isRoleSelectMenu()) {
|
|
336
412
|
const message = serializeInteractionMessage(interaction);
|
|
337
|
-
return
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
413
|
+
return enrichInteractionChannel(
|
|
414
|
+
{
|
|
415
|
+
...base,
|
|
416
|
+
kind: "roleSelect",
|
|
417
|
+
...serializeSelectMenu(interaction),
|
|
418
|
+
...message ? { message } : {}
|
|
419
|
+
},
|
|
420
|
+
interaction
|
|
421
|
+
);
|
|
343
422
|
}
|
|
344
423
|
if (interaction.isMentionableSelectMenu()) {
|
|
345
424
|
const message = serializeInteractionMessage(interaction);
|
|
346
|
-
return
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
425
|
+
return enrichInteractionChannel(
|
|
426
|
+
{
|
|
427
|
+
...base,
|
|
428
|
+
kind: "mentionableSelect",
|
|
429
|
+
...serializeSelectMenu(interaction),
|
|
430
|
+
...message ? { message } : {}
|
|
431
|
+
},
|
|
432
|
+
interaction
|
|
433
|
+
);
|
|
352
434
|
}
|
|
353
435
|
if (interaction.isChannelSelectMenu()) {
|
|
354
436
|
const message = serializeInteractionMessage(interaction);
|
|
355
|
-
return
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
437
|
+
return enrichInteractionChannel(
|
|
438
|
+
{
|
|
439
|
+
...base,
|
|
440
|
+
kind: "channelSelect",
|
|
441
|
+
...serializeSelectMenu(interaction),
|
|
442
|
+
...message ? { message } : {}
|
|
443
|
+
},
|
|
444
|
+
interaction
|
|
445
|
+
);
|
|
361
446
|
}
|
|
362
447
|
if (interaction.isModalSubmit()) {
|
|
363
|
-
return
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
448
|
+
return enrichInteractionChannel(
|
|
449
|
+
{
|
|
450
|
+
...base,
|
|
451
|
+
kind: "modalSubmit",
|
|
452
|
+
customId: interaction.customId,
|
|
453
|
+
fields: serializeModalFields(interaction)
|
|
454
|
+
},
|
|
455
|
+
interaction
|
|
456
|
+
);
|
|
369
457
|
}
|
|
370
|
-
return base;
|
|
458
|
+
return enrichInteractionChannel(base, interaction);
|
|
459
|
+
}
|
|
460
|
+
function enrichInteractionChannel(base, interaction) {
|
|
461
|
+
if (!("channel" in interaction) || !interaction.channel || interaction.channel.isDMBased()) {
|
|
462
|
+
return base;
|
|
463
|
+
}
|
|
464
|
+
const ch = interaction.channel;
|
|
465
|
+
const out = { ...base };
|
|
466
|
+
if (typeof ch.type === "number") {
|
|
467
|
+
out.channelType = ch.type;
|
|
468
|
+
}
|
|
469
|
+
if ("parentId" in ch && typeof ch.parentId === "string") {
|
|
470
|
+
out.parentChannelId = ch.parentId;
|
|
471
|
+
}
|
|
472
|
+
return out;
|
|
371
473
|
}
|
|
372
474
|
|
|
373
475
|
// src/discord/runtime/discordjs-adapter.ts
|
|
@@ -447,7 +549,7 @@ function mapDiscordErrorToActionExecutionError(error) {
|
|
|
447
549
|
}
|
|
448
550
|
return null;
|
|
449
551
|
}
|
|
450
|
-
var DiscordJsRuntimeAdapter = class {
|
|
552
|
+
var DiscordJsRuntimeAdapter = class _DiscordJsRuntimeAdapter {
|
|
451
553
|
constructor(options) {
|
|
452
554
|
this.options = options;
|
|
453
555
|
const intentBits = options.intents.map((intent) => BOT_INTENT_BITS[intent]);
|
|
@@ -477,7 +579,14 @@ var DiscordJsRuntimeAdapter = class {
|
|
|
477
579
|
addMemberRole: (payload) => this.addMemberRole(payload),
|
|
478
580
|
removeMemberRole: (payload) => this.removeMemberRole(payload),
|
|
479
581
|
addMessageReaction: (payload) => this.addMessageReaction(payload),
|
|
480
|
-
removeOwnMessageReaction: (payload) => this.removeOwnMessageReaction(payload)
|
|
582
|
+
removeOwnMessageReaction: (payload) => this.removeOwnMessageReaction(payload),
|
|
583
|
+
timeoutMember: (payload) => this.timeoutMember(payload),
|
|
584
|
+
removeMemberTimeout: (payload) => this.removeMemberTimeout(payload),
|
|
585
|
+
createChannel: (payload) => this.createChannel(payload),
|
|
586
|
+
editChannel: (payload) => this.editChannel(payload),
|
|
587
|
+
deleteChannel: (payload) => this.deleteChannel(payload),
|
|
588
|
+
createThread: (payload) => this.createThread(payload),
|
|
589
|
+
archiveThread: (payload) => this.archiveThread(payload)
|
|
481
590
|
};
|
|
482
591
|
}
|
|
483
592
|
options;
|
|
@@ -605,6 +714,23 @@ var DiscordJsRuntimeAdapter = class {
|
|
|
605
714
|
this.client.off(import_discord2.Events.MessageDelete, listener);
|
|
606
715
|
};
|
|
607
716
|
}
|
|
717
|
+
case "messageBulkDelete": {
|
|
718
|
+
const listener = (messages, channel) => {
|
|
719
|
+
handler({
|
|
720
|
+
receivedAt: Date.now(),
|
|
721
|
+
...this.shardEnvelope(),
|
|
722
|
+
channelId: channel.id,
|
|
723
|
+
guildId: channel.guildId,
|
|
724
|
+
messageIds: [...messages.keys()],
|
|
725
|
+
channelType: channel.type,
|
|
726
|
+
..."parentId" in channel && typeof channel.parentId === "string" ? { parentChannelId: channel.parentId } : {}
|
|
727
|
+
});
|
|
728
|
+
};
|
|
729
|
+
this.client.on(import_discord2.Events.MessageBulkDelete, listener);
|
|
730
|
+
return () => {
|
|
731
|
+
this.client.off(import_discord2.Events.MessageBulkDelete, listener);
|
|
732
|
+
};
|
|
733
|
+
}
|
|
608
734
|
case "messageReactionAdd": {
|
|
609
735
|
const listener = (reaction, user) => {
|
|
610
736
|
handler({
|
|
@@ -742,6 +868,46 @@ var DiscordJsRuntimeAdapter = class {
|
|
|
742
868
|
this.client.off(import_discord2.Events.ThreadDelete, listener);
|
|
743
869
|
};
|
|
744
870
|
}
|
|
871
|
+
case "channelCreate": {
|
|
872
|
+
const listener = (channel) => {
|
|
873
|
+
handler({
|
|
874
|
+
receivedAt: Date.now(),
|
|
875
|
+
...this.shardEnvelope(),
|
|
876
|
+
channel: serializeChannel(channel)
|
|
877
|
+
});
|
|
878
|
+
};
|
|
879
|
+
this.client.on(import_discord2.Events.ChannelCreate, listener);
|
|
880
|
+
return () => {
|
|
881
|
+
this.client.off(import_discord2.Events.ChannelCreate, listener);
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
case "channelUpdate": {
|
|
885
|
+
const listener = (oldChannel, newChannel) => {
|
|
886
|
+
handler({
|
|
887
|
+
receivedAt: Date.now(),
|
|
888
|
+
...this.shardEnvelope(),
|
|
889
|
+
oldChannel: serializeChannel(oldChannel),
|
|
890
|
+
channel: serializeChannel(newChannel)
|
|
891
|
+
});
|
|
892
|
+
};
|
|
893
|
+
this.client.on(import_discord2.Events.ChannelUpdate, listener);
|
|
894
|
+
return () => {
|
|
895
|
+
this.client.off(import_discord2.Events.ChannelUpdate, listener);
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
case "channelDelete": {
|
|
899
|
+
const listener = (channel) => {
|
|
900
|
+
handler({
|
|
901
|
+
receivedAt: Date.now(),
|
|
902
|
+
...this.shardEnvelope(),
|
|
903
|
+
channel: serializeChannel(channel)
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
this.client.on(import_discord2.Events.ChannelDelete, listener);
|
|
907
|
+
return () => {
|
|
908
|
+
this.client.off(import_discord2.Events.ChannelDelete, listener);
|
|
909
|
+
};
|
|
910
|
+
}
|
|
745
911
|
default:
|
|
746
912
|
return () => void 0;
|
|
747
913
|
}
|
|
@@ -996,6 +1162,112 @@ var DiscordJsRuntimeAdapter = class {
|
|
|
996
1162
|
emoji: payload.emoji
|
|
997
1163
|
};
|
|
998
1164
|
}
|
|
1165
|
+
static maxTimeoutMs = 28 * 24 * 60 * 60 * 1e3;
|
|
1166
|
+
async timeoutMember(payload) {
|
|
1167
|
+
if (typeof payload.durationMs !== "number" || !Number.isFinite(payload.durationMs) || payload.durationMs < 1 || payload.durationMs > _DiscordJsRuntimeAdapter.maxTimeoutMs) {
|
|
1168
|
+
throw new ActionExecutionError(
|
|
1169
|
+
"INVALID_REQUEST",
|
|
1170
|
+
`durationMs must be between 1 and ${_DiscordJsRuntimeAdapter.maxTimeoutMs} (28 days).`
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
const guild = await this.client.guilds.fetch(payload.guildId);
|
|
1174
|
+
const member = await guild.members.fetch(payload.userId);
|
|
1175
|
+
await member.timeout(payload.durationMs, payload.reason);
|
|
1176
|
+
return {
|
|
1177
|
+
guildId: payload.guildId,
|
|
1178
|
+
userId: payload.userId
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
async removeMemberTimeout(payload) {
|
|
1182
|
+
const guild = await this.client.guilds.fetch(payload.guildId);
|
|
1183
|
+
const member = await guild.members.fetch(payload.userId);
|
|
1184
|
+
await member.timeout(null, payload.reason);
|
|
1185
|
+
return serializeGuildMember(await member.fetch());
|
|
1186
|
+
}
|
|
1187
|
+
async createChannel(payload) {
|
|
1188
|
+
const guild = await this.client.guilds.fetch(payload.guildId);
|
|
1189
|
+
const created = await guild.channels.create({
|
|
1190
|
+
name: payload.name,
|
|
1191
|
+
type: payload.type ?? import_discord2.ChannelType.GuildText,
|
|
1192
|
+
...payload.parentId ? { parent: payload.parentId } : {},
|
|
1193
|
+
...payload.topic !== void 0 ? { topic: payload.topic } : {},
|
|
1194
|
+
...payload.reason ? { reason: payload.reason } : {}
|
|
1195
|
+
});
|
|
1196
|
+
return serializeChannel(created);
|
|
1197
|
+
}
|
|
1198
|
+
async editChannel(payload) {
|
|
1199
|
+
const raw = await this.client.channels.fetch(payload.channelId);
|
|
1200
|
+
if (!raw) {
|
|
1201
|
+
throw new ActionExecutionError("NOT_FOUND", `Channel "${payload.channelId}" was not found.`);
|
|
1202
|
+
}
|
|
1203
|
+
if (!("edit" in raw) || typeof raw.edit !== "function") {
|
|
1204
|
+
throw new ActionExecutionError("INVALID_REQUEST", `Channel "${payload.channelId}" cannot be edited.`);
|
|
1205
|
+
}
|
|
1206
|
+
const edited = await raw.edit({
|
|
1207
|
+
...payload.name !== void 0 ? { name: payload.name ?? void 0 } : {},
|
|
1208
|
+
...payload.parentId !== void 0 ? { parent: payload.parentId } : {},
|
|
1209
|
+
...payload.topic !== void 0 ? { topic: payload.topic } : {},
|
|
1210
|
+
...payload.reason ? { reason: payload.reason } : {}
|
|
1211
|
+
});
|
|
1212
|
+
return serializeChannel(edited);
|
|
1213
|
+
}
|
|
1214
|
+
async deleteChannel(payload) {
|
|
1215
|
+
const raw = await this.client.channels.fetch(payload.channelId);
|
|
1216
|
+
if (!raw) {
|
|
1217
|
+
throw new ActionExecutionError("NOT_FOUND", `Channel "${payload.channelId}" was not found.`);
|
|
1218
|
+
}
|
|
1219
|
+
if (!("delete" in raw) || typeof raw.delete !== "function") {
|
|
1220
|
+
throw new ActionExecutionError("INVALID_REQUEST", `Channel "${payload.channelId}" cannot be deleted.`);
|
|
1221
|
+
}
|
|
1222
|
+
await raw.delete(payload.reason);
|
|
1223
|
+
return {
|
|
1224
|
+
deleted: true,
|
|
1225
|
+
channelId: payload.channelId
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
async createThread(payload) {
|
|
1229
|
+
const parent = await this.client.channels.fetch(payload.parentChannelId);
|
|
1230
|
+
if (!parent || !parent.isTextBased()) {
|
|
1231
|
+
throw new ActionExecutionError(
|
|
1232
|
+
"NOT_FOUND",
|
|
1233
|
+
`Parent channel "${payload.parentChannelId}" was not found or is not text-based.`
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
if (payload.messageId) {
|
|
1237
|
+
if (!("messages" in parent) || !parent.messages) {
|
|
1238
|
+
throw new ActionExecutionError(
|
|
1239
|
+
"INVALID_REQUEST",
|
|
1240
|
+
`Channel "${payload.parentChannelId}" does not support fetching messages.`
|
|
1241
|
+
);
|
|
1242
|
+
}
|
|
1243
|
+
const msg = await parent.messages.fetch(payload.messageId);
|
|
1244
|
+
const thread2 = await msg.startThread({
|
|
1245
|
+
name: payload.name,
|
|
1246
|
+
...payload.reason ? { reason: payload.reason } : {},
|
|
1247
|
+
...payload.autoArchiveDuration ? { autoArchiveDuration: payload.autoArchiveDuration } : {}
|
|
1248
|
+
});
|
|
1249
|
+
return serializeThread(thread2);
|
|
1250
|
+
}
|
|
1251
|
+
if (!("threads" in parent) || !parent.threads || typeof parent.threads.create !== "function") {
|
|
1252
|
+
throw new ActionExecutionError("INVALID_REQUEST", `Channel "${payload.parentChannelId}" cannot create threads.`);
|
|
1253
|
+
}
|
|
1254
|
+
const threadOptions = Object.assign(
|
|
1255
|
+
{ name: payload.name },
|
|
1256
|
+
payload.type === "private" ? { type: import_discord2.ChannelType.PrivateThread } : {},
|
|
1257
|
+
payload.reason ? { reason: payload.reason } : {},
|
|
1258
|
+
payload.autoArchiveDuration ? { autoArchiveDuration: payload.autoArchiveDuration } : {}
|
|
1259
|
+
);
|
|
1260
|
+
const thread = await parent.threads.create(threadOptions);
|
|
1261
|
+
return serializeThread(thread);
|
|
1262
|
+
}
|
|
1263
|
+
async archiveThread(payload) {
|
|
1264
|
+
const raw = await this.client.channels.fetch(payload.threadId);
|
|
1265
|
+
if (!raw || !raw.isThread()) {
|
|
1266
|
+
throw new ActionExecutionError("NOT_FOUND", `Thread "${payload.threadId}" was not found.`);
|
|
1267
|
+
}
|
|
1268
|
+
await raw.setArchived(payload.archived ?? true, payload.reason);
|
|
1269
|
+
return serializeThread(raw);
|
|
1270
|
+
}
|
|
999
1271
|
};
|
|
1000
1272
|
function createDiscordJsRuntimeAdapter(options) {
|
|
1001
1273
|
return new DiscordJsRuntimeAdapter(options);
|
|
@@ -1017,6 +1289,7 @@ function createConnectionId() {
|
|
|
1017
1289
|
}
|
|
1018
1290
|
|
|
1019
1291
|
// src/bridge/subscriptions.ts
|
|
1292
|
+
var THREAD_CHANNEL_TYPES = /* @__PURE__ */ new Set([10, 11, 12]);
|
|
1020
1293
|
function normalizeStringList(value) {
|
|
1021
1294
|
if (value === void 0) {
|
|
1022
1295
|
return void 0;
|
|
@@ -1025,6 +1298,16 @@ function normalizeStringList(value) {
|
|
|
1025
1298
|
const normalized = [...new Set(rawValues.filter((entry) => typeof entry === "string" && entry.length > 0))].sort();
|
|
1026
1299
|
return normalized.length > 0 ? normalized : void 0;
|
|
1027
1300
|
}
|
|
1301
|
+
function normalizeNumberList(value) {
|
|
1302
|
+
if (value === void 0) {
|
|
1303
|
+
return void 0;
|
|
1304
|
+
}
|
|
1305
|
+
const rawValues = Array.isArray(value) ? value : [value];
|
|
1306
|
+
const normalized = [
|
|
1307
|
+
...new Set(rawValues.filter((entry) => typeof entry === "number" && Number.isFinite(entry)))
|
|
1308
|
+
].sort((a, b) => a - b);
|
|
1309
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
1310
|
+
}
|
|
1028
1311
|
function normalizeKindList(value) {
|
|
1029
1312
|
if (value === void 0) {
|
|
1030
1313
|
return void 0;
|
|
@@ -1046,6 +1329,9 @@ function normalizeEventSubscriptionFilter(filter) {
|
|
|
1046
1329
|
const commandNames = normalizeStringList(filter.commandName);
|
|
1047
1330
|
const customIds = normalizeStringList(filter.customId);
|
|
1048
1331
|
const interactionKinds = normalizeKindList(filter.interactionKind);
|
|
1332
|
+
const channelTypes = normalizeNumberList(filter.channelType);
|
|
1333
|
+
const parentChannelIds = normalizeStringList(filter.parentChannelId);
|
|
1334
|
+
const threadIds = normalizeStringList(filter.threadId);
|
|
1049
1335
|
if (guildIds) {
|
|
1050
1336
|
normalized.guildId = guildIds;
|
|
1051
1337
|
}
|
|
@@ -1064,6 +1350,15 @@ function normalizeEventSubscriptionFilter(filter) {
|
|
|
1064
1350
|
if (interactionKinds) {
|
|
1065
1351
|
normalized.interactionKind = interactionKinds;
|
|
1066
1352
|
}
|
|
1353
|
+
if (channelTypes) {
|
|
1354
|
+
normalized.channelType = channelTypes;
|
|
1355
|
+
}
|
|
1356
|
+
if (parentChannelIds) {
|
|
1357
|
+
normalized.parentChannelId = parentChannelIds;
|
|
1358
|
+
}
|
|
1359
|
+
if (threadIds) {
|
|
1360
|
+
normalized.threadId = threadIds;
|
|
1361
|
+
}
|
|
1067
1362
|
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
1068
1363
|
}
|
|
1069
1364
|
function normalizeEventSubscription(subscription) {
|
|
@@ -1094,6 +1389,24 @@ function matchesKind(value, allowed) {
|
|
|
1094
1389
|
}
|
|
1095
1390
|
return allowed.includes(value);
|
|
1096
1391
|
}
|
|
1392
|
+
function matchesNumberField(value, allowed) {
|
|
1393
|
+
if (!allowed) {
|
|
1394
|
+
return true;
|
|
1395
|
+
}
|
|
1396
|
+
if (value === void 0) {
|
|
1397
|
+
return false;
|
|
1398
|
+
}
|
|
1399
|
+
return allowed.includes(value);
|
|
1400
|
+
}
|
|
1401
|
+
function threadIdFromMessageLike(message) {
|
|
1402
|
+
if (message.channelType === void 0) {
|
|
1403
|
+
return void 0;
|
|
1404
|
+
}
|
|
1405
|
+
if (THREAD_CHANNEL_TYPES.has(message.channelType)) {
|
|
1406
|
+
return message.channelId;
|
|
1407
|
+
}
|
|
1408
|
+
return void 0;
|
|
1409
|
+
}
|
|
1097
1410
|
function eventMetadata(name, payload) {
|
|
1098
1411
|
switch (name) {
|
|
1099
1412
|
case "ready":
|
|
@@ -1101,36 +1414,66 @@ function eventMetadata(name, payload) {
|
|
|
1101
1414
|
case "interactionCreate": {
|
|
1102
1415
|
const interactionPayload = payload;
|
|
1103
1416
|
const ix = interactionPayload.interaction;
|
|
1417
|
+
const threadId = ix.channelId && ix.channelType !== void 0 && THREAD_CHANNEL_TYPES.has(ix.channelType) ? ix.channelId : void 0;
|
|
1104
1418
|
return {
|
|
1105
1419
|
...ix.guildId ? { guildId: ix.guildId } : {},
|
|
1106
1420
|
...ix.channelId ? { channelId: ix.channelId } : {},
|
|
1107
1421
|
userId: ix.user.id,
|
|
1108
1422
|
...ix.commandName ? { commandName: ix.commandName } : {},
|
|
1109
1423
|
...ix.customId ? { customId: ix.customId } : {},
|
|
1110
|
-
interactionKind: ix.kind
|
|
1424
|
+
interactionKind: ix.kind,
|
|
1425
|
+
...ix.channelType !== void 0 ? { channelType: ix.channelType } : {},
|
|
1426
|
+
...ix.parentChannelId ? { parentChannelId: ix.parentChannelId } : {},
|
|
1427
|
+
...threadId ? { threadId } : {}
|
|
1111
1428
|
};
|
|
1112
1429
|
}
|
|
1113
1430
|
case "messageCreate": {
|
|
1114
1431
|
const messagePayload = payload;
|
|
1432
|
+
const msg = messagePayload.message;
|
|
1433
|
+
const threadId = threadIdFromMessageLike(msg);
|
|
1115
1434
|
return {
|
|
1116
|
-
...
|
|
1117
|
-
channelId:
|
|
1118
|
-
...
|
|
1435
|
+
...msg.guildId ? { guildId: msg.guildId } : {},
|
|
1436
|
+
channelId: msg.channelId,
|
|
1437
|
+
...msg.author ? { userId: msg.author.id } : {},
|
|
1438
|
+
...msg.channelType !== void 0 ? { channelType: msg.channelType } : {},
|
|
1439
|
+
...msg.parentChannelId ? { parentChannelId: msg.parentChannelId } : {},
|
|
1440
|
+
...threadId ? { threadId } : {}
|
|
1119
1441
|
};
|
|
1120
1442
|
}
|
|
1121
1443
|
case "messageUpdate": {
|
|
1122
1444
|
const messagePayload = payload;
|
|
1445
|
+
const msg = messagePayload.message;
|
|
1446
|
+
const threadId = threadIdFromMessageLike(msg);
|
|
1123
1447
|
return {
|
|
1124
|
-
...
|
|
1125
|
-
channelId:
|
|
1126
|
-
...
|
|
1448
|
+
...msg.guildId ? { guildId: msg.guildId } : {},
|
|
1449
|
+
channelId: msg.channelId,
|
|
1450
|
+
...msg.author ? { userId: msg.author.id } : {},
|
|
1451
|
+
...msg.channelType !== void 0 ? { channelType: msg.channelType } : {},
|
|
1452
|
+
...msg.parentChannelId ? { parentChannelId: msg.parentChannelId } : {},
|
|
1453
|
+
...threadId ? { threadId } : {}
|
|
1127
1454
|
};
|
|
1128
1455
|
}
|
|
1129
1456
|
case "messageDelete": {
|
|
1130
1457
|
const messagePayload = payload;
|
|
1458
|
+
const msg = messagePayload.message;
|
|
1459
|
+
const threadId = threadIdFromMessageLike(msg);
|
|
1131
1460
|
return {
|
|
1132
|
-
...
|
|
1133
|
-
channelId:
|
|
1461
|
+
...msg.guildId ? { guildId: msg.guildId } : {},
|
|
1462
|
+
channelId: msg.channelId,
|
|
1463
|
+
...msg.channelType !== void 0 ? { channelType: msg.channelType } : {},
|
|
1464
|
+
...msg.parentChannelId ? { parentChannelId: msg.parentChannelId } : {},
|
|
1465
|
+
...threadId ? { threadId } : {}
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
case "messageBulkDelete": {
|
|
1469
|
+
const bulkPayload = payload;
|
|
1470
|
+
const threadId = bulkPayload.channelType !== void 0 && THREAD_CHANNEL_TYPES.has(bulkPayload.channelType) ? bulkPayload.channelId : void 0;
|
|
1471
|
+
return {
|
|
1472
|
+
guildId: bulkPayload.guildId,
|
|
1473
|
+
channelId: bulkPayload.channelId,
|
|
1474
|
+
...bulkPayload.channelType !== void 0 ? { channelType: bulkPayload.channelType } : {},
|
|
1475
|
+
...bulkPayload.parentChannelId ? { parentChannelId: bulkPayload.parentChannelId } : {},
|
|
1476
|
+
...threadId ? { threadId } : {}
|
|
1134
1477
|
};
|
|
1135
1478
|
}
|
|
1136
1479
|
case "messageReactionAdd": {
|
|
@@ -1183,7 +1526,22 @@ function eventMetadata(name, payload) {
|
|
|
1183
1526
|
const threadPayload = payload;
|
|
1184
1527
|
return {
|
|
1185
1528
|
guildId: threadPayload.thread.guildId,
|
|
1186
|
-
...threadPayload.thread.parentId ? { channelId: threadPayload.thread.parentId } : { channelId: threadPayload.thread.id }
|
|
1529
|
+
...threadPayload.thread.parentId ? { channelId: threadPayload.thread.parentId } : { channelId: threadPayload.thread.id },
|
|
1530
|
+
channelType: threadPayload.thread.type,
|
|
1531
|
+
...threadPayload.thread.parentId ? { parentChannelId: threadPayload.thread.parentId } : {},
|
|
1532
|
+
threadId: threadPayload.thread.id
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
case "channelCreate":
|
|
1536
|
+
case "channelUpdate":
|
|
1537
|
+
case "channelDelete": {
|
|
1538
|
+
const channelPayload = payload;
|
|
1539
|
+
const ch = channelPayload.channel;
|
|
1540
|
+
return {
|
|
1541
|
+
...ch.guildId ? { guildId: ch.guildId } : {},
|
|
1542
|
+
channelId: ch.id,
|
|
1543
|
+
channelType: ch.type,
|
|
1544
|
+
...ch.parentId ? { parentChannelId: ch.parentId } : {}
|
|
1187
1545
|
};
|
|
1188
1546
|
}
|
|
1189
1547
|
default:
|
|
@@ -1196,7 +1554,7 @@ function matchesEventSubscription(subscription, payload) {
|
|
|
1196
1554
|
return true;
|
|
1197
1555
|
}
|
|
1198
1556
|
const metadata = eventMetadata(normalized.name, payload);
|
|
1199
|
-
return matchesField(metadata.guildId, normalized.filter.guildId) && matchesField(metadata.channelId, normalized.filter.channelId) && matchesField(metadata.userId, normalized.filter.userId) && matchesField(metadata.commandName, normalized.filter.commandName) && matchesField(metadata.customId, normalized.filter.customId) && matchesKind(metadata.interactionKind, normalized.filter.interactionKind);
|
|
1557
|
+
return matchesField(metadata.guildId, normalized.filter.guildId) && matchesField(metadata.channelId, normalized.filter.channelId) && matchesField(metadata.userId, normalized.filter.userId) && matchesField(metadata.commandName, normalized.filter.commandName) && matchesField(metadata.customId, normalized.filter.customId) && matchesKind(metadata.interactionKind, normalized.filter.interactionKind) && matchesNumberField(metadata.channelType, normalized.filter.channelType) && matchesField(metadata.parentChannelId, normalized.filter.parentChannelId) && matchesField(metadata.threadId, normalized.filter.threadId);
|
|
1200
1558
|
}
|
|
1201
1559
|
|
|
1202
1560
|
// src/bridge/transport/security.ts
|
|
@@ -2359,7 +2717,14 @@ function connectBotBridge(options) {
|
|
|
2359
2717
|
addMemberRole: (payload, sendOptions) => invokeAction("addMemberRole", payload, sendOptions),
|
|
2360
2718
|
removeMemberRole: (payload, sendOptions) => invokeAction("removeMemberRole", payload, sendOptions),
|
|
2361
2719
|
addMessageReaction: (payload, sendOptions) => invokeAction("addMessageReaction", payload, sendOptions),
|
|
2362
|
-
removeOwnMessageReaction: (payload, sendOptions) => invokeAction("removeOwnMessageReaction", payload, sendOptions)
|
|
2720
|
+
removeOwnMessageReaction: (payload, sendOptions) => invokeAction("removeOwnMessageReaction", payload, sendOptions),
|
|
2721
|
+
timeoutMember: (payload, sendOptions) => invokeAction("timeoutMember", payload, sendOptions),
|
|
2722
|
+
removeMemberTimeout: (payload, sendOptions) => invokeAction("removeMemberTimeout", payload, sendOptions),
|
|
2723
|
+
createChannel: (payload, sendOptions) => invokeAction("createChannel", payload, sendOptions),
|
|
2724
|
+
editChannel: (payload, sendOptions) => invokeAction("editChannel", payload, sendOptions),
|
|
2725
|
+
deleteChannel: (payload, sendOptions) => invokeAction("deleteChannel", payload, sendOptions),
|
|
2726
|
+
createThread: (payload, sendOptions) => invokeAction("createThread", payload, sendOptions),
|
|
2727
|
+
archiveThread: (payload, sendOptions) => invokeAction("archiveThread", payload, sendOptions)
|
|
2363
2728
|
};
|
|
2364
2729
|
return {
|
|
2365
2730
|
actions,
|