@spatulox/simplediscordbot 3.1.2 → 4.0.0

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