@spatulox/simplediscordbot 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -554,20 +554,60 @@ declare class UserManager extends BasicUserManager {
554
554
  static find(userId: string): Promise<User | null>;
555
555
  }
556
556
 
557
+ declare enum ModalFieldType {
558
+ SHORT = 0,
559
+ LONG = 1,
560
+ NUMBER = 2,
561
+ DATE = 3,
562
+ PHONE = 4
563
+ }
564
+ interface ModalField {
565
+ type: ModalFieldType;
566
+ label: string;
567
+ placeholder?: string;
568
+ required?: boolean;
569
+ }
557
570
  declare class ModalManager {
558
571
  /**
559
- * Load modal from JSON file and return ModalBuilder
572
+ * Creates base Modal - SIMPLE API !
573
+ */
574
+ static create(modalTitle: string, customId: string): ModalBuilder;
575
+ /**
576
+ * Individual field creator
577
+ */
578
+ private static _createField;
579
+ /**
580
+ * Simple modal with ONE field - DIRECT ModalBuilder return !
581
+ */
582
+ static simple(customId: string, modalTitle: string | null, field: ModalField): ModalBuilder;
583
+ /**
584
+ * Title + Description modal preset
560
585
  */
561
- static load(filename: string): Promise<ModalBuilder | false>;
586
+ static titleDescription(customId: string, modalTitle: string, title: Omit<ModalField, "type">, description: Omit<ModalField, "type">): ModalBuilder;
562
587
  /**
563
- * List all modal files
588
+ * Date modal preset
564
589
  */
565
- static list(): Promise<string[] | false>;
566
- private static jsonToBuilder;
567
- private static fieldJsonToInput;
590
+ static date(customId: string, modalTitle?: string, inputLabel?: string): ModalBuilder;
591
+ /**
592
+ * Number modal preset
593
+ */
594
+ static number(customId: string, modalTitle?: string, inputLabel?: string): ModalBuilder;
595
+ /**
596
+ * Number modal preset
597
+ */
598
+ static phone(customId: string, modalTitle?: string, inputLabel?: string): ModalBuilder;
599
+ /**
600
+ * Add field to existing modal (Fluent API)
601
+ */
602
+ static add(modal: ModalBuilder, field: ModalField[]): ModalBuilder;
603
+ static add(modal: ModalBuilder, field: ModalField): ModalBuilder;
568
604
  static parseNumber(value: string): number | null;
569
605
  static parsePhone(value: string): string | null;
570
606
  static parseDate(value: string): Date | null;
607
+ /**
608
+ * Transform modal to interaction.showModal() format
609
+ */
610
+ static toInteraction(modal: ModalBuilder): ModalBuilder;
571
611
  }
572
612
 
