@spatulox/simplediscordbot 3.2.0 → 4.0.1

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/index.js CHANGED
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
11
  if (from && typeof from === "object" || typeof from === "function") {
@@ -23,37 +23,41 @@ __export(index_exports, {
23
23
  Bot: () => Bot,
24
24
  BotEnv: () => BotEnv,
25
25
  ButtonManager: () => ButtonManager,
26
- CacheManager: () => import_utils22.CacheManager,
26
+ CacheManager: () => import_utils23.CacheManager,
27
27
  ChartManager: () => ChartManager,
28
28
  ComponentManager: () => ComponentManager,
29
29
  DiscordRegex: () => DiscordRegex,
30
30
  EmbedManager: () => EmbedManager,
31
- FileManager: () => import_utils21.FileManager,
31
+ FileManager: () => import_utils22.FileManager,
32
32
  GuildManager: () => GuildManager,
33
- Log: () => import_utils24.Log,
33
+ Log: () => import_utils25.Log,
34
34
  ModalFieldType: () => ModalFieldType,
35
35
  ModalManager: () => ModalManager,
36
+ PaginationManager: () => PaginationManager,
36
37
  ReactionManager: () => ReactionManager,
37
38
  SelectMenuManager: () => SelectMenuManager,
38
39
  SimpleColor: () => SimpleColor,
39
40
  SimpleDiscordBotInfo: () => SimpleDiscordBotInfo,
40
- SimpleMutex: () => import_utils25.SimpleMutex,
41
- Time: () => import_utils23.Time,
41
+ SimpleMutex: () => import_utils26.SimpleMutex,
42
+ Time: () => import_utils24.Time,
42
43
  UserManager: () => UserManager,
43
44
  WebhookManager: () => WebhookManager
44
45
  });
45
46
  module.exports = __toCommonJS(index_exports);
46
47
 
47
48
  // src/core/Bot.ts
48
- var import_discord6 = require("discord.js");
49
+ var import_discord7 = require("discord.js");
49
50
  var import_utils3 = require("@spatulox/utils");
50
51
  var import_utils4 = require("@spatulox/utils");
51
52
  var import_utils5 = require("@spatulox/utils");
52
53
 
53
54
  // src/core/BotLog.ts
54
- var import_discord2 = require("discord.js");
55
+ var import_discord3 = require("discord.js");
55
56
  var import_utils = require("@spatulox/utils");
56
57
 
58
+ // src/manager/builder/SendableComponentBuilder.ts
59
+ var import_discord2 = require("discord.js");
60
+
57
61
  // src/manager/interactible/SelectMenuManager.ts
58
62
  var import_discord = require("discord.js");
59
63
  var SelectMenuManager = class _SelectMenuManager {
@@ -163,11 +167,20 @@ var SelectMenuManager = class _SelectMenuManager {
163
167
  flags: ephemeral ? [import_discord.MessageFlags.Ephemeral] : []
164
168
  };
165
169
  }
166
- static toInteractionEdit(menus) {
170
+ /**
171
+ * Options to edit an existing message : message.edit()
172
+ */
173
+ static toMessageUpdate(menus) {
167
174
  return {
168
175
  components: this._createRowsToReturn(menus)
169
176
  };
170
177
  }
178
+ /**
179
+ * Options for interaction.update() and interaction.editReply() (buttons, select menus, modals, deferred replies)
180
+ */
181
+ static toInteractionUpdate(menus) {
182
+ return this.toMessageUpdate(menus);
183
+ }
171
184
  static _createRowsToReturn(menus) {
172
185
  if (Array.isArray(menus)) {
173
186
  return menus.map(
@@ -178,6 +191,65 @@ var SelectMenuManager = class _SelectMenuManager {
178
191
  }
179
192
  };
180
193
 
194
+ // src/manager/builder/SendableComponentBuilder.ts
195
+ var SendableComponentBuilder = class {
196
+ static isSendableComponent(thing) {
197
+ return thing instanceof import_discord2.EmbedBuilder || thing instanceof import_discord2.ContainerBuilder || thing instanceof import_discord2.BaseSelectMenuBuilder || thing instanceof import_discord2.ActionRowBuilder;
198
+ }
199
+ /**
200
+ * A ContainerBuilder turns the whole message into a Components V2 one
201
+ */
202
+ static isComponentsV2(components) {
203
+ const comps = Array.isArray(components) ? components : [components];
204
+ return comps.some((comp) => comp instanceof import_discord2.ContainerBuilder);
205
+ }
206
+ static build(base, content, components) {
207
+ const comps = (Array.isArray(components) ? components : [components]).filter((comp) => !!comp);
208
+ const componentsV2 = this.isComponentsV2(comps);
209
+ const embeds = [];
210
+ const rows = [];
211
+ if (content) {
212
+ if (componentsV2) {
213
+ rows.push(new import_discord2.TextDisplayBuilder().setContent(content));
214
+ } else {
215
+ base.content = content;
216
+ }
217
+ }
218
+ for (const comp of comps) {
219
+ if (comp instanceof import_discord2.EmbedBuilder) {
220
+ if (componentsV2) {
221
+ throw new Error("An EmbedBuilder cannot be sent alongside a ContainerBuilder (Components V2 messages don't support embeds)");
222
+ }
223
+ embeds.push(comp);
224
+ } else if (SelectMenuManager.isSelectMenuList(comp)) {
225
+ rows.push(SelectMenuManager.row(comp));
226
+ } else if (comp instanceof import_discord2.ContainerBuilder || comp instanceof import_discord2.ActionRowBuilder) {
227
+ rows.push(comp);
228
+ }
229
+ }
230
+ if (embeds.length > 0) base.embeds = embeds;
231
+ if (rows.length > 0) base.components = rows;
232
+ if (componentsV2) base.flags = [import_discord2.MessageFlags.IsComponentsV2];
233
+ return base;
234
+ }
235
+ static buildInteraction(content, component, ephemeral) {
236
+ const base = this.build({}, content, component);
237
+ if (ephemeral) {
238
+ base.flags = [...Array.isArray(base.flags) ? base.flags : [], import_discord2.MessageFlags.Ephemeral];
239
+ }
240
+ return base;
241
+ }
242
+ static buildMessage(contentOrComponent, component) {
243
+ const content = typeof contentOrComponent === "string" ? contentOrComponent : null;
244
+ const components = typeof contentOrComponent === "string" || contentOrComponent === null || contentOrComponent === void 0 ? component : contentOrComponent;
245
+ const hasComponents = Array.isArray(components) ? components.length > 0 : !!components;
246
+ if (!content && !hasComponents) {
247
+ throw new Error("At least content or component need to be defined to build a message");
248
+ }
249
+ return this.build({}, content, components);
250
+ }
251
+ };
252
+
181
253
  // src/core/BotEnv.ts
182
254
  var BotEnv = {
183
255
  get token() {
@@ -186,7 +258,7 @@ var BotEnv = {
186
258
  return token;
187
259
  },
188
260
  get dev() {
189
- return !!process.env.DISCORD_BOT_DEV;
261
+ return ["true", "1"].includes(process.env.DISCORD_BOT_DEV?.trim().toLowerCase() ?? "");
190
262
  }
191
263
  };
192
264
 
@@ -196,10 +268,8 @@ var BotLog = class _BotLog {
196
268
  static warnChannel = null;
197
269
  static debugChannel = null;
198
270
  static errorChannel = null;
199
- constructor() {
200
- }
201
271
  static config() {
202
- return Bot.config.log;
272
+ return Bot.config?.log;
203
273
  }
204
274
  /**
205
275
  * Initialize Discord logging channels and update Bot.log references
@@ -230,91 +300,28 @@ var BotLog = class _BotLog {
230
300
  }
231
301
  }
232
302
  }
233
- /*public static async initDiscordLogging(): Promise<void> {
234
- if (!Bot.client.isReady()) {
235
- Log.warn('Client not ready for Discord logging init');
236
- return;
237
- }
238
-
239
- if (Bot.config.log?.info.channelId) {
240
- try {
241
- const logCh = await Bot.client.channels.fetch(Bot.config.log.info.channelId) as TextChannel;
242
- if (logCh?.isTextBased()) {
243
- BotLog.logChannel = logCh;
244
- } else {
245
- Log.warn(`Log channel ${Bot.config.log.info.channelId} invalid`);
246
- }
247
- } catch (error) {
248
- Log.error(`Log channel fetch failed: ${error}`);
249
- }
250
- }
251
-
252
- if (Bot.config.log?.warn.channelId) {
253
- try {
254
- const errorCh = await Bot.client.channels.fetch(Bot.config.log.warn.channelId) as TextChannel;
255
- if (errorCh?.isTextBased()) {
256
- BotLog.warnChannel = errorCh;
257
- } else {
258
- Log.warn(`Warn channel ${Bot.config.log.warn.channelId} invalid`);
259
- }
260
- } catch (error) {
261
- Log.error(`Warn channel fetch failed: ${error}`);
262
- }
263
- }
264
-
265
- if (Bot.config.log?.error.channelId) {
266
- try {
267
- const errorCh = await Bot.client.channels.fetch(Bot.config.log.error.channelId) as TextChannel;
268
- if (errorCh?.isTextBased()) {
269
- BotLog.errorChannel = errorCh;
270
- } else {
271
- Log.warn(`Error channel ${Bot.config.log.error.channelId} invalid`);
272
- }
273
- } catch (error) {
274
- Log.error(`Error channel fetch failed: ${error}`);
275
- }
276
- }
277
-
278
- if (Bot.config.log?.debug.channelId) {
279
- try {
280
- const errorCh = await Bot.client.channels.fetch(Bot.config.log.debug.channelId) as TextChannel;
281
- if (errorCh?.isTextBased()) {
282
- BotLog.debugChannel = errorCh;
283
- } else {
284
- Log.warn(`Debug channel ${Bot.config.log.debug.channelId} invalid`);
285
- }
286
- } catch (error) {
287
- Log.error(`Debug channel fetch failed: ${error}`);
288
- }
289
- }
290
- }*/
291
303
  /**
292
304
  * Send content to specific Discord channel
293
305
  */
294
306
  static async _sendToChannel(channel, content, prefix = "info") {
295
307
  if (!channel) return;
296
- let msg;
297
308
  try {
298
- if (content instanceof import_discord2.EmbedBuilder) {
299
- const text = content.data.description ?? content.data.title;
300
- if (text) {
301
- import_utils.Log.info(text);
302
- }
303
- msg = await channel.send({ embeds: [content] });
304
- } else if (SelectMenuManager.isSelectMenuList(content)) {
305
- msg = await channel.send({ components: SelectMenuManager.rows(content) });
306
- } else if (content instanceof import_discord2.ContainerBuilder) {
307
- msg = await channel.send({ components: [content], flags: import_discord2.MessageFlags.IsComponentsV2 });
308
- } else if (content instanceof import_discord2.ActionRowBuilder) {
309
- msg = await channel.send({ components: [content] });
310
- } else {
309
+ if (typeof content === "string") {
311
310
  const timestamp = `\`${(/* @__PURE__ */ new Date()).toISOString()}\``;
312
- msg = await channel.send(`[${timestamp}] [${prefix.toUpperCase()}] ${content}`);
311
+ return await channel.send(`[${timestamp}] [${prefix.toUpperCase()}] ${content}`);
313
312
  }
313
+ return await channel.send(SendableComponentBuilder.buildMessage(content));
314
314
  } catch (error) {
315
315
  import_utils.Log.error(`Failed to send to Discord channel: ${error}`);
316
316
  }
317
- return msg;
317
+ }
318
+ /**
319
+ * Text printed in the console : the string itself, or the description / title of an embed
320
+ */
321
+ static _consoleText(content) {
322
+ if (typeof content === "string") return content;
323
+ if (content instanceof import_discord3.EmbedBuilder) return content.data.description ?? content.data.title ?? null;
324
+ return null;
318
325
  }
319
326
  /**
320
327
  * Send INFO log - TEXT or EMBED ! Respecte config.log.info
@@ -322,8 +329,9 @@ var BotLog = class _BotLog {
322
329
  static async info(content) {
323
330
  const logConfig = Bot.config?.log;
324
331
  if (!logConfig || logConfig.info.console) {
325
- if (typeof content == "string") {
326
- import_utils.Log.info(content);
332
+ const text = this._consoleText(content);
333
+ if (text) {
334
+ import_utils.Log.info(text);
327
335
  }
328
336
  }
329
337
  if (logConfig?.info.discord && this.logChannel) {
@@ -334,10 +342,11 @@ var BotLog = class _BotLog {
334
342
  * Send ERROR log - TEXT or EMBED ! Respecte config.log.error
335
343
  */
336
344
  static async error(content) {
337
- const logConfig = Bot.config.log;
345
+ const logConfig = Bot.config?.log;
338
346
  if (!logConfig || logConfig.error.console) {
339
- if (typeof content == "string") {
340
- import_utils.Log.error(content);
347
+ const text = this._consoleText(content);
348
+ if (text) {
349
+ import_utils.Log.error(text);
341
350
  }
342
351
  }
343
352
  if (logConfig?.error.discord && this.errorChannel) {
@@ -348,10 +357,11 @@ var BotLog = class _BotLog {
348
357
  * Send WARNING log - TEXT or EMBED ! Respecte config.log.warn
349
358
  */
350
359
  static async warn(content) {
351
- const logConfig = Bot.config.log;
360
+ const logConfig = Bot.config?.log;
352
361
  if (!logConfig || logConfig?.warn.console) {
353
- if (typeof content == "string") {
354
- import_utils.Log.warn(content);
362
+ const text = this._consoleText(content);
363
+ if (text) {
364
+ import_utils.Log.warn(text);
355
365
  }
356
366
  }
357
367
  if (logConfig?.warn.discord && this.warnChannel) {
@@ -363,10 +373,11 @@ var BotLog = class _BotLog {
363
373
  */
364
374
  static async debug(content) {
365
375
  if (!BotEnv.dev) return;
366
- const logConfig = Bot.config.log;
376
+ const logConfig = Bot.config?.log;
367
377
  if (!logConfig || logConfig?.debug.console) {
368
- if (typeof content == "string") {
369
- import_utils.Log.debug(content);
378
+ const text = this._consoleText(content);
379
+ if (text) {
380
+ import_utils.Log.debug(text);
370
381
  }
371
382
  }
372
383
  if (logConfig?.debug.discord && this.debugChannel) {
@@ -376,7 +387,7 @@ var BotLog = class _BotLog {
376
387
  };
377
388
 
378
389
  // src/manager/messages/EmbedManager.ts
379
- var import_discord3 = require("discord.js");
390
+ var import_discord4 = require("discord.js");
380
391
 
381
392
  // src/constants/SimpleColor.ts
382
393
  var SimpleColor = /* @__PURE__ */ ((SimpleColor2) => {
@@ -426,13 +437,13 @@ var EmbedManager = class {
426
437
  return Bot.client?.user?.displayAvatarURL({ forceStatic: false, size: 128 }) || "";
427
438
  }
428
439
  static get DEFAULT_COLOR() {
429
- return Bot.config.defaultSimpleColor || 6064856 /* default */;
440
+ return Bot.config?.defaultSimpleColor ?? 6064856 /* default */;
430
441
  }
431
442
  /**
432
443
  * Creates base embed - SAME SIMPLE API !
433
444
  */
434
445
  static create(color = null) {
435
- const embed = new import_discord3.EmbedBuilder().setTimestamp(/* @__PURE__ */ new Date());
446
+ const embed = new import_discord4.EmbedBuilder().setTimestamp(/* @__PURE__ */ new Date());
436
447
  const colorC = color ?? this.DEFAULT_COLOR;
437
448
  if (colorC !== "transparent" /* transparent */) {
438
449
  embed.setColor(colorC);
@@ -451,38 +462,38 @@ var EmbedManager = class {
451
462
  /**
452
463
  * Creates simple embed with just description
453
464
  */
454
- static simple(description, color = null) {
455
- return this.create(color).setDescription(description);
465
+ static simple(description2, color = null) {
466
+ return this.create(color).setDescription(description2);
456
467
  }
457
468
  /**
458
469
  * Creates error embed
459
470
  */
460
- static error(description) {
461
- return this.create(8912917 /* error */).setTitle("Something went Wrong").setDescription(description);
471
+ static error(description2) {
472
+ return this.create(8912917 /* error */).setTitle("Something went Wrong").setDescription(description2);
462
473
  }
463
474
  /**
464
475
  * Creates success embed
465
476
  */
466
- static success(description) {
467
- return this.create(25600 /* minecraft */).setTitle("Success").setDescription(description);
477
+ static success(description2) {
478
+ return this.create(25600 /* minecraft */).setTitle("Success").setDescription(description2);
468
479
  }
469
480
  /**
470
481
  * Creates a simple description embed
471
482
  */
472
- static description(description) {
473
- return this.create().setDescription(description).setFooter(null).setTimestamp(null);
483
+ static description(description2) {
484
+ return this.create().setDescription(description2).setFooter(null).setTimestamp(null);
474
485
  }
475
486
  /**
476
487
  * Creates debug embed
477
488
  */
478
- static debug(description) {
479
- return this.create(65280 /* green */).setTitle("Debug").setDescription(description);
489
+ static debug(description2) {
490
+ return this.create(65280 /* green */).setTitle("Debug").setDescription(description2);
480
491
  }
481
492
  /**
482
493
  * Defer ephemeral reply
483
494
  */
484
495
  static deferEphemeral() {
485
- return { flags: import_discord3.MessageFlags.Ephemeral };
496
+ return { flags: import_discord4.MessageFlags.Ephemeral };
486
497
  }
487
498
  /**
488
499
  * Quick field adder
@@ -502,17 +513,23 @@ var EmbedManager = class {
502
513
  static toInteraction(embed, ephemeral = false) {
503
514
  return {
504
515
  embeds: [embed],
505
- flags: ephemeral ? [import_discord3.MessageFlags.Ephemeral] : []
516
+ flags: ephemeral ? [import_discord4.MessageFlags.Ephemeral] : []
506
517
  };
507
518
  }
508
519
  /**
509
- * Transform embed into objet for interaction.editReply()
520
+ * Options to edit an existing message : message.edit()
510
521
  */
511
- static toInteractionEdit(embed) {
522
+ static toMessageUpdate(embed) {
512
523
  return {
513
524
  embeds: [embed]
514
525
  };
515
526
  }
527
+ /**
528
+ * Options for interaction.update() and interaction.editReply() (buttons, select menus, modals, deferred replies)
529
+ */
530
+ static toInteractionUpdate(embed) {
531
+ return this.toMessageUpdate(embed);
532
+ }
516
533
  /**
517
534
  * Transform embed into objet to send a message
518
535
  */
@@ -526,67 +543,6 @@ var EmbedManager = class {
526
543
  // src/core/BotMessage.ts
527
544
  var import_discord5 = require("discord.js");
528
545
  var import_utils2 = require("@spatulox/utils");
529
-
530
- // src/manager/builder/SendableComponentBuilder.ts
531
- var import_discord4 = require("discord.js");
532
- var import_builders = require("@discordjs/builders");
533
- var SendableComponentBuilder = class {
534
- static isSendableComponent(thing) {
535
- return thing instanceof import_discord4.EmbedBuilder || thing instanceof import_discord4.ContainerBuilder || thing instanceof import_builders.BaseSelectMenuBuilder || thing instanceof import_discord4.ActionRowBuilder;
536
- }
537
- static build(base, content, components) {
538
- if (content) {
539
- base.content = content;
540
- }
541
- const comps = Array.isArray(components) ? components : [components].filter(Boolean);
542
- for (const comp of comps) {
543
- base.embeds = base.embeds || [];
544
- base.components = base.components || [];
545
- if (comp instanceof import_discord4.EmbedBuilder) {
546
- base.embeds.push(comp);
547
- }
548
- if (SelectMenuManager.isSelectMenuList(comp)) {
549
- base.components.push(SelectMenuManager.row(comp));
550
- }
551
- if (comp instanceof import_discord4.ContainerBuilder) {
552
- base.components.push(comp);
553
- }
554
- if (comp instanceof import_discord4.ActionRowBuilder) {
555
- base.components.push(comp);
556
- }
557
- }
558
- return base;
559
- }
560
- static buildInteraction(content, component, ephemeral) {
561
- let base = {};
562
- this.build(base, content, component);
563
- if (ephemeral) {
564
- base.flags = [import_discord4.MessageFlags.Ephemeral];
565
- }
566
- return base;
567
- }
568
- static buildMessage(contentOrComponent, component) {
569
- let base = {};
570
- if (typeof contentOrComponent === "string" && !component) {
571
- return this.build(base, contentOrComponent);
572
- }
573
- if (typeof contentOrComponent !== "string" && !component) {
574
- if (contentOrComponent instanceof import_discord4.ContainerBuilder) {
575
- base.flags = [import_discord4.MessageFlags.IsComponentsV2];
576
- }
577
- return this.build(base, null, contentOrComponent);
578
- }
579
- if (typeof contentOrComponent == "string" && component) {
580
- if (component instanceof import_discord4.ContainerBuilder) {
581
- base.flags = [import_discord4.MessageFlags.IsComponentsV2];
582
- }
583
- return this.build(base, contentOrComponent, component);
584
- }
585
- throw new Error("At least content or component need to be defined to build a message");
586
- }
587
- };
588
-
589
- // src/core/BotMessage.ts
590
546
  var BotMessage = class {
591
547
  static async send(channel, content, component) {
592
548
  try {
@@ -595,42 +551,34 @@ var BotMessage = class {
595
551
  return null;
596
552
  }
597
553
  if (typeof channel === "string") {
598
- const fetchedChannel = Bot.client.channels.cache.get(channel);
554
+ const fetchedChannel = Bot.client.channels.cache.get(channel) ?? await Bot.client.channels.fetch(channel).catch(() => null);
599
555
  if (!fetchedChannel?.isTextBased()) {
600
556
  import_utils2.Log.warn(`Cannot send message : Invalid channel ID: ${channel}`);
601
557
  return null;
602
558
  }
603
559
  channel = fetchedChannel;
604
560
  }
605
- let messageCreate;
606
- if (typeof content !== "string" && !component) {
607
- if (SendableComponentBuilder.isSendableComponent(content)) {
608
- messageCreate = SendableComponentBuilder.buildMessage(content);
609
- } else {
610
- messageCreate = content;
611
- }
612
- } else {
613
- content = content;
614
- if (content && component) {
615
- messageCreate = SendableComponentBuilder.buildMessage(content, component);
616
- } else if (content) {
617
- messageCreate = SendableComponentBuilder.buildMessage(content);
618
- } else if (component) {
619
- messageCreate = SendableComponentBuilder.buildMessage(component);
620
- } else {
621
- throw new Error("Cannot send message : content and component cannot be null at the same time");
622
- }
623
- }
624
- try {
625
- return await channel.send(messageCreate);
626
- } catch (e) {
627
- throw e;
628
- }
561
+ return await channel.send(this.buildPayload(content, component));
629
562
  } catch (e) {
630
563
  import_utils2.Log.error(`Cannot send message : ${e}`);
631
564
  return null;
632
565
  }
633
566
  }
567
+ static buildPayload(content, component) {
568
+ if (typeof content === "string") {
569
+ return component ? SendableComponentBuilder.buildMessage(content, component) : SendableComponentBuilder.buildMessage(content);
570
+ }
571
+ if (content === null || content === void 0) {
572
+ if (!component) {
573
+ throw new Error("Cannot send message : content and component cannot be null at the same time");
574
+ }
575
+ return SendableComponentBuilder.buildMessage(component);
576
+ }
577
+ if (SendableComponentBuilder.isSendableComponent(content) || Array.isArray(content)) {
578
+ return SendableComponentBuilder.buildMessage(content);
579
+ }
580
+ return content;
581
+ }
634
582
  static async sendDM(userOrId, content, component) {
635
583
  try {
636
584
  if (!userOrId) {
@@ -648,17 +596,7 @@ var BotMessage = class {
648
596
  }
649
597
  targetUser = fetchedUser;
650
598
  }
651
- let messageCreate;
652
- if (typeof content === "string" && component) {
653
- messageCreate = SendableComponentBuilder.buildMessage(content, component);
654
- } else if (typeof content === "string") {
655
- messageCreate = SendableComponentBuilder.buildMessage(content);
656
- } else if (SendableComponentBuilder.isSendableComponent(content)) {
657
- messageCreate = SendableComponentBuilder.buildMessage(content);
658
- } else {
659
- messageCreate = content;
660
- }
661
- return await targetUser.send(messageCreate);
599
+ return await targetUser.send(this.buildPayload(content, component));
662
600
  } catch (error) {
663
601
  import_utils2.Log.error(`Cannot send DM to ${userOrId}: ${error}`);
664
602
  return null;
@@ -670,9 +608,9 @@ var BotMessage = class {
670
608
  static success(channel, message) {
671
609
  const embed = EmbedManager.success(message);
672
610
  if (channel instanceof import_discord5.User || channel instanceof import_discord5.GuildMember) {
673
- return this.sendDM(channel, message, embed);
611
+ return this.sendDM(channel, embed);
674
612
  }
675
- return this.send(channel, message, embed);
613
+ return this.send(channel, embed);
676
614
  }
677
615
  /**
678
616
  * Quick error message
@@ -680,62 +618,62 @@ var BotMessage = class {
680
618
  static error(channel, message) {
681
619
  const embed = EmbedManager.error(message);
682
620
  if (channel instanceof import_discord5.User || channel instanceof import_discord5.GuildMember) {
683
- return this.sendDM(channel, message, embed);
621
+ return this.sendDM(channel, embed);
684
622
  }
685
- return this.send(channel, message, embed);
623
+ return this.send(channel, embed);
686
624
  }
687
625
  };
688
626
 
689
627
  // src/core/BotInteraction.ts
628
+ var import_discord6 = require("discord.js");
690
629
  var BotInteraction = class {
691
630
  /**
692
631
  * InteractionReplyOptions && InteractionUpdateOptions
693
632
  * The two have "content", "embeds" & "flags" field, so an internal cast is ok, unless discord/discordjs deprecate it
694
633
  */
695
634
  static buildReplyOptions(content, component, ephemeral) {
696
- return this._buildOptions(content, component, ephemeral);
635
+ return SendableComponentBuilder.buildInteraction(content, component, ephemeral);
697
636
  }
698
637
  static buildUpdateOptions(content, component) {
699
- return this._buildOptions(content, component, false);
638
+ return SendableComponentBuilder.buildInteraction(content, component, false);
700
639
  }
701
- static _buildOptions(content, component, ephemeral) {
702
- return SendableComponentBuilder.buildInteraction(content, component, ephemeral);
640
+ /**
641
+ * Normalize the (content, component, ephemeral) overloads :
642
+ * (string, ephemeral?) | (component, ephemeral?) | (string, component, ephemeral?)
643
+ */
644
+ static resolveArgs(content, component, ephemeral) {
645
+ if (typeof content === "string") {
646
+ if (typeof component === "boolean") {
647
+ return this.buildReplyOptions(content, null, component);
648
+ }
649
+ return this.buildReplyOptions(content, component ?? null, ephemeral);
650
+ }
651
+ return this.buildReplyOptions(null, content, typeof component === "boolean" ? component : ephemeral);
703
652
  }
704
- static async send(interaction, content, component = false, ephemeral = false) {
653
+ static async send(interaction, content, component, ephemeral = false) {
705
654
  if (!interaction.isRepliable()) return false;
706
- const options = this.buildReplyOptions(
707
- typeof content === "string" ? content : null,
708
- typeof content === "string" ? component : content,
709
- typeof content === "string" ? ephemeral : component
710
- );
655
+ const options = this.resolveArgs(content, component, ephemeral);
711
656
  if (!interaction.deferred && !interaction.replied) {
712
657
  return await interaction.reply(options);
713
658
  } else {
714
659
  return await interaction.followUp(options);
715
660
  }
716
661
  }
717
- static async reply(interaction, content, component = false, ephemeral = false) {
662
+ static async reply(interaction, content, component, ephemeral = false) {
718
663
  if (!interaction.isRepliable()) return false;
719
- const options = this.buildReplyOptions(
720
- typeof content === "string" ? content : "",
721
- typeof content === "string" ? component : content,
722
- typeof content === "string" ? ephemeral : component
723
- );
724
- return await interaction.reply(options);
725
- }
726
- static async followUp(interaction, content, component = false, ephemeral = false) {
727
- if (!interaction.isMessageComponent()) return false;
728
- const options = this.buildReplyOptions(
729
- typeof content === "string" ? content : "",
730
- typeof content === "string" ? component : content,
731
- typeof content === "string" ? ephemeral : component
732
- );
733
- return await interaction.followUp(options);
664
+ return await interaction.reply(this.resolveArgs(content, component, ephemeral));
665
+ }
666
+ static async followUp(interaction, content, component, ephemeral = false) {
667
+ if (!interaction.isRepliable()) return false;
668
+ return await interaction.followUp(this.resolveArgs(content, component, ephemeral));
734
669
  }
735
- static async defer(interaction) {
670
+ /**
671
+ * @param ephemeral Only used by commands : components and modals defer the message they come from
672
+ */
673
+ static async defer(interaction, ephemeral = false) {
736
674
  if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
737
675
  if (!interaction.deferred && !interaction.replied) {
738
- return await interaction.deferReply();
676
+ return await interaction.deferReply(ephemeral ? { flags: import_discord6.MessageFlags.Ephemeral } : void 0);
739
677
  }
740
678
  return;
741
679
  }
@@ -747,81 +685,37 @@ var BotInteraction = class {
747
685
  }
748
686
  static async update(interaction, content, component) {
749
687
  const options = this.buildUpdateOptions(
750
- typeof content === "string" ? content : "",
751
- typeof content === "string" ? component : content
688
+ typeof content === "string" ? content : null,
689
+ typeof content === "string" ? component ?? null : content
752
690
  );
691
+ if (!interaction.isRepliable()) return false;
692
+ if (interaction.deferred || interaction.replied) {
693
+ return await interaction.editReply(options);
694
+ }
753
695
  if (interaction.isMessageComponent()) {
754
696
  return await interaction.update(options);
755
697
  }
756
- if (!interaction.isCommand()) return false;
757
- if (interaction.deferred || interaction.replied) {
758
- return await interaction.editReply(options);
698
+ if (interaction.isModalSubmit() && interaction.isFromMessage()) {
699
+ return await interaction.update(options);
759
700
  }
760
701
  return false;
761
702
  }
762
703
  };
763
704
 
764
705
  // package.json
765
- var package_default = {
766
- name: "@spatulox/simplediscordbot",
767
- version: "3.1.2",
768
- author: "Spatulox",
769
- description: "Simple discord bot framework to set up a bot under 30 secondes",
770
- exports: {
771
- types: "./dist/index.d.ts",
772
- import: "./dist/index.js",
773
- require: "./dist/index.js"
774
- },
775
- types: "./dist/index.d.ts",
776
- scripts: {
777
- "type-check": "tsc --noEmit",
778
- build: "npm run type-check && rm -rf ./dist/ && tsup",
779
- dev: "npm run type-check && tsx watch src/test/index.ts",
780
- patch: "npm run build && npm version patch",
781
- minor: "npm run build && npm version minor",
782
- major: "npm run build && npm version major",
783
- "pub:patch": "npm run patch && npm publish --access public",
784
- "pub:minor": "npm run minor && npm publish --access public",
785
- "pub:major": "npm run major && npm publish --access public"
786
- },
787
- license: "MIT",
788
- dependencies: {
789
- "@spatulox/discord-interaction-manager": "^2.4.0",
790
- "@spatulox/utils": "^0.2.0"
791
- },
792
- peerDependencies: {
793
- "discord.js": "^14.26.0"
794
- },
795
- devDependencies: {
796
- "@types/node": "^22.14.0",
797
- "@types/node-schedule": "^2.1.7",
798
- "discord.js": "^14.26.0",
799
- dotenv: "^17.2.4",
800
- tsup: "^8.5.1",
801
- tsx: "^4.20.3",
802
- typescript: "^5.9.3"
803
- },
804
- keywords: [
805
- "discord",
806
- "framework",
807
- "bot",
808
- "client",
809
- "discordjs",
810
- "discord.js",
811
- "node"
812
- ],
813
- bugs: {
814
- url: "https://github.com/spatulox-discord/SimpleDiscordBot/issues"
815
- }
816
- };
706
+ var name = "@spatulox/simplediscordbot";
707
+ var version = "4.0.0";
708
+ var author = "Spatulox";
709
+ var description = "Simple discord bot framework to set up a bot under 30 secondes";
710
+ var license = "MIT";
817
711
 
818
712
  // src/SimpleDiscordBotInfo.ts
819
713
  var SimpleDiscordBotInfo = {
820
- name: package_default.name,
821
- version: package_default.version,
822
- author: package_default.author,
823
- description: package_default.description,
824
- license: package_default.license
714
+ name,
715
+ version,
716
+ author,
717
+ description,
718
+ license
825
719
  };
826
720
 
827
721
  // src/core/Bot.ts
@@ -832,8 +726,9 @@ var Bot = class _Bot {
832
726
  static interaction = BotInteraction;
833
727
  // Instance properties
834
728
  static _client;
835
- static criticConfig;
729
+ static token;
836
730
  static _config;
731
+ static randomActivityInterval = null;
837
732
  get config() {
838
733
  return _Bot._config;
839
734
  }
@@ -846,34 +741,41 @@ var Bot = class _Bot {
846
741
  static get config() {
847
742
  return _Bot._config;
848
743
  }
744
+ /**
745
+ * Resolves once the login is done (true) or has definitively failed (false)
746
+ */
747
+ started;
849
748
  constructor(client, config = {}) {
850
749
  import_utils4.Log.info("----------------------------------------------------");
851
750
  import_utils4.Log.info("Starting Bot");
852
- _Bot.criticConfig = { dev: BotEnv.dev, token: BotEnv.token };
751
+ _Bot.token = BotEnv.token;
853
752
  _Bot._config = config;
854
753
  _Bot._client = client;
855
- (async () => {
856
- import_utils4.Log.info(`Using discord.js version: ${import_discord6.version}`);
754
+ _Bot._client.once(import_discord7.Events.ClientReady, async () => {
755
+ if (_Bot._client.user) {
756
+ await _Bot.log.initDiscordLogging();
757
+ import_utils4.Log.info(`Connected on ${_Bot._client.guilds.cache.size} servers as ${_Bot._client.user.tag}`);
758
+ _Bot.log.info(EmbedManager.description("Bot Started"));
759
+ }
760
+ });
761
+ this.started = (async () => {
762
+ import_utils4.Log.info(`Using discord.js version: ${import_discord7.version}`);
857
763
  import_utils4.Log.info(`Using simplediscordbot version: ${SimpleDiscordBotInfo.version}`);
858
764
  import_utils4.Log.info("Trying to connect to Discord Servers");
859
765
  await import_utils5.InternetChecker.checkConnection(3);
860
- await this.login();
861
- })();
766
+ return await this.login();
767
+ })().catch((error) => {
768
+ import_utils4.Log.error(`Failed to start the bot: ${error}`);
769
+ return false;
770
+ });
862
771
  }
863
772
  async login(maxTries = 3) {
864
- let success = false;
773
+ if (_Bot._client.isReady()) return true;
865
774
  let tries = 0;
866
- while (!success && tries < maxTries) {
775
+ while (tries < maxTries) {
867
776
  try {
868
- await _Bot._client.login(_Bot.criticConfig.token);
869
- success = true;
870
- _Bot._client.on(import_discord6.Events.ClientReady, async () => {
871
- if (_Bot._client.user) {
872
- await _Bot.log.initDiscordLogging();
873
- import_utils4.Log.info(`Connected on ${_Bot._client.guilds.cache.size} servers as ${_Bot._client.user.tag}`);
874
- _Bot.log.info(EmbedManager.description("Bot Started"));
875
- }
876
- });
777
+ await _Bot._client.login(_Bot.token);
778
+ return true;
877
779
  } catch (error) {
878
780
  import_utils4.Log.error(`Connection error : ${error}. Trying again...`);
879
781
  tries++;
@@ -882,11 +784,8 @@ var Bot = class _Bot {
882
784
  );
883
785
  }
884
786
  }
885
- if (!success) {
886
- import_utils4.Log.error("Impossible to connect the bot after 3 attempts");
887
- return false;
888
- }
889
- return true;
787
+ import_utils4.Log.error(`Impossible to connect the bot after ${maxTries} attempts`);
788
+ return false;
890
789
  }
891
790
  static setActivity(message, type) {
892
791
  if (_Bot._client.user) {
@@ -899,6 +798,7 @@ var Bot = class _Bot {
899
798
  import_utils4.Log.error("Bot.randomActivity = [{}] is empty");
900
799
  return;
901
800
  }
801
+ _Bot.stopRandomActivity();
902
802
  const pickRandom = () => {
903
803
  const random = randomActivity[Math.floor(Math.random() * randomActivity.length)];
904
804
  _Bot.setActivity(random.message, random.type);
@@ -910,32 +810,40 @@ var Bot = class _Bot {
910
810
  return;
911
811
  }
912
812
  pickRandom();
913
- setInterval(async () => {
914
- pickRandom();
915
- }, intervalMs);
916
- import_utils4.Log.info(`Random activity started (every ${Math.round(intervalMs / 6e4)}min)`);
813
+ _Bot.randomActivityInterval = setInterval(pickRandom, intervalMs);
814
+ import_utils4.Log.info(`Random activity started (every ${intervalMs >= 6e4 ? `${Math.round(intervalMs / 6e4)}min` : `${Math.round(intervalMs / 1e3)}s`})`);
917
815
  return;
918
816
  }
817
+ /**
818
+ * Stop the rotation started by setRandomActivity(), the current activity is kept
819
+ */
820
+ static stopRandomActivity() {
821
+ if (_Bot.randomActivityInterval) {
822
+ clearInterval(_Bot.randomActivityInterval);
823
+ _Bot.randomActivityInterval = null;
824
+ }
825
+ }
919
826
  };
920
827
 
921
828
  // src/index.ts
922
- var import_utils21 = require("@spatulox/utils");
923
829
  var import_utils22 = require("@spatulox/utils");
830
+ var import_utils23 = require("@spatulox/utils");
924
831
 
925
832
  // src/manager/messages/WebhookManager.ts
926
- var import_discord7 = require("discord.js");
833
+ var import_discord8 = require("discord.js");
927
834
  var import_promises = require("fs/promises");
928
835
  var import_path = require("path");
929
836
  var WebhookManager = class {
930
- constructor(client, name, avatarPathOrUrl) {
837
+ constructor(client, name2, avatarPathOrUrl) {
931
838
  this.client = client;
932
- this.name = name;
839
+ this.name = name2;
933
840
  this.avatarPathOrUrl = avatarPathOrUrl;
934
841
  }
935
842
  client;
936
843
  name;
937
844
  avatarPathOrUrl;
938
- webhook = null;
845
+ /** One webhook per channel id (the parent channel id for threads) */
846
+ webhooks = /* @__PURE__ */ new Map();
939
847
  async getAvatar() {
940
848
  if (!this.avatarPathOrUrl) return null;
941
849
  if (this.avatarPathOrUrl.startsWith("http://") || this.avatarPathOrUrl.startsWith("https://")) {
@@ -957,48 +865,52 @@ var WebhookManager = class {
957
865
  if (!channel) {
958
866
  throw new Error(`Channel ${channelId} not found`);
959
867
  }
960
- if (!(channel instanceof import_discord7.TextChannel) && !(channel instanceof import_discord7.ThreadChannel)) {
868
+ if (!(channel instanceof import_discord8.TextChannel) && !(channel instanceof import_discord8.ThreadChannel)) {
961
869
  throw new Error(`Channel ${channelId} is not a TextChannel nor a ThreadChannel`);
962
870
  }
963
871
  return channel;
964
872
  }
965
873
  /**
966
- * Get or create webhook (lazy initialization)
874
+ * Channel owning the webhook : the parent channel when targeting a thread
875
+ */
876
+ getWebhookChannel(channel) {
877
+ if (!(channel instanceof import_discord8.ThreadChannel)) return channel;
878
+ const parent = channel.parent;
879
+ if (!parent || !(parent instanceof import_discord8.BaseGuildTextChannel) && !(parent instanceof import_discord8.ThreadOnlyChannel)) {
880
+ throw new Error("Targeted channel parent is not a BaseGuildTextChannel or ThreadOnlyChannel");
881
+ }
882
+ return parent;
883
+ }
884
+ /**
885
+ * Get or create webhook (lazy initialization, cached per channel)
967
886
  * Create the webhook in the parent channel if it's in a thread
968
887
  */
969
- async getWebhook(channelId) {
970
- if (this.webhook) return this.webhook;
888
+ async getWebhook(channel) {
971
889
  try {
972
- const textThreadChannel = await this.getChannel(channelId);
973
- let textChannel;
974
- if (textThreadChannel instanceof import_discord7.ThreadChannel) {
975
- const parent = textThreadChannel.parent;
976
- if (!parent || !(parent instanceof import_discord7.BaseGuildTextChannel) && !(parent instanceof import_discord7.ThreadOnlyChannel)) {
977
- throw new Error("Targeted channel parent is not a BaseGuildTextChannel or ThreadOnlyChannel");
978
- }
979
- textChannel = parent;
980
- } else {
981
- textChannel = textThreadChannel;
982
- }
890
+ const textChannel = this.getWebhookChannel(channel);
891
+ const cached = this.webhooks.get(textChannel.id);
892
+ if (cached) return cached;
983
893
  const webhooks = await textChannel.fetchWebhooks();
984
- this.webhook = webhooks.find(
894
+ const webhook = webhooks.find(
985
895
  (h) => h.name === this.name && h.owner?.id === this.client.user?.id
986
896
  ) ?? await textChannel.createWebhook({
987
897
  name: this.name,
988
898
  avatar: await this.getAvatar(),
989
899
  reason: "Auto-created by WebhookManager"
990
900
  });
991
- Bot.log.debug(`Webhook ${this.webhook.id} ready for channel ${channelId}`);
992
- return this.webhook;
901
+ this.webhooks.set(textChannel.id, webhook);
902
+ Bot.log.debug(`Webhook ${webhook.id} ready for channel ${channel.id}`);
903
+ return webhook;
993
904
  } catch (error) {
994
- Bot.log.error(`Failed to setup webhook for ${channelId}: ${error}`);
905
+ Bot.log.error(`Failed to setup webhook for ${channel.id}: ${error}`);
995
906
  throw error;
996
907
  }
997
908
  }
998
909
  async send(channelId, content) {
999
- const webhook = await this.getWebhook(channelId);
910
+ const channel = await this.getChannel(channelId);
911
+ const webhook = await this.getWebhook(channel);
1000
912
  let options = {};
1001
- if (SendableComponentBuilder.isSendableComponent(content)) {
913
+ if (SendableComponentBuilder.isSendableComponent(content) || Array.isArray(content)) {
1002
914
  options = SendableComponentBuilder.buildMessage(content);
1003
915
  } else if (typeof content === "string") {
1004
916
  options.content = content;
@@ -1007,8 +919,7 @@ var WebhookManager = class {
1007
919
  } else {
1008
920
  options.content = String(content);
1009
921
  }
1010
- const channelType = await this.getChannel(channelId);
1011
- if (channelType instanceof import_discord7.ThreadChannel) {
922
+ if (channel instanceof import_discord8.ThreadChannel) {
1012
923
  options.threadId = channelId;
1013
924
  }
1014
925
  try {
@@ -1034,10 +945,13 @@ var WebhookManager = class {
1034
945
  * Delete webhook
1035
946
  */
1036
947
  async delete(channelId, reason) {
1037
- if (!this.webhook) return;
948
+ const channel = await this.getChannel(channelId);
949
+ const webhookChannelId = this.getWebhookChannel(channel).id;
950
+ const webhook = this.webhooks.get(webhookChannelId);
951
+ if (!webhook) return;
1038
952
  try {
1039
- await this.webhook.delete(reason ?? "Deleted by WebhookManager");
1040
- Bot.log.info(`Webhook ${this.webhook.id} deleted from ${channelId}`);
953
+ await webhook.delete(reason ?? "Deleted by WebhookManager");
954
+ Bot.log.info(`Webhook ${webhook.id} deleted from ${channelId}`);
1041
955
  } catch (error) {
1042
956
  if (error.message.includes("Unknown Webhook")) {
1043
957
  Bot.log.warn(`Webhook already deleted from ${channelId}`);
@@ -1045,326 +959,105 @@ var WebhookManager = class {
1045
959
  Bot.log.error(`Failed to delete webhook from ${channelId}: ${error}`);
1046
960
  }
1047
961
  } finally {
1048
- this.webhook = null;
962
+ this.webhooks.delete(webhookChannelId);
1049
963
  }
1050
964
  }
1051
965
  };
1052
966
 
1053
967
  // src/manager/messages/ReactionManager.ts
1054
- var import_utils9 = require("@spatulox/utils");
1055
-
1056
- // src/manager/guild/ChannelManager/GuildTextChannelManager.ts
1057
- var import_discord8 = require("discord.js");
1058
-
1059
- // src/manager/guild/ChannelManager/GuildChannelManager.ts
1060
- var import_utils7 = require("@spatulox/utils");
1061
-
1062
- // src/manager/guild/ChannelManager/GuildMessageManager.ts
968
+ var import_discord9 = require("discord.js");
1063
969
  var import_utils6 = require("@spatulox/utils");
1064
- var GuildMessageManager = class {
970
+ var ReactionManager = class {
1065
971
  /**
1066
- * Impl
972
+ * Any text based channel : guild channels, threads and DMs
1067
973
  */
1068
- static async send(channelId, content_or_component_or_options) {
1069
- try {
1070
- const channel = await GuildTextChannelManager.find(channelId);
1071
- if (!channel) {
1072
- import_utils6.Log.error(`Channel ${channelId} not found in guild`);
1073
- return null;
1074
- }
1075
- let payload;
1076
- if (typeof content_or_component_or_options === "string") {
1077
- payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
1078
- } else if (SendableComponentBuilder.isSendableComponent(content_or_component_or_options) || Array.isArray(content_or_component_or_options)) {
1079
- payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
1080
- } else {
1081
- payload = content_or_component_or_options;
1082
- }
1083
- return await channel.send(payload);
1084
- } catch (error) {
1085
- import_utils6.Log.error(`Failed to send message to ${channelId}: ${error}`);
1086
- throw error;
974
+ static async fetchMessage(channelId, messageId) {
975
+ const channel = Bot.client.channels.cache.get(channelId) ?? await Bot.client.channels.fetch(channelId);
976
+ if (!channel?.isTextBased()) {
977
+ throw new Error(`Channel ${channelId} not found or not text based`);
1087
978
  }
979
+ return await channel.messages.fetch(messageId);
1088
980
  }
1089
981
  /**
1090
- * Delete message
982
+ * Add a reaction to a message
1091
983
  */
1092
- static async delete(channelId, messageId) {
984
+ static async add(channelId, messageId, emoji) {
1093
985
  try {
1094
- const channel = await GuildTextChannelManager.find(channelId);
1095
- if (!channel) {
1096
- import_utils6.Log.error(`Channel ${channelId} not found`);
1097
- return false;
1098
- }
1099
- const message = await channel.messages.fetch(messageId);
1100
- await message.delete();
1101
- import_utils6.Log.info(`Deleted message ${messageId} from ${channelId}`);
1102
- return true;
986
+ const message = await this.fetchMessage(channelId, messageId);
987
+ await message.react(emoji);
988
+ import_utils6.Log.info(`Added reaction ${emoji} to message ${messageId}`);
1103
989
  } catch (error) {
1104
- import_utils6.Log.error(`Failed to delete message ${messageId} from ${channelId}: ${error}`);
1105
- return false;
990
+ import_utils6.Log.error(`Failed to add reaction to ${messageId}: ${error}`);
991
+ throw error;
1106
992
  }
1107
993
  }
1108
994
  /**
1109
- * Fetch messages (last X messages, default 10)
995
+ * Delete a reaction from a user
1110
996
  */
1111
- static async fetch(channelId, limit = 10) {
997
+ static async remove(channelId, messageId, emoji, userId) {
1112
998
  try {
1113
- const channel = await GuildTextChannelManager.find(channelId);
1114
- if (!channel) {
1115
- import_utils6.Log.error(`Channel ${channelId} not found`);
1116
- return [];
999
+ const message = await this.fetchMessage(channelId, messageId);
1000
+ const reaction = message.reactions.resolve((0, import_discord9.parseEmoji)(emoji)?.id ?? emoji);
1001
+ if (!reaction) {
1002
+ throw new Error(`Reaction ${emoji} not found on message ${messageId}`);
1117
1003
  }
1118
- const messages = await channel.messages.fetch({ limit });
1119
- import_utils6.Log.info(`Fetched ${messages.size} messages from ${channelId}`);
1120
- return Array.from(messages.values());
1004
+ const user = await Bot.client.users.fetch(userId);
1005
+ await reaction.users.remove(user);
1006
+ import_utils6.Log.info(`Removed reaction ${emoji} from user ${userId} on message ${messageId}`);
1121
1007
  } catch (error) {
1122
- import_utils6.Log.error(`Failed to fetch messages from ${channelId}: ${error}`);
1123
- return [];
1008
+ import_utils6.Log.error(`Failed to remove reaction from ${messageId}: ${error}`);
1009
+ throw error;
1124
1010
  }
1125
1011
  }
1126
1012
  /**
1127
- * Fetch single message
1013
+ * Get all reaction of a message
1128
1014
  */
1129
- static async fetchOne(channelId, messageId) {
1015
+ static async getAll(channelId, messageId) {
1130
1016
  try {
1131
- const channel = await GuildTextChannelManager.find(channelId);
1132
- if (!channel) {
1133
- import_utils6.Log.error(`Channel ${channelId} not found`);
1134
- return null;
1017
+ const message = await this.fetchMessage(channelId, messageId);
1018
+ const reactions = message.reactions.cache;
1019
+ const reactionList = [];
1020
+ for (const reaction of reactions.values()) {
1021
+ const users = await reaction.users.fetch();
1022
+ reactionList.push({
1023
+ emoji: reaction.emoji,
1024
+ count: reaction.count,
1025
+ users: Array.from(users.values())
1026
+ });
1135
1027
  }
1136
- const message = await channel.messages.fetch(messageId);
1137
- return message;
1028
+ import_utils6.Log.info(`Fetched ${reactionList.length} reactions for message ${messageId}`);
1029
+ return reactionList;
1138
1030
  } catch (error) {
1139
- import_utils6.Log.error(`Failed to fetch message ${messageId} from ${channelId}: ${error}`);
1140
- return null;
1031
+ import_utils6.Log.error(`Failed to fetch reactions for ${messageId}: ${error}`);
1032
+ throw error;
1141
1033
  }
1142
1034
  }
1143
- };
1144
-
1145
- // src/manager/guild/ChannelManager/GuildChannelManager.ts
1146
- var GuildChannelManager = class _GuildChannelManager {
1147
- static message = GuildMessageManager;
1148
1035
  /**
1149
- * Recherche un channel par ID dans une guild spécifique
1036
+ * Delete all reaction
1150
1037
  */
1151
- static async findInGuild(guildId, channelId) {
1038
+ static async clear(channelId, messageId) {
1152
1039
  try {
1153
- const guild = Bot.client.guilds.cache.get(guildId);
1154
- if (!guild) {
1155
- import_utils7.Log.warn(`Guild ${guildId} not found`);
1156
- return null;
1157
- }
1158
- const channel = await guild.channels.fetch(channelId);
1159
- return channel ?? null;
1040
+ const message = await this.fetchMessage(channelId, messageId);
1041
+ await message.reactions.removeAll();
1042
+ import_utils6.Log.info(`Cleared all reactions from message ${messageId}`);
1160
1043
  } catch (error) {
1161
- import_utils7.Log.error(`Failed to find channel ${channelId} in guild ${guildId}: ${error}`);
1162
- return null;
1163
- }
1164
- }
1165
- static async find(channelId) {
1166
- try {
1167
- const cached = Bot.client.channels.cache.get(channelId);
1168
- if (cached && !cached.isDMBased()) return cached;
1169
- const channel = await Bot.client.channels.fetch(channelId);
1170
- if (channel && !channel.isDMBased()) return channel;
1171
- import_utils7.Log.warn(`Channel ${channelId} not found in any guild`);
1172
- return null;
1173
- } catch (error) {
1174
- import_utils7.Log.error(`Failed to find channel ${channelId}: ${error}`);
1175
- return null;
1176
- }
1177
- }
1178
- static findAll(guildId) {
1179
- try {
1180
- const guild = Bot.client.guilds.cache.get(guildId);
1181
- if (!guild) {
1182
- import_utils7.Log.warn(`Guild ${guildId} not found`);
1183
- return [];
1184
- }
1185
- return Array.from(guild.channels.cache.values());
1186
- } catch (error) {
1187
- import_utils7.Log.error(`Failed to find channel ${guildId}: ${error}`);
1188
- return [];
1189
- }
1190
- }
1191
- /**
1192
- * Recherche channels par nom (insensible à la casse)
1193
- */
1194
- static findByName(guildId, name) {
1195
- try {
1196
- const guild = Bot.client.guilds.cache.get(guildId);
1197
- if (!guild) {
1198
- import_utils7.Log.warn(`Guild ${guildId} not found`);
1199
- return [];
1200
- }
1201
- return Array.from(guild.channels.cache.values()).filter(
1202
- (channel) => channel.name.toLowerCase().includes(name.toLowerCase())
1203
- );
1204
- } catch (error) {
1205
- import_utils7.Log.error(`Failed to find channel ${guildId}: ${error}`);
1206
- return [];
1207
- }
1208
- }
1209
- static async _create(guildId, options) {
1210
- try {
1211
- const guild = Bot.client.guilds.cache.get(guildId);
1212
- if (!guild) {
1213
- throw new Error(`Guild ${guildId} not found`);
1214
- }
1215
- const channel = await guild.channels.create(options);
1216
- import_utils7.Log.info(`Created channel ${channel.name} (${channel.id}) in guild ${guildId}`);
1217
- return channel;
1218
- } catch (error) {
1219
- import_utils7.Log.error(`Failed to create channel in guild ${guildId}: ${error}`);
1220
- throw error;
1221
- }
1222
- }
1223
- static async delete(channelId) {
1224
- try {
1225
- const channel = await _GuildChannelManager.find(channelId);
1226
- if (!channel) {
1227
- throw new Error(`Channel ${channelId} not found`);
1228
- }
1229
- await channel.delete();
1230
- import_utils7.Log.info(`Deleted channel ${channelId}`);
1231
- return true;
1232
- } catch (error) {
1233
- import_utils7.Log.error(`Failed to delete channel ${channelId}: ${error}`);
1234
- throw error;
1235
- }
1236
- }
1237
- };
1238
-
1239
- // src/manager/guild/ChannelManager/GuildTextChannelManager.ts
1240
- var import_utils8 = require("@spatulox/utils");
1241
- var GuildTextChannelManager = class extends GuildChannelManager {
1242
- static async findInGuild(guildId, channelId) {
1243
- const channel = await super.findInGuild(guildId, channelId);
1244
- return channel?.isTextBased() ? channel : null;
1245
- }
1246
- static async find(channelId) {
1247
- const channel = await super.find(channelId);
1248
- return channel?.isTextBased() ? channel : null;
1249
- }
1250
- static findAll(guildId) {
1251
- const guild = Bot.client.guilds.cache.get(guildId);
1252
- if (!guild) {
1253
- import_utils8.Log.warn(`Guild ${guildId} not found`);
1254
- return [];
1255
- }
1256
- return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord8.TextChannel);
1257
- }
1258
- static async create(guildId, name, options) {
1259
- return await super._create(guildId, {
1260
- name,
1261
- type: import_discord8.ChannelType.GuildText,
1262
- ...options
1263
- });
1264
- }
1265
- };
1266
-
1267
- // src/manager/messages/ReactionManager.ts
1268
- var ReactionManager = class {
1269
- /**
1270
- * Add a reaction to a message
1271
- */
1272
- static async add(channelId, messageId, emoji) {
1273
- try {
1274
- const channel = await GuildTextChannelManager.find(channelId);
1275
- if (!channel) {
1276
- throw new Error(`Channel ${channelId} not found`);
1277
- }
1278
- if (!channel.isTextBased()) {
1279
- throw new Error(`Channel ${channelId} is not text based`);
1280
- }
1281
- const message = await channel.messages.fetch(messageId);
1282
- await message.react(emoji);
1283
- import_utils9.Log.info(`Added reaction ${emoji} to message ${messageId}`);
1284
- } catch (error) {
1285
- import_utils9.Log.error(`Failed to add reaction to ${messageId}: ${error}`);
1286
- throw error;
1287
- }
1288
- }
1289
- /**
1290
- * Delete a reaction from a user
1291
- */
1292
- static async remove(channelId, messageId, emoji, userId) {
1293
- try {
1294
- const channel = await GuildTextChannelManager.find(channelId);
1295
- if (!channel) {
1296
- throw new Error(`Channel ${channelId} not found`);
1297
- }
1298
- const message = await channel.messages.fetch(messageId);
1299
- const reaction = message.reactions.resolve(emoji);
1300
- if (!reaction) {
1301
- throw new Error(`Reaction ${emoji} not found on message ${messageId}`);
1302
- }
1303
- const user = await Bot.client.users.fetch(userId);
1304
- await reaction.users.remove(user);
1305
- import_utils9.Log.info(`Removed reaction ${emoji} from user ${userId} on message ${messageId}`);
1306
- } catch (error) {
1307
- import_utils9.Log.error(`Failed to remove reaction from ${messageId}: ${error}`);
1308
- throw error;
1309
- }
1310
- }
1311
- /**
1312
- * Get all reaction of a message
1313
- */
1314
- static async getAll(channelId, messageId) {
1315
- try {
1316
- const channel = await GuildTextChannelManager.find(channelId);
1317
- if (!channel) {
1318
- throw new Error(`Channel ${channelId} not found`);
1319
- }
1320
- const message = await channel.messages.fetch(messageId);
1321
- const reactions = message.reactions.cache;
1322
- const reactionList = [];
1323
- for (const reaction of reactions.values()) {
1324
- const users = await reaction.users.fetch();
1325
- reactionList.push({
1326
- emoji: reaction.emoji,
1327
- count: reaction.count,
1328
- users: Array.from(users.values())
1329
- });
1330
- }
1331
- import_utils9.Log.info(`Fetched ${reactionList.length} reactions for message ${messageId}`);
1332
- return reactionList;
1333
- } catch (error) {
1334
- import_utils9.Log.error(`Failed to fetch reactions for ${messageId}: ${error}`);
1335
- throw error;
1336
- }
1337
- }
1338
- /**
1339
- * Delete all reaction
1340
- */
1341
- static async clear(channelId, messageId) {
1342
- try {
1343
- const channel = await GuildTextChannelManager.find(channelId);
1344
- if (!channel) {
1345
- throw new Error(`Channel ${channelId} not found`);
1346
- }
1347
- const message = await channel.messages.fetch(messageId);
1348
- await message.reactions.removeAll();
1349
- import_utils9.Log.info(`Cleared all reactions from message ${messageId}`);
1350
- } catch (error) {
1351
- import_utils9.Log.error(`Failed to clear reactions from ${messageId}: ${error}`);
1352
- throw error;
1044
+ import_utils6.Log.error(`Failed to clear reactions from ${messageId}: ${error}`);
1045
+ throw error;
1353
1046
  }
1354
1047
  }
1355
1048
  };
1356
1049
 
1357
1050
  // src/manager/guild/GuildManager.ts
1358
- var import_discord14 = require("discord.js");
1051
+ var import_discord18 = require("discord.js");
1359
1052
  var import_utils18 = require("@spatulox/utils");
1360
1053
  var import_utils19 = require("@spatulox/utils");
1361
1054
 
1362
1055
  // src/manager/guild/GuildUserManager.ts
1363
- var import_utils11 = require("@spatulox/utils");
1056
+ var import_utils8 = require("@spatulox/utils");
1364
1057
 
1365
1058
  // src/manager/direct/BasicUserManager.ts
1366
- var import_discord9 = require("discord.js");
1367
- var import_utils10 = require("@spatulox/utils");
1059
+ var import_discord10 = require("discord.js");
1060
+ var import_utils7 = require("@spatulox/utils");
1368
1061
  var BasicUserManager = class {
1369
1062
  /**
1370
1063
  * Find member in specific guild
@@ -1380,7 +1073,7 @@ var BasicUserManager = class {
1380
1073
  const cached = targetGuild.members.cache.get(memberId);
1381
1074
  if (cached) return cached;
1382
1075
  const member = await targetGuild.members.fetch(memberId).catch(() => null);
1383
- if (!member) import_utils10.Log.error(`UserManager: Member ${memberId} not found in guild ${targetGuild.id}`);
1076
+ if (!member) import_utils7.Log.error(`UserManager: Member ${memberId} not found in guild ${targetGuild.id}`);
1384
1077
  return member;
1385
1078
  }
1386
1079
  /**
@@ -1416,26 +1109,27 @@ var BasicUserManager = class {
1416
1109
  );
1417
1110
  } else if (typeof content_or_component_or_options === "string") {
1418
1111
  payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
1419
- } else if (SendableComponentBuilder.isSendableComponent(content_or_component_or_options)) {
1112
+ } else if (SendableComponentBuilder.isSendableComponent(content_or_component_or_options) || Array.isArray(content_or_component_or_options)) {
1420
1113
  payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
1421
1114
  } else {
1422
1115
  payload = content_or_component_or_options;
1423
1116
  }
1424
1117
  const message = await dmChannel.send(payload);
1425
- if (user instanceof import_discord9.GuildMember) {
1426
- import_utils10.Log.info(`Sent DM to ${user.id} (${user.user.username}): "${(payload.content || "Embed/Component").substring(0, 50)}..."`);
1118
+ if (user instanceof import_discord10.GuildMember) {
1119
+ import_utils7.Log.info(`Sent DM to ${user.id} (${user.user.username}): "${(payload.content || "Embed/Component").substring(0, 50)}..."`);
1427
1120
  } else {
1428
- import_utils10.Log.info(`Sent DM to ${user.id} (${user.username}): "${(payload.content || "Embed/Component").substring(0, 50)}..."`);
1121
+ import_utils7.Log.info(`Sent DM to ${user.id} (${user.username}): "${(payload.content || "Embed/Component").substring(0, 50)}..."`);
1429
1122
  }
1430
1123
  return message;
1431
1124
  } catch (error) {
1432
- import_utils10.Log.error(`Failed to send DM to ${user_id_or_user}: ${error}`);
1125
+ import_utils7.Log.error(`Failed to send DM to ${user_id_or_user}: ${error}`);
1433
1126
  throw new Error(`Cannot send DM to ${user_id_or_user}`);
1434
1127
  }
1435
1128
  }
1436
1129
  };
1437
1130
 
1438
1131
  // src/manager/guild/GuildUserManager.ts
1132
+ var import_discord11 = require("discord.js");
1439
1133
  var import_promises2 = require("timers/promises");
1440
1134
  var MAX_NICKNAME_LENGTH = 32;
1441
1135
  var GuildUserManager = class extends BasicUserManager {
@@ -1447,15 +1141,18 @@ var GuildUserManager = class extends BasicUserManager {
1447
1141
  try {
1448
1142
  const oldName = member.displayName;
1449
1143
  await member.setNickname(nickname.trim());
1450
- import_utils11.Log.info(`Renaming user: ${oldName} \u2192 ${nickname.trim()}`);
1144
+ import_utils8.Log.info(`Renaming user: ${oldName} \u2192 ${nickname.trim()}`);
1451
1145
  await (0, import_promises2.setTimeout)(1500);
1452
1146
  return true;
1453
1147
  } catch (error) {
1454
- console.error(`Attempt ${attempts + 1} failed when renaming ${member.displayName} into ${nickname.trim()}:`, error);
1148
+ import_utils8.Log.error(`Attempt ${attempts + 1} failed when renaming ${member.displayName} into ${nickname.trim()}: ${error}`);
1149
+ if (error?.code === import_discord11.RESTJSONErrorCodes.MissingPermissions || error?.code === import_discord11.RESTJSONErrorCodes.MissingAccess) {
1150
+ break;
1151
+ }
1455
1152
  await (0, import_promises2.setTimeout)(1e3);
1456
1153
  }
1457
1154
  }
1458
- Bot.log.info(EmbedManager.error(`Failed to rename ${member.displayName} to ${nickname.trim()} after ${maxAttempts} attempts.`));
1155
+ Bot.log.error(EmbedManager.error(`Failed to rename ${member.displayName} to ${nickname.trim()}.`));
1459
1156
  return false;
1460
1157
  }
1461
1158
  /**
@@ -1465,13 +1162,13 @@ var GuildUserManager = class extends BasicUserManager {
1465
1162
  try {
1466
1163
  const guild = await GuildManager.find(guildId);
1467
1164
  if (!guild) {
1468
- import_utils11.Log.warn(`Guild ${guildId} not found`);
1165
+ import_utils8.Log.warn(`Guild ${guildId} not found`);
1469
1166
  return false;
1470
1167
  }
1471
1168
  const ban = await guild.bans.fetch(userId);
1472
1169
  return !!ban;
1473
1170
  } catch (error) {
1474
- import_utils11.Log.debug(`User ${userId} is not banned from guild ${guildId}`);
1171
+ import_utils8.Log.debug(`User ${userId} is not banned from guild ${guildId}`);
1475
1172
  return false;
1476
1173
  }
1477
1174
  }
@@ -1485,170 +1182,356 @@ var GuildUserManager = class extends BasicUserManager {
1485
1182
  throw new Error(`Member ${memberId} not found or not in a voice channel`);
1486
1183
  }
1487
1184
  await member.voice.disconnect();
1488
- import_utils11.Log.info(`Disconnected member ${memberId} from voice in guild ${guildId}`);
1185
+ import_utils8.Log.info(`Disconnected member ${memberId} from voice in guild ${guildId}`);
1489
1186
  } catch (error) {
1490
- import_utils11.Log.error(`Failed to disconnect member ${memberId} from voice in ${guildId}: ${error}`);
1187
+ import_utils8.Log.error(`Failed to disconnect member ${memberId} from voice in ${guildId}: ${error}`);
1491
1188
  throw error;
1492
1189
  }
1493
1190
  }
1494
1191
  /**
1495
1192
  * Check if a member is in voice
1496
1193
  */
1497
- static async isInVoice(memberId, guildId) {
1194
+ static async isInVoice(guildId, memberId) {
1498
1195
  try {
1499
1196
  const member = await GuildManager.user.findInGuild(guildId, memberId);
1500
1197
  if (!member) {
1501
- throw new Error(`User ${guildId} not found`);
1198
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1502
1199
  }
1503
1200
  return member.voice.channelId !== null;
1504
1201
  } catch (error) {
1505
- import_utils11.Log.debug(`Member ${memberId} not found or not in voice in guild ${guildId}`);
1506
- return false;
1202
+ import_utils8.Log.debug(`Member ${memberId} not found or not in voice in guild ${guildId}`);
1203
+ return false;
1204
+ }
1205
+ }
1206
+ /**
1207
+ * Mute a member
1208
+ */
1209
+ static async mute(guildId, memberId, reason) {
1210
+ try {
1211
+ const member = await GuildManager.user.findInGuild(guildId, memberId);
1212
+ if (!member) {
1213
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1214
+ }
1215
+ await member.voice.setMute(true, reason);
1216
+ import_utils8.Log.info(`Server muted ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1217
+ } catch (error) {
1218
+ import_utils8.Log.error(`Failed to server mute ${memberId} in ${guildId}: ${error}`);
1219
+ throw error;
1220
+ }
1221
+ }
1222
+ /**
1223
+ * Unmute a member
1224
+ */
1225
+ static async unmute(guildId, memberId, reason) {
1226
+ try {
1227
+ const member = await GuildManager.user.findInGuild(guildId, memberId);
1228
+ if (!member) {
1229
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1230
+ }
1231
+ await member.voice.setMute(false, reason);
1232
+ import_utils8.Log.info(`Server unmuted ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1233
+ } catch (error) {
1234
+ import_utils8.Log.error(`Failed to server unmute ${memberId} in ${guildId}: ${error}`);
1235
+ throw error;
1236
+ }
1237
+ }
1238
+ /**
1239
+ * Deafen a member
1240
+ */
1241
+ static async deafen(guildId, memberId, reason) {
1242
+ try {
1243
+ const member = await GuildManager.user.findInGuild(guildId, memberId);
1244
+ if (!member) {
1245
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1246
+ }
1247
+ await member.voice.setDeaf(true, reason);
1248
+ import_utils8.Log.info(`Server deafened ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1249
+ } catch (error) {
1250
+ import_utils8.Log.error(`Failed to server deafen ${memberId} in ${guildId}: ${error}`);
1251
+ throw error;
1252
+ }
1253
+ }
1254
+ /**
1255
+ * Undeafen member voice
1256
+ */
1257
+ static async undeafen(guildId, memberId, reason) {
1258
+ try {
1259
+ const member = await GuildManager.user.findInGuild(guildId, memberId);
1260
+ if (!member) {
1261
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1262
+ }
1263
+ await member.voice.setDeaf(false, reason);
1264
+ import_utils8.Log.info(`Server undeafened ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1265
+ } catch (error) {
1266
+ import_utils8.Log.error(`Failed to server undeafen ${memberId} in ${guildId}: ${error}`);
1267
+ throw error;
1268
+ }
1269
+ }
1270
+ /**
1271
+ * Timeout a member
1272
+ */
1273
+ static async timeout(guildId, memberId, duration, reason) {
1274
+ try {
1275
+ const member = await GuildManager.user.findInGuild(guildId, memberId);
1276
+ if (!member) {
1277
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1278
+ }
1279
+ await member.timeout(duration, reason);
1280
+ import_utils8.Log.info(`Timed out ${memberId} for ${duration}ms in guild ${guildId}: ${reason || "No reason"}`);
1281
+ } catch (error) {
1282
+ import_utils8.Log.error(`Failed to timeout ${memberId} in ${guildId}: ${error}`);
1283
+ throw error;
1284
+ }
1285
+ }
1286
+ /**
1287
+ * Remove the timeout of a member
1288
+ */
1289
+ static async untimeout(guildId, memberId, reason) {
1290
+ try {
1291
+ const member = await GuildManager.user.findInGuild(guildId, memberId);
1292
+ if (!member) {
1293
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1294
+ }
1295
+ await member.timeout(null, reason);
1296
+ import_utils8.Log.info(`Untimed out ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1297
+ } catch (error) {
1298
+ import_utils8.Log.error(`Failed to untimeout ${memberId} in ${guildId}: ${error}`);
1299
+ throw error;
1300
+ }
1301
+ }
1302
+ /**
1303
+ * Kick a member
1304
+ */
1305
+ static async kick(guildId, memberId, reason) {
1306
+ try {
1307
+ const member = await GuildManager.user.findInGuild(guildId, memberId);
1308
+ if (!member) {
1309
+ throw new Error(`Member ${memberId} not found in guild ${guildId}`);
1310
+ }
1311
+ await member.kick(reason);
1312
+ import_utils8.Log.info(`Kicked ${memberId} from guild ${guildId}: ${reason || "No reason"}`);
1313
+ } catch (error) {
1314
+ import_utils8.Log.error(`Failed to kick ${memberId} from ${guildId}: ${error}`);
1315
+ throw error;
1316
+ }
1317
+ }
1318
+ static async ban(guildId, userId, banOption) {
1319
+ const guild = await GuildManager.find(guildId);
1320
+ if (!guild) {
1321
+ throw new Error(`Guild ${guildId} not found`);
1322
+ }
1323
+ try {
1324
+ await guild.members.ban(userId, banOption);
1325
+ import_utils8.Log.info(`Banned user ${userId} from guild ${guildId}`);
1326
+ } catch (error) {
1327
+ import_utils8.Log.error(`Failed to ban user ${userId} from guild ${guildId}: ${error}`);
1328
+ throw error;
1329
+ }
1330
+ }
1331
+ static async unban(guildId, userId, reason) {
1332
+ const guild = await GuildManager.find(guildId);
1333
+ if (!guild) {
1334
+ throw new Error(`Guild ${guildId} not found`);
1335
+ }
1336
+ try {
1337
+ await guild.members.unban(userId, reason);
1338
+ import_utils8.Log.info(`Unbanned user ${userId} from guild ${guildId}`);
1339
+ } catch (error) {
1340
+ import_utils8.Log.error(`Failed to unban user ${userId} from guild ${guildId}: ${error}`);
1341
+ throw error;
1342
+ }
1343
+ }
1344
+ };
1345
+
1346
+ // src/manager/guild/ChannelManager/GuildChannelManager.ts
1347
+ var import_utils10 = require("@spatulox/utils");
1348
+
1349
+ // src/manager/guild/ChannelManager/GuildMessageManager.ts
1350
+ var import_utils9 = require("@spatulox/utils");
1351
+ var GuildMessageManager = class {
1352
+ /**
1353
+ * Any guild channel able to hold messages : text, announcement, thread, voice / stage text chat
1354
+ */
1355
+ static async findTextBased(channelId) {
1356
+ const channel = await GuildChannelManager.find(channelId);
1357
+ return channel?.isTextBased() ? channel : null;
1358
+ }
1359
+ /**
1360
+ * Impl
1361
+ */
1362
+ static async send(channelId, content_or_component_or_options) {
1363
+ try {
1364
+ const channel = await this.findTextBased(channelId);
1365
+ if (!channel) {
1366
+ import_utils9.Log.error(`Channel ${channelId} not found in guild`);
1367
+ return null;
1368
+ }
1369
+ let payload;
1370
+ if (typeof content_or_component_or_options === "string") {
1371
+ payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
1372
+ } else if (SendableComponentBuilder.isSendableComponent(content_or_component_or_options) || Array.isArray(content_or_component_or_options)) {
1373
+ payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
1374
+ } else {
1375
+ payload = content_or_component_or_options;
1376
+ }
1377
+ return await channel.send(payload);
1378
+ } catch (error) {
1379
+ import_utils9.Log.error(`Failed to send message to ${channelId}: ${error}`);
1380
+ throw error;
1507
1381
  }
1508
1382
  }
1509
1383
  /**
1510
- * Mute a member
1384
+ * Delete message
1511
1385
  */
1512
- static async mute(guildId, memberId, reason) {
1386
+ static async delete(channelId, messageId) {
1513
1387
  try {
1514
- const member = await GuildManager.user.findInGuild(guildId, memberId);
1515
- if (!member) {
1516
- throw new Error(`User ${guildId} not found`);
1388
+ const channel = await this.findTextBased(channelId);
1389
+ if (!channel) {
1390
+ import_utils9.Log.error(`Channel ${channelId} not found`);
1391
+ return false;
1517
1392
  }
1518
- await member.voice.setMute(true, reason);
1519
- import_utils11.Log.info(`Server muted ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1393
+ const message = await channel.messages.fetch(messageId);
1394
+ await message.delete();
1395
+ import_utils9.Log.info(`Deleted message ${messageId} from ${channelId}`);
1396
+ return true;
1520
1397
  } catch (error) {
1521
- import_utils11.Log.error(`Failed to server mute ${memberId} in ${guildId}:, error`);
1522
- throw error;
1398
+ import_utils9.Log.error(`Failed to delete message ${messageId} from ${channelId}: ${error}`);
1399
+ return false;
1523
1400
  }
1524
1401
  }
1525
1402
  /**
1526
- * Unmute a member
1403
+ * Fetch messages (last X messages, default 10)
1527
1404
  */
1528
- static async unmute(guildId, memberId, reason) {
1405
+ static async fetch(channelId, limit = 10) {
1529
1406
  try {
1530
- const member = await GuildManager.user.findInGuild(guildId, memberId);
1531
- if (!member) {
1532
- throw new Error(`User ${guildId} not found`);
1407
+ const channel = await this.findTextBased(channelId);
1408
+ if (!channel) {
1409
+ import_utils9.Log.error(`Channel ${channelId} not found`);
1410
+ return [];
1533
1411
  }
1534
- await member.voice.setMute(false, reason);
1535
- import_utils11.Log.info(`Server unmuted ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1412
+ const messages = await channel.messages.fetch({ limit });
1413
+ import_utils9.Log.info(`Fetched ${messages.size} messages from ${channelId}`);
1414
+ return Array.from(messages.values());
1536
1415
  } catch (error) {
1537
- import_utils11.Log.error(`Failed to server unmute ${memberId} in ${guildId}: ${error}`);
1538
- throw error;
1416
+ import_utils9.Log.error(`Failed to fetch messages from ${channelId}: ${error}`);
1417
+ return [];
1539
1418
  }
1540
1419
  }
1541
1420
  /**
1542
- * Deafen a member
1421
+ * Fetch single message
1543
1422
  */
1544
- static async deafen(guildId, memberId, reason) {
1423
+ static async fetchOne(channelId, messageId) {
1545
1424
  try {
1546
- const member = await GuildManager.user.findInGuild(guildId, memberId);
1547
- if (!member) {
1548
- throw new Error(`User ${guildId} not found`);
1425
+ const channel = await this.findTextBased(channelId);
1426
+ if (!channel) {
1427
+ import_utils9.Log.error(`Channel ${channelId} not found`);
1428
+ return null;
1549
1429
  }
1550
- await member.voice.setDeaf(true, reason);
1551
- import_utils11.Log.info(`Server deafened ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1430
+ const message = await channel.messages.fetch(messageId);
1431
+ return message;
1552
1432
  } catch (error) {
1553
- import_utils11.Log.error(`Failed to server deafen ${memberId} in ${guildId}: ${error}`);
1554
- throw error;
1433
+ import_utils9.Log.error(`Failed to fetch message ${messageId} from ${channelId}: ${error}`);
1434
+ return null;
1555
1435
  }
1556
1436
  }
1437
+ };
1438
+
1439
+ // src/manager/guild/ChannelManager/GuildChannelManager.ts
1440
+ var GuildChannelManager = class _GuildChannelManager {
1441
+ static message = GuildMessageManager;
1557
1442
  /**
1558
- * Undeafen member voice
1443
+ * Recherche un channel par ID dans une guild spécifique
1559
1444
  */
1560
- static async undeafen(guildId, memberId, reason) {
1445
+ static async findInGuild(guildId, channelId) {
1561
1446
  try {
1562
- const member = await GuildManager.user.findInGuild(guildId, memberId);
1563
- if (!member) {
1564
- throw new Error(`User ${guildId} not found`);
1447
+ const guild = Bot.client.guilds.cache.get(guildId);
1448
+ if (!guild) {
1449
+ import_utils10.Log.warn(`Guild ${guildId} not found`);
1450
+ return null;
1565
1451
  }
1566
- await member.voice.setDeaf(false, reason);
1567
- import_utils11.Log.info(`Server undeafened ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1452
+ const channel = await guild.channels.fetch(channelId);
1453
+ return channel ?? null;
1568
1454
  } catch (error) {
1569
- import_utils11.Log.error(`Failed to server undeafen ${memberId} in ${guildId}: ${error}`);
1570
- throw error;
1455
+ import_utils10.Log.error(`Failed to find channel ${channelId} in guild ${guildId}: ${error}`);
1456
+ return null;
1571
1457
  }
1572
1458
  }
1573
- /**
1574
- * Timeout a member
1575
- */
1576
- static async timeout(guildId, memberId, duration, reason) {
1459
+ static async find(channelId) {
1577
1460
  try {
1578
- const member = await GuildManager.user.findInGuild(guildId, memberId);
1579
- if (!member) {
1580
- throw new Error(`User ${guildId} not found`);
1581
- }
1582
- const expires = Date.now() + duration;
1583
- await member.timeout(expires, reason);
1584
- import_utils11.Log.info(`Timed out ${memberId} for ${duration}ms in guild ${guildId}: ${reason || "No reason"}`);
1461
+ const cached = Bot.client.channels.cache.get(channelId);
1462
+ if (cached && !cached.isDMBased()) return cached;
1463
+ const channel = await Bot.client.channels.fetch(channelId);
1464
+ if (channel && !channel.isDMBased()) return channel;
1465
+ import_utils10.Log.warn(`Channel ${channelId} not found in any guild`);
1466
+ return null;
1585
1467
  } catch (error) {
1586
- import_utils11.Log.error(`Failed to timeout ${memberId} in ${guildId}: ${error}`);
1587
- throw error;
1468
+ import_utils10.Log.error(`Failed to find channel ${channelId}: ${error}`);
1469
+ return null;
1588
1470
  }
1589
1471
  }
1590
- /**
1591
- * Remove the timeout of a member
1592
- */
1593
- static async untimeout(guildId, memberId, reason) {
1472
+ static findAll(guildId) {
1594
1473
  try {
1595
- const member = await GuildManager.user.findInGuild(guildId, memberId);
1596
- if (!member) {
1597
- throw new Error(`User ${guildId} not found`);
1474
+ const guild = Bot.client.guilds.cache.get(guildId);
1475
+ if (!guild) {
1476
+ import_utils10.Log.warn(`Guild ${guildId} not found`);
1477
+ return [];
1598
1478
  }
1599
- await member.timeout(null, reason);
1600
- import_utils11.Log.info(`Untimed out ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
1479
+ return Array.from(guild.channels.cache.values());
1601
1480
  } catch (error) {
1602
- import_utils11.Log.error(`Failed to untimeout ${memberId} in ${guildId}: ${error}`);
1603
- throw error;
1481
+ import_utils10.Log.error(`Failed to find channel ${guildId}: ${error}`);
1482
+ return [];
1604
1483
  }
1605
1484
  }
1606
1485
  /**
1607
- * Kick a member
1486
+ * Recherche channels par nom (insensible à la casse)
1608
1487
  */
1609
- static async kick(guildId, memberId, reason) {
1488
+ static findByName(guildId, name2) {
1610
1489
  try {
1611
- const member = await GuildManager.user.findInGuild(guildId, memberId);
1612
- if (!member) {
1613
- throw new Error(`User ${guildId} not found`);
1490
+ const guild = Bot.client.guilds.cache.get(guildId);
1491
+ if (!guild) {
1492
+ import_utils10.Log.warn(`Guild ${guildId} not found`);
1493
+ return [];
1614
1494
  }
1615
- await member.kick(reason);
1616
- import_utils11.Log.info(`Kicked ${memberId} from guild ${guildId}: ${reason || "No reason"}`);
1495
+ return Array.from(guild.channels.cache.values()).filter(
1496
+ (channel) => channel.name.toLowerCase().includes(name2.toLowerCase())
1497
+ );
1617
1498
  } catch (error) {
1618
- import_utils11.Log.error(`Failed to kick ${memberId} from ${guildId}: ${error}`);
1619
- throw error;
1499
+ import_utils10.Log.error(`Failed to find channel ${guildId}: ${error}`);
1500
+ return [];
1620
1501
  }
1621
1502
  }
1622
- static async ban(guildId, userId, banOption) {
1623
- const guild = await GuildManager.find(guildId);
1624
- if (!guild) {
1625
- throw new Error(`Guild ${guildId} not found`);
1626
- }
1503
+ static async _create(guildId, options) {
1627
1504
  try {
1628
- await guild.members.ban(userId, banOption);
1629
- import_utils11.Log.info(`Banned user ${userId} from guild ${guildId}`);
1505
+ const guild = Bot.client.guilds.cache.get(guildId);
1506
+ if (!guild) {
1507
+ throw new Error(`Guild ${guildId} not found`);
1508
+ }
1509
+ const channel = await guild.channels.create(options);
1510
+ import_utils10.Log.info(`Created channel ${channel.name} (${channel.id}) in guild ${guildId}`);
1511
+ return channel;
1630
1512
  } catch (error) {
1631
- import_utils11.Log.error(`Failed to ban user ${userId} from guild ${guildId}: ${error}`);
1513
+ import_utils10.Log.error(`Failed to create channel in guild ${guildId}: ${error}`);
1632
1514
  throw error;
1633
1515
  }
1634
1516
  }
1635
- static async unban(guildId, userId, reason) {
1636
- const guild = await GuildManager.find(guildId);
1637
- if (!guild) {
1638
- throw new Error(`Guild ${guildId} not found`);
1639
- }
1517
+ static async delete(channelId) {
1640
1518
  try {
1641
- await guild.members.unban(userId, reason);
1642
- import_utils11.Log.info(`Unbanned user ${userId} from guild ${guildId}`);
1519
+ const channel = await _GuildChannelManager.find(channelId);
1520
+ if (!channel) {
1521
+ throw new Error(`Channel ${channelId} not found`);
1522
+ }
1523
+ await channel.delete();
1524
+ import_utils10.Log.info(`Deleted channel ${channelId}`);
1525
+ return true;
1643
1526
  } catch (error) {
1644
- import_utils11.Log.error(`Failed to unban user ${userId} from guild ${guildId}: ${error}`);
1645
- throw error;
1527
+ import_utils10.Log.error(`Failed to delete channel ${channelId}: ${error}`);
1528
+ return false;
1646
1529
  }
1647
1530
  }
1648
1531
  };
1649
1532
 
1650
1533
  // src/manager/guild/RoleManager.ts
1651
- var import_utils12 = require("@spatulox/utils");
1534
+ var import_utils11 = require("@spatulox/utils");
1652
1535
  var RoleManager = class {
1653
1536
  /**
1654
1537
  * Add role - CACHE ONLY
@@ -1659,14 +1542,14 @@ var RoleManager = class {
1659
1542
  try {
1660
1543
  const role = member.guild.roles.cache.get(roleId);
1661
1544
  if (!role) {
1662
- import_utils12.Log.warn(`Role ${roleId} not found in cache`);
1545
+ import_utils11.Log.warn(`Role ${roleId} not found in cache`);
1663
1546
  return false;
1664
1547
  }
1665
1548
  await member.roles.add(role);
1666
- import_utils12.Log.info(`\u2705 Added ${role.name} to ${member.displayName}`);
1549
+ import_utils11.Log.info(`\u2705 Added ${role.name} to ${member.displayName}`);
1667
1550
  return true;
1668
1551
  } catch (error) {
1669
- import_utils12.Log.error(`Failed to add role ${roleId}: ${error}`);
1552
+ import_utils11.Log.error(`Failed to add role ${roleId}: ${error}`);
1670
1553
  return false;
1671
1554
  }
1672
1555
  }
@@ -1677,23 +1560,16 @@ var RoleManager = class {
1677
1560
  */
1678
1561
  static async remove(member, roleIdOrName) {
1679
1562
  try {
1680
- let role;
1681
- if (typeof roleIdOrName === "string" && roleIdOrName.length === 18) {
1682
- role = member.roles.cache.get(roleIdOrName);
1683
- } else {
1684
- role = member.roles.cache.find(
1685
- (r) => r.id === roleIdOrName || r.name.toLowerCase() === roleIdOrName.toString().toLowerCase()
1686
- );
1687
- }
1563
+ const role = this.resolve(member.roles.cache, roleIdOrName);
1688
1564
  if (!role) {
1689
- import_utils12.Log.warn(`Role ${roleIdOrName} not found for ${member.displayName}`);
1565
+ import_utils11.Log.warn(`Role ${roleIdOrName} not found for ${member.displayName}`);
1690
1566
  return false;
1691
1567
  }
1692
1568
  await member.roles.remove(role);
1693
- import_utils12.Log.info(`\u2705 Removed ${role.name} from ${member.displayName}`);
1569
+ import_utils11.Log.info(`\u2705 Removed ${role.name} from ${member.displayName}`);
1694
1570
  return true;
1695
1571
  } catch (error) {
1696
- import_utils12.Log.error(`Failed to remove role ${roleIdOrName}: ${error}`);
1572
+ import_utils11.Log.error(`Failed to remove role ${roleIdOrName}: ${error}`);
1697
1573
  return false;
1698
1574
  }
1699
1575
  }
@@ -1701,9 +1577,9 @@ var RoleManager = class {
1701
1577
  * Toggle role (add/remove)
1702
1578
  */
1703
1579
  static async toggle(member, roleIdOrName) {
1704
- const role = member.roles.cache.get(roleIdOrName) || member.roles.cache.find((r) => r.name.toLowerCase() === roleIdOrName.toString().toLowerCase());
1580
+ const role = this.resolve(member.guild.roles.cache, roleIdOrName);
1705
1581
  if (!role) {
1706
- import_utils12.Log.warn(`Role ${roleIdOrName} not found`);
1582
+ import_utils11.Log.warn(`Role ${roleIdOrName} not found`);
1707
1583
  throw new Error(`Role not found`);
1708
1584
  }
1709
1585
  if (member.roles.cache.has(role.id)) {
@@ -1718,84 +1594,115 @@ var RoleManager = class {
1718
1594
  * Check if member has role
1719
1595
  */
1720
1596
  static hasRole(member, roleIdOrName) {
1721
- if (typeof roleIdOrName === "string" && roleIdOrName.length === 18) {
1722
- return member.roles.cache.has(roleIdOrName);
1723
- }
1724
- return member.roles.cache.some(
1725
- (r) => r.id === roleIdOrName || r.name.toLowerCase() === roleIdOrName.toString().toLowerCase()
1726
- );
1597
+ return !!this.resolve(member.roles.cache, roleIdOrName);
1598
+ }
1599
+ /**
1600
+ * Search by id first, then by name (case insensitive). Snowflakes are 17 to 20 digits long,
1601
+ * so the length of the string can't tell an id from a name
1602
+ */
1603
+ static resolve(roles, roleIdOrName) {
1604
+ return roles.get(roleIdOrName) ?? roles.find((r) => r.name.toLowerCase() === roleIdOrName.toLowerCase());
1727
1605
  }
1728
1606
  };
1729
1607
 
1730
1608
  // src/manager/guild/ChannelManager/ForumChannelManager.ts
1731
- var import_discord10 = require("discord.js");
1732
- var import_utils13 = require("@spatulox/utils");
1609
+ var import_discord12 = require("discord.js");
1610
+ var import_utils12 = require("@spatulox/utils");
1733
1611
  var ForumChannelManager = class extends GuildChannelManager {
1734
1612
  static async findInGuild(guildId, channelId) {
1735
1613
  const channel = await super.findInGuild(guildId, channelId);
1736
- return channel instanceof import_discord10.ForumChannel ? channel : null;
1614
+ return channel instanceof import_discord12.ForumChannel ? channel : null;
1737
1615
  }
1738
1616
  static async find(channelId) {
1739
1617
  const channel = await super.find(channelId);
1740
- return channel instanceof import_discord10.ForumChannel ? channel : null;
1618
+ return channel instanceof import_discord12.ForumChannel ? channel : null;
1741
1619
  }
1742
1620
  static findAll(guildId) {
1743
1621
  const guild = Bot.client.guilds.cache.get(guildId);
1744
1622
  if (!guild) {
1745
- import_utils13.Log.warn(`Guild ${guildId} not found`);
1623
+ import_utils12.Log.warn(`Guild ${guildId} not found`);
1746
1624
  return [];
1747
1625
  }
1748
- return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord10.ForumChannel);
1626
+ return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord12.ForumChannel);
1749
1627
  }
1750
- static async create(guildId, name, options) {
1628
+ static async create(guildId, name2, options) {
1751
1629
  return await super._create(guildId, {
1752
- name,
1753
- type: import_discord10.ChannelType.GuildForum,
1630
+ name: name2,
1631
+ type: import_discord12.ChannelType.GuildForum,
1754
1632
  ...options
1755
1633
  });
1756
1634
  }
1757
1635
  };
1758
1636
 
1759
1637
  // src/manager/guild/ChannelManager/NewsChannelManager.ts
1760
- var import_discord11 = require("discord.js");
1761
- var import_utils14 = require("@spatulox/utils");
1638
+ var import_discord13 = require("discord.js");
1639
+ var import_utils13 = require("@spatulox/utils");
1762
1640
  var NewsChannelManager = class extends GuildChannelManager {
1763
1641
  static async findInGuild(guildId, channelId) {
1764
1642
  const channel = await super.findInGuild(guildId, channelId);
1765
- return channel instanceof import_discord11.NewsChannel ? channel : null;
1643
+ return channel instanceof import_discord13.NewsChannel ? channel : null;
1766
1644
  }
1767
1645
  static async find(channelId) {
1768
1646
  const channel = await super.find(channelId);
1769
- return channel instanceof import_discord11.NewsChannel ? channel : null;
1647
+ return channel instanceof import_discord13.NewsChannel ? channel : null;
1770
1648
  }
1771
1649
  static findAll(guildId) {
1772
1650
  const guild = Bot.client.guilds.cache.get(guildId);
1773
1651
  if (!guild) {
1774
- import_utils14.Log.warn(`Guild ${guildId} not found`);
1652
+ import_utils13.Log.warn(`Guild ${guildId} not found`);
1775
1653
  return [];
1776
1654
  }
1777
- return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord11.NewsChannel);
1655
+ return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord13.NewsChannel);
1778
1656
  }
1779
- static async create(guildId, name, options) {
1657
+ static async create(guildId, name2, options) {
1780
1658
  return await super._create(guildId, {
1781
- name,
1782
- type: import_discord11.ChannelType.GuildAnnouncement,
1659
+ name: name2,
1660
+ type: import_discord13.ChannelType.GuildAnnouncement,
1783
1661
  ...options
1784
1662
  });
1785
1663
  }
1786
1664
  };
1787
1665
 
1788
1666
  // src/manager/guild/ChannelManager/StageChannelManager.ts
1789
- var import_discord12 = require("discord.js");
1790
- var import_utils15 = require("@spatulox/utils");
1667
+ var import_discord14 = require("discord.js");
1668
+ var import_utils14 = require("@spatulox/utils");
1791
1669
  var StageChannelManager = class extends GuildChannelManager {
1792
1670
  static async findInGuild(guildId, channelId) {
1793
1671
  const channel = await super.findInGuild(guildId, channelId);
1794
- return channel instanceof import_discord12.StageChannel ? channel : null;
1672
+ return channel instanceof import_discord14.StageChannel ? channel : null;
1673
+ }
1674
+ static async find(channelId) {
1675
+ const channel = await super.find(channelId);
1676
+ return channel instanceof import_discord14.StageChannel ? channel : null;
1677
+ }
1678
+ static findAll(guildId) {
1679
+ const guild = Bot.client.guilds.cache.get(guildId);
1680
+ if (!guild) {
1681
+ import_utils14.Log.warn(`Guild ${guildId} not found`);
1682
+ return [];
1683
+ }
1684
+ return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord14.StageChannel);
1685
+ }
1686
+ static async create(guildId, name2, options) {
1687
+ return await super._create(guildId, {
1688
+ name: name2,
1689
+ type: import_discord14.ChannelType.GuildStageVoice,
1690
+ ...options
1691
+ });
1692
+ }
1693
+ };
1694
+
1695
+ // src/manager/guild/ChannelManager/GuildTextChannelManager.ts
1696
+ var import_discord15 = require("discord.js");
1697
+ var import_utils15 = require("@spatulox/utils");
1698
+ var GuildTextChannelManager = class extends GuildChannelManager {
1699
+ static async findInGuild(guildId, channelId) {
1700
+ const channel = await super.findInGuild(guildId, channelId);
1701
+ return channel instanceof import_discord15.TextChannel ? channel : null;
1795
1702
  }
1796
1703
  static async find(channelId) {
1797
1704
  const channel = await super.find(channelId);
1798
- return channel instanceof import_discord12.StageChannel ? channel : null;
1705
+ return channel instanceof import_discord15.TextChannel ? channel : null;
1799
1706
  }
1800
1707
  static findAll(guildId) {
1801
1708
  const guild = Bot.client.guilds.cache.get(guildId);
@@ -1803,18 +1710,19 @@ var StageChannelManager = class extends GuildChannelManager {
1803
1710
  import_utils15.Log.warn(`Guild ${guildId} not found`);
1804
1711
  return [];
1805
1712
  }
1806
- return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord12.StageChannel);
1713
+ return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord15.TextChannel);
1807
1714
  }
1808
- static async create(guildId, name, options) {
1715
+ static async create(guildId, name2, options) {
1809
1716
  return await super._create(guildId, {
1810
- name,
1811
- type: import_discord12.ChannelType.GuildStageVoice,
1717
+ name: name2,
1718
+ type: import_discord15.ChannelType.GuildText,
1812
1719
  ...options
1813
1720
  });
1814
1721
  }
1815
1722
  };
1816
1723
 
1817
1724
  // src/manager/guild/ChannelManager/ThreadChannelManager.ts
1725
+ var import_discord16 = require("discord.js");
1818
1726
  var ThreadChannelManager = class {
1819
1727
  static async findInGuild(guildId, channelId) {
1820
1728
  const channel = await GuildChannelManager.findInGuild(guildId, channelId);
@@ -1829,16 +1737,15 @@ var ThreadChannelManager = class {
1829
1737
  return channels.filter((c) => c.isThread());
1830
1738
  }
1831
1739
  static async createFromChannel(parentId, options) {
1832
- const channel = await GuildTextChannelManager.find(parentId);
1833
- if (!channel || !channel.isTextBased()) {
1834
- throw new Error("Parent must be a text-based channel");
1740
+ const channel = await GuildChannelManager.find(parentId);
1741
+ if (!(channel instanceof import_discord16.TextChannel) && !(channel instanceof import_discord16.NewsChannel)) {
1742
+ throw new Error("Parent must be a text or announcement channel");
1835
1743
  }
1836
1744
  const thread = await channel.threads.create(options);
1837
1745
  return thread;
1838
1746
  }
1839
1747
  static async createFromMessage(message, options) {
1840
- const channel = await GuildChannelManager.find(message.id);
1841
- if (!channel) throw new Error("Message channel not found");
1748
+ if (!message.inGuild()) throw new Error("Cannot start a thread from a message outside of a guild");
1842
1749
  return await message.startThread(options);
1843
1750
  }
1844
1751
  /**
@@ -1856,16 +1763,16 @@ var ThreadChannelManager = class {
1856
1763
  };
1857
1764
 
1858
1765
  // src/manager/guild/ChannelManager/GuildVoiceChannelManager.ts
1859
- var import_discord13 = require("discord.js");
1766
+ var import_discord17 = require("discord.js");
1860
1767
  var import_utils16 = require("@spatulox/utils");
1861
1768
  var GuildVoiceChannelManager = class extends GuildChannelManager {
1862
1769
  static async findInGuild(guildId, channelId) {
1863
1770
  const channel = await super.findInGuild(guildId, channelId);
1864
- return channel?.isVoiceBased() ? channel : null;
1771
+ return channel instanceof import_discord17.VoiceChannel ? channel : null;
1865
1772
  }
1866
1773
  static async find(channelId) {
1867
1774
  const channel = await super.find(channelId);
1868
- return channel?.isVoiceBased() ? channel : null;
1775
+ return channel instanceof import_discord17.VoiceChannel ? channel : null;
1869
1776
  }
1870
1777
  static findAll(guildId) {
1871
1778
  const guild = Bot.client.guilds.cache.get(guildId);
@@ -1873,12 +1780,12 @@ var GuildVoiceChannelManager = class extends GuildChannelManager {
1873
1780
  import_utils16.Log.warn(`Guild ${guildId} not found`);
1874
1781
  return [];
1875
1782
  }
1876
- return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord13.VoiceChannel);
1783
+ return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord17.VoiceChannel);
1877
1784
  }
1878
- static async create(guildId, name, options) {
1785
+ static async create(guildId, name2, options) {
1879
1786
  return await super._create(guildId, {
1880
- name,
1881
- type: import_discord13.ChannelType.GuildVoice,
1787
+ name: name2,
1788
+ type: import_discord17.ChannelType.GuildVoice,
1882
1789
  ...options
1883
1790
  });
1884
1791
  }
@@ -1896,6 +1803,7 @@ var GuildChannelList = class {
1896
1803
  };
1897
1804
 
1898
1805
  // src/manager/guild/InviteManager.ts
1806
+ var import_promises3 = require("timers/promises");
1899
1807
  var import_utils17 = require("@spatulox/utils");
1900
1808
  var InviteManager = class {
1901
1809
  /**
@@ -1923,9 +1831,19 @@ var InviteManager = class {
1923
1831
  }
1924
1832
  }
1925
1833
  /**
1926
- * Delete an invitation
1834
+ * Find an invite by its code or its url (discord.gg/code, discord.com/invite/code)
1927
1835
  */
1928
- static async delete(invite) {
1836
+ static async find(codeOrUrl) {
1837
+ try {
1838
+ return await Bot.client.fetchInvite(codeOrUrl);
1839
+ } catch (error) {
1840
+ import_utils17.Log.error(`Failed to find invite ${codeOrUrl}: ${error}`);
1841
+ return null;
1842
+ }
1843
+ }
1844
+ static async delete(inviteOrCode) {
1845
+ const invite = typeof inviteOrCode === "string" ? await this.find(inviteOrCode) : inviteOrCode;
1846
+ if (!invite) return false;
1929
1847
  try {
1930
1848
  await invite.delete();
1931
1849
  import_utils17.Log.info(`Deleted invite ${invite.code} from guild ${invite.guild?.id}`);
@@ -1953,6 +1871,33 @@ var InviteManager = class {
1953
1871
  throw error;
1954
1872
  }
1955
1873
  }
1874
+ /**
1875
+ * Check if an invite is older than maxAgeMs (default 1 hour).
1876
+ * Permanent invites (maxAge = 0) and excluded codes are never considered old
1877
+ */
1878
+ static isOld(invite, excludedCodes = [], maxAgeMs = 60 * 60 * 1e3) {
1879
+ if (!invite.createdAt) return false;
1880
+ return invite.maxAge !== 0 && !excludedCodes.includes(invite.code) && invite.createdAt.getTime() < Date.now() - maxAgeMs;
1881
+ }
1882
+ /**
1883
+ * Delete every old invite of a guild, returns the number of deleted invites
1884
+ */
1885
+ static async cleanup(guildId, excludedCodes = [], maxAgeMs) {
1886
+ try {
1887
+ const invites = await this.list(guildId);
1888
+ let deletedCount = 0;
1889
+ for (const invite of invites) {
1890
+ if (!this.isOld(invite, excludedCodes, maxAgeMs)) continue;
1891
+ if (await this.delete(invite)) deletedCount++;
1892
+ await (0, import_promises3.setTimeout)(100);
1893
+ }
1894
+ import_utils17.Log.info(`Invite cleanup ${guildId}: ${deletedCount} old invites deleted`);
1895
+ return deletedCount;
1896
+ } catch (error) {
1897
+ import_utils17.Log.error(`Invite cleanup failed for ${guildId}: ${error}`);
1898
+ return 0;
1899
+ }
1900
+ }
1956
1901
  };
1957
1902
 
1958
1903
  // src/manager/guild/GuildManager.ts
@@ -1988,9 +1933,9 @@ var GuildManager = class {
1988
1933
  /**
1989
1934
  * Search guild member by ID
1990
1935
  */
1991
- static async searchMember(memberId, guildId) {
1936
+ static async searchMember(guildId, memberId) {
1992
1937
  try {
1993
- return await this.user.findInGuild(guildId, guildId);
1938
+ return await this.user.findInGuild(guildId, memberId);
1994
1939
  } catch (error) {
1995
1940
  import_utils18.Log.error(`Failed to fetch member ${memberId} in guild ${guildId}: ${error}`);
1996
1941
  return null;
@@ -1999,9 +1944,9 @@ var GuildManager = class {
1999
1944
  /**
2000
1945
  * Check if member is still in guild
2001
1946
  */
2002
- static async isMemberInGuild(memberId, guildId) {
1947
+ static async isMemberInGuild(guildId, memberId) {
2003
1948
  try {
2004
- return await this.user.isInGuild(memberId, guildId);
1949
+ return await this.user.isInGuild(guildId, memberId);
2005
1950
  } catch (error) {
2006
1951
  return error.code !== 10007;
2007
1952
  }
@@ -2011,7 +1956,7 @@ var GuildManager = class {
2011
1956
  */
2012
1957
  static async fetchAllMembers(guildId, MAX_ATTEMPTS = 3, RETRY_DELAY = import_utils19.Time.minute.MIN_05.toMilliseconds()) {
2013
1958
  let guild;
2014
- if (guildId instanceof import_discord14.Guild) {
1959
+ if (guildId instanceof import_discord18.Guild) {
2015
1960
  guild = guildId;
2016
1961
  } else {
2017
1962
  let tmp = Bot.client.guilds.cache.get(guildId);
@@ -2064,10 +2009,10 @@ var GuildManager = class {
2064
2009
  if (!toChannel) {
2065
2010
  throw new Error(`To channel ${toChannelId} not found`);
2066
2011
  }
2067
- if (!(fromChannel instanceof import_discord14.VoiceChannel || fromChannel instanceof import_discord14.StageChannel)) {
2012
+ if (!(fromChannel instanceof import_discord18.VoiceChannel || fromChannel instanceof import_discord18.StageChannel)) {
2068
2013
  throw new Error(`From channel ${fromChannelId} is not a voice/stage channel`);
2069
2014
  }
2070
- if (!(toChannel instanceof import_discord14.VoiceChannel || toChannel instanceof import_discord14.StageChannel)) {
2015
+ if (!(toChannel instanceof import_discord18.VoiceChannel || toChannel instanceof import_discord18.StageChannel)) {
2071
2016
  throw new Error(`To channel ${toChannelId} is not a voice/stage channel`);
2072
2017
  }
2073
2018
  if (member.voice.channelId !== fromChannelId) {
@@ -2101,7 +2046,7 @@ var UserManager = class extends BasicUserManager {
2101
2046
  };
2102
2047
 
2103
2048
  // src/manager/interactible/ModalManager.ts
2104
- var import_discord15 = require("discord.js");
2049
+ var import_discord19 = require("discord.js");
2105
2050
  var ModalFieldType = /* @__PURE__ */ ((ModalFieldType2) => {
2106
2051
  ModalFieldType2[ModalFieldType2["SHORT"] = 0] = "SHORT";
2107
2052
  ModalFieldType2[ModalFieldType2["LONG"] = 1] = "LONG";
@@ -2115,13 +2060,13 @@ var ModalManager = class {
2115
2060
  * Creates base Modal - SIMPLE API !
2116
2061
  */
2117
2062
  static create(modalTitle, customId) {
2118
- return new import_discord15.ModalBuilder().setTitle(modalTitle).setCustomId(customId);
2063
+ return new import_discord19.ModalBuilder().setTitle(modalTitle).setCustomId(customId);
2119
2064
  }
2120
2065
  /**
2121
2066
  * Individual field creator
2122
2067
  */
2123
2068
  static _createField(opt) {
2124
- const builder = new import_discord15.TextInputBuilder().setCustomId(opt.customId).setRequired(opt.required ?? false);
2069
+ const builder = new import_discord19.TextInputBuilder().setCustomId(opt.customId).setRequired(opt.required ?? false);
2125
2070
  if (opt.value) {
2126
2071
  builder.setValue(opt.value);
2127
2072
  }
@@ -2132,22 +2077,22 @@ var ModalManager = class {
2132
2077
  }
2133
2078
  switch (opt.type) {
2134
2079
  case 0 /* SHORT */:
2135
- builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(4e3);
2080
+ builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(4e3);
2136
2081
  break;
2137
2082
  case 1 /* LONG */:
2138
- builder.setStyle(import_discord15.TextInputStyle.Paragraph).setMaxLength(4e3);
2083
+ builder.setStyle(import_discord19.TextInputStyle.Paragraph).setMaxLength(4e3);
2139
2084
  break;
2140
2085
  case 2 /* NUMBER */:
2141
- builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(10);
2086
+ builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(10);
2142
2087
  break;
2143
2088
  case 3 /* DATE */:
2144
- builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(10).setPlaceholder("YYYY-MM-DD / DD-MM-YYYY or YYYY/MM/DD / DD/MM/YYYY");
2089
+ builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(10).setPlaceholder("YYYY-MM-DD / DD-MM-YYYY or YYYY/MM/DD / DD/MM/YYYY");
2145
2090
  break;
2146
2091
  case 4 /* PHONE */:
2147
- builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(20);
2092
+ builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(20);
2148
2093
  break;
2149
2094
  }
2150
- return new import_discord15.LabelBuilder().setLabel(opt.label).setTextInputComponent(builder);
2095
+ return new import_discord19.LabelBuilder().setLabel(opt.label).setTextInputComponent(builder);
2151
2096
  }
2152
2097
  /**
2153
2098
  * Simple modal with ONE field - DIRECT ModalBuilder return !
@@ -2156,7 +2101,7 @@ var ModalManager = class {
2156
2101
  const modal = this.create(modalTitle ?? Bot.config?.botName ?? "Bot", customId);
2157
2102
  const opt = {
2158
2103
  ...field,
2159
- customId: `${customId}_input`,
2104
+ customId: field.customId ?? `${customId}_input`,
2160
2105
  placeholder: "placeholder" in field && field.placeholder ? field.placeholder : `Enter ${field.label.toLowerCase()}`,
2161
2106
  value: field.value
2162
2107
  };
@@ -2166,21 +2111,23 @@ var ModalManager = class {
2166
2111
  /**
2167
2112
  * Title + Description modal preset
2168
2113
  */
2169
- static titleDescription(customId, modalTitle, title, description) {
2114
+ static titleDescription(customId, modalTitle, title, description2) {
2170
2115
  const modal = this.create(modalTitle, customId);
2171
2116
  const titleField = {
2172
2117
  customId: `${customId}_title`,
2173
2118
  label: title.label,
2174
2119
  placeholder: title.placeholder ?? `Enter ${title.label.toLowerCase()}`,
2175
2120
  type: 0 /* SHORT */,
2176
- required: title.required
2121
+ required: title.required,
2122
+ value: title.value
2177
2123
  };
2178
2124
  const descField = {
2179
2125
  customId: `${customId}_desc`,
2180
- label: description.label,
2181
- placeholder: description.placeholder ?? `Enter ${description.label.toLowerCase()}`,
2126
+ label: description2.label,
2127
+ placeholder: description2.placeholder ?? `Enter ${description2.label.toLowerCase()}`,
2182
2128
  type: 1 /* LONG */,
2183
- required: description.required
2129
+ required: description2.required,
2130
+ value: description2.value
2184
2131
  };
2185
2132
  modal.addLabelComponents(this._createField(titleField));
2186
2133
  modal.addLabelComponents(this._createField(descField));
@@ -2188,21 +2135,25 @@ var ModalManager = class {
2188
2135
  }
2189
2136
  /**
2190
2137
  * Date modal preset
2138
+ * @param suffix true (default) : the modal customId is `${customId}_date` and the input `${customId}_date_input`,
2139
+ * false : the modal keeps `customId` and the input is `${customId}_input`. Same for number() (_number) and phone() (_phone_number)
2191
2140
  */
2192
- static date(customId, modalTitle = "Select Date", inputLabel = "Date") {
2193
- return this.simple(`${customId}_date`, modalTitle, { label: inputLabel, type: 3 /* DATE */ });
2141
+ static date(customId, modalTitle = "Select Date", inputLabel = "Date", suffix = true) {
2142
+ return this.simple(suffix ? `${customId}_date` : customId, modalTitle, { label: inputLabel, type: 3 /* DATE */ });
2194
2143
  }
2195
2144
  /**
2196
2145
  * Number modal preset
2146
+ * @param suffix See date() : `${customId}_number` by default, `customId` when false
2197
2147
  */
2198
- static number(customId, modalTitle = "Enter a Number", inputLabel = "Number") {
2199
- return this.simple(`${customId}_number`, modalTitle, { label: inputLabel, type: 2 /* NUMBER */, placeholder: "Enter a number" });
2148
+ static number(customId, modalTitle = "Enter a Number", inputLabel = "Number", suffix = true) {
2149
+ return this.simple(suffix ? `${customId}_number` : customId, modalTitle, { label: inputLabel, type: 2 /* NUMBER */, placeholder: "Enter a number" });
2200
2150
  }
2201
2151
  /**
2202
- * Number modal preset
2152
+ * Phone modal preset
2153
+ * @param suffix See date() : `${customId}_phone_number` by default, `customId` when false
2203
2154
  */
2204
- static phone(customId, modalTitle = "Enter a Phone number", inputLabel = "Phone number") {
2205
- return this.simple(`${customId}_phone_number`, modalTitle, { label: inputLabel, type: 4 /* PHONE */, placeholder: "Enter a phone number" });
2155
+ static phone(customId, modalTitle = "Enter a Phone number", inputLabel = "Phone number", suffix = true) {
2156
+ return this.simple(suffix ? `${customId}_phone_number` : customId, modalTitle, { label: inputLabel, type: 4 /* PHONE */, placeholder: "Enter a phone number" });
2206
2157
  }
2207
2158
  static add(modal, field) {
2208
2159
  if (Array.isArray(field)) {
@@ -2213,7 +2164,7 @@ var ModalManager = class {
2213
2164
  }
2214
2165
  const opt = {
2215
2166
  ...field,
2216
- customId: `${modal.data.custom_id}_${field.label}`
2167
+ customId: field.customId ?? `${modal.data.custom_id}_${field.label}`
2217
2168
  };
2218
2169
  modal.addLabelComponents(this._createField(opt));
2219
2170
  return modal;
@@ -2232,124 +2183,128 @@ var ModalManager = class {
2232
2183
  static parseDate(value) {
2233
2184
  if (/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/.test(value)) {
2234
2185
  const [year, month, day] = value.split("-").map(Number);
2235
- const date = new Date(year, month - 1, day);
2236
- return isNaN(date.getTime()) ? null : date;
2186
+ return this.buildDate(year, month, day);
2237
2187
  }
2238
2188
  if (/^(0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])-\d{4}$/.test(value)) {
2239
2189
  const [day, month, year] = value.split("-").map(Number);
2240
- const date = new Date(year, month - 1, day);
2241
- return isNaN(date.getTime()) ? null : date;
2190
+ return this.buildDate(year, month, day);
2242
2191
  }
2243
2192
  if (/^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/\d{4}$/.test(value)) {
2244
2193
  const [day, month, year] = value.split("/").map(Number);
2245
- const date = new Date(year, month - 1, day);
2246
- return isNaN(date.getTime()) ? null : date;
2194
+ return this.buildDate(year, month, day);
2247
2195
  }
2248
2196
  if (/^\d{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])$/.test(value)) {
2249
2197
  const [year, month, day] = value.split("/").map(Number);
2250
- const date = new Date(year, month - 1, day);
2251
- return isNaN(date.getTime()) ? null : date;
2198
+ return this.buildDate(year, month, day);
2252
2199
  }
2253
2200
  return null;
2254
2201
  }
2202
+ /**
2203
+ * new Date() silently rolls an impossible date over (31/02 becomes 02/03) : reject any date that doesn't round-trip
2204
+ */
2205
+ static buildDate(year, month, day) {
2206
+ const date = new Date(year, month - 1, day);
2207
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return null;
2208
+ return date;
2209
+ }
2255
2210
  };
2256
2211
 
2257
2212
  // src/manager/messages/ComponentManager.ts
2258
- var import_discord16 = require("discord.js");
2213
+ var import_discord20 = require("discord.js");
2259
2214
  var ComponentManager = class {
2260
2215
  static get DEFAULT_COLOR() {
2261
- return Bot.config?.defaultSimpleColor || 6064856 /* default */;
2216
+ return Bot.config?.defaultSimpleColor ?? 6064856 /* default */;
2262
2217
  }
2263
2218
  /**
2264
2219
  * Creates base ComponentV2
2265
2220
  */
2266
2221
  static create(option) {
2267
- const container = new import_discord16.ContainerBuilder();
2222
+ const container = new import_discord20.ContainerBuilder();
2268
2223
  const colorC = option?.color ?? this.DEFAULT_COLOR;
2269
2224
  if (colorC !== "transparent" /* transparent */) {
2270
2225
  container.setAccentColor(colorC);
2271
2226
  }
2272
2227
  if (option?.title || option?.thumbnailUrl) {
2273
2228
  if (option?.thumbnailUrl) {
2274
- const headerSection = new import_discord16.SectionBuilder().addTextDisplayComponents(
2275
- new import_discord16.TextDisplayBuilder().setContent(
2229
+ const headerSection = new import_discord20.SectionBuilder().addTextDisplayComponents(
2230
+ new import_discord20.TextDisplayBuilder().setContent(
2276
2231
  option?.title ? option.title : "\u200B"
2277
2232
  )
2278
2233
  ).setThumbnailAccessory(
2279
- new import_discord16.ThumbnailBuilder().setURL(option.thumbnailUrl)
2234
+ new import_discord20.ThumbnailBuilder().setURL(option.thumbnailUrl)
2280
2235
  );
2281
2236
  container.addSectionComponents(headerSection);
2282
2237
  } else {
2283
2238
  container.addTextDisplayComponents(
2284
- new import_discord16.TextDisplayBuilder().setContent(option.title)
2239
+ new import_discord20.TextDisplayBuilder().setContent(option.title)
2285
2240
  );
2286
2241
  }
2287
- if (option?.description) {
2288
- container.addTextDisplayComponents(new import_discord16.TextDisplayBuilder().setContent(option.description));
2289
- }
2290
- if (option?.separator) {
2291
- container.addSeparatorComponents(this.separator(option.separator));
2292
- }
2242
+ }
2243
+ if (option?.description) {
2244
+ container.addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(option.description));
2245
+ }
2246
+ if (option?.separator && (option.title || option.thumbnailUrl || option.description)) {
2247
+ container.addSeparatorComponents(this.separator(option.separator));
2293
2248
  }
2294
2249
  return container;
2295
2250
  }
2296
2251
  /**
2297
2252
  * Creates simple ComponentV2 with just description
2298
2253
  */
2299
- static simple(description, color = null) {
2300
- return this.create({ color }).addTextDisplayComponents(new import_discord16.TextDisplayBuilder().setContent(description)).addSeparatorComponents(this.separator());
2254
+ static simple(description2, color = null) {
2255
+ return this.create({ color }).addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(description2)).addSeparatorComponents(this.separator());
2301
2256
  }
2302
2257
  /**
2303
2258
  * Creates success ComponentV2
2304
2259
  */
2305
- static success(description) {
2306
- return this.create({ title: "Success", color: 65280 /* success */ }).addTextDisplayComponents(new import_discord16.TextDisplayBuilder().setContent(description)).addSeparatorComponents(this.separator());
2260
+ static success(description2) {
2261
+ return this.create({ title: "Success", color: 65280 /* success */ }).addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(description2)).addSeparatorComponents(this.separator());
2307
2262
  }
2308
2263
  /**
2309
2264
  * Creates debug ComponentV2
2310
2265
  */
2311
- static debug(description) {
2266
+ static debug(description2) {
2312
2267
  return this.create({ title: "Debug", color: 25600 /* minecraft */ }).addTextDisplayComponents(
2313
- new import_discord16.TextDisplayBuilder().setContent(description)
2268
+ new import_discord20.TextDisplayBuilder().setContent(description2)
2314
2269
  ).addSeparatorComponents(this.separator());
2315
2270
  }
2316
2271
  /**
2317
2272
  * Creates error ComponentV2
2318
2273
  */
2319
- static error(description) {
2274
+ static error(description2) {
2320
2275
  return this.create({ title: "Something went wrong", color: 8912917 /* error */ }).addTextDisplayComponents(
2321
- new import_discord16.TextDisplayBuilder().setContent(description)
2276
+ new import_discord20.TextDisplayBuilder().setContent(description2)
2322
2277
  ).addSeparatorComponents(this.separator());
2323
2278
  }
2324
- static separator(spacing = import_discord16.SeparatorSpacingSize.Small) {
2325
- return new import_discord16.SeparatorBuilder().setDivider(true).setSpacing(spacing);
2279
+ static separator(spacing = import_discord20.SeparatorSpacingSize.Small) {
2280
+ return new import_discord20.SeparatorBuilder().setDivider(true).setSpacing(spacing);
2326
2281
  }
2327
2282
  /**
2328
2283
  * Quick field adder
2329
2284
  */
2330
2285
  static fieldAddText(container, options) {
2331
- options.name && container.addTextDisplayComponents(new import_discord16.TextDisplayBuilder().setContent(`__**${options.name}**__`));
2332
- options.value && container.addTextDisplayComponents(new import_discord16.TextDisplayBuilder().setContent(options.value));
2286
+ options.name && container.addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(`__**${options.name}**__`));
2287
+ options.value && container.addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(options.value));
2333
2288
  }
2334
2289
  static field(container, field) {
2335
2290
  const hasText = ("name" in field || "value" in field) && (field.name || field.value);
2336
2291
  if ("button" in field && Array.isArray(field.button) && field.button.length > 0) {
2337
- const actionRow = new import_discord16.ActionRowBuilder().addComponents(field.button);
2292
+ const actionRow = new import_discord20.ActionRowBuilder().addComponents(field.button);
2338
2293
  if (hasText) this.fieldAddText(container, { name: field.name, value: field.value });
2339
2294
  container.addActionRowComponents(actionRow);
2340
2295
  } else if ("button" in field && !Array.isArray(field.button) || "thumbnailUrl" in field) {
2341
2296
  if (hasText) {
2342
- const section = new import_discord16.SectionBuilder();
2297
+ const section = new import_discord20.SectionBuilder();
2343
2298
  this.fieldAddText(section, { name: field.name, value: field.value });
2344
2299
  if ("button" in field && !Array.isArray(field.button)) {
2345
2300
  section.setButtonAccessory(field.button);
2346
2301
  } else if ("thumbnailUrl" in field) {
2347
- section.setThumbnailAccessory(new import_discord16.ThumbnailBuilder().setURL(field.thumbnailUrl));
2302
+ section.setThumbnailAccessory(new import_discord20.ThumbnailBuilder().setURL(field.thumbnailUrl));
2348
2303
  }
2349
2304
  container.addSectionComponents(section);
2350
2305
  } else {
2351
2306
  if ("button" in field && !Array.isArray(field.button)) {
2352
- const actionRow = new import_discord16.ActionRowBuilder().addComponents(field.button);
2307
+ const actionRow = new import_discord20.ActionRowBuilder().addComponents(field.button);
2353
2308
  container.addActionRowComponents(actionRow);
2354
2309
  }
2355
2310
  }
@@ -2388,9 +2343,9 @@ var ComponentManager = class {
2388
2343
  * Add a media gallery (links)
2389
2344
  */
2390
2345
  static mediaGallery(container, medias) {
2391
- const gallery = new import_discord16.MediaGalleryBuilder();
2346
+ const gallery = new import_discord20.MediaGalleryBuilder();
2392
2347
  medias.forEach((med) => {
2393
- gallery.addItems(new import_discord16.MediaGalleryItemBuilder().setURL(med.url).setSpoiler(med.spoiler ?? false));
2348
+ gallery.addItems(new import_discord20.MediaGalleryItemBuilder().setURL(med.url).setSpoiler(med.spoiler ?? false));
2394
2349
  });
2395
2350
  container.addMediaGalleryComponents(gallery);
2396
2351
  return container;
@@ -2407,22 +2362,25 @@ var ComponentManager = class {
2407
2362
  const files = [];
2408
2363
  const fileArray = Array.isArray(file) ? file : [file];
2409
2364
  fileArray.forEach((f) => {
2410
- const attachment = new import_discord16.AttachmentBuilder(f.buffer, {
2365
+ const attachment = new import_discord20.AttachmentBuilder(f.buffer, {
2411
2366
  name: f.name
2412
2367
  });
2413
2368
  files.push(attachment);
2414
2369
  container.addFileComponents(
2415
- new import_discord16.FileBuilder().setURL(`attachment://${f.name}`).setSpoiler(f.spoiler ?? false)
2370
+ new import_discord20.FileBuilder().setURL(`attachment://${f.name}`).setSpoiler(f.spoiler ?? false)
2416
2371
  );
2417
2372
  container.addSeparatorComponents(this.separator());
2418
2373
  });
2419
2374
  return { container, files };
2420
2375
  }
2376
+ /**
2377
+ * Returns a copy with the footer, so calling toMessage() / toInteraction() twice on the same
2378
+ * container doesn't stack footers
2379
+ */
2421
2380
  static footer(container) {
2422
- container.addTextDisplayComponents(
2423
- new import_discord16.TextDisplayBuilder().setContent(`-# **${Bot.config?.botName || "Bot"} \xB7 <t:${Math.floor(Date.now() / 1e3)}:d> <t:${Math.floor(Date.now() / 1e3)}:t>**`)
2381
+ return new import_discord20.ContainerBuilder(container.toJSON()).addTextDisplayComponents(
2382
+ new import_discord20.TextDisplayBuilder().setContent(`-# **${Bot.config?.botName || "Bot"} \xB7 <t:${Math.floor(Date.now() / 1e3)}:d> <t:${Math.floor(Date.now() / 1e3)}:t>**`)
2424
2383
  );
2425
- return container;
2426
2384
  }
2427
2385
  /**
2428
2386
  * Transform ComponentV2 into object for channel.send()
@@ -2432,27 +2390,27 @@ var ComponentManager = class {
2432
2390
  */
2433
2391
  static toMessage(container, file = null, footer = true) {
2434
2392
  if (footer) {
2435
- this.footer(container);
2393
+ container = this.footer(container);
2436
2394
  }
2437
2395
  if (file) {
2438
2396
  return {
2439
2397
  components: [container],
2440
2398
  files: Array.isArray(file) ? file : [file],
2441
- flags: [import_discord16.MessageFlags.IsComponentsV2]
2399
+ flags: [import_discord20.MessageFlags.IsComponentsV2]
2442
2400
  };
2443
2401
  }
2444
2402
  return {
2445
2403
  components: [container],
2446
- flags: [import_discord16.MessageFlags.IsComponentsV2]
2404
+ flags: [import_discord20.MessageFlags.IsComponentsV2]
2447
2405
  };
2448
2406
  }
2449
- static toInteraction(container, file = null, footer = true) {
2407
+ static toInteraction(container, file = null, footer = true, ephemeral = false) {
2450
2408
  if (footer) {
2451
- this.footer(container);
2409
+ container = this.footer(container);
2452
2410
  }
2453
2411
  const base = {
2454
2412
  components: [container],
2455
- flags: [import_discord16.MessageFlags.IsComponentsV2]
2413
+ flags: ephemeral ? [import_discord20.MessageFlags.IsComponentsV2, import_discord20.MessageFlags.Ephemeral] : [import_discord20.MessageFlags.IsComponentsV2]
2456
2414
  };
2457
2415
  if (file) {
2458
2416
  return {
@@ -2462,12 +2420,16 @@ var ComponentManager = class {
2462
2420
  }
2463
2421
  return base;
2464
2422
  }
2465
- static toInteractionEdit(container, file = null, footer = true) {
2423
+ /**
2424
+ * Options to edit an existing message : message.edit(). The Components V2 flag is set, so a legacy message can be turned into a V2 one
2425
+ */
2426
+ static toMessageUpdate(container, file = null, footer = true) {
2466
2427
  if (footer) {
2467
- this.footer(container);
2428
+ container = this.footer(container);
2468
2429
  }
2469
2430
  const base = {
2470
- components: [container]
2431
+ components: [container],
2432
+ flags: [import_discord20.MessageFlags.IsComponentsV2]
2471
2433
  };
2472
2434
  if (file) {
2473
2435
  return {
@@ -2477,10 +2439,16 @@ var ComponentManager = class {
2477
2439
  }
2478
2440
  return base;
2479
2441
  }
2442
+ /**
2443
+ * Options for interaction.update() and interaction.editReply() (buttons, select menus, modals, deferred replies), with the Components V2 flag
2444
+ */
2445
+ static toInteractionUpdate(container, file = null, footer = true) {
2446
+ return this.toMessageUpdate(container, file, footer);
2447
+ }
2480
2448
  };
2481
2449
 
2482
2450
  // src/manager/messages/ChartManager.ts
2483
- var import_discord17 = require("discord.js");
2451
+ var import_discord21 = require("discord.js");
2484
2452
  var SPARK_BLOCKS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
2485
2453
  var DEFAULT_MAX_POINTS = 50;
2486
2454
  var EMPTY = "\u2014";
@@ -2490,7 +2458,7 @@ var ChartManager = class _ChartManager {
2490
2458
  */
2491
2459
  static progressBar(label, value, max = 100, options = {}) {
2492
2460
  const line = `${label} : ${_ChartManager.renderBar(value, max, options)}`;
2493
- return new import_discord17.TextDisplayBuilder().setContent(_ChartManager.wrap(line, options.codeBlock));
2461
+ return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(line, options.codeBlock));
2494
2462
  }
2495
2463
  /**
2496
2464
  * Several gauges in ONE TextDisplay, so a dashboard of 6 metrics still costs 1 component.
@@ -2502,7 +2470,7 @@ var ChartManager = class _ChartManager {
2502
2470
  const opts = { ...options, ...row.options };
2503
2471
  return `${row.label.padEnd(width, " ")} : ${_ChartManager.renderBar(row.value, row.max ?? 100, opts)}`;
2504
2472
  });
2505
- return new import_discord17.TextDisplayBuilder().setContent(_ChartManager.wrap(lines.join("\n"), options.codeBlock));
2473
+ return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(lines.join("\n"), options.codeBlock));
2506
2474
  }
2507
2475
  /**
2508
2476
  * A one line curve : `RAM : ▁▂▃▅▇█▆▄▃▂▁ 62 %`. One block character per point, the last
@@ -2510,7 +2478,7 @@ var ChartManager = class _ChartManager {
2510
2478
  */
2511
2479
  static sparkline(label, values, options = {}) {
2512
2480
  const line = `${label} : ${_ChartManager.renderSpark(values, options)}`;
2513
- return new import_discord17.TextDisplayBuilder().setContent(_ChartManager.wrap(line, options.codeBlock));
2481
+ return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(line, options.codeBlock));
2514
2482
  }
2515
2483
  /**
2516
2484
  * Several curves in ONE TextDisplay, the sparkline counterpart of progressBars().
@@ -2523,7 +2491,7 @@ var ChartManager = class _ChartManager {
2523
2491
  const opts = { ...base, ...row.options };
2524
2492
  return `${row.label.padEnd(width, " ")} : ${_ChartManager.renderSpark(row.values, opts)}`;
2525
2493
  });
2526
- return new import_discord17.TextDisplayBuilder().setContent(_ChartManager.wrap(lines.join("\n"), options.codeBlock));
2494
+ return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(lines.join("\n"), options.codeBlock));
2527
2495
  }
2528
2496
  /**
2529
2497
  * Only fills the bounds that were not given explicitly, and only when asked : a row
@@ -2585,29 +2553,32 @@ var ChartManager = class _ChartManager {
2585
2553
  };
2586
2554
 
2587
2555
  // src/manager/interactible/ButtonManager.ts
2588
- var import_discord18 = require("discord.js");
2556
+ var import_discord22 = require("discord.js");
2589
2557
  var ButtonManager = class _ButtonManager {
2590
2558
  static create(options) {
2591
- const btn = new import_discord18.ButtonBuilder().setCustomId(options.customId).setLabel(options.label ?? "Button").setStyle(options.style).setDisabled(options.disabled ?? false);
2559
+ const btn = new import_discord22.ButtonBuilder().setCustomId(options.customId).setStyle(options.style).setDisabled(options.disabled ?? false);
2560
+ if (options.label || !options.emoji) {
2561
+ btn.setLabel(options.label ?? "Button");
2562
+ }
2592
2563
  if (options.emoji) {
2593
2564
  btn.setEmoji(options.emoji);
2594
2565
  }
2595
2566
  return btn;
2596
2567
  }
2597
2568
  static primary(options) {
2598
- return this.create({ ...options, style: import_discord18.ButtonStyle.Primary });
2569
+ return this.create({ ...options, style: import_discord22.ButtonStyle.Primary });
2599
2570
  }
2600
2571
  static success(options) {
2601
- return this.create({ ...options, style: import_discord18.ButtonStyle.Success });
2572
+ return this.create({ ...options, style: import_discord22.ButtonStyle.Success });
2602
2573
  }
2603
2574
  static secondary(options) {
2604
- return this.create({ ...options, style: import_discord18.ButtonStyle.Secondary });
2575
+ return this.create({ ...options, style: import_discord22.ButtonStyle.Secondary });
2605
2576
  }
2606
2577
  static danger(options) {
2607
- return this.create({ ...options, style: import_discord18.ButtonStyle.Danger });
2578
+ return this.create({ ...options, style: import_discord22.ButtonStyle.Danger });
2608
2579
  }
2609
2580
  static link(options) {
2610
- const btn = new import_discord18.ButtonBuilder().setLabel(options.label).setStyle(import_discord18.ButtonStyle.Link).setURL(options.url);
2581
+ const btn = new import_discord22.ButtonBuilder().setLabel(options.label).setStyle(import_discord22.ButtonStyle.Link).setURL(options.url);
2611
2582
  if (options.emoji) btn.setEmoji(options.emoji);
2612
2583
  return btn;
2613
2584
  }
@@ -2619,7 +2590,7 @@ var ButtonManager = class _ButtonManager {
2619
2590
  }
2620
2591
  static row(but) {
2621
2592
  const buttons = Array.isArray(but) ? but.slice(0, 5) : [but];
2622
- return new import_discord18.ActionRowBuilder().addComponents(buttons);
2593
+ return new import_discord22.ActionRowBuilder().addComponents(buttons);
2623
2594
  }
2624
2595
  static toMessage(button) {
2625
2596
  return {
@@ -2629,40 +2600,154 @@ var ButtonManager = class _ButtonManager {
2629
2600
  static toInteraction(button, ephemeral = false) {
2630
2601
  return {
2631
2602
  components: this.createRowsToReturn(button),
2632
- flags: ephemeral ? [import_discord18.MessageFlags.Ephemeral] : []
2603
+ flags: ephemeral ? [import_discord22.MessageFlags.Ephemeral] : []
2633
2604
  };
2634
2605
  }
2635
- static toInteractionEdit(button) {
2606
+ /**
2607
+ * Options to edit an existing message : message.edit()
2608
+ */
2609
+ static toMessageUpdate(button) {
2636
2610
  return {
2637
2611
  components: this.createRowsToReturn(button)
2638
2612
  };
2639
2613
  }
2614
+ /**
2615
+ * Options for interaction.update() and interaction.editReply() (buttons, select menus, modals, deferred replies)
2616
+ */
2617
+ static toInteractionUpdate(button) {
2618
+ return this.toMessageUpdate(button);
2619
+ }
2620
+ /**
2621
+ * Consecutive buttons are grouped by 5 in the same row (like row() does), action rows are kept as is
2622
+ */
2640
2623
  static createRowsToReturn(button) {
2641
- if (Array.isArray(button)) {
2642
- return button.map(
2643
- (btn) => btn instanceof import_discord18.ActionRowBuilder ? btn : _ButtonManager.row(btn)
2644
- );
2624
+ const items = Array.isArray(button) ? button : [button];
2625
+ const rows = [];
2626
+ let pending = [];
2627
+ const flush = () => {
2628
+ for (let i = 0; i < pending.length; i += 5) {
2629
+ rows.push(_ButtonManager.row(pending.slice(i, i + 5)));
2630
+ }
2631
+ pending = [];
2632
+ };
2633
+ for (const item of items) {
2634
+ if (item instanceof import_discord22.ActionRowBuilder) {
2635
+ flush();
2636
+ rows.push(item);
2637
+ } else {
2638
+ pending.push(item);
2639
+ }
2640
+ }
2641
+ flush();
2642
+ return rows;
2643
+ }
2644
+ };
2645
+
2646
+ // src/manager/interactible/PaginationManager.ts
2647
+ var import_discord23 = require("discord.js");
2648
+ var import_utils21 = require("@spatulox/utils");
2649
+ var PaginationManager = class {
2650
+ /**
2651
+ * Reply to the interaction (or edit the deferred reply) with the first page and navigation buttons.
2652
+ * Only the user who triggered the interaction can navigate, and the buttons are disabled when the
2653
+ * collector ends.
2654
+ */
2655
+ static async send(interaction, pages, options = {}) {
2656
+ if (pages.length === 0) {
2657
+ import_utils21.Log.error("PaginationManager: at least one page is required");
2658
+ return null;
2659
+ }
2660
+ const prefix = `pag_${interaction.id}_`;
2661
+ let currentPage = 0;
2662
+ const payload = (disabled = false) => {
2663
+ const page = pages[currentPage];
2664
+ return {
2665
+ content: page.content ?? "",
2666
+ embeds: [page.embed],
2667
+ components: [this.row(prefix, currentPage, pages.length, disabled)]
2668
+ };
2669
+ };
2670
+ let message;
2671
+ if (interaction.deferred || interaction.replied) {
2672
+ message = await interaction.editReply(payload());
2673
+ } else {
2674
+ const response = await interaction.reply({
2675
+ ...payload(),
2676
+ flags: options.ephemeral ? [import_discord23.MessageFlags.Ephemeral] : [],
2677
+ withResponse: true
2678
+ });
2679
+ message = response.resource?.message ?? await interaction.fetchReply();
2645
2680
  }
2646
- return button instanceof import_discord18.ActionRowBuilder ? [button] : [_ButtonManager.row(button)];
2681
+ const collector = message.createMessageComponentCollector({
2682
+ componentType: import_discord23.ComponentType.Button,
2683
+ filter: (i) => i.customId.startsWith(prefix),
2684
+ time: options.time ?? 6e4,
2685
+ idle: options.idle ?? 15e3
2686
+ });
2687
+ collector.on("collect", async (i) => {
2688
+ try {
2689
+ if (i.user.id !== interaction.user.id) {
2690
+ await i.reply({ content: "Only the user who opened this pagination can use it", flags: [import_discord23.MessageFlags.Ephemeral] });
2691
+ return;
2692
+ }
2693
+ switch (i.customId.slice(prefix.length)) {
2694
+ case "first":
2695
+ currentPage = 0;
2696
+ break;
2697
+ case "prev":
2698
+ currentPage = Math.max(0, currentPage - 1);
2699
+ break;
2700
+ case "next":
2701
+ currentPage = Math.min(pages.length - 1, currentPage + 1);
2702
+ break;
2703
+ case "last":
2704
+ currentPage = pages.length - 1;
2705
+ break;
2706
+ }
2707
+ await i.update(payload());
2708
+ } catch (error) {
2709
+ import_utils21.Log.error(`PaginationManager: failed to update the page: ${error}`);
2710
+ }
2711
+ });
2712
+ collector.on("end", async () => {
2713
+ await interaction.editReply({ components: [this.row(prefix, currentPage, pages.length, true)] }).catch((error) => import_utils21.Log.warn(`PaginationManager: failed to disable the buttons: ${error}`));
2714
+ });
2715
+ return collector;
2716
+ }
2717
+ static row(prefix, currentPage, pageCount, disabled) {
2718
+ const isFirst = currentPage === 0;
2719
+ const isLast = currentPage === pageCount - 1;
2720
+ return new import_discord23.ActionRowBuilder().addComponents(
2721
+ ButtonManager.secondary({ customId: `${prefix}first`, emoji: "\u23EA", disabled: disabled || isFirst }),
2722
+ ButtonManager.secondary({ customId: `${prefix}prev`, emoji: "\u2B05\uFE0F", disabled: disabled || isFirst }),
2723
+ // Page indicator only : always disabled, it can't be clicked
2724
+ ButtonManager.secondary({ customId: `${prefix}page`, label: `${currentPage + 1}/${pageCount}`, disabled: true }),
2725
+ ButtonManager.secondary({ customId: `${prefix}next`, emoji: "\u27A1\uFE0F", disabled: disabled || isLast }),
2726
+ ButtonManager.secondary({ customId: `${prefix}last`, emoji: "\u23E9", disabled: disabled || isLast })
2727
+ );
2647
2728
  }
2648
2729
  };
2649
2730
 
2650
2731
  // src/index.ts
2651
- var import_utils23 = require("@spatulox/utils");
2652
2732
  var import_utils24 = require("@spatulox/utils");
2653
2733
  var import_utils25 = require("@spatulox/utils");
2734
+ var import_utils26 = require("@spatulox/utils");
2654
2735
 
2655
2736
  // src/constants/DiscordRegex.ts
2656
- var DiscordRegex = class {
2737
+ var DiscordRegex = class _DiscordRegex {
2657
2738
  // Caractères spéciaux
2658
2739
  static SPACE = "\u200B";
2659
2740
  // URLs basiques
2660
2741
  static URL_REGEX = /(https?:\/\/[^\s<>]+)/i;
2742
+ // URL on a Discord domain (discord.com, discord.gg, discordapp.com, cdn.discordapp.com, discord.media...)
2743
+ static DISCORD_URL = /^https?:\/\/(?:[\w-]+\.)*(?:discord\.com|discord\.gg|discordapp\.com|discordapp\.net|discord\.media)(?:[\/?#]\S*)?$/i;
2661
2744
  /* DISCORD REGEX */
2662
- static USER_REGEX = /<@\d{18}>/;
2663
- static BOT_REGEX = /<@\d{19}>/;
2664
- static CHANNEL_REGEX = /(<#\d{19}>)|(<id:(browse|customize|guide)>)/;
2665
- static ROLE_REGEX = /<@&\d{19}>/;
2745
+ // Snowflakes (user, bot, channel, role, guild ids) are 17 to 20 digits long, their length says nothing about their type
2746
+ static USER_REGEX = /<@!?\d{17,20}>/;
2747
+ /** @deprecated A bot mention can't be told apart from a user mention : same as USER_REGEX */
2748
+ static BOT_REGEX = _DiscordRegex.USER_REGEX;
2749
+ static CHANNEL_REGEX = /(<#\d{17,20}>)|(<id:(browse|customize|guide)>)/;
2750
+ static ROLE_REGEX = /<@&\d{17,20}>/;
2666
2751
  /**
2667
2752
  * Mention a User
2668
2753
  * Mention a Role
@@ -2679,32 +2764,33 @@ var DiscordRegex = class {
2679
2764
  `(${this.DISCORD_PING_REGEX.source})|(${this.CHANNEL_REGEX.source})`
2680
2765
  );
2681
2766
  // ID Discord (user, channel guild)
2682
- static USER_ID = /^[0-9]{18}$/;
2683
- static CHANNEL_ID = /^[0-9]{18}$/;
2684
- static GUILD_ID = /^[0-9]{19}$/;
2685
- static BOT_ID = /^[0-9]{19}$/;
2767
+ static SNOWFLAKE = /^[0-9]{17,20}$/;
2768
+ static USER_ID = _DiscordRegex.SNOWFLAKE;
2769
+ static CHANNEL_ID = _DiscordRegex.SNOWFLAKE;
2770
+ static GUILD_ID = _DiscordRegex.SNOWFLAKE;
2771
+ static BOT_ID = _DiscordRegex.SNOWFLAKE;
2686
2772
  // Username Discord (2-32 caractères alphanumériques + _ .)
2687
- static USERNAME = /^[a-zA-Z0-9_]{2,32}$/;
2773
+ static USERNAME = /^[a-zA-Z0-9_.]{2,32}$/;
2688
2774
  // Username + discrim (ancien format)
2689
2775
  static USERNAME_DISCRIM = /^[a-zA-Z0-9_]{2,32}#\d{4}$/;
2690
2776
  // Channel mention <#123456789012345678>
2691
- static CHANNEL_MENTION = /^<#([0-9]{18})>$/;
2777
+ static CHANNEL_MENTION = /^<#([0-9]{17,20})>$/;
2692
2778
  // User mention <@123456789012345678> ou <@!123456789012345678>
2693
- static USER_MENTION = /^<@!?([0-9]{18})>$/;
2779
+ static USER_MENTION = /^<@!?([0-9]{17,20})>$/;
2694
2780
  // Role mention <@&123456789012345678>
2695
- static ROLE_MENTION = /^<@&([0-9]{18})>$/;
2696
- // URL Invite Discord
2697
- static INVITE = /^discord(?:app\.com\/invite|gg)\/[a-zA-Z0-9]+$/;
2698
- // Emoji Discord (custom or unicode)
2699
- static EMOJI = /^<a?:[a-zA-Z0-9_]{2,32}:[0-9]{18}>$|^[\u{1F300}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]+$/u;
2781
+ static ROLE_MENTION = /^<@&([0-9]{17,20})>$/;
2782
+ // URL Invite Discord : discord.gg/code, discord.com/invite/code, discordapp.com/invite/code (with or without https://)
2783
+ static INVITE = /^(?:https?:\/\/)?(?:www\.)?(?:discord\.gg|discord(?:app)?\.com\/invite)\/[a-zA-Z0-9-]+$/i;
2784
+ // Emoji Discord (custom or unicode, skin tones / ZWJ sequences / flags included)
2785
+ static EMOJI = /^<a?:[a-zA-Z0-9_]{2,32}:[0-9]{17,20}>$|^[\p{Extended_Pictographic}\p{Regional_Indicator}][\p{Extended_Pictographic}\p{Regional_Indicator}\p{Emoji_Modifier}\u200D\uFE0F]*$/u;
2700
2786
  /**
2701
- * Validate Discord ID Discord (18)
2787
+ * Validate a Discord ID (snowflake, 17 to 20 digits)
2702
2788
  */
2703
2789
  static isDiscordId(id) {
2704
- return this.USER_ID.test(id) || this.GUILD_ID.test(id) || this.CHANNEL_ID.test(id);
2790
+ return this.SNOWFLAKE.test(id);
2705
2791
  }
2706
2792
  /**
2707
- * Validate a bot ID (19)
2793
+ * @deprecated A bot mention can't be told apart from a user mention : same as isUserMention()
2708
2794
  */
2709
2795
  static isBotMention(mention) {
2710
2796
  return this.BOT_REGEX.test(mention);
@@ -2722,7 +2808,7 @@ var DiscordRegex = class {
2722
2808
  return this.USERNAME.test(username);
2723
2809
  }
2724
2810
  /**
2725
- * Type guard for Discord ID
2811
+ * @deprecated Same as isDiscordId()
2726
2812
  */
2727
2813
  static isDiscordIdType(id) {
2728
2814
  return this.isDiscordId(id);
@@ -2731,7 +2817,7 @@ var DiscordRegex = class {
2731
2817
  * Any Discord URL
2732
2818
  */
2733
2819
  static isDiscordUrl(url) {
2734
- return this.URL_REGEX.test(url) || this.INVITE.test(url);
2820
+ return this.DISCORD_URL.test(url) || this.INVITE.test(url);
2735
2821
  }
2736
2822
  /**
2737
2823
  * Any discord mention
@@ -2746,15 +2832,18 @@ var DiscordRegex = class {
2746
2832
  return {
2747
2833
  SPACE: this.SPACE,
2748
2834
  URL_REGEX: this.URL_REGEX,
2835
+ DISCORD_URL: this.DISCORD_URL,
2749
2836
  USER_REGEX: this.USER_REGEX,
2750
2837
  BOT_REGEX: this.BOT_REGEX,
2751
2838
  CHANNEL_REGEX: this.CHANNEL_REGEX,
2752
2839
  ROLE_REGEX: this.ROLE_REGEX,
2753
2840
  DISCORD_PING_REGEX: this.DISCORD_PING_REGEX,
2754
2841
  DISCORD_MENTION_REGEX: this.DISCORD_MENTION_REGEX,
2842
+ SNOWFLAKE: this.SNOWFLAKE,
2755
2843
  USER_ID: this.USER_ID,
2756
2844
  CHANNEL_ID: this.CHANNEL_ID,
2757
2845
  GUILD_ID: this.GUILD_ID,
2846
+ BOT_ID: this.BOT_ID,
2758
2847
  USERNAME: this.USERNAME,
2759
2848
  USERNAME_DISCRIM: this.USERNAME_DISCRIM,
2760
2849
  CHANNEL_MENTION: this.CHANNEL_MENTION,
@@ -2780,6 +2869,7 @@ var DiscordRegex = class {
2780
2869
  Log,
2781
2870
  ModalFieldType,
2782
2871
  ModalManager,
2872
+ PaginationManager,
2783
2873
  ReactionManager,
2784
2874
  SelectMenuManager,
2785
2875
  SimpleColor,