@spatulox/simplediscordbot 3.2.0 → 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/CHANGELOG.md +43 -0
- package/dist/index.d.mts +193 -57
- package/dist/index.d.ts +193 -57
- package/dist/index.js +1023 -931
- package/dist/index.mjs +959 -858
- package/package.json +21 -7
- package/.env.example +0 -2
- package/prompt-message-for-wiki.txt +0 -18
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
|
|
8
|
-
__defProp(target,
|
|
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: () =>
|
|
26
|
+
CacheManager: () => import_utils23.CacheManager,
|
|
27
27
|
ChartManager: () => ChartManager,
|
|
28
28
|
ComponentManager: () => ComponentManager,
|
|
29
29
|
DiscordRegex: () => DiscordRegex,
|
|
30
30
|
EmbedManager: () => EmbedManager,
|
|
31
|
-
FileManager: () =>
|
|
31
|
+
FileManager: () => import_utils22.FileManager,
|
|
32
32
|
GuildManager: () => GuildManager,
|
|
33
|
-
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: () =>
|
|
41
|
-
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
326
|
-
|
|
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
|
|
347
|
+
const logConfig = Bot.config?.log;
|
|
338
348
|
if (!logConfig || logConfig.error.console) {
|
|
339
|
-
|
|
340
|
-
|
|
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
|
|
362
|
+
const logConfig = Bot.config?.log;
|
|
352
363
|
if (!logConfig || logConfig?.warn.console) {
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
378
|
+
const logConfig = Bot.config?.log;
|
|
367
379
|
if (!logConfig || logConfig?.debug.console) {
|
|
368
|
-
|
|
369
|
-
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
455
|
-
return this.create(color).setDescription(
|
|
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(
|
|
461
|
-
return this.create(8912917 /* error */).setTitle("Something went Wrong").setDescription(
|
|
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(
|
|
467
|
-
return this.create(25600 /* minecraft */).setTitle("Success").setDescription(
|
|
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(
|
|
473
|
-
return this.create().setDescription(
|
|
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(
|
|
479
|
-
return this.create(65280 /* green */).setTitle("Debug").setDescription(
|
|
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:
|
|
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 ? [
|
|
518
|
+
flags: ephemeral ? [import_discord4.MessageFlags.Ephemeral] : []
|
|
506
519
|
};
|
|
507
520
|
}
|
|
508
521
|
/**
|
|
509
|
-
*
|
|
522
|
+
* Options to edit an existing message : message.edit()
|
|
510
523
|
*/
|
|
511
|
-
static
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
613
|
+
return this.sendDM(channel, embed);
|
|
674
614
|
}
|
|
675
|
-
return this.send(channel,
|
|
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,
|
|
623
|
+
return this.sendDM(channel, embed);
|
|
684
624
|
}
|
|
685
|
-
return this.send(channel,
|
|
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
|
|
637
|
+
return SendableComponentBuilder.buildInteraction(content, component, ephemeral);
|
|
697
638
|
}
|
|
698
639
|
static buildUpdateOptions(content, component) {
|
|
699
|
-
return
|
|
640
|
+
return SendableComponentBuilder.buildInteraction(content, component, false);
|
|
700
641
|
}
|
|
701
|
-
|
|
702
|
-
|
|
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
|
|
655
|
+
static async send(interaction, content, component, ephemeral = false) {
|
|
705
656
|
if (!interaction.isRepliable()) return false;
|
|
706
|
-
const options = this.
|
|
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
|
|
664
|
+
static async reply(interaction, content, component, ephemeral = false) {
|
|
718
665
|
if (!interaction.isRepliable()) return false;
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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
|
-
|
|
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 (
|
|
757
|
-
|
|
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
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
exports: {
|
|
771
|
-
types: "./dist/index.d.ts",
|
|
772
|
-
import: "./dist/index.js",
|
|
773
|
-
require: "./dist/index.js"
|
|
774
|
-
},
|
|
775
|
-
types: "./dist/index.d.ts",
|
|
776
|
-
scripts: {
|
|
777
|
-
"type-check": "tsc --noEmit",
|
|
778
|
-
build: "npm run type-check && rm -rf ./dist/ && tsup",
|
|
779
|
-
dev: "npm run type-check && tsx watch src/test/index.ts",
|
|
780
|
-
patch: "npm run build && npm version patch",
|
|
781
|
-
minor: "npm run build && npm version minor",
|
|
782
|
-
major: "npm run build && npm version major",
|
|
783
|
-
"pub:patch": "npm run patch && npm publish --access public",
|
|
784
|
-
"pub:minor": "npm run minor && npm publish --access public",
|
|
785
|
-
"pub:major": "npm run major && npm publish --access public"
|
|
786
|
-
},
|
|
787
|
-
license: "MIT",
|
|
788
|
-
dependencies: {
|
|
789
|
-
"@spatulox/discord-interaction-manager": "^2.4.0",
|
|
790
|
-
"@spatulox/utils": "^0.2.0"
|
|
791
|
-
},
|
|
792
|
-
peerDependencies: {
|
|
793
|
-
"discord.js": "^14.26.0"
|
|
794
|
-
},
|
|
795
|
-
devDependencies: {
|
|
796
|
-
"@types/node": "^22.14.0",
|
|
797
|
-
"@types/node-schedule": "^2.1.7",
|
|
798
|
-
"discord.js": "^14.26.0",
|
|
799
|
-
dotenv: "^17.2.4",
|
|
800
|
-
tsup: "^8.5.1",
|
|
801
|
-
tsx: "^4.20.3",
|
|
802
|
-
typescript: "^5.9.3"
|
|
803
|
-
},
|
|
804
|
-
keywords: [
|
|
805
|
-
"discord",
|
|
806
|
-
"framework",
|
|
807
|
-
"bot",
|
|
808
|
-
"client",
|
|
809
|
-
"discordjs",
|
|
810
|
-
"discord.js",
|
|
811
|
-
"node"
|
|
812
|
-
],
|
|
813
|
-
bugs: {
|
|
814
|
-
url: "https://github.com/spatulox-discord/SimpleDiscordBot/issues"
|
|
815
|
-
}
|
|
816
|
-
};
|
|
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
|
|
821
|
-
version
|
|
822
|
-
author
|
|
823
|
-
description
|
|
824
|
-
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
|
|
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.
|
|
753
|
+
_Bot.token = BotEnv.token;
|
|
853
754
|
_Bot._config = config;
|
|
854
755
|
_Bot._client = client;
|
|
855
|
-
(async () => {
|
|
856
|
-
|
|
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
|
-
|
|
775
|
+
if (_Bot._client.isReady()) return true;
|
|
865
776
|
let tries = 0;
|
|
866
|
-
while (
|
|
777
|
+
while (tries < maxTries) {
|
|
867
778
|
try {
|
|
868
|
-
await _Bot._client.login(_Bot.
|
|
869
|
-
|
|
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
|
-
|
|
886
|
-
|
|
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,32 +812,40 @@ var Bot = class _Bot {
|
|
|
910
812
|
return;
|
|
911
813
|
}
|
|
912
814
|
pickRandom();
|
|
913
|
-
setInterval(
|
|
914
|
-
|
|
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
|
|
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,
|
|
839
|
+
constructor(client, name2, avatarPathOrUrl) {
|
|
931
840
|
this.client = client;
|
|
932
|
-
this.name =
|
|
841
|
+
this.name = name2;
|
|
933
842
|
this.avatarPathOrUrl = avatarPathOrUrl;
|
|
934
843
|
}
|
|
935
844
|
client;
|
|
936
845
|
name;
|
|
937
846
|
avatarPathOrUrl;
|
|
938
|
-
webhook
|
|
847
|
+
/** One webhook per channel id (the parent channel id for threads) */
|
|
848
|
+
webhooks = /* @__PURE__ */ new Map();
|
|
939
849
|
async getAvatar() {
|
|
940
850
|
if (!this.avatarPathOrUrl) return null;
|
|
941
851
|
if (this.avatarPathOrUrl.startsWith("http://") || this.avatarPathOrUrl.startsWith("https://")) {
|
|
@@ -957,48 +867,52 @@ var WebhookManager = class {
|
|
|
957
867
|
if (!channel) {
|
|
958
868
|
throw new Error(`Channel ${channelId} not found`);
|
|
959
869
|
}
|
|
960
|
-
if (!(channel instanceof
|
|
870
|
+
if (!(channel instanceof import_discord8.TextChannel) && !(channel instanceof import_discord8.ThreadChannel)) {
|
|
961
871
|
throw new Error(`Channel ${channelId} is not a TextChannel nor a ThreadChannel`);
|
|
962
872
|
}
|
|
963
873
|
return channel;
|
|
964
874
|
}
|
|
965
875
|
/**
|
|
966
|
-
*
|
|
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)
|
|
967
888
|
* Create the webhook in the parent channel if it's in a thread
|
|
968
889
|
*/
|
|
969
|
-
async getWebhook(
|
|
970
|
-
if (this.webhook) return this.webhook;
|
|
890
|
+
async getWebhook(channel) {
|
|
971
891
|
try {
|
|
972
|
-
const
|
|
973
|
-
|
|
974
|
-
if (
|
|
975
|
-
const parent = textThreadChannel.parent;
|
|
976
|
-
if (!parent || !(parent instanceof import_discord7.BaseGuildTextChannel) && !(parent instanceof import_discord7.ThreadOnlyChannel)) {
|
|
977
|
-
throw new Error("Targeted channel parent is not a BaseGuildTextChannel or ThreadOnlyChannel");
|
|
978
|
-
}
|
|
979
|
-
textChannel = parent;
|
|
980
|
-
} else {
|
|
981
|
-
textChannel = textThreadChannel;
|
|
982
|
-
}
|
|
892
|
+
const textChannel = this.getWebhookChannel(channel);
|
|
893
|
+
const cached = this.webhooks.get(textChannel.id);
|
|
894
|
+
if (cached) return cached;
|
|
983
895
|
const webhooks = await textChannel.fetchWebhooks();
|
|
984
|
-
|
|
896
|
+
const webhook = webhooks.find(
|
|
985
897
|
(h) => h.name === this.name && h.owner?.id === this.client.user?.id
|
|
986
898
|
) ?? await textChannel.createWebhook({
|
|
987
899
|
name: this.name,
|
|
988
900
|
avatar: await this.getAvatar(),
|
|
989
901
|
reason: "Auto-created by WebhookManager"
|
|
990
902
|
});
|
|
991
|
-
|
|
992
|
-
|
|
903
|
+
this.webhooks.set(textChannel.id, webhook);
|
|
904
|
+
Bot.log.debug(`Webhook ${webhook.id} ready for channel ${channel.id}`);
|
|
905
|
+
return webhook;
|
|
993
906
|
} catch (error) {
|
|
994
|
-
Bot.log.error(`Failed to setup webhook for ${
|
|
907
|
+
Bot.log.error(`Failed to setup webhook for ${channel.id}: ${error}`);
|
|
995
908
|
throw error;
|
|
996
909
|
}
|
|
997
910
|
}
|
|
998
911
|
async send(channelId, content) {
|
|
999
|
-
const
|
|
912
|
+
const channel = await this.getChannel(channelId);
|
|
913
|
+
const webhook = await this.getWebhook(channel);
|
|
1000
914
|
let options = {};
|
|
1001
|
-
if (SendableComponentBuilder.isSendableComponent(content)) {
|
|
915
|
+
if (SendableComponentBuilder.isSendableComponent(content) || Array.isArray(content)) {
|
|
1002
916
|
options = SendableComponentBuilder.buildMessage(content);
|
|
1003
917
|
} else if (typeof content === "string") {
|
|
1004
918
|
options.content = content;
|
|
@@ -1007,8 +921,7 @@ var WebhookManager = class {
|
|
|
1007
921
|
} else {
|
|
1008
922
|
options.content = String(content);
|
|
1009
923
|
}
|
|
1010
|
-
|
|
1011
|
-
if (channelType instanceof import_discord7.ThreadChannel) {
|
|
924
|
+
if (channel instanceof import_discord8.ThreadChannel) {
|
|
1012
925
|
options.threadId = channelId;
|
|
1013
926
|
}
|
|
1014
927
|
try {
|
|
@@ -1034,10 +947,13 @@ var WebhookManager = class {
|
|
|
1034
947
|
* Delete webhook
|
|
1035
948
|
*/
|
|
1036
949
|
async delete(channelId, reason) {
|
|
1037
|
-
|
|
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;
|
|
1038
954
|
try {
|
|
1039
|
-
await
|
|
1040
|
-
Bot.log.info(`Webhook ${
|
|
955
|
+
await webhook.delete(reason ?? "Deleted by WebhookManager");
|
|
956
|
+
Bot.log.info(`Webhook ${webhook.id} deleted from ${channelId}`);
|
|
1041
957
|
} catch (error) {
|
|
1042
958
|
if (error.message.includes("Unknown Webhook")) {
|
|
1043
959
|
Bot.log.warn(`Webhook already deleted from ${channelId}`);
|
|
@@ -1045,326 +961,105 @@ var WebhookManager = class {
|
|
|
1045
961
|
Bot.log.error(`Failed to delete webhook from ${channelId}: ${error}`);
|
|
1046
962
|
}
|
|
1047
963
|
} finally {
|
|
1048
|
-
this.
|
|
964
|
+
this.webhooks.delete(webhookChannelId);
|
|
1049
965
|
}
|
|
1050
966
|
}
|
|
1051
967
|
};
|
|
1052
968
|
|
|
1053
969
|
// src/manager/messages/ReactionManager.ts
|
|
1054
|
-
var
|
|
1055
|
-
|
|
1056
|
-
// src/manager/guild/ChannelManager/GuildTextChannelManager.ts
|
|
1057
|
-
var import_discord8 = require("discord.js");
|
|
1058
|
-
|
|
1059
|
-
// src/manager/guild/ChannelManager/GuildChannelManager.ts
|
|
1060
|
-
var import_utils7 = require("@spatulox/utils");
|
|
1061
|
-
|
|
1062
|
-
// src/manager/guild/ChannelManager/GuildMessageManager.ts
|
|
970
|
+
var import_discord9 = require("discord.js");
|
|
1063
971
|
var import_utils6 = require("@spatulox/utils");
|
|
1064
|
-
var
|
|
972
|
+
var ReactionManager = class {
|
|
1065
973
|
/**
|
|
1066
|
-
*
|
|
974
|
+
* Any text based channel : guild channels, threads and DMs
|
|
1067
975
|
*/
|
|
1068
|
-
static async
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
import_utils6.Log.error(`Channel ${channelId} not found in guild`);
|
|
1073
|
-
return null;
|
|
1074
|
-
}
|
|
1075
|
-
let payload;
|
|
1076
|
-
if (typeof content_or_component_or_options === "string") {
|
|
1077
|
-
payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
1078
|
-
} else if (SendableComponentBuilder.isSendableComponent(content_or_component_or_options) || Array.isArray(content_or_component_or_options)) {
|
|
1079
|
-
payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
1080
|
-
} else {
|
|
1081
|
-
payload = content_or_component_or_options;
|
|
1082
|
-
}
|
|
1083
|
-
return await channel.send(payload);
|
|
1084
|
-
} catch (error) {
|
|
1085
|
-
import_utils6.Log.error(`Failed to send message to ${channelId}: ${error}`);
|
|
1086
|
-
throw error;
|
|
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`);
|
|
1087
980
|
}
|
|
981
|
+
return await channel.messages.fetch(messageId);
|
|
1088
982
|
}
|
|
1089
983
|
/**
|
|
1090
|
-
*
|
|
984
|
+
* Add a reaction to a message
|
|
1091
985
|
*/
|
|
1092
|
-
static async
|
|
986
|
+
static async add(channelId, messageId, emoji) {
|
|
1093
987
|
try {
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
return false;
|
|
1098
|
-
}
|
|
1099
|
-
const message = await channel.messages.fetch(messageId);
|
|
1100
|
-
await message.delete();
|
|
1101
|
-
import_utils6.Log.info(`Deleted message ${messageId} from ${channelId}`);
|
|
1102
|
-
return true;
|
|
988
|
+
const message = await this.fetchMessage(channelId, messageId);
|
|
989
|
+
await message.react(emoji);
|
|
990
|
+
import_utils6.Log.info(`Added reaction ${emoji} to message ${messageId}`);
|
|
1103
991
|
} catch (error) {
|
|
1104
|
-
import_utils6.Log.error(`Failed to
|
|
1105
|
-
|
|
992
|
+
import_utils6.Log.error(`Failed to add reaction to ${messageId}: ${error}`);
|
|
993
|
+
throw error;
|
|
1106
994
|
}
|
|
1107
995
|
}
|
|
1108
996
|
/**
|
|
1109
|
-
*
|
|
997
|
+
* Delete a reaction from a user
|
|
1110
998
|
*/
|
|
1111
|
-
static async
|
|
999
|
+
static async remove(channelId, messageId, emoji, userId) {
|
|
1112
1000
|
try {
|
|
1113
|
-
const
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
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}`);
|
|
1117
1005
|
}
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
|
|
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}`);
|
|
1121
1009
|
} catch (error) {
|
|
1122
|
-
import_utils6.Log.error(`Failed to
|
|
1123
|
-
|
|
1010
|
+
import_utils6.Log.error(`Failed to remove reaction from ${messageId}: ${error}`);
|
|
1011
|
+
throw error;
|
|
1124
1012
|
}
|
|
1125
1013
|
}
|
|
1126
1014
|
/**
|
|
1127
|
-
*
|
|
1015
|
+
* Get all reaction of a message
|
|
1128
1016
|
*/
|
|
1129
|
-
static async
|
|
1017
|
+
static async getAll(channelId, messageId) {
|
|
1130
1018
|
try {
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
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
|
+
});
|
|
1135
1029
|
}
|
|
1136
|
-
|
|
1137
|
-
return
|
|
1030
|
+
import_utils6.Log.info(`Fetched ${reactionList.length} reactions for message ${messageId}`);
|
|
1031
|
+
return reactionList;
|
|
1138
1032
|
} catch (error) {
|
|
1139
|
-
import_utils6.Log.error(`Failed to fetch
|
|
1140
|
-
|
|
1033
|
+
import_utils6.Log.error(`Failed to fetch reactions for ${messageId}: ${error}`);
|
|
1034
|
+
throw error;
|
|
1141
1035
|
}
|
|
1142
1036
|
}
|
|
1143
|
-
};
|
|
1144
|
-
|
|
1145
|
-
// src/manager/guild/ChannelManager/GuildChannelManager.ts
|
|
1146
|
-
var GuildChannelManager = class _GuildChannelManager {
|
|
1147
|
-
static message = GuildMessageManager;
|
|
1148
1037
|
/**
|
|
1149
|
-
*
|
|
1038
|
+
* Delete all reaction
|
|
1150
1039
|
*/
|
|
1151
|
-
static async
|
|
1040
|
+
static async clear(channelId, messageId) {
|
|
1152
1041
|
try {
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
return null;
|
|
1157
|
-
}
|
|
1158
|
-
const channel = await guild.channels.fetch(channelId);
|
|
1159
|
-
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}`);
|
|
1160
1045
|
} catch (error) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
static async find(channelId) {
|
|
1166
|
-
try {
|
|
1167
|
-
const cached = Bot.client.channels.cache.get(channelId);
|
|
1168
|
-
if (cached && !cached.isDMBased()) return cached;
|
|
1169
|
-
const channel = await Bot.client.channels.fetch(channelId);
|
|
1170
|
-
if (channel && !channel.isDMBased()) return channel;
|
|
1171
|
-
import_utils7.Log.warn(`Channel ${channelId} not found in any guild`);
|
|
1172
|
-
return null;
|
|
1173
|
-
} catch (error) {
|
|
1174
|
-
import_utils7.Log.error(`Failed to find channel ${channelId}: ${error}`);
|
|
1175
|
-
return null;
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
static findAll(guildId) {
|
|
1179
|
-
try {
|
|
1180
|
-
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1181
|
-
if (!guild) {
|
|
1182
|
-
import_utils7.Log.warn(`Guild ${guildId} not found`);
|
|
1183
|
-
return [];
|
|
1184
|
-
}
|
|
1185
|
-
return Array.from(guild.channels.cache.values());
|
|
1186
|
-
} catch (error) {
|
|
1187
|
-
import_utils7.Log.error(`Failed to find channel ${guildId}: ${error}`);
|
|
1188
|
-
return [];
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Recherche channels par nom (insensible à la casse)
|
|
1193
|
-
*/
|
|
1194
|
-
static findByName(guildId, name) {
|
|
1195
|
-
try {
|
|
1196
|
-
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1197
|
-
if (!guild) {
|
|
1198
|
-
import_utils7.Log.warn(`Guild ${guildId} not found`);
|
|
1199
|
-
return [];
|
|
1200
|
-
}
|
|
1201
|
-
return Array.from(guild.channels.cache.values()).filter(
|
|
1202
|
-
(channel) => channel.name.toLowerCase().includes(name.toLowerCase())
|
|
1203
|
-
);
|
|
1204
|
-
} catch (error) {
|
|
1205
|
-
import_utils7.Log.error(`Failed to find channel ${guildId}: ${error}`);
|
|
1206
|
-
return [];
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
static async _create(guildId, options) {
|
|
1210
|
-
try {
|
|
1211
|
-
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1212
|
-
if (!guild) {
|
|
1213
|
-
throw new Error(`Guild ${guildId} not found`);
|
|
1214
|
-
}
|
|
1215
|
-
const channel = await guild.channels.create(options);
|
|
1216
|
-
import_utils7.Log.info(`Created channel ${channel.name} (${channel.id}) in guild ${guildId}`);
|
|
1217
|
-
return channel;
|
|
1218
|
-
} catch (error) {
|
|
1219
|
-
import_utils7.Log.error(`Failed to create channel in guild ${guildId}: ${error}`);
|
|
1220
|
-
throw error;
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
static async delete(channelId) {
|
|
1224
|
-
try {
|
|
1225
|
-
const channel = await _GuildChannelManager.find(channelId);
|
|
1226
|
-
if (!channel) {
|
|
1227
|
-
throw new Error(`Channel ${channelId} not found`);
|
|
1228
|
-
}
|
|
1229
|
-
await channel.delete();
|
|
1230
|
-
import_utils7.Log.info(`Deleted channel ${channelId}`);
|
|
1231
|
-
return true;
|
|
1232
|
-
} catch (error) {
|
|
1233
|
-
import_utils7.Log.error(`Failed to delete channel ${channelId}: ${error}`);
|
|
1234
|
-
throw error;
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
};
|
|
1238
|
-
|
|
1239
|
-
// src/manager/guild/ChannelManager/GuildTextChannelManager.ts
|
|
1240
|
-
var import_utils8 = require("@spatulox/utils");
|
|
1241
|
-
var GuildTextChannelManager = class extends GuildChannelManager {
|
|
1242
|
-
static async findInGuild(guildId, channelId) {
|
|
1243
|
-
const channel = await super.findInGuild(guildId, channelId);
|
|
1244
|
-
return channel?.isTextBased() ? channel : null;
|
|
1245
|
-
}
|
|
1246
|
-
static async find(channelId) {
|
|
1247
|
-
const channel = await super.find(channelId);
|
|
1248
|
-
return channel?.isTextBased() ? channel : null;
|
|
1249
|
-
}
|
|
1250
|
-
static findAll(guildId) {
|
|
1251
|
-
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1252
|
-
if (!guild) {
|
|
1253
|
-
import_utils8.Log.warn(`Guild ${guildId} not found`);
|
|
1254
|
-
return [];
|
|
1255
|
-
}
|
|
1256
|
-
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord8.TextChannel);
|
|
1257
|
-
}
|
|
1258
|
-
static async create(guildId, name, options) {
|
|
1259
|
-
return await super._create(guildId, {
|
|
1260
|
-
name,
|
|
1261
|
-
type: import_discord8.ChannelType.GuildText,
|
|
1262
|
-
...options
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
};
|
|
1266
|
-
|
|
1267
|
-
// src/manager/messages/ReactionManager.ts
|
|
1268
|
-
var ReactionManager = class {
|
|
1269
|
-
/**
|
|
1270
|
-
* Add a reaction to a message
|
|
1271
|
-
*/
|
|
1272
|
-
static async add(channelId, messageId, emoji) {
|
|
1273
|
-
try {
|
|
1274
|
-
const channel = await GuildTextChannelManager.find(channelId);
|
|
1275
|
-
if (!channel) {
|
|
1276
|
-
throw new Error(`Channel ${channelId} not found`);
|
|
1277
|
-
}
|
|
1278
|
-
if (!channel.isTextBased()) {
|
|
1279
|
-
throw new Error(`Channel ${channelId} is not text based`);
|
|
1280
|
-
}
|
|
1281
|
-
const message = await channel.messages.fetch(messageId);
|
|
1282
|
-
await message.react(emoji);
|
|
1283
|
-
import_utils9.Log.info(`Added reaction ${emoji} to message ${messageId}`);
|
|
1284
|
-
} catch (error) {
|
|
1285
|
-
import_utils9.Log.error(`Failed to add reaction to ${messageId}: ${error}`);
|
|
1286
|
-
throw error;
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
/**
|
|
1290
|
-
* Delete a reaction from a user
|
|
1291
|
-
*/
|
|
1292
|
-
static async remove(channelId, messageId, emoji, userId) {
|
|
1293
|
-
try {
|
|
1294
|
-
const channel = await GuildTextChannelManager.find(channelId);
|
|
1295
|
-
if (!channel) {
|
|
1296
|
-
throw new Error(`Channel ${channelId} not found`);
|
|
1297
|
-
}
|
|
1298
|
-
const message = await channel.messages.fetch(messageId);
|
|
1299
|
-
const reaction = message.reactions.resolve(emoji);
|
|
1300
|
-
if (!reaction) {
|
|
1301
|
-
throw new Error(`Reaction ${emoji} not found on message ${messageId}`);
|
|
1302
|
-
}
|
|
1303
|
-
const user = await Bot.client.users.fetch(userId);
|
|
1304
|
-
await reaction.users.remove(user);
|
|
1305
|
-
import_utils9.Log.info(`Removed reaction ${emoji} from user ${userId} on message ${messageId}`);
|
|
1306
|
-
} catch (error) {
|
|
1307
|
-
import_utils9.Log.error(`Failed to remove reaction from ${messageId}: ${error}`);
|
|
1308
|
-
throw error;
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
/**
|
|
1312
|
-
* Get all reaction of a message
|
|
1313
|
-
*/
|
|
1314
|
-
static async getAll(channelId, messageId) {
|
|
1315
|
-
try {
|
|
1316
|
-
const channel = await GuildTextChannelManager.find(channelId);
|
|
1317
|
-
if (!channel) {
|
|
1318
|
-
throw new Error(`Channel ${channelId} not found`);
|
|
1319
|
-
}
|
|
1320
|
-
const message = await channel.messages.fetch(messageId);
|
|
1321
|
-
const reactions = message.reactions.cache;
|
|
1322
|
-
const reactionList = [];
|
|
1323
|
-
for (const reaction of reactions.values()) {
|
|
1324
|
-
const users = await reaction.users.fetch();
|
|
1325
|
-
reactionList.push({
|
|
1326
|
-
emoji: reaction.emoji,
|
|
1327
|
-
count: reaction.count,
|
|
1328
|
-
users: Array.from(users.values())
|
|
1329
|
-
});
|
|
1330
|
-
}
|
|
1331
|
-
import_utils9.Log.info(`Fetched ${reactionList.length} reactions for message ${messageId}`);
|
|
1332
|
-
return reactionList;
|
|
1333
|
-
} catch (error) {
|
|
1334
|
-
import_utils9.Log.error(`Failed to fetch reactions for ${messageId}: ${error}`);
|
|
1335
|
-
throw error;
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
/**
|
|
1339
|
-
* Delete all reaction
|
|
1340
|
-
*/
|
|
1341
|
-
static async clear(channelId, messageId) {
|
|
1342
|
-
try {
|
|
1343
|
-
const channel = await GuildTextChannelManager.find(channelId);
|
|
1344
|
-
if (!channel) {
|
|
1345
|
-
throw new Error(`Channel ${channelId} not found`);
|
|
1346
|
-
}
|
|
1347
|
-
const message = await channel.messages.fetch(messageId);
|
|
1348
|
-
await message.reactions.removeAll();
|
|
1349
|
-
import_utils9.Log.info(`Cleared all reactions from message ${messageId}`);
|
|
1350
|
-
} catch (error) {
|
|
1351
|
-
import_utils9.Log.error(`Failed to clear reactions from ${messageId}: ${error}`);
|
|
1352
|
-
throw error;
|
|
1046
|
+
import_utils6.Log.error(`Failed to clear reactions from ${messageId}: ${error}`);
|
|
1047
|
+
throw error;
|
|
1353
1048
|
}
|
|
1354
1049
|
}
|
|
1355
1050
|
};
|
|
1356
1051
|
|
|
1357
1052
|
// src/manager/guild/GuildManager.ts
|
|
1358
|
-
var
|
|
1053
|
+
var import_discord18 = require("discord.js");
|
|
1359
1054
|
var import_utils18 = require("@spatulox/utils");
|
|
1360
1055
|
var import_utils19 = require("@spatulox/utils");
|
|
1361
1056
|
|
|
1362
1057
|
// src/manager/guild/GuildUserManager.ts
|
|
1363
|
-
var
|
|
1058
|
+
var import_utils8 = require("@spatulox/utils");
|
|
1364
1059
|
|
|
1365
1060
|
// src/manager/direct/BasicUserManager.ts
|
|
1366
|
-
var
|
|
1367
|
-
var
|
|
1061
|
+
var import_discord10 = require("discord.js");
|
|
1062
|
+
var import_utils7 = require("@spatulox/utils");
|
|
1368
1063
|
var BasicUserManager = class {
|
|
1369
1064
|
/**
|
|
1370
1065
|
* Find member in specific guild
|
|
@@ -1380,7 +1075,7 @@ var BasicUserManager = class {
|
|
|
1380
1075
|
const cached = targetGuild.members.cache.get(memberId);
|
|
1381
1076
|
if (cached) return cached;
|
|
1382
1077
|
const member = await targetGuild.members.fetch(memberId).catch(() => null);
|
|
1383
|
-
if (!member)
|
|
1078
|
+
if (!member) import_utils7.Log.error(`UserManager: Member ${memberId} not found in guild ${targetGuild.id}`);
|
|
1384
1079
|
return member;
|
|
1385
1080
|
}
|
|
1386
1081
|
/**
|
|
@@ -1416,26 +1111,27 @@ var BasicUserManager = class {
|
|
|
1416
1111
|
);
|
|
1417
1112
|
} else if (typeof content_or_component_or_options === "string") {
|
|
1418
1113
|
payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
1419
|
-
} 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)) {
|
|
1420
1115
|
payload = SendableComponentBuilder.buildMessage(content_or_component_or_options);
|
|
1421
1116
|
} else {
|
|
1422
1117
|
payload = content_or_component_or_options;
|
|
1423
1118
|
}
|
|
1424
1119
|
const message = await dmChannel.send(payload);
|
|
1425
|
-
if (user instanceof
|
|
1426
|
-
|
|
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)}..."`);
|
|
1427
1122
|
} else {
|
|
1428
|
-
|
|
1123
|
+
import_utils7.Log.info(`Sent DM to ${user.id} (${user.username}): "${(payload.content || "Embed/Component").substring(0, 50)}..."`);
|
|
1429
1124
|
}
|
|
1430
1125
|
return message;
|
|
1431
1126
|
} catch (error) {
|
|
1432
|
-
|
|
1127
|
+
import_utils7.Log.error(`Failed to send DM to ${user_id_or_user}: ${error}`);
|
|
1433
1128
|
throw new Error(`Cannot send DM to ${user_id_or_user}`);
|
|
1434
1129
|
}
|
|
1435
1130
|
}
|
|
1436
1131
|
};
|
|
1437
1132
|
|
|
1438
1133
|
// src/manager/guild/GuildUserManager.ts
|
|
1134
|
+
var import_discord11 = require("discord.js");
|
|
1439
1135
|
var import_promises2 = require("timers/promises");
|
|
1440
1136
|
var MAX_NICKNAME_LENGTH = 32;
|
|
1441
1137
|
var GuildUserManager = class extends BasicUserManager {
|
|
@@ -1447,15 +1143,18 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
1447
1143
|
try {
|
|
1448
1144
|
const oldName = member.displayName;
|
|
1449
1145
|
await member.setNickname(nickname.trim());
|
|
1450
|
-
|
|
1146
|
+
import_utils8.Log.info(`Renaming user: ${oldName} \u2192 ${nickname.trim()}`);
|
|
1451
1147
|
await (0, import_promises2.setTimeout)(1500);
|
|
1452
1148
|
return true;
|
|
1453
1149
|
} catch (error) {
|
|
1454
|
-
|
|
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
|
+
}
|
|
1455
1154
|
await (0, import_promises2.setTimeout)(1e3);
|
|
1456
1155
|
}
|
|
1457
1156
|
}
|
|
1458
|
-
Bot.log.
|
|
1157
|
+
Bot.log.error(EmbedManager.error(`Failed to rename ${member.displayName} to ${nickname.trim()}.`));
|
|
1459
1158
|
return false;
|
|
1460
1159
|
}
|
|
1461
1160
|
/**
|
|
@@ -1465,13 +1164,13 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
1465
1164
|
try {
|
|
1466
1165
|
const guild = await GuildManager.find(guildId);
|
|
1467
1166
|
if (!guild) {
|
|
1468
|
-
|
|
1167
|
+
import_utils8.Log.warn(`Guild ${guildId} not found`);
|
|
1469
1168
|
return false;
|
|
1470
1169
|
}
|
|
1471
1170
|
const ban = await guild.bans.fetch(userId);
|
|
1472
1171
|
return !!ban;
|
|
1473
1172
|
} catch (error) {
|
|
1474
|
-
|
|
1173
|
+
import_utils8.Log.debug(`User ${userId} is not banned from guild ${guildId}`);
|
|
1475
1174
|
return false;
|
|
1476
1175
|
}
|
|
1477
1176
|
}
|
|
@@ -1485,170 +1184,356 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
1485
1184
|
throw new Error(`Member ${memberId} not found or not in a voice channel`);
|
|
1486
1185
|
}
|
|
1487
1186
|
await member.voice.disconnect();
|
|
1488
|
-
|
|
1187
|
+
import_utils8.Log.info(`Disconnected member ${memberId} from voice in guild ${guildId}`);
|
|
1489
1188
|
} catch (error) {
|
|
1490
|
-
|
|
1189
|
+
import_utils8.Log.error(`Failed to disconnect member ${memberId} from voice in ${guildId}: ${error}`);
|
|
1491
1190
|
throw error;
|
|
1492
1191
|
}
|
|
1493
1192
|
}
|
|
1494
1193
|
/**
|
|
1495
1194
|
* Check if a member is in voice
|
|
1496
1195
|
*/
|
|
1497
|
-
static async isInVoice(
|
|
1196
|
+
static async isInVoice(guildId, memberId) {
|
|
1498
1197
|
try {
|
|
1499
1198
|
const member = await GuildManager.user.findInGuild(guildId, memberId);
|
|
1500
1199
|
if (!member) {
|
|
1501
|
-
throw new Error(`
|
|
1200
|
+
throw new Error(`Member ${memberId} not found in guild ${guildId}`);
|
|
1502
1201
|
}
|
|
1503
1202
|
return member.voice.channelId !== null;
|
|
1504
1203
|
} catch (error) {
|
|
1505
|
-
|
|
1506
|
-
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;
|
|
1507
1383
|
}
|
|
1508
1384
|
}
|
|
1509
1385
|
/**
|
|
1510
|
-
*
|
|
1386
|
+
* Delete message
|
|
1511
1387
|
*/
|
|
1512
|
-
static async
|
|
1388
|
+
static async delete(channelId, messageId) {
|
|
1513
1389
|
try {
|
|
1514
|
-
const
|
|
1515
|
-
if (!
|
|
1516
|
-
|
|
1390
|
+
const channel = await this.findTextBased(channelId);
|
|
1391
|
+
if (!channel) {
|
|
1392
|
+
import_utils9.Log.error(`Channel ${channelId} not found`);
|
|
1393
|
+
return false;
|
|
1517
1394
|
}
|
|
1518
|
-
await
|
|
1519
|
-
|
|
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;
|
|
1520
1399
|
} catch (error) {
|
|
1521
|
-
|
|
1522
|
-
|
|
1400
|
+
import_utils9.Log.error(`Failed to delete message ${messageId} from ${channelId}: ${error}`);
|
|
1401
|
+
return false;
|
|
1523
1402
|
}
|
|
1524
1403
|
}
|
|
1525
1404
|
/**
|
|
1526
|
-
*
|
|
1405
|
+
* Fetch messages (last X messages, default 10)
|
|
1527
1406
|
*/
|
|
1528
|
-
static async
|
|
1407
|
+
static async fetch(channelId, limit = 10) {
|
|
1529
1408
|
try {
|
|
1530
|
-
const
|
|
1531
|
-
if (!
|
|
1532
|
-
|
|
1409
|
+
const channel = await this.findTextBased(channelId);
|
|
1410
|
+
if (!channel) {
|
|
1411
|
+
import_utils9.Log.error(`Channel ${channelId} not found`);
|
|
1412
|
+
return [];
|
|
1533
1413
|
}
|
|
1534
|
-
await
|
|
1535
|
-
|
|
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());
|
|
1536
1417
|
} catch (error) {
|
|
1537
|
-
|
|
1538
|
-
|
|
1418
|
+
import_utils9.Log.error(`Failed to fetch messages from ${channelId}: ${error}`);
|
|
1419
|
+
return [];
|
|
1539
1420
|
}
|
|
1540
1421
|
}
|
|
1541
1422
|
/**
|
|
1542
|
-
*
|
|
1423
|
+
* Fetch single message
|
|
1543
1424
|
*/
|
|
1544
|
-
static async
|
|
1425
|
+
static async fetchOne(channelId, messageId) {
|
|
1545
1426
|
try {
|
|
1546
|
-
const
|
|
1547
|
-
if (!
|
|
1548
|
-
|
|
1427
|
+
const channel = await this.findTextBased(channelId);
|
|
1428
|
+
if (!channel) {
|
|
1429
|
+
import_utils9.Log.error(`Channel ${channelId} not found`);
|
|
1430
|
+
return null;
|
|
1549
1431
|
}
|
|
1550
|
-
await
|
|
1551
|
-
|
|
1432
|
+
const message = await channel.messages.fetch(messageId);
|
|
1433
|
+
return message;
|
|
1552
1434
|
} catch (error) {
|
|
1553
|
-
|
|
1554
|
-
|
|
1435
|
+
import_utils9.Log.error(`Failed to fetch message ${messageId} from ${channelId}: ${error}`);
|
|
1436
|
+
return null;
|
|
1555
1437
|
}
|
|
1556
1438
|
}
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1441
|
+
// src/manager/guild/ChannelManager/GuildChannelManager.ts
|
|
1442
|
+
var GuildChannelManager = class _GuildChannelManager {
|
|
1443
|
+
static message = GuildMessageManager;
|
|
1557
1444
|
/**
|
|
1558
|
-
*
|
|
1445
|
+
* Recherche un channel par ID dans une guild spécifique
|
|
1559
1446
|
*/
|
|
1560
|
-
static async
|
|
1447
|
+
static async findInGuild(guildId, channelId) {
|
|
1561
1448
|
try {
|
|
1562
|
-
const
|
|
1563
|
-
if (!
|
|
1564
|
-
|
|
1449
|
+
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1450
|
+
if (!guild) {
|
|
1451
|
+
import_utils10.Log.warn(`Guild ${guildId} not found`);
|
|
1452
|
+
return null;
|
|
1565
1453
|
}
|
|
1566
|
-
await
|
|
1567
|
-
|
|
1454
|
+
const channel = await guild.channels.fetch(channelId);
|
|
1455
|
+
return channel ?? null;
|
|
1568
1456
|
} catch (error) {
|
|
1569
|
-
|
|
1570
|
-
|
|
1457
|
+
import_utils10.Log.error(`Failed to find channel ${channelId} in guild ${guildId}: ${error}`);
|
|
1458
|
+
return null;
|
|
1571
1459
|
}
|
|
1572
1460
|
}
|
|
1573
|
-
|
|
1574
|
-
* Timeout a member
|
|
1575
|
-
*/
|
|
1576
|
-
static async timeout(guildId, memberId, duration, reason) {
|
|
1461
|
+
static async find(channelId) {
|
|
1577
1462
|
try {
|
|
1578
|
-
const
|
|
1579
|
-
if (!
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
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;
|
|
1585
1469
|
} catch (error) {
|
|
1586
|
-
|
|
1587
|
-
|
|
1470
|
+
import_utils10.Log.error(`Failed to find channel ${channelId}: ${error}`);
|
|
1471
|
+
return null;
|
|
1588
1472
|
}
|
|
1589
1473
|
}
|
|
1590
|
-
|
|
1591
|
-
* Remove the timeout of a member
|
|
1592
|
-
*/
|
|
1593
|
-
static async untimeout(guildId, memberId, reason) {
|
|
1474
|
+
static findAll(guildId) {
|
|
1594
1475
|
try {
|
|
1595
|
-
const
|
|
1596
|
-
if (!
|
|
1597
|
-
|
|
1476
|
+
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1477
|
+
if (!guild) {
|
|
1478
|
+
import_utils10.Log.warn(`Guild ${guildId} not found`);
|
|
1479
|
+
return [];
|
|
1598
1480
|
}
|
|
1599
|
-
|
|
1600
|
-
import_utils11.Log.info(`Untimed out ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
|
|
1481
|
+
return Array.from(guild.channels.cache.values());
|
|
1601
1482
|
} catch (error) {
|
|
1602
|
-
|
|
1603
|
-
|
|
1483
|
+
import_utils10.Log.error(`Failed to find channel ${guildId}: ${error}`);
|
|
1484
|
+
return [];
|
|
1604
1485
|
}
|
|
1605
1486
|
}
|
|
1606
1487
|
/**
|
|
1607
|
-
*
|
|
1488
|
+
* Recherche channels par nom (insensible à la casse)
|
|
1608
1489
|
*/
|
|
1609
|
-
static
|
|
1490
|
+
static findByName(guildId, name2) {
|
|
1610
1491
|
try {
|
|
1611
|
-
const
|
|
1612
|
-
if (!
|
|
1613
|
-
|
|
1492
|
+
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1493
|
+
if (!guild) {
|
|
1494
|
+
import_utils10.Log.warn(`Guild ${guildId} not found`);
|
|
1495
|
+
return [];
|
|
1614
1496
|
}
|
|
1615
|
-
|
|
1616
|
-
|
|
1497
|
+
return Array.from(guild.channels.cache.values()).filter(
|
|
1498
|
+
(channel) => channel.name.toLowerCase().includes(name2.toLowerCase())
|
|
1499
|
+
);
|
|
1617
1500
|
} catch (error) {
|
|
1618
|
-
|
|
1619
|
-
|
|
1501
|
+
import_utils10.Log.error(`Failed to find channel ${guildId}: ${error}`);
|
|
1502
|
+
return [];
|
|
1620
1503
|
}
|
|
1621
1504
|
}
|
|
1622
|
-
static async
|
|
1623
|
-
const guild = await GuildManager.find(guildId);
|
|
1624
|
-
if (!guild) {
|
|
1625
|
-
throw new Error(`Guild ${guildId} not found`);
|
|
1626
|
-
}
|
|
1505
|
+
static async _create(guildId, options) {
|
|
1627
1506
|
try {
|
|
1628
|
-
|
|
1629
|
-
|
|
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;
|
|
1630
1514
|
} catch (error) {
|
|
1631
|
-
|
|
1515
|
+
import_utils10.Log.error(`Failed to create channel in guild ${guildId}: ${error}`);
|
|
1632
1516
|
throw error;
|
|
1633
1517
|
}
|
|
1634
1518
|
}
|
|
1635
|
-
static async
|
|
1636
|
-
const guild = await GuildManager.find(guildId);
|
|
1637
|
-
if (!guild) {
|
|
1638
|
-
throw new Error(`Guild ${guildId} not found`);
|
|
1639
|
-
}
|
|
1519
|
+
static async delete(channelId) {
|
|
1640
1520
|
try {
|
|
1641
|
-
await
|
|
1642
|
-
|
|
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;
|
|
1643
1528
|
} catch (error) {
|
|
1644
|
-
|
|
1645
|
-
|
|
1529
|
+
import_utils10.Log.error(`Failed to delete channel ${channelId}: ${error}`);
|
|
1530
|
+
return false;
|
|
1646
1531
|
}
|
|
1647
1532
|
}
|
|
1648
1533
|
};
|
|
1649
1534
|
|
|
1650
1535
|
// src/manager/guild/RoleManager.ts
|
|
1651
|
-
var
|
|
1536
|
+
var import_utils11 = require("@spatulox/utils");
|
|
1652
1537
|
var RoleManager = class {
|
|
1653
1538
|
/**
|
|
1654
1539
|
* Add role - CACHE ONLY
|
|
@@ -1659,14 +1544,14 @@ var RoleManager = class {
|
|
|
1659
1544
|
try {
|
|
1660
1545
|
const role = member.guild.roles.cache.get(roleId);
|
|
1661
1546
|
if (!role) {
|
|
1662
|
-
|
|
1547
|
+
import_utils11.Log.warn(`Role ${roleId} not found in cache`);
|
|
1663
1548
|
return false;
|
|
1664
1549
|
}
|
|
1665
1550
|
await member.roles.add(role);
|
|
1666
|
-
|
|
1551
|
+
import_utils11.Log.info(`\u2705 Added ${role.name} to ${member.displayName}`);
|
|
1667
1552
|
return true;
|
|
1668
1553
|
} catch (error) {
|
|
1669
|
-
|
|
1554
|
+
import_utils11.Log.error(`Failed to add role ${roleId}: ${error}`);
|
|
1670
1555
|
return false;
|
|
1671
1556
|
}
|
|
1672
1557
|
}
|
|
@@ -1677,23 +1562,16 @@ var RoleManager = class {
|
|
|
1677
1562
|
*/
|
|
1678
1563
|
static async remove(member, roleIdOrName) {
|
|
1679
1564
|
try {
|
|
1680
|
-
|
|
1681
|
-
if (typeof roleIdOrName === "string" && roleIdOrName.length === 18) {
|
|
1682
|
-
role = member.roles.cache.get(roleIdOrName);
|
|
1683
|
-
} else {
|
|
1684
|
-
role = member.roles.cache.find(
|
|
1685
|
-
(r) => r.id === roleIdOrName || r.name.toLowerCase() === roleIdOrName.toString().toLowerCase()
|
|
1686
|
-
);
|
|
1687
|
-
}
|
|
1565
|
+
const role = this.resolve(member.roles.cache, roleIdOrName);
|
|
1688
1566
|
if (!role) {
|
|
1689
|
-
|
|
1567
|
+
import_utils11.Log.warn(`Role ${roleIdOrName} not found for ${member.displayName}`);
|
|
1690
1568
|
return false;
|
|
1691
1569
|
}
|
|
1692
1570
|
await member.roles.remove(role);
|
|
1693
|
-
|
|
1571
|
+
import_utils11.Log.info(`\u2705 Removed ${role.name} from ${member.displayName}`);
|
|
1694
1572
|
return true;
|
|
1695
1573
|
} catch (error) {
|
|
1696
|
-
|
|
1574
|
+
import_utils11.Log.error(`Failed to remove role ${roleIdOrName}: ${error}`);
|
|
1697
1575
|
return false;
|
|
1698
1576
|
}
|
|
1699
1577
|
}
|
|
@@ -1701,9 +1579,9 @@ var RoleManager = class {
|
|
|
1701
1579
|
* Toggle role (add/remove)
|
|
1702
1580
|
*/
|
|
1703
1581
|
static async toggle(member, roleIdOrName) {
|
|
1704
|
-
const role =
|
|
1582
|
+
const role = this.resolve(member.guild.roles.cache, roleIdOrName);
|
|
1705
1583
|
if (!role) {
|
|
1706
|
-
|
|
1584
|
+
import_utils11.Log.warn(`Role ${roleIdOrName} not found`);
|
|
1707
1585
|
throw new Error(`Role not found`);
|
|
1708
1586
|
}
|
|
1709
1587
|
if (member.roles.cache.has(role.id)) {
|
|
@@ -1718,84 +1596,115 @@ var RoleManager = class {
|
|
|
1718
1596
|
* Check if member has role
|
|
1719
1597
|
*/
|
|
1720
1598
|
static hasRole(member, roleIdOrName) {
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
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());
|
|
1727
1607
|
}
|
|
1728
1608
|
};
|
|
1729
1609
|
|
|
1730
1610
|
// src/manager/guild/ChannelManager/ForumChannelManager.ts
|
|
1731
|
-
var
|
|
1732
|
-
var
|
|
1611
|
+
var import_discord12 = require("discord.js");
|
|
1612
|
+
var import_utils12 = require("@spatulox/utils");
|
|
1733
1613
|
var ForumChannelManager = class extends GuildChannelManager {
|
|
1734
1614
|
static async findInGuild(guildId, channelId) {
|
|
1735
1615
|
const channel = await super.findInGuild(guildId, channelId);
|
|
1736
|
-
return channel instanceof
|
|
1616
|
+
return channel instanceof import_discord12.ForumChannel ? channel : null;
|
|
1737
1617
|
}
|
|
1738
1618
|
static async find(channelId) {
|
|
1739
1619
|
const channel = await super.find(channelId);
|
|
1740
|
-
return channel instanceof
|
|
1620
|
+
return channel instanceof import_discord12.ForumChannel ? channel : null;
|
|
1741
1621
|
}
|
|
1742
1622
|
static findAll(guildId) {
|
|
1743
1623
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1744
1624
|
if (!guild) {
|
|
1745
|
-
|
|
1625
|
+
import_utils12.Log.warn(`Guild ${guildId} not found`);
|
|
1746
1626
|
return [];
|
|
1747
1627
|
}
|
|
1748
|
-
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof
|
|
1628
|
+
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord12.ForumChannel);
|
|
1749
1629
|
}
|
|
1750
|
-
static async create(guildId,
|
|
1630
|
+
static async create(guildId, name2, options) {
|
|
1751
1631
|
return await super._create(guildId, {
|
|
1752
|
-
name,
|
|
1753
|
-
type:
|
|
1632
|
+
name: name2,
|
|
1633
|
+
type: import_discord12.ChannelType.GuildForum,
|
|
1754
1634
|
...options
|
|
1755
1635
|
});
|
|
1756
1636
|
}
|
|
1757
1637
|
};
|
|
1758
1638
|
|
|
1759
1639
|
// src/manager/guild/ChannelManager/NewsChannelManager.ts
|
|
1760
|
-
var
|
|
1761
|
-
var
|
|
1640
|
+
var import_discord13 = require("discord.js");
|
|
1641
|
+
var import_utils13 = require("@spatulox/utils");
|
|
1762
1642
|
var NewsChannelManager = class extends GuildChannelManager {
|
|
1763
1643
|
static async findInGuild(guildId, channelId) {
|
|
1764
1644
|
const channel = await super.findInGuild(guildId, channelId);
|
|
1765
|
-
return channel instanceof
|
|
1645
|
+
return channel instanceof import_discord13.NewsChannel ? channel : null;
|
|
1766
1646
|
}
|
|
1767
1647
|
static async find(channelId) {
|
|
1768
1648
|
const channel = await super.find(channelId);
|
|
1769
|
-
return channel instanceof
|
|
1649
|
+
return channel instanceof import_discord13.NewsChannel ? channel : null;
|
|
1770
1650
|
}
|
|
1771
1651
|
static findAll(guildId) {
|
|
1772
1652
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1773
1653
|
if (!guild) {
|
|
1774
|
-
|
|
1654
|
+
import_utils13.Log.warn(`Guild ${guildId} not found`);
|
|
1775
1655
|
return [];
|
|
1776
1656
|
}
|
|
1777
|
-
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof
|
|
1657
|
+
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord13.NewsChannel);
|
|
1778
1658
|
}
|
|
1779
|
-
static async create(guildId,
|
|
1659
|
+
static async create(guildId, name2, options) {
|
|
1780
1660
|
return await super._create(guildId, {
|
|
1781
|
-
name,
|
|
1782
|
-
type:
|
|
1661
|
+
name: name2,
|
|
1662
|
+
type: import_discord13.ChannelType.GuildAnnouncement,
|
|
1783
1663
|
...options
|
|
1784
1664
|
});
|
|
1785
1665
|
}
|
|
1786
1666
|
};
|
|
1787
1667
|
|
|
1788
1668
|
// src/manager/guild/ChannelManager/StageChannelManager.ts
|
|
1789
|
-
var
|
|
1790
|
-
var
|
|
1669
|
+
var import_discord14 = require("discord.js");
|
|
1670
|
+
var import_utils14 = require("@spatulox/utils");
|
|
1791
1671
|
var StageChannelManager = class extends GuildChannelManager {
|
|
1792
1672
|
static async findInGuild(guildId, channelId) {
|
|
1793
1673
|
const channel = await super.findInGuild(guildId, channelId);
|
|
1794
|
-
return channel instanceof
|
|
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;
|
|
1795
1704
|
}
|
|
1796
1705
|
static async find(channelId) {
|
|
1797
1706
|
const channel = await super.find(channelId);
|
|
1798
|
-
return channel instanceof
|
|
1707
|
+
return channel instanceof import_discord15.TextChannel ? channel : null;
|
|
1799
1708
|
}
|
|
1800
1709
|
static findAll(guildId) {
|
|
1801
1710
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
@@ -1803,18 +1712,19 @@ var StageChannelManager = class extends GuildChannelManager {
|
|
|
1803
1712
|
import_utils15.Log.warn(`Guild ${guildId} not found`);
|
|
1804
1713
|
return [];
|
|
1805
1714
|
}
|
|
1806
|
-
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof
|
|
1715
|
+
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord15.TextChannel);
|
|
1807
1716
|
}
|
|
1808
|
-
static async create(guildId,
|
|
1717
|
+
static async create(guildId, name2, options) {
|
|
1809
1718
|
return await super._create(guildId, {
|
|
1810
|
-
name,
|
|
1811
|
-
type:
|
|
1719
|
+
name: name2,
|
|
1720
|
+
type: import_discord15.ChannelType.GuildText,
|
|
1812
1721
|
...options
|
|
1813
1722
|
});
|
|
1814
1723
|
}
|
|
1815
1724
|
};
|
|
1816
1725
|
|
|
1817
1726
|
// src/manager/guild/ChannelManager/ThreadChannelManager.ts
|
|
1727
|
+
var import_discord16 = require("discord.js");
|
|
1818
1728
|
var ThreadChannelManager = class {
|
|
1819
1729
|
static async findInGuild(guildId, channelId) {
|
|
1820
1730
|
const channel = await GuildChannelManager.findInGuild(guildId, channelId);
|
|
@@ -1829,16 +1739,15 @@ var ThreadChannelManager = class {
|
|
|
1829
1739
|
return channels.filter((c) => c.isThread());
|
|
1830
1740
|
}
|
|
1831
1741
|
static async createFromChannel(parentId, options) {
|
|
1832
|
-
const channel = await
|
|
1833
|
-
if (!channel
|
|
1834
|
-
throw new Error("Parent must be a text
|
|
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");
|
|
1835
1745
|
}
|
|
1836
1746
|
const thread = await channel.threads.create(options);
|
|
1837
1747
|
return thread;
|
|
1838
1748
|
}
|
|
1839
1749
|
static async createFromMessage(message, options) {
|
|
1840
|
-
|
|
1841
|
-
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");
|
|
1842
1751
|
return await message.startThread(options);
|
|
1843
1752
|
}
|
|
1844
1753
|
/**
|
|
@@ -1856,16 +1765,16 @@ var ThreadChannelManager = class {
|
|
|
1856
1765
|
};
|
|
1857
1766
|
|
|
1858
1767
|
// src/manager/guild/ChannelManager/GuildVoiceChannelManager.ts
|
|
1859
|
-
var
|
|
1768
|
+
var import_discord17 = require("discord.js");
|
|
1860
1769
|
var import_utils16 = require("@spatulox/utils");
|
|
1861
1770
|
var GuildVoiceChannelManager = class extends GuildChannelManager {
|
|
1862
1771
|
static async findInGuild(guildId, channelId) {
|
|
1863
1772
|
const channel = await super.findInGuild(guildId, channelId);
|
|
1864
|
-
return channel
|
|
1773
|
+
return channel instanceof import_discord17.VoiceChannel ? channel : null;
|
|
1865
1774
|
}
|
|
1866
1775
|
static async find(channelId) {
|
|
1867
1776
|
const channel = await super.find(channelId);
|
|
1868
|
-
return channel
|
|
1777
|
+
return channel instanceof import_discord17.VoiceChannel ? channel : null;
|
|
1869
1778
|
}
|
|
1870
1779
|
static findAll(guildId) {
|
|
1871
1780
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
@@ -1873,12 +1782,12 @@ var GuildVoiceChannelManager = class extends GuildChannelManager {
|
|
|
1873
1782
|
import_utils16.Log.warn(`Guild ${guildId} not found`);
|
|
1874
1783
|
return [];
|
|
1875
1784
|
}
|
|
1876
|
-
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof
|
|
1785
|
+
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof import_discord17.VoiceChannel);
|
|
1877
1786
|
}
|
|
1878
|
-
static async create(guildId,
|
|
1787
|
+
static async create(guildId, name2, options) {
|
|
1879
1788
|
return await super._create(guildId, {
|
|
1880
|
-
name,
|
|
1881
|
-
type:
|
|
1789
|
+
name: name2,
|
|
1790
|
+
type: import_discord17.ChannelType.GuildVoice,
|
|
1882
1791
|
...options
|
|
1883
1792
|
});
|
|
1884
1793
|
}
|
|
@@ -1896,6 +1805,7 @@ var GuildChannelList = class {
|
|
|
1896
1805
|
};
|
|
1897
1806
|
|
|
1898
1807
|
// src/manager/guild/InviteManager.ts
|
|
1808
|
+
var import_promises3 = require("timers/promises");
|
|
1899
1809
|
var import_utils17 = require("@spatulox/utils");
|
|
1900
1810
|
var InviteManager = class {
|
|
1901
1811
|
/**
|
|
@@ -1923,9 +1833,19 @@ var InviteManager = class {
|
|
|
1923
1833
|
}
|
|
1924
1834
|
}
|
|
1925
1835
|
/**
|
|
1926
|
-
*
|
|
1836
|
+
* Find an invite by its code or its url (discord.gg/code, discord.com/invite/code)
|
|
1927
1837
|
*/
|
|
1928
|
-
static async
|
|
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;
|
|
1929
1849
|
try {
|
|
1930
1850
|
await invite.delete();
|
|
1931
1851
|
import_utils17.Log.info(`Deleted invite ${invite.code} from guild ${invite.guild?.id}`);
|
|
@@ -1953,6 +1873,33 @@ var InviteManager = class {
|
|
|
1953
1873
|
throw error;
|
|
1954
1874
|
}
|
|
1955
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
|
+
}
|
|
1956
1903
|
};
|
|
1957
1904
|
|
|
1958
1905
|
// src/manager/guild/GuildManager.ts
|
|
@@ -1988,9 +1935,9 @@ var GuildManager = class {
|
|
|
1988
1935
|
/**
|
|
1989
1936
|
* Search guild member by ID
|
|
1990
1937
|
*/
|
|
1991
|
-
static async searchMember(
|
|
1938
|
+
static async searchMember(guildId, memberId) {
|
|
1992
1939
|
try {
|
|
1993
|
-
return await this.user.findInGuild(guildId,
|
|
1940
|
+
return await this.user.findInGuild(guildId, memberId);
|
|
1994
1941
|
} catch (error) {
|
|
1995
1942
|
import_utils18.Log.error(`Failed to fetch member ${memberId} in guild ${guildId}: ${error}`);
|
|
1996
1943
|
return null;
|
|
@@ -1999,9 +1946,9 @@ var GuildManager = class {
|
|
|
1999
1946
|
/**
|
|
2000
1947
|
* Check if member is still in guild
|
|
2001
1948
|
*/
|
|
2002
|
-
static async isMemberInGuild(
|
|
1949
|
+
static async isMemberInGuild(guildId, memberId) {
|
|
2003
1950
|
try {
|
|
2004
|
-
return await this.user.isInGuild(
|
|
1951
|
+
return await this.user.isInGuild(guildId, memberId);
|
|
2005
1952
|
} catch (error) {
|
|
2006
1953
|
return error.code !== 10007;
|
|
2007
1954
|
}
|
|
@@ -2011,7 +1958,7 @@ var GuildManager = class {
|
|
|
2011
1958
|
*/
|
|
2012
1959
|
static async fetchAllMembers(guildId, MAX_ATTEMPTS = 3, RETRY_DELAY = import_utils19.Time.minute.MIN_05.toMilliseconds()) {
|
|
2013
1960
|
let guild;
|
|
2014
|
-
if (guildId instanceof
|
|
1961
|
+
if (guildId instanceof import_discord18.Guild) {
|
|
2015
1962
|
guild = guildId;
|
|
2016
1963
|
} else {
|
|
2017
1964
|
let tmp = Bot.client.guilds.cache.get(guildId);
|
|
@@ -2064,10 +2011,10 @@ var GuildManager = class {
|
|
|
2064
2011
|
if (!toChannel) {
|
|
2065
2012
|
throw new Error(`To channel ${toChannelId} not found`);
|
|
2066
2013
|
}
|
|
2067
|
-
if (!(fromChannel instanceof
|
|
2014
|
+
if (!(fromChannel instanceof import_discord18.VoiceChannel || fromChannel instanceof import_discord18.StageChannel)) {
|
|
2068
2015
|
throw new Error(`From channel ${fromChannelId} is not a voice/stage channel`);
|
|
2069
2016
|
}
|
|
2070
|
-
if (!(toChannel instanceof
|
|
2017
|
+
if (!(toChannel instanceof import_discord18.VoiceChannel || toChannel instanceof import_discord18.StageChannel)) {
|
|
2071
2018
|
throw new Error(`To channel ${toChannelId} is not a voice/stage channel`);
|
|
2072
2019
|
}
|
|
2073
2020
|
if (member.voice.channelId !== fromChannelId) {
|
|
@@ -2101,7 +2048,7 @@ var UserManager = class extends BasicUserManager {
|
|
|
2101
2048
|
};
|
|
2102
2049
|
|
|
2103
2050
|
// src/manager/interactible/ModalManager.ts
|
|
2104
|
-
var
|
|
2051
|
+
var import_discord19 = require("discord.js");
|
|
2105
2052
|
var ModalFieldType = /* @__PURE__ */ ((ModalFieldType2) => {
|
|
2106
2053
|
ModalFieldType2[ModalFieldType2["SHORT"] = 0] = "SHORT";
|
|
2107
2054
|
ModalFieldType2[ModalFieldType2["LONG"] = 1] = "LONG";
|
|
@@ -2115,13 +2062,13 @@ var ModalManager = class {
|
|
|
2115
2062
|
* Creates base Modal - SIMPLE API !
|
|
2116
2063
|
*/
|
|
2117
2064
|
static create(modalTitle, customId) {
|
|
2118
|
-
return new
|
|
2065
|
+
return new import_discord19.ModalBuilder().setTitle(modalTitle).setCustomId(customId);
|
|
2119
2066
|
}
|
|
2120
2067
|
/**
|
|
2121
2068
|
* Individual field creator
|
|
2122
2069
|
*/
|
|
2123
2070
|
static _createField(opt) {
|
|
2124
|
-
const builder = new
|
|
2071
|
+
const builder = new import_discord19.TextInputBuilder().setCustomId(opt.customId).setRequired(opt.required ?? false);
|
|
2125
2072
|
if (opt.value) {
|
|
2126
2073
|
builder.setValue(opt.value);
|
|
2127
2074
|
}
|
|
@@ -2132,22 +2079,22 @@ var ModalManager = class {
|
|
|
2132
2079
|
}
|
|
2133
2080
|
switch (opt.type) {
|
|
2134
2081
|
case 0 /* SHORT */:
|
|
2135
|
-
builder.setStyle(
|
|
2082
|
+
builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(4e3);
|
|
2136
2083
|
break;
|
|
2137
2084
|
case 1 /* LONG */:
|
|
2138
|
-
builder.setStyle(
|
|
2085
|
+
builder.setStyle(import_discord19.TextInputStyle.Paragraph).setMaxLength(4e3);
|
|
2139
2086
|
break;
|
|
2140
2087
|
case 2 /* NUMBER */:
|
|
2141
|
-
builder.setStyle(
|
|
2088
|
+
builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(10);
|
|
2142
2089
|
break;
|
|
2143
2090
|
case 3 /* DATE */:
|
|
2144
|
-
builder.setStyle(
|
|
2091
|
+
builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(10).setPlaceholder("YYYY-MM-DD / DD-MM-YYYY or YYYY/MM/DD / DD/MM/YYYY");
|
|
2145
2092
|
break;
|
|
2146
2093
|
case 4 /* PHONE */:
|
|
2147
|
-
builder.setStyle(
|
|
2094
|
+
builder.setStyle(import_discord19.TextInputStyle.Short).setMaxLength(20);
|
|
2148
2095
|
break;
|
|
2149
2096
|
}
|
|
2150
|
-
return new
|
|
2097
|
+
return new import_discord19.LabelBuilder().setLabel(opt.label).setTextInputComponent(builder);
|
|
2151
2098
|
}
|
|
2152
2099
|
/**
|
|
2153
2100
|
* Simple modal with ONE field - DIRECT ModalBuilder return !
|
|
@@ -2156,7 +2103,7 @@ var ModalManager = class {
|
|
|
2156
2103
|
const modal = this.create(modalTitle ?? Bot.config?.botName ?? "Bot", customId);
|
|
2157
2104
|
const opt = {
|
|
2158
2105
|
...field,
|
|
2159
|
-
customId: `${customId}_input`,
|
|
2106
|
+
customId: field.customId ?? `${customId}_input`,
|
|
2160
2107
|
placeholder: "placeholder" in field && field.placeholder ? field.placeholder : `Enter ${field.label.toLowerCase()}`,
|
|
2161
2108
|
value: field.value
|
|
2162
2109
|
};
|
|
@@ -2166,21 +2113,23 @@ var ModalManager = class {
|
|
|
2166
2113
|
/**
|
|
2167
2114
|
* Title + Description modal preset
|
|
2168
2115
|
*/
|
|
2169
|
-
static titleDescription(customId, modalTitle, title,
|
|
2116
|
+
static titleDescription(customId, modalTitle, title, description2) {
|
|
2170
2117
|
const modal = this.create(modalTitle, customId);
|
|
2171
2118
|
const titleField = {
|
|
2172
2119
|
customId: `${customId}_title`,
|
|
2173
2120
|
label: title.label,
|
|
2174
2121
|
placeholder: title.placeholder ?? `Enter ${title.label.toLowerCase()}`,
|
|
2175
2122
|
type: 0 /* SHORT */,
|
|
2176
|
-
required: title.required
|
|
2123
|
+
required: title.required,
|
|
2124
|
+
value: title.value
|
|
2177
2125
|
};
|
|
2178
2126
|
const descField = {
|
|
2179
2127
|
customId: `${customId}_desc`,
|
|
2180
|
-
label:
|
|
2181
|
-
placeholder:
|
|
2128
|
+
label: description2.label,
|
|
2129
|
+
placeholder: description2.placeholder ?? `Enter ${description2.label.toLowerCase()}`,
|
|
2182
2130
|
type: 1 /* LONG */,
|
|
2183
|
-
required:
|
|
2131
|
+
required: description2.required,
|
|
2132
|
+
value: description2.value
|
|
2184
2133
|
};
|
|
2185
2134
|
modal.addLabelComponents(this._createField(titleField));
|
|
2186
2135
|
modal.addLabelComponents(this._createField(descField));
|
|
@@ -2188,21 +2137,25 @@ var ModalManager = class {
|
|
|
2188
2137
|
}
|
|
2189
2138
|
/**
|
|
2190
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)
|
|
2191
2142
|
*/
|
|
2192
|
-
static date(customId, modalTitle = "Select Date", inputLabel = "Date") {
|
|
2193
|
-
return this.simple(`${customId}_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 */ });
|
|
2194
2145
|
}
|
|
2195
2146
|
/**
|
|
2196
2147
|
* Number modal preset
|
|
2148
|
+
* @param suffix See date() : `${customId}_number` by default, `customId` when false
|
|
2197
2149
|
*/
|
|
2198
|
-
static number(customId, modalTitle = "Enter a Number", inputLabel = "Number") {
|
|
2199
|
-
return this.simple(`${customId}_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" });
|
|
2200
2152
|
}
|
|
2201
2153
|
/**
|
|
2202
|
-
*
|
|
2154
|
+
* Phone modal preset
|
|
2155
|
+
* @param suffix See date() : `${customId}_phone_number` by default, `customId` when false
|
|
2203
2156
|
*/
|
|
2204
|
-
static phone(customId, modalTitle = "Enter a Phone number", inputLabel = "Phone number") {
|
|
2205
|
-
return this.simple(`${customId}_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" });
|
|
2206
2159
|
}
|
|
2207
2160
|
static add(modal, field) {
|
|
2208
2161
|
if (Array.isArray(field)) {
|
|
@@ -2213,7 +2166,7 @@ var ModalManager = class {
|
|
|
2213
2166
|
}
|
|
2214
2167
|
const opt = {
|
|
2215
2168
|
...field,
|
|
2216
|
-
customId: `${modal.data.custom_id}_${field.label}`
|
|
2169
|
+
customId: field.customId ?? `${modal.data.custom_id}_${field.label}`
|
|
2217
2170
|
};
|
|
2218
2171
|
modal.addLabelComponents(this._createField(opt));
|
|
2219
2172
|
return modal;
|
|
@@ -2232,124 +2185,128 @@ var ModalManager = class {
|
|
|
2232
2185
|
static parseDate(value) {
|
|
2233
2186
|
if (/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/.test(value)) {
|
|
2234
2187
|
const [year, month, day] = value.split("-").map(Number);
|
|
2235
|
-
|
|
2236
|
-
return isNaN(date.getTime()) ? null : date;
|
|
2188
|
+
return this.buildDate(year, month, day);
|
|
2237
2189
|
}
|
|
2238
2190
|
if (/^(0[1-9]|[12]\d|3[01])-(0[1-9]|1[0-2])-\d{4}$/.test(value)) {
|
|
2239
2191
|
const [day, month, year] = value.split("-").map(Number);
|
|
2240
|
-
|
|
2241
|
-
return isNaN(date.getTime()) ? null : date;
|
|
2192
|
+
return this.buildDate(year, month, day);
|
|
2242
2193
|
}
|
|
2243
2194
|
if (/^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/\d{4}$/.test(value)) {
|
|
2244
2195
|
const [day, month, year] = value.split("/").map(Number);
|
|
2245
|
-
|
|
2246
|
-
return isNaN(date.getTime()) ? null : date;
|
|
2196
|
+
return this.buildDate(year, month, day);
|
|
2247
2197
|
}
|
|
2248
2198
|
if (/^\d{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])$/.test(value)) {
|
|
2249
2199
|
const [year, month, day] = value.split("/").map(Number);
|
|
2250
|
-
|
|
2251
|
-
return isNaN(date.getTime()) ? null : date;
|
|
2200
|
+
return this.buildDate(year, month, day);
|
|
2252
2201
|
}
|
|
2253
2202
|
return null;
|
|
2254
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
|
+
}
|
|
2255
2212
|
};
|
|
2256
2213
|
|
|
2257
2214
|
// src/manager/messages/ComponentManager.ts
|
|
2258
|
-
var
|
|
2215
|
+
var import_discord20 = require("discord.js");
|
|
2259
2216
|
var ComponentManager = class {
|
|
2260
2217
|
static get DEFAULT_COLOR() {
|
|
2261
|
-
return Bot.config?.defaultSimpleColor
|
|
2218
|
+
return Bot.config?.defaultSimpleColor ?? 6064856 /* default */;
|
|
2262
2219
|
}
|
|
2263
2220
|
/**
|
|
2264
2221
|
* Creates base ComponentV2
|
|
2265
2222
|
*/
|
|
2266
2223
|
static create(option) {
|
|
2267
|
-
const container = new
|
|
2224
|
+
const container = new import_discord20.ContainerBuilder();
|
|
2268
2225
|
const colorC = option?.color ?? this.DEFAULT_COLOR;
|
|
2269
2226
|
if (colorC !== "transparent" /* transparent */) {
|
|
2270
2227
|
container.setAccentColor(colorC);
|
|
2271
2228
|
}
|
|
2272
2229
|
if (option?.title || option?.thumbnailUrl) {
|
|
2273
2230
|
if (option?.thumbnailUrl) {
|
|
2274
|
-
const headerSection = new
|
|
2275
|
-
new
|
|
2231
|
+
const headerSection = new import_discord20.SectionBuilder().addTextDisplayComponents(
|
|
2232
|
+
new import_discord20.TextDisplayBuilder().setContent(
|
|
2276
2233
|
option?.title ? option.title : "\u200B"
|
|
2277
2234
|
)
|
|
2278
2235
|
).setThumbnailAccessory(
|
|
2279
|
-
new
|
|
2236
|
+
new import_discord20.ThumbnailBuilder().setURL(option.thumbnailUrl)
|
|
2280
2237
|
);
|
|
2281
2238
|
container.addSectionComponents(headerSection);
|
|
2282
2239
|
} else {
|
|
2283
2240
|
container.addTextDisplayComponents(
|
|
2284
|
-
new
|
|
2241
|
+
new import_discord20.TextDisplayBuilder().setContent(option.title)
|
|
2285
2242
|
);
|
|
2286
2243
|
}
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
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));
|
|
2293
2250
|
}
|
|
2294
2251
|
return container;
|
|
2295
2252
|
}
|
|
2296
2253
|
/**
|
|
2297
2254
|
* Creates simple ComponentV2 with just description
|
|
2298
2255
|
*/
|
|
2299
|
-
static simple(
|
|
2300
|
-
return this.create({ color }).addTextDisplayComponents(new
|
|
2256
|
+
static simple(description2, color = null) {
|
|
2257
|
+
return this.create({ color }).addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(description2)).addSeparatorComponents(this.separator());
|
|
2301
2258
|
}
|
|
2302
2259
|
/**
|
|
2303
2260
|
* Creates success ComponentV2
|
|
2304
2261
|
*/
|
|
2305
|
-
static success(
|
|
2306
|
-
return this.create({ title: "Success", color: 65280 /* success */ }).addTextDisplayComponents(new
|
|
2262
|
+
static success(description2) {
|
|
2263
|
+
return this.create({ title: "Success", color: 65280 /* success */ }).addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(description2)).addSeparatorComponents(this.separator());
|
|
2307
2264
|
}
|
|
2308
2265
|
/**
|
|
2309
2266
|
* Creates debug ComponentV2
|
|
2310
2267
|
*/
|
|
2311
|
-
static debug(
|
|
2268
|
+
static debug(description2) {
|
|
2312
2269
|
return this.create({ title: "Debug", color: 25600 /* minecraft */ }).addTextDisplayComponents(
|
|
2313
|
-
new
|
|
2270
|
+
new import_discord20.TextDisplayBuilder().setContent(description2)
|
|
2314
2271
|
).addSeparatorComponents(this.separator());
|
|
2315
2272
|
}
|
|
2316
2273
|
/**
|
|
2317
2274
|
* Creates error ComponentV2
|
|
2318
2275
|
*/
|
|
2319
|
-
static error(
|
|
2276
|
+
static error(description2) {
|
|
2320
2277
|
return this.create({ title: "Something went wrong", color: 8912917 /* error */ }).addTextDisplayComponents(
|
|
2321
|
-
new
|
|
2278
|
+
new import_discord20.TextDisplayBuilder().setContent(description2)
|
|
2322
2279
|
).addSeparatorComponents(this.separator());
|
|
2323
2280
|
}
|
|
2324
|
-
static separator(spacing =
|
|
2325
|
-
return new
|
|
2281
|
+
static separator(spacing = import_discord20.SeparatorSpacingSize.Small) {
|
|
2282
|
+
return new import_discord20.SeparatorBuilder().setDivider(true).setSpacing(spacing);
|
|
2326
2283
|
}
|
|
2327
2284
|
/**
|
|
2328
2285
|
* Quick field adder
|
|
2329
2286
|
*/
|
|
2330
2287
|
static fieldAddText(container, options) {
|
|
2331
|
-
options.name && container.addTextDisplayComponents(new
|
|
2332
|
-
options.value && container.addTextDisplayComponents(new
|
|
2288
|
+
options.name && container.addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(`__**${options.name}**__`));
|
|
2289
|
+
options.value && container.addTextDisplayComponents(new import_discord20.TextDisplayBuilder().setContent(options.value));
|
|
2333
2290
|
}
|
|
2334
2291
|
static field(container, field) {
|
|
2335
2292
|
const hasText = ("name" in field || "value" in field) && (field.name || field.value);
|
|
2336
2293
|
if ("button" in field && Array.isArray(field.button) && field.button.length > 0) {
|
|
2337
|
-
const actionRow = new
|
|
2294
|
+
const actionRow = new import_discord20.ActionRowBuilder().addComponents(field.button);
|
|
2338
2295
|
if (hasText) this.fieldAddText(container, { name: field.name, value: field.value });
|
|
2339
2296
|
container.addActionRowComponents(actionRow);
|
|
2340
2297
|
} else if ("button" in field && !Array.isArray(field.button) || "thumbnailUrl" in field) {
|
|
2341
2298
|
if (hasText) {
|
|
2342
|
-
const section = new
|
|
2299
|
+
const section = new import_discord20.SectionBuilder();
|
|
2343
2300
|
this.fieldAddText(section, { name: field.name, value: field.value });
|
|
2344
2301
|
if ("button" in field && !Array.isArray(field.button)) {
|
|
2345
2302
|
section.setButtonAccessory(field.button);
|
|
2346
2303
|
} else if ("thumbnailUrl" in field) {
|
|
2347
|
-
section.setThumbnailAccessory(new
|
|
2304
|
+
section.setThumbnailAccessory(new import_discord20.ThumbnailBuilder().setURL(field.thumbnailUrl));
|
|
2348
2305
|
}
|
|
2349
2306
|
container.addSectionComponents(section);
|
|
2350
2307
|
} else {
|
|
2351
2308
|
if ("button" in field && !Array.isArray(field.button)) {
|
|
2352
|
-
const actionRow = new
|
|
2309
|
+
const actionRow = new import_discord20.ActionRowBuilder().addComponents(field.button);
|
|
2353
2310
|
container.addActionRowComponents(actionRow);
|
|
2354
2311
|
}
|
|
2355
2312
|
}
|
|
@@ -2388,9 +2345,9 @@ var ComponentManager = class {
|
|
|
2388
2345
|
* Add a media gallery (links)
|
|
2389
2346
|
*/
|
|
2390
2347
|
static mediaGallery(container, medias) {
|
|
2391
|
-
const gallery = new
|
|
2348
|
+
const gallery = new import_discord20.MediaGalleryBuilder();
|
|
2392
2349
|
medias.forEach((med) => {
|
|
2393
|
-
gallery.addItems(new
|
|
2350
|
+
gallery.addItems(new import_discord20.MediaGalleryItemBuilder().setURL(med.url).setSpoiler(med.spoiler ?? false));
|
|
2394
2351
|
});
|
|
2395
2352
|
container.addMediaGalleryComponents(gallery);
|
|
2396
2353
|
return container;
|
|
@@ -2407,22 +2364,25 @@ var ComponentManager = class {
|
|
|
2407
2364
|
const files = [];
|
|
2408
2365
|
const fileArray = Array.isArray(file) ? file : [file];
|
|
2409
2366
|
fileArray.forEach((f) => {
|
|
2410
|
-
const attachment = new
|
|
2367
|
+
const attachment = new import_discord20.AttachmentBuilder(f.buffer, {
|
|
2411
2368
|
name: f.name
|
|
2412
2369
|
});
|
|
2413
2370
|
files.push(attachment);
|
|
2414
2371
|
container.addFileComponents(
|
|
2415
|
-
new
|
|
2372
|
+
new import_discord20.FileBuilder().setURL(`attachment://${f.name}`).setSpoiler(f.spoiler ?? false)
|
|
2416
2373
|
);
|
|
2417
2374
|
container.addSeparatorComponents(this.separator());
|
|
2418
2375
|
});
|
|
2419
2376
|
return { container, files };
|
|
2420
2377
|
}
|
|
2378
|
+
/**
|
|
2379
|
+
* Returns a copy with the footer, so calling toMessage() / toInteraction() twice on the same
|
|
2380
|
+
* container doesn't stack footers
|
|
2381
|
+
*/
|
|
2421
2382
|
static footer(container) {
|
|
2422
|
-
container.addTextDisplayComponents(
|
|
2423
|
-
new
|
|
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>**`)
|
|
2424
2385
|
);
|
|
2425
|
-
return container;
|
|
2426
2386
|
}
|
|
2427
2387
|
/**
|
|
2428
2388
|
* Transform ComponentV2 into object for channel.send()
|
|
@@ -2432,27 +2392,27 @@ var ComponentManager = class {
|
|
|
2432
2392
|
*/
|
|
2433
2393
|
static toMessage(container, file = null, footer = true) {
|
|
2434
2394
|
if (footer) {
|
|
2435
|
-
this.footer(container);
|
|
2395
|
+
container = this.footer(container);
|
|
2436
2396
|
}
|
|
2437
2397
|
if (file) {
|
|
2438
2398
|
return {
|
|
2439
2399
|
components: [container],
|
|
2440
2400
|
files: Array.isArray(file) ? file : [file],
|
|
2441
|
-
flags: [
|
|
2401
|
+
flags: [import_discord20.MessageFlags.IsComponentsV2]
|
|
2442
2402
|
};
|
|
2443
2403
|
}
|
|
2444
2404
|
return {
|
|
2445
2405
|
components: [container],
|
|
2446
|
-
flags: [
|
|
2406
|
+
flags: [import_discord20.MessageFlags.IsComponentsV2]
|
|
2447
2407
|
};
|
|
2448
2408
|
}
|
|
2449
|
-
static toInteraction(container, file = null, footer = true) {
|
|
2409
|
+
static toInteraction(container, file = null, footer = true, ephemeral = false) {
|
|
2450
2410
|
if (footer) {
|
|
2451
|
-
this.footer(container);
|
|
2411
|
+
container = this.footer(container);
|
|
2452
2412
|
}
|
|
2453
2413
|
const base = {
|
|
2454
2414
|
components: [container],
|
|
2455
|
-
flags: [
|
|
2415
|
+
flags: ephemeral ? [import_discord20.MessageFlags.IsComponentsV2, import_discord20.MessageFlags.Ephemeral] : [import_discord20.MessageFlags.IsComponentsV2]
|
|
2456
2416
|
};
|
|
2457
2417
|
if (file) {
|
|
2458
2418
|
return {
|
|
@@ -2462,12 +2422,16 @@ var ComponentManager = class {
|
|
|
2462
2422
|
}
|
|
2463
2423
|
return base;
|
|
2464
2424
|
}
|
|
2465
|
-
|
|
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) {
|
|
2466
2429
|
if (footer) {
|
|
2467
|
-
this.footer(container);
|
|
2430
|
+
container = this.footer(container);
|
|
2468
2431
|
}
|
|
2469
2432
|
const base = {
|
|
2470
|
-
components: [container]
|
|
2433
|
+
components: [container],
|
|
2434
|
+
flags: [import_discord20.MessageFlags.IsComponentsV2]
|
|
2471
2435
|
};
|
|
2472
2436
|
if (file) {
|
|
2473
2437
|
return {
|
|
@@ -2477,10 +2441,16 @@ var ComponentManager = class {
|
|
|
2477
2441
|
}
|
|
2478
2442
|
return base;
|
|
2479
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
|
+
}
|
|
2480
2450
|
};
|
|
2481
2451
|
|
|
2482
2452
|
// src/manager/messages/ChartManager.ts
|
|
2483
|
-
var
|
|
2453
|
+
var import_discord21 = require("discord.js");
|
|
2484
2454
|
var SPARK_BLOCKS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
|
|
2485
2455
|
var DEFAULT_MAX_POINTS = 50;
|
|
2486
2456
|
var EMPTY = "\u2014";
|
|
@@ -2490,7 +2460,7 @@ var ChartManager = class _ChartManager {
|
|
|
2490
2460
|
*/
|
|
2491
2461
|
static progressBar(label, value, max = 100, options = {}) {
|
|
2492
2462
|
const line = `${label} : ${_ChartManager.renderBar(value, max, options)}`;
|
|
2493
|
-
return new
|
|
2463
|
+
return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(line, options.codeBlock));
|
|
2494
2464
|
}
|
|
2495
2465
|
/**
|
|
2496
2466
|
* Several gauges in ONE TextDisplay, so a dashboard of 6 metrics still costs 1 component.
|
|
@@ -2502,7 +2472,7 @@ var ChartManager = class _ChartManager {
|
|
|
2502
2472
|
const opts = { ...options, ...row.options };
|
|
2503
2473
|
return `${row.label.padEnd(width, " ")} : ${_ChartManager.renderBar(row.value, row.max ?? 100, opts)}`;
|
|
2504
2474
|
});
|
|
2505
|
-
return new
|
|
2475
|
+
return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(lines.join("\n"), options.codeBlock));
|
|
2506
2476
|
}
|
|
2507
2477
|
/**
|
|
2508
2478
|
* A one line curve : `RAM : ▁▂▃▅▇█▆▄▃▂▁ 62 %`. One block character per point, the last
|
|
@@ -2510,7 +2480,7 @@ var ChartManager = class _ChartManager {
|
|
|
2510
2480
|
*/
|
|
2511
2481
|
static sparkline(label, values, options = {}) {
|
|
2512
2482
|
const line = `${label} : ${_ChartManager.renderSpark(values, options)}`;
|
|
2513
|
-
return new
|
|
2483
|
+
return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(line, options.codeBlock));
|
|
2514
2484
|
}
|
|
2515
2485
|
/**
|
|
2516
2486
|
* Several curves in ONE TextDisplay, the sparkline counterpart of progressBars().
|
|
@@ -2523,7 +2493,7 @@ var ChartManager = class _ChartManager {
|
|
|
2523
2493
|
const opts = { ...base, ...row.options };
|
|
2524
2494
|
return `${row.label.padEnd(width, " ")} : ${_ChartManager.renderSpark(row.values, opts)}`;
|
|
2525
2495
|
});
|
|
2526
|
-
return new
|
|
2496
|
+
return new import_discord21.TextDisplayBuilder().setContent(_ChartManager.wrap(lines.join("\n"), options.codeBlock));
|
|
2527
2497
|
}
|
|
2528
2498
|
/**
|
|
2529
2499
|
* Only fills the bounds that were not given explicitly, and only when asked : a row
|
|
@@ -2585,29 +2555,32 @@ var ChartManager = class _ChartManager {
|
|
|
2585
2555
|
};
|
|
2586
2556
|
|
|
2587
2557
|
// src/manager/interactible/ButtonManager.ts
|
|
2588
|
-
var
|
|
2558
|
+
var import_discord22 = require("discord.js");
|
|
2589
2559
|
var ButtonManager = class _ButtonManager {
|
|
2590
2560
|
static create(options) {
|
|
2591
|
-
const btn = new
|
|
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
|
+
}
|
|
2592
2565
|
if (options.emoji) {
|
|
2593
2566
|
btn.setEmoji(options.emoji);
|
|
2594
2567
|
}
|
|
2595
2568
|
return btn;
|
|
2596
2569
|
}
|
|
2597
2570
|
static primary(options) {
|
|
2598
|
-
return this.create({ ...options, style:
|
|
2571
|
+
return this.create({ ...options, style: import_discord22.ButtonStyle.Primary });
|
|
2599
2572
|
}
|
|
2600
2573
|
static success(options) {
|
|
2601
|
-
return this.create({ ...options, style:
|
|
2574
|
+
return this.create({ ...options, style: import_discord22.ButtonStyle.Success });
|
|
2602
2575
|
}
|
|
2603
2576
|
static secondary(options) {
|
|
2604
|
-
return this.create({ ...options, style:
|
|
2577
|
+
return this.create({ ...options, style: import_discord22.ButtonStyle.Secondary });
|
|
2605
2578
|
}
|
|
2606
2579
|
static danger(options) {
|
|
2607
|
-
return this.create({ ...options, style:
|
|
2580
|
+
return this.create({ ...options, style: import_discord22.ButtonStyle.Danger });
|
|
2608
2581
|
}
|
|
2609
2582
|
static link(options) {
|
|
2610
|
-
const btn = new
|
|
2583
|
+
const btn = new import_discord22.ButtonBuilder().setLabel(options.label).setStyle(import_discord22.ButtonStyle.Link).setURL(options.url);
|
|
2611
2584
|
if (options.emoji) btn.setEmoji(options.emoji);
|
|
2612
2585
|
return btn;
|
|
2613
2586
|
}
|
|
@@ -2619,7 +2592,7 @@ var ButtonManager = class _ButtonManager {
|
|
|
2619
2592
|
}
|
|
2620
2593
|
static row(but) {
|
|
2621
2594
|
const buttons = Array.isArray(but) ? but.slice(0, 5) : [but];
|
|
2622
|
-
return new
|
|
2595
|
+
return new import_discord22.ActionRowBuilder().addComponents(buttons);
|
|
2623
2596
|
}
|
|
2624
2597
|
static toMessage(button) {
|
|
2625
2598
|
return {
|
|
@@ -2629,40 +2602,154 @@ var ButtonManager = class _ButtonManager {
|
|
|
2629
2602
|
static toInteraction(button, ephemeral = false) {
|
|
2630
2603
|
return {
|
|
2631
2604
|
components: this.createRowsToReturn(button),
|
|
2632
|
-
flags: ephemeral ? [
|
|
2605
|
+
flags: ephemeral ? [import_discord22.MessageFlags.Ephemeral] : []
|
|
2633
2606
|
};
|
|
2634
2607
|
}
|
|
2635
|
-
|
|
2608
|
+
/**
|
|
2609
|
+
* Options to edit an existing message : message.edit()
|
|
2610
|
+
*/
|
|
2611
|
+
static toMessageUpdate(button) {
|
|
2636
2612
|
return {
|
|
2637
2613
|
components: this.createRowsToReturn(button)
|
|
2638
2614
|
};
|
|
2639
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
|
+
*/
|
|
2640
2625
|
static createRowsToReturn(button) {
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
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();
|
|
2645
2682
|
}
|
|
2646
|
-
|
|
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
|
+
);
|
|
2647
2730
|
}
|
|
2648
2731
|
};
|
|
2649
2732
|
|
|
2650
2733
|
// src/index.ts
|
|
2651
|
-
var import_utils23 = require("@spatulox/utils");
|
|
2652
2734
|
var import_utils24 = require("@spatulox/utils");
|
|
2653
2735
|
var import_utils25 = require("@spatulox/utils");
|
|
2736
|
+
var import_utils26 = require("@spatulox/utils");
|
|
2654
2737
|
|
|
2655
2738
|
// src/constants/DiscordRegex.ts
|
|
2656
|
-
var DiscordRegex = class {
|
|
2739
|
+
var DiscordRegex = class _DiscordRegex {
|
|
2657
2740
|
// Caractères spéciaux
|
|
2658
2741
|
static SPACE = "\u200B";
|
|
2659
2742
|
// URLs basiques
|
|
2660
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;
|
|
2661
2746
|
/* DISCORD REGEX */
|
|
2662
|
-
|
|
2663
|
-
static
|
|
2664
|
-
|
|
2665
|
-
static
|
|
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}>/;
|
|
2666
2753
|
/**
|
|
2667
2754
|
* Mention a User
|
|
2668
2755
|
* Mention a Role
|
|
@@ -2679,32 +2766,33 @@ var DiscordRegex = class {
|
|
|
2679
2766
|
`(${this.DISCORD_PING_REGEX.source})|(${this.CHANNEL_REGEX.source})`
|
|
2680
2767
|
);
|
|
2681
2768
|
// ID Discord (user, channel guild)
|
|
2682
|
-
static
|
|
2683
|
-
static
|
|
2684
|
-
static
|
|
2685
|
-
static
|
|
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;
|
|
2686
2774
|
// Username Discord (2-32 caractères alphanumériques + _ .)
|
|
2687
|
-
static USERNAME = /^[a-zA-Z0-9_]{2,32}$/;
|
|
2775
|
+
static USERNAME = /^[a-zA-Z0-9_.]{2,32}$/;
|
|
2688
2776
|
// Username + discrim (ancien format)
|
|
2689
2777
|
static USERNAME_DISCRIM = /^[a-zA-Z0-9_]{2,32}#\d{4}$/;
|
|
2690
2778
|
// Channel mention <#123456789012345678>
|
|
2691
|
-
static CHANNEL_MENTION = /^<#([0-9]{
|
|
2779
|
+
static CHANNEL_MENTION = /^<#([0-9]{17,20})>$/;
|
|
2692
2780
|
// User mention <@123456789012345678> ou <@!123456789012345678>
|
|
2693
|
-
static USER_MENTION = /^<@!?([0-9]{
|
|
2781
|
+
static USER_MENTION = /^<@!?([0-9]{17,20})>$/;
|
|
2694
2782
|
// Role mention <@&123456789012345678>
|
|
2695
|
-
static ROLE_MENTION = /^<@&([0-9]{
|
|
2696
|
-
// URL Invite Discord
|
|
2697
|
-
static INVITE = /^discord(?:app
|
|
2698
|
-
// Emoji Discord (custom or unicode)
|
|
2699
|
-
static EMOJI = /^<a?:[a-zA-Z0-9_]{2,32}:[0-9]{
|
|
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;
|
|
2700
2788
|
/**
|
|
2701
|
-
* Validate Discord ID
|
|
2789
|
+
* Validate a Discord ID (snowflake, 17 to 20 digits)
|
|
2702
2790
|
*/
|
|
2703
2791
|
static isDiscordId(id) {
|
|
2704
|
-
return this.
|
|
2792
|
+
return this.SNOWFLAKE.test(id);
|
|
2705
2793
|
}
|
|
2706
2794
|
/**
|
|
2707
|
-
*
|
|
2795
|
+
* @deprecated A bot mention can't be told apart from a user mention : same as isUserMention()
|
|
2708
2796
|
*/
|
|
2709
2797
|
static isBotMention(mention) {
|
|
2710
2798
|
return this.BOT_REGEX.test(mention);
|
|
@@ -2722,7 +2810,7 @@ var DiscordRegex = class {
|
|
|
2722
2810
|
return this.USERNAME.test(username);
|
|
2723
2811
|
}
|
|
2724
2812
|
/**
|
|
2725
|
-
*
|
|
2813
|
+
* @deprecated Same as isDiscordId()
|
|
2726
2814
|
*/
|
|
2727
2815
|
static isDiscordIdType(id) {
|
|
2728
2816
|
return this.isDiscordId(id);
|
|
@@ -2731,7 +2819,7 @@ var DiscordRegex = class {
|
|
|
2731
2819
|
* Any Discord URL
|
|
2732
2820
|
*/
|
|
2733
2821
|
static isDiscordUrl(url) {
|
|
2734
|
-
return this.
|
|
2822
|
+
return this.DISCORD_URL.test(url) || this.INVITE.test(url);
|
|
2735
2823
|
}
|
|
2736
2824
|
/**
|
|
2737
2825
|
* Any discord mention
|
|
@@ -2746,15 +2834,18 @@ var DiscordRegex = class {
|
|
|
2746
2834
|
return {
|
|
2747
2835
|
SPACE: this.SPACE,
|
|
2748
2836
|
URL_REGEX: this.URL_REGEX,
|
|
2837
|
+
DISCORD_URL: this.DISCORD_URL,
|
|
2749
2838
|
USER_REGEX: this.USER_REGEX,
|
|
2750
2839
|
BOT_REGEX: this.BOT_REGEX,
|
|
2751
2840
|
CHANNEL_REGEX: this.CHANNEL_REGEX,
|
|
2752
2841
|
ROLE_REGEX: this.ROLE_REGEX,
|
|
2753
2842
|
DISCORD_PING_REGEX: this.DISCORD_PING_REGEX,
|
|
2754
2843
|
DISCORD_MENTION_REGEX: this.DISCORD_MENTION_REGEX,
|
|
2844
|
+
SNOWFLAKE: this.SNOWFLAKE,
|
|
2755
2845
|
USER_ID: this.USER_ID,
|
|
2756
2846
|
CHANNEL_ID: this.CHANNEL_ID,
|
|
2757
2847
|
GUILD_ID: this.GUILD_ID,
|
|
2848
|
+
BOT_ID: this.BOT_ID,
|
|
2758
2849
|
USERNAME: this.USERNAME,
|
|
2759
2850
|
USERNAME_DISCRIM: this.USERNAME_DISCRIM,
|
|
2760
2851
|
CHANNEL_MENTION: this.CHANNEL_MENTION,
|
|
@@ -2780,6 +2871,7 @@ var DiscordRegex = class {
|
|
|
2780
2871
|
Log,
|
|
2781
2872
|
ModalFieldType,
|
|
2782
2873
|
ModalManager,
|
|
2874
|
+
PaginationManager,
|
|
2783
2875
|
ReactionManager,
|
|
2784
2876
|
SelectMenuManager,
|
|
2785
2877
|
SimpleColor,
|