novaapp-sdk 1.0.9 → 1.0.10

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
@@ -498,7 +498,8 @@ declare class ServersAPI {
498
498
 
499
499
  declare class InteractionsAPI {
500
500
  private readonly http;
501
- constructor(http: HttpClient);
501
+ private readonly emitter;
502
+ constructor(http: HttpClient, emitter: EventEmitter);
502
503
  /**
503
504
  * Acknowledge an interaction without sending a visible response.
504
505
  * Shows a loading state to the user. You must follow up with `respond()`.
@@ -538,6 +539,47 @@ declare class InteractionsAPI {
538
539
  * }
539
540
  */
540
541
  poll(options?: PollInteractionsOptions): Promise<Interaction[]>;
542
+ /**
543
+ * Open a modal for the user who triggered an interaction and await their submission.
544
+ *
545
+ * Internally this:
546
+ * 1. Calls `respond(interactionId, { modal })` to push the modal to the client UI.
547
+ * 2. Listens for the next `interactionCreate` event whose type is `MODAL_SUBMIT`
548
+ * and whose `customId` matches your modal's `customId`.
549
+ * 3. Resolves with the submitted `Interaction` (containing `modalData`), or `null`
550
+ * if the user closes the modal without submitting within the timeout.
551
+ *
552
+ * @param interactionId - ID of the triggering interaction.
553
+ * @param modal - Modal definition (title, customId, fields).
554
+ * @param options.timeout - Max milliseconds to wait (default: 300 000 = 5 min).
555
+ *
556
+ * @example
557
+ * client.on('interactionCreate', async (interaction) => {
558
+ * if (interaction.commandName === 'report') {
559
+ * const submitted = await client.interactions.awaitModal(interaction.id, {
560
+ * title: 'Submit a report',
561
+ * customId: 'report_modal',
562
+ * fields: [
563
+ * { customId: 'reason', label: 'Reason', type: 'paragraph', required: true, maxLength: 500 },
564
+ * ],
565
+ * })
566
+ *
567
+ * if (!submitted) {
568
+ * // User dismissed the modal or timed out — nothing to do
569
+ * return
570
+ * }
571
+ *
572
+ * const reason = submitted.modalData?.reason
573
+ * await client.interactions.respond(submitted.id, {
574
+ * content: `Report received: ${reason}`,
575
+ * ephemeral: true,
576
+ * })
577
+ * }
578
+ * })
579
+ */
580
+ awaitModal(interactionId: string, modal: BotModalDefinition, options?: {
581
+ timeout?: number;
582
+ }): Promise<Interaction | null>;
541
583
  }
542
584
 
543
585
  declare class PermissionsAPI {
package/dist/index.d.ts CHANGED
@@ -498,7 +498,8 @@ declare class ServersAPI {
498
498
 
499
499
  declare class InteractionsAPI {
500
500
  private readonly http;
501
- constructor(http: HttpClient);
501
+ private readonly emitter;
502
+ constructor(http: HttpClient, emitter: EventEmitter);
502
503
  /**
503
504
  * Acknowledge an interaction without sending a visible response.
504
505
  * Shows a loading state to the user. You must follow up with `respond()`.
@@ -538,6 +539,47 @@ declare class InteractionsAPI {
538
539
  * }
539
540
  */
540
541
  poll(options?: PollInteractionsOptions): Promise<Interaction[]>;
542
+ /**
543
+ * Open a modal for the user who triggered an interaction and await their submission.
544
+ *
545
+ * Internally this:
546
+ * 1. Calls `respond(interactionId, { modal })` to push the modal to the client UI.
547
+ * 2. Listens for the next `interactionCreate` event whose type is `MODAL_SUBMIT`
548
+ * and whose `customId` matches your modal's `customId`.
549
+ * 3. Resolves with the submitted `Interaction` (containing `modalData`), or `null`
550
+ * if the user closes the modal without submitting within the timeout.
551
+ *
552
+ * @param interactionId - ID of the triggering interaction.
553
+ * @param modal - Modal definition (title, customId, fields).
554
+ * @param options.timeout - Max milliseconds to wait (default: 300 000 = 5 min).
555
+ *
556
+ * @example
557
+ * client.on('interactionCreate', async (interaction) => {
558
+ * if (interaction.commandName === 'report') {
559
+ * const submitted = await client.interactions.awaitModal(interaction.id, {
560
+ * title: 'Submit a report',
561
+ * customId: 'report_modal',
562
+ * fields: [
563
+ * { customId: 'reason', label: 'Reason', type: 'paragraph', required: true, maxLength: 500 },
564
+ * ],
565
+ * })
566
+ *
567
+ * if (!submitted) {
568
+ * // User dismissed the modal or timed out — nothing to do
569
+ * return
570
+ * }
571
+ *
572
+ * const reason = submitted.modalData?.reason
573
+ * await client.interactions.respond(submitted.id, {
574
+ * content: `Report received: ${reason}`,
575
+ * ephemeral: true,
576
+ * })
577
+ * }
578
+ * })
579
+ */
580
+ awaitModal(interactionId: string, modal: BotModalDefinition, options?: {
581
+ timeout?: number;
582
+ }): Promise<Interaction | null>;
541
583
  }
542
584
 
543
585
  declare class PermissionsAPI {
package/dist/index.js CHANGED
@@ -273,8 +273,9 @@ var ServersAPI = class {
273
273
 
274
274
  // src/api/interactions.ts
275
275
  var InteractionsAPI = class {
276
- constructor(http) {
276
+ constructor(http, emitter) {
277
277
  this.http = http;
278
+ this.emitter = emitter;
278
279
  }
279
280
  /**
280
281
  * Acknowledge an interaction without sending a visible response.
@@ -323,6 +324,71 @@ var InteractionsAPI = class {
323
324
  const qs = params.toString();
324
325
  return this.http.get(`/interactions${qs ? `?${qs}` : ""}`);
325
326
  }
327
+ /**
328
+ * Open a modal for the user who triggered an interaction and await their submission.
329
+ *
330
+ * Internally this:
331
+ * 1. Calls `respond(interactionId, { modal })` to push the modal to the client UI.
332
+ * 2. Listens for the next `interactionCreate` event whose type is `MODAL_SUBMIT`
333
+ * and whose `customId` matches your modal's `customId`.
334
+ * 3. Resolves with the submitted `Interaction` (containing `modalData`), or `null`
335
+ * if the user closes the modal without submitting within the timeout.
336
+ *
337
+ * @param interactionId - ID of the triggering interaction.
338
+ * @param modal - Modal definition (title, customId, fields).
339
+ * @param options.timeout - Max milliseconds to wait (default: 300 000 = 5 min).
340
+ *
341
+ * @example
342
+ * client.on('interactionCreate', async (interaction) => {
343
+ * if (interaction.commandName === 'report') {
344
+ * const submitted = await client.interactions.awaitModal(interaction.id, {
345
+ * title: 'Submit a report',
346
+ * customId: 'report_modal',
347
+ * fields: [
348
+ * { customId: 'reason', label: 'Reason', type: 'paragraph', required: true, maxLength: 500 },
349
+ * ],
350
+ * })
351
+ *
352
+ * if (!submitted) {
353
+ * // User dismissed the modal or timed out — nothing to do
354
+ * return
355
+ * }
356
+ *
357
+ * const reason = submitted.modalData?.reason
358
+ * await client.interactions.respond(submitted.id, {
359
+ * content: `Report received: ${reason}`,
360
+ * ephemeral: true,
361
+ * })
362
+ * }
363
+ * })
364
+ */
365
+ awaitModal(interactionId, modal, options = {}) {
366
+ const ms = options.timeout ?? 3e5;
367
+ let listener = null;
368
+ let timer = null;
369
+ const waitPromise = new Promise((resolve) => {
370
+ timer = setTimeout(() => {
371
+ if (listener) this.emitter.off("interactionCreate", listener);
372
+ resolve(null);
373
+ }, ms);
374
+ listener = (interaction) => {
375
+ if (interaction.type === "MODAL_SUBMIT" && interaction.customId === modal.customId) {
376
+ if (timer) clearTimeout(timer);
377
+ if (listener) this.emitter.off("interactionCreate", listener);
378
+ resolve(interaction);
379
+ }
380
+ };
381
+ this.emitter.on("interactionCreate", listener);
382
+ });
383
+ return this.respond(interactionId, { modal }).then(
384
+ () => waitPromise,
385
+ (err) => {
386
+ if (timer) clearTimeout(timer);
387
+ if (listener) this.emitter.off("interactionCreate", listener);
388
+ return Promise.reject(err);
389
+ }
390
+ );
391
+ }
326
392
  };
327
393
 
328
394
  // src/api/permissions.ts
@@ -401,7 +467,7 @@ var NovaClient = class extends import_node_events.EventEmitter {
401
467
  this.commands = new CommandsAPI(this.http);
402
468
  this.members = new MembersAPI(this.http);
403
469
  this.servers = new ServersAPI(this.http);
404
- this.interactions = new InteractionsAPI(this.http);
470
+ this.interactions = new InteractionsAPI(this.http, this);
405
471
  this.permissions = new PermissionsAPI(this.http);
406
472
  this.on("error", () => {
407
473
  });
package/dist/index.mjs CHANGED
@@ -240,8 +240,9 @@ var ServersAPI = class {
240
240
 
241
241
  // src/api/interactions.ts
242
242
  var InteractionsAPI = class {
243
- constructor(http) {
243
+ constructor(http, emitter) {
244
244
  this.http = http;
245
+ this.emitter = emitter;
245
246
  }
246
247
  /**
247
248
  * Acknowledge an interaction without sending a visible response.
@@ -290,6 +291,71 @@ var InteractionsAPI = class {
290
291
  const qs = params.toString();
291
292
  return this.http.get(`/interactions${qs ? `?${qs}` : ""}`);
292
293
  }
294
+ /**
295
+ * Open a modal for the user who triggered an interaction and await their submission.
296
+ *
297
+ * Internally this:
298
+ * 1. Calls `respond(interactionId, { modal })` to push the modal to the client UI.
299
+ * 2. Listens for the next `interactionCreate` event whose type is `MODAL_SUBMIT`
300
+ * and whose `customId` matches your modal's `customId`.
301
+ * 3. Resolves with the submitted `Interaction` (containing `modalData`), or `null`
302
+ * if the user closes the modal without submitting within the timeout.
303
+ *
304
+ * @param interactionId - ID of the triggering interaction.
305
+ * @param modal - Modal definition (title, customId, fields).
306
+ * @param options.timeout - Max milliseconds to wait (default: 300 000 = 5 min).
307
+ *
308
+ * @example
309
+ * client.on('interactionCreate', async (interaction) => {
310
+ * if (interaction.commandName === 'report') {
311
+ * const submitted = await client.interactions.awaitModal(interaction.id, {
312
+ * title: 'Submit a report',
313
+ * customId: 'report_modal',
314
+ * fields: [
315
+ * { customId: 'reason', label: 'Reason', type: 'paragraph', required: true, maxLength: 500 },
316
+ * ],
317
+ * })
318
+ *
319
+ * if (!submitted) {
320
+ * // User dismissed the modal or timed out — nothing to do
321
+ * return
322
+ * }
323
+ *
324
+ * const reason = submitted.modalData?.reason
325
+ * await client.interactions.respond(submitted.id, {
326
+ * content: `Report received: ${reason}`,
327
+ * ephemeral: true,
328
+ * })
329
+ * }
330
+ * })
331
+ */
332
+ awaitModal(interactionId, modal, options = {}) {
333
+ const ms = options.timeout ?? 3e5;
334
+ let listener = null;
335
+ let timer = null;
336
+ const waitPromise = new Promise((resolve) => {
337
+ timer = setTimeout(() => {
338
+ if (listener) this.emitter.off("interactionCreate", listener);
339
+ resolve(null);
340
+ }, ms);
341
+ listener = (interaction) => {
342
+ if (interaction.type === "MODAL_SUBMIT" && interaction.customId === modal.customId) {
343
+ if (timer) clearTimeout(timer);
344
+ if (listener) this.emitter.off("interactionCreate", listener);
345
+ resolve(interaction);
346
+ }
347
+ };
348
+ this.emitter.on("interactionCreate", listener);
349
+ });
350
+ return this.respond(interactionId, { modal }).then(
351
+ () => waitPromise,
352
+ (err) => {
353
+ if (timer) clearTimeout(timer);
354
+ if (listener) this.emitter.off("interactionCreate", listener);
355
+ return Promise.reject(err);
356
+ }
357
+ );
358
+ }
293
359
  };
294
360
 
295
361
  // src/api/permissions.ts
@@ -368,7 +434,7 @@ var NovaClient = class extends EventEmitter {
368
434
  this.commands = new CommandsAPI(this.http);
369
435
  this.members = new MembersAPI(this.http);
370
436
  this.servers = new ServersAPI(this.http);
371
- this.interactions = new InteractionsAPI(this.http);
437
+ this.interactions = new InteractionsAPI(this.http, this);
372
438
  this.permissions = new PermissionsAPI(this.http);
373
439
  this.on("error", () => {
374
440
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "novaapp-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Official SDK for building bots on the Nova platform",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",