573
613
  type SelectMenuCreateOption = {
package/dist/index.d.ts CHANGED
@@ -554,20 +554,60 @@ declare class UserManager extends BasicUserManager {
554
554
  static find(userId: string): Promise<User | null>;
555
555
  }
556
556
 
557
+ declare enum ModalFieldType {
558
+ SHORT = 0,
559
+ LONG = 1,
560
+ NUMBER = 2,
561
+ DATE = 3,
562
+ PHONE = 4
563
+ }
564
+ interface ModalField {
565
+ type: ModalFieldType;
566
+ label: string;
567
+ placeholder?: string;
568
+ required?: boolean;
569
+ }
557
570
  declare class ModalManager {
558
571
  /**
559
- * Load modal from JSON file and return ModalBuilder
572
+ * Creates base Modal - SIMPLE API !
573
+ */
574
+ static create(modalTitle: string, customId: string): ModalBuilder;
575
+ /**
576
+ * Individual field creator
577
+ */
578
+ private static _createField;
579
+ /**
580
+ * Simple modal with ONE field - DIRECT ModalBuilder return !
581
+ */
582
+ static simple(customId: string, modalTitle: string | null, field: ModalField): ModalBuilder;
583
+ /**
584
+ * Title + Description modal preset
560
585
  */
561
- static load(filename: string): Promise<ModalBuilder | false>;
586
+ static titleDescription(customId: string, modalTitle: string, title: Omit<ModalField, "type">, description: Omit<ModalField, "type">): ModalBuilder;
562
587
  /**
563
- * List all modal files
588
+ * Date modal preset
564
589
  */
565
- static list(): Promise<string[] | false>;
566
- private static jsonToBuilder;
567
- private static fieldJsonToInput;
590
+ static date(customId: string, modalTitle?: string, inputLabel?: string): ModalBuilder;
591
+ /**
592
+ * Number modal preset
593
+ */
594
+ static number(customId: string, modalTitle?: string, inputLabel?: string): ModalBuilder;
595
+ /**
596
+ * Number modal preset
597
+ */
598
+ static phone(customId: string, modalTitle?: string, inputLabel?: string): ModalBuilder;
599
+ /**
600
+ * Add field to existing modal (Fluent API)
601
+ */
602
+ static add(modal: ModalBuilder, field: ModalField[]): ModalBuilder;
603
+ static add(modal: ModalBuilder, field: ModalField): ModalBuilder;
568
604
  static parseNumber(value: string): number | null;
569
605
  static parsePhone(value: string): string | null;
570
606
  static parseDate(value: string): Date | null;
607
+ /**
608
+ * Transform modal to interaction.showModal() format
609
+ */
610
+ static toInteraction(modal: ModalBuilder): ModalBuilder;
571
611
  }
572
612
 
573
613
  type SelectMenuCreateOption = {
package/dist/index.js CHANGED
@@ -2145,7 +2145,7 @@ var InviteManager = class {
2145
2145
  */
2146
2146
  static async list(guildId) {
2147
2147
  try {
2148
- const guild = Bot.client.guilds.cache.get(guildId);
2148
+ const guild = await GuildManager.find(guildId);
2149
2149
  if (!guild) {
2150
2150
  throw new Error(`Guild ${guildId} not found`);
2151
2151
  }
@@ -2299,61 +2299,111 @@ var UserManager = class extends BasicUserManager {
2299
2299
 
2300
2300
  // src/manager/interactions/ModalManager.ts
2301
2301
  var import_discord15 = require("discord.js");
2302
- var ModalManager = class _ModalManager {
2302
+ var ModalManager = class {
2303
2303
  /**
2304
- * Load modal from JSON file and return ModalBuilder
2304
+ * Creates base Modal - SIMPLE API !
2305
2305
  */
2306
- static async load(filename) {
2307
- try {
2308
- const file = await FileManager.readJsonFile(`./handlers/${"modals" /* MODAL */}/${filename}`);
2309
- if (!file) return false;
2310
- return _ModalManager.jsonToBuilder(file);
2311
- } catch {
2312
- return false;
2313
- }
2306
+ static create(modalTitle, customId) {
2307
+ return new import_discord15.ModalBuilder().setTitle(modalTitle).setCustomId(customId);
2314
2308
  }
2315
2309
  /**
2316
- * List all modal files
2310
+ * Individual field creator
2317
2311
  */
2318
- static async list() {
2319
- try {
2320
- const files = await FileManager.listJsonFiles(`./handlers/${"modals" /* MODAL */}`);
2321
- return files || [];
2322
- } catch {
2323
- return false;
2324
- }
2312
+ static _createField(opt) {
2313
+ const builder = new import_discord15.TextInputBuilder().setCustomId(opt.customId).setRequired(opt.required ?? false);
2314
+ if (opt.placeholder) {
2315
+ builder.setPlaceholder(opt.placeholder);
2316
+ } else {
2317
+ builder.setPlaceholder(`Enter ${opt.label.toLowerCase()}`);
2318
+ }
2319
+ switch (opt.type) {
2320
+ case 0 /* SHORT */:
2321
+ builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(4e3);
2322
+ break;
2323
+ case 1 /* LONG */:
2324
+ builder.setStyle(import_discord15.TextInputStyle.Paragraph).setMaxLength(4e3);
2325
+ break;
2326
+ case 2 /* NUMBER */:
2327
+ builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(10);
2328
+ break;
2329
+ case 3 /* DATE */:
2330
+ builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(10);
2331
+ break;
2332
+ case 4 /* PHONE */:
2333
+ builder.setStyle(import_discord15.TextInputStyle.Short).setMaxLength(20);
2334
+ break;
2335
+ }
2336
+ return new import_discord15.LabelBuilder().setLabel(opt.label).setTextInputComponent(builder);
2337
+ }
2338
+ /**
2339
+ * Simple modal with ONE field - DIRECT ModalBuilder return !
2340
+ */
2341
+ static simple(customId, modalTitle, field) {
2342
+ const modal = this.create(modalTitle ?? Bot.config?.botName ?? "Bot", customId);
2343
+ const opt = {
2344
+ ...field,
2345
+ customId: `${customId}_input`,
2346
+ placeholder: field.placeholder ?? `Enter ${field.label.toLowerCase()}`
2347
+ };
2348
+ modal.addLabelComponents(this._createField(opt));
2349
+ return modal;
2325
2350
  }
2326
- static jsonToBuilder(json) {
2327
- const modal = new import_discord15.ModalBuilder().setCustomId(json.customId).setTitle(json.title.slice(0, 45));
2328
- const actionRows = [];
2329
- for (const fieldJson of json.fields) {
2330
- const input = this.fieldJsonToInput(fieldJson);
2331
- const row = new import_discord15.ActionRowBuilder().addComponents(input);
2332
- actionRows.push(row);
2333
- }
2334
- return modal.addComponents(...actionRows);
2351
+ /**
2352
+ * Title + Description modal preset
2353
+ */
2354
+ static titleDescription(customId, modalTitle, title, description) {
2355
+ const modal = this.create(modalTitle, customId);
2356
+ const titleField = {
2357
+ customId: `${customId}_title`,
2358
+ label: title.label,
2359
+ placeholder: title.placeholder ?? `Enter ${title.label.toLowerCase()}`,
2360
+ type: 0 /* SHORT */,
2361
+ required: title.required
2362
+ };
2363
+ const descField = {
2364
+ customId: `${customId}_desc`,
2365
+ label: description.label,
2366
+ placeholder: description.placeholder ?? `Enter ${description.label.toLowerCase()}`,
2367
+ type: 1 /* LONG */,
2368
+ required: description.required
2369
+ };
2370
+ modal.addLabelComponents(this._createField(titleField));
2371
+ modal.addLabelComponents(this._createField(descField));
2372
+ return modal;
2335
2373
  }
2336
- static fieldJsonToInput(fieldJson) {
2337
- const input = new import_discord15.TextInputBuilder().setCustomId(fieldJson.customId).setLabel(fieldJson.title.slice(0, 45)).setPlaceholder(fieldJson.placeholder || "Enter value...").setRequired(fieldJson.required !== false).setMinLength(fieldJson.minLength || 0).setMaxLength(fieldJson.maxLength || 400);
2338
- const style = fieldJson.style;
2339
- if (typeof style === "number") {
2340
- input.setStyle(style);
2341
- } else {
2342
- switch (style) {
2343
- case "Number":
2344
- case "Phone":
2345
- case "Date":
2346
- input.setStyle(import_discord15.TextInputStyle.Short);
2347
- input.setPlaceholder(
2348
- style === "Number" ? "123" : style === "Phone" ? "+33 6 12 34 56 78" : "2024-02-05"
2349
- );
2350
- break;
2351
- default:
2352
- input.setStyle(import_discord15.TextInputStyle.Short);
2374
+ /**
2375
+ * Date modal preset
2376
+ */
2377
+ static date(customId, modalTitle = "Select Date", inputLabel = "Date") {
2378
+ return this.simple(`${customId}_date`, modalTitle, { label: inputLabel, type: 3 /* DATE */, placeholder: "YYYY-MM-DD or DD/MM/YYYY" });
2379
+ }
2380
+ /**
2381
+ * Number modal preset
2382
+ */
2383
+ static number(customId, modalTitle = "Enter a Number", inputLabel = "Number") {
2384
+ return this.simple(`${customId}_number`, modalTitle, { label: inputLabel, type: 2 /* NUMBER */, placeholder: "Enter a number" });
2385
+ }
2386
+ /**
2387
+ * Number modal preset
2388
+ */
2389
+ static phone(customId, modalTitle = "Enter a Phone number", inputLabel = "Phone number") {
2390
+ return this.simple(`${customId}_phone_number`, modalTitle, { label: inputLabel, type: 4 /* PHONE */, placeholder: "Enter a phone number" });
2391
+ }
2392
+ static add(modal, field) {
2393
+ if (Array.isArray(field)) {
2394
+ for (const f of field) {
2395
+ this.add(modal, f);
2353
2396
  }
2397
+ return modal;
2354
2398
  }
2355
- return input;
2399
+ const opt = {
2400
+ ...field,
2401
+ customId: `${modal.data.custom_id}_${field.label}`
2402
+ };
2403
+ modal.addLabelComponents(this._createField(opt));
2404
+ return modal;
2356
2405
  }
2406
+ // Keep your existing parse methods
2357
2407
  static parseNumber(value) {
2358
2408
  if (!/^\d+$/.test(value)) return null;
2359
2409
  const num = parseInt(value);
@@ -2382,6 +2432,12 @@ var ModalManager = class _ModalManager {
2382
2432
  }
2383
2433
  return null;
2384
2434
  }
2435
+ /**
2436
+ * Transform modal to interaction.showModal() format
2437
+ */
2438
+ static toInteraction(modal) {
2439
+ return modal;
2440
+ }
2385
2441
  };
2386
2442
 
2387
2443
  // src/manager/interactions/SelectMenuManager.ts
@@ -2524,7 +2580,7 @@ var SimpleMutex = class {
2524
2580
  // package.json
2525
2581
  var package_default = {
2526
2582
  name: "@spatulox/simplediscordbot",
2527
- version: "1.1.0",
2583
+ version: "1.1.1",
2528
2584
  author: "Spatulox",
2529
2585
  description: "Simple discord bot framework to set up a bot under 30 secondes",
2530
2586
  exports: {
package/dist/index.mjs CHANGED
@@ -2110,7 +2110,7 @@ var InviteManager = class {
2110
2110
  */
2111
2111
  static async list(guildId) {
2112
2112
  try {
2113
- const guild = Bot.client.guilds.cache.get(guildId);
2113
+ const guild = await GuildManager.find(guildId);
2114
2114
  if (!guild) {
2115
2115
  throw new Error(`Guild ${guildId} not found`);
2116
2116
  }
@@ -2264,66 +2264,116 @@ var UserManager = class extends BasicUserManager {
2264
2264
 
2265
2265
  // src/manager/interactions/ModalManager.ts
2266
2266
  import {
2267
- ActionRowBuilder as ActionRowBuilder3,
2268
2267
  ModalBuilder,
2269
2268
  TextInputBuilder,
2270
- TextInputStyle
2269
+ TextInputStyle,
2270
+ LabelBuilder
2271
2271
  } from "discord.js";
2272
- var ModalManager = class _ModalManager {
2272
+ var ModalManager = class {
2273
2273
  /**
2274
- * Load modal from JSON file and return ModalBuilder
2274
+ * Creates base Modal - SIMPLE API !
2275
2275
  */
2276
- static async load(filename) {
2277
- try {
2278
- const file = await FileManager.readJsonFile(`./handlers/${"modals" /* MODAL */}/${filename}`);
2279
- if (!file) return false;
2280
- return _ModalManager.jsonToBuilder(file);
2281
- } catch {
2282
- return false;
2283
- }
2276
+ static create(modalTitle, customId) {
2277
+ return new ModalBuilder().setTitle(modalTitle).setCustomId(customId);
2284
2278
  }
2285
2279
  /**
2286
- * List all modal files
2280
+ * Individual field creator
2287
2281
  */
2288
- static async list() {
2289
- try {
2290
- const files = await FileManager.listJsonFiles(`./handlers/${"modals" /* MODAL */}`);
2291
- return files || [];
2292
- } catch {
2293
- return false;
2294
- }
2282
+ static _createField(opt) {
2283
+ const builder = new TextInputBuilder().setCustomId(opt.customId).setRequired(opt.required ?? false);
2284
+ if (opt.placeholder) {
2285
+ builder.setPlaceholder(opt.placeholder);
2286
+ } else {
2287
+ builder.setPlaceholder(`Enter ${opt.label.toLowerCase()}`);
2288
+ }
2289
+ switch (opt.type) {
2290
+ case 0 /* SHORT */:
2291
+ builder.setStyle(TextInputStyle.Short).setMaxLength(4e3);
2292
+ break;
2293
+ case 1 /* LONG */:
2294
+ builder.setStyle(TextInputStyle.Paragraph).setMaxLength(4e3);
2295
+ break;
2296
+ case 2 /* NUMBER */:
2297
+ builder.setStyle(TextInputStyle.Short).setMaxLength(10);
2298
+ break;
2299
+ case 3 /* DATE */:
2300
+ builder.setStyle(TextInputStyle.Short).setMaxLength(10);
2301
+ break;
2302
+ case 4 /* PHONE */:
2303
+ builder.setStyle(TextInputStyle.Short).setMaxLength(20);
2304
+ break;
2305
+ }
2306
+ return new LabelBuilder().setLabel(opt.label).setTextInputComponent(builder);
2307
+ }
2308
+ /**
2309
+ * Simple modal with ONE field - DIRECT ModalBuilder return !
2310
+ */
2311
+ static simple(customId, modalTitle, field) {
2312
+ const modal = this.create(modalTitle ?? Bot.config?.botName ?? "Bot", customId);
2313
+ const opt = {
2314
+ ...field,
2315
+ customId: `${customId}_input`,
2316
+ placeholder: field.placeholder ?? `Enter ${field.label.toLowerCase()}`
2317
+ };
2318
+ modal.addLabelComponents(this._createField(opt));
2319
+ return modal;
2295
2320
  }
2296
- static jsonToBuilder(json) {
2297
- const modal = new ModalBuilder().setCustomId(json.customId).setTitle(json.title.slice(0, 45));
2298
- const actionRows = [];
2299
- for (const fieldJson of json.fields) {
2300
- const input = this.fieldJsonToInput(fieldJson);
2301
- const row = new ActionRowBuilder3().addComponents(input);
2302
- actionRows.push(row);
2303
- }
2304
- return modal.addComponents(...actionRows);
2321
+ /**
2322
+ * Title + Description modal preset
2323
+ */
2324
+ static titleDescription(customId, modalTitle, title, description) {
2325
+ const modal = this.create(modalTitle, customId);
2326
+ const titleField = {
2327
+ customId: `${customId}_title`,
2328
+ label: title.label,
2329
+ placeholder: title.placeholder ?? `Enter ${title.label.toLowerCase()}`,
2330
+ type: 0 /* SHORT */,
2331
+ required: title.required
2332
+ };
2333
+ const descField = {
2334
+ customId: `${customId}_desc`,
2335
+ label: description.label,
2336
+ placeholder: description.placeholder ?? `Enter ${description.label.toLowerCase()}`,
2337
+ type: 1 /* LONG */,
2338
+ required: description.required
2339
+ };
2340
+ modal.addLabelComponents(this._createField(titleField));
2341
+ modal.addLabelComponents(this._createField(descField));
2342
+ return modal;
2305
2343
  }
2306
- static fieldJsonToInput(fieldJson) {
2307
- const input = new TextInputBuilder().setCustomId(fieldJson.customId).setLabel(fieldJson.title.slice(0, 45)).setPlaceholder(fieldJson.placeholder || "Enter value...").setRequired(fieldJson.required !== false).setMinLength(fieldJson.minLength || 0).setMaxLength(fieldJson.maxLength || 400);
2308
- const style = fieldJson.style;
2309
- if (typeof style === "number") {
2310
- input.setStyle(style);
2311
- } else {
2312
- switch (style) {
2313
- case "Number":
2314
- case "Phone":
2315
- case "Date":
2316
- input.setStyle(TextInputStyle.Short);
2317
- input.setPlaceholder(
2318
- style === "Number" ? "123" : style === "Phone" ? "+33 6 12 34 56 78" : "2024-02-05"
2319
- );
2320
- break;
2321
- default:
2322
- input.setStyle(TextInputStyle.Short);
2344
+ /**
2345
+ * Date modal preset
2346
+ */
2347
+ static date(customId, modalTitle = "Select Date", inputLabel = "Date") {
2348
+ return this.simple(`${customId}_date`, modalTitle, { label: inputLabel, type: 3 /* DATE */, placeholder: "YYYY-MM-DD or DD/MM/YYYY" });
2349
+ }
2350
+ /**
2351
+ * Number modal preset
2352
+ */
2353
+ static number(customId, modalTitle = "Enter a Number", inputLabel = "Number") {
2354
+ return this.simple(`${customId}_number`, modalTitle, { label: inputLabel, type: 2 /* NUMBER */, placeholder: "Enter a number" });
2355
+ }
2356
+ /**
2357
+ * Number modal preset
2358
+ */
2359
+ static phone(customId, modalTitle = "Enter a Phone number", inputLabel = "Phone number") {
2360
+ return this.simple(`${customId}_phone_number`, modalTitle, { label: inputLabel, type: 4 /* PHONE */, placeholder: "Enter a phone number" });
2361
+ }
2362
+ static add(modal, field) {
2363
+ if (Array.isArray(field)) {
2364
+ for (const f of field) {
2365
+ this.add(modal, f);
2323
2366
  }
2367
+ return modal;
2324
2368
  }
2325
- return input;
2369
+ const opt = {
2370
+ ...field,
2371
+ customId: `${modal.data.custom_id}_${field.label}`
2372
+ };
2373
+ modal.addLabelComponents(this._createField(opt));
2374
+ return modal;
2326
2375
  }
2376
+ // Keep your existing parse methods
2327
2377
  static parseNumber(value) {
2328
2378
  if (!/^\d+$/.test(value)) return null;
2329
2379
  const num = parseInt(value);
@@ -2352,11 +2402,17 @@ var ModalManager = class _ModalManager {
2352
2402
  }
2353
2403
  return null;
2354
2404
  }
2405
+ /**
2406
+ * Transform modal to interaction.showModal() format
2407
+ */
2408
+ static toInteraction(modal) {
2409
+ return modal;
2410
+ }
2355
2411
  };
2356
2412
 
2357
2413
  // src/manager/interactions/SelectMenuManager.ts
2358
2414
  import {
2359
- ActionRowBuilder as ActionRowBuilder4,
2415
+ ActionRowBuilder as ActionRowBuilder3,
2360
2416
  StringSelectMenuBuilder,
2361
2417
  StringSelectMenuOptionBuilder,
2362
2418
  UserSelectMenuBuilder,
@@ -2387,7 +2443,7 @@ var SelectMenuManager = class {
2387
2443
  * Pagination menu
2388
2444
  */
2389
2445
  static paginated(customId, options, pageSize = 25) {
2390
- const row = new ActionRowBuilder4();
2446
+ const row = new ActionRowBuilder3();
2391
2447
  for (let i = 0; i < options.length; i += pageSize) {
2392
2448
  const pageOptions = options.slice(i, i + pageSize);
2393
2449
  const menu = new StringSelectMenuBuilder().setCustomId(`${customId}_page_${Math.floor(i / pageSize)}`).setPlaceholder(`Page ${Math.floor(i / pageSize) + 1}`).addOptions(pageOptions.map((opt) => {
@@ -2449,7 +2505,7 @@ var SelectMenuManager = class {
2449
2505
  * ActionRow
2450
2506
  */
2451
2507
  static row(component) {
2452
- return new ActionRowBuilder4().addComponents(component);
2508
+ return new ActionRowBuilder3().addComponents(component);
2453
2509
  }
2454
2510
  /**
2455
2511
  * Rows multiples (5 max)
@@ -2502,7 +2558,7 @@ var SimpleMutex = class {
2502
2558
  // package.json
2503
2559
  var package_default = {
2504
2560
  name: "@spatulox/simplediscordbot",
2505
- version: "1.1.0",
2561
+ version: "1.1.1",
2506
2562
  author: "Spatulox",
2507
2563
  description: "Simple discord bot framework to set up a bot under 30 secondes",
2508
2564
  exports: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spatulox/simplediscordbot",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "author": "Spatulox",
5
5
  "description": "Simple discord bot framework to set up a bot under 30 secondes",
6
6
  "exports": {