@moody-djs/prompts 1.0.1 → 1.0.3

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/Prompt.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var d=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var l=(i,t)=>d(i,"name",{value:t,configurable:!0});var b=(i,t)=>{for(var e in t)d(i,e,{get:t[e],enumerable:!0})},h=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of g(t))!M.call(i,n)&&n!==e&&d(i,n,{get:()=>t[n],enumerable:!(o=x(t,n))||o.enumerable});return i};var C=i=>h(d({},"__esModule",{value:!0}),i);var y={};b(y,{Prompt:()=>S});module.exports=C(y);var c=require("discord.js");var m=class i extends Error{static{l(this,"PromptError")}constructor(t){super(t),Error.captureStackTrace?.(this,i)}};var S=class{constructor(t,e,o){this.initialState=e;let n=[],r=l(()=>this.context.previousStates.pop()??this.initialState,"goBack");this.context={...t,previousStates:n,goBack:r},this.states=new Map(o.map(a=>[a.name,a]))}static{l(this,"Prompt")}context;currentState;components=new c.Collection;collector;states;async start(t){return this.context.interaction=t,this.changeState(this.initialState,t)}async changeState(t,e){let o=this.states.get(t);if(!o)return Promise.reject(new m(`State ${t} not found.`));this.context.previousStates.push(this.currentState?.name??this.initialState),this.currentState=o;let n=await o.onEntered?.(this.context);if(n)return this.changeState(n,e);let r=await this.prepareMessageOptions(o),a=e.replied||e.deferred?await e.editReply({embeds:r.embeds,components:r.components,content:r.content}):await e.reply(r);return this.collector&&this.collector.stop(),this.collector=a.createMessageComponentCollector({time:o.timeout||12e4,filter:l(s=>s.user.id===e.user.id,"filter")}),this.collector.on("collect",this.handleCollect.bind(this)),!0}async handleCollect(t){let e=this.components.get(t.customId);if(!e)throw new m(`Couldn't find component with customId: ${t.customId}`);if(e.type===1||e.type===3){let n=typeof e.component=="function"?await e.component(this.context):e.component,r=typeof n.modal=="function"?await n.modal(t):n.modal;if(!r){await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let u=await this.getNewStateFromCallback(e)??this.currentState?.name;return u?void this.changeState(u,t):t.deleteReply()}let a=c.SnowflakeUtil.generate().toString();r.setCustomId(a),await t.showModal(r);let s=await t.awaitModalSubmit({time:3e5,filter:l(u=>u.user.id===t.user.id&&u.customId===a,"filter")}).catch(()=>null);if(!s)return;await s.deferUpdate(),this.collector?.stop(),this.context.interaction=s;let p=await this.getNewStateFromCallback(e,s)??this.currentState?.name;return p?void this.changeState(p,t):t.deleteReply()}await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let o=await this.getNewStateFromCallback(e)??this.currentState?.name;if(!o)return t.deleteReply();this.changeState(o,t)}async prepareMessageOptions(t){let e=typeof t.message=="object"?t.message:await t.message(this.context);return{components:await this.formatComponents(e),fetchReply:!0,flags:e.ephemeral?c.MessageFlags.Ephemeral:0,content:typeof e.content=="function"?await e.content?.(this.context):e.content,embeds:Array.isArray(e.embeds)?e.embeds:await e.embeds(this.context)}}async getNewStateFromCallback(t,e){if(typeof t.callback=="string")return t.callback;if(t.type===1||t.type===3){if(!e)throw new m("No modal submit interaction found when required.");return t.callback(this.context,e)}return t.callback(this.context)}async formatComponents(t){let e=[],o=Array.isArray(t.components)?t.components:await t.components(this.context);this.components.clear();for(let n of o){let r=new c.ActionRowBuilder;for(let a of n){let s=typeof a.component=="function"?await a.component(this.context):a.component,p=c.SnowflakeUtil.generate().toString();"button"in s?(s.button.setCustomId(p),this.components.set(p,a),r.addComponents(s.button)):(s.setCustomId(p),this.components.set(p,a),r.addComponents(s))}e.push(r)}return e}};0&&(module.exports={Prompt});
package/dist/Prompt.mjs DELETED
@@ -1 +0,0 @@
1
- var S=Object.defineProperty;var c=(m,t)=>S(m,"name",{value:t,configurable:!0});import{ActionRowBuilder as x,Collection as g,MessageFlags as M,SnowflakeUtil as u}from"discord.js";var p=class m extends Error{static{c(this,"PromptError")}constructor(t){super(t),Error.captureStackTrace?.(this,m)}};var d=class{constructor(t,e,o){this.initialState=e;let i=[],n=c(()=>this.context.previousStates.pop()??this.initialState,"goBack");this.context={...t,previousStates:i,goBack:n},this.states=new Map(o.map(r=>[r.name,r]))}static{c(this,"Prompt")}context;currentState;components=new g;collector;states;async start(t){return this.context.interaction=t,this.changeState(this.initialState,t)}async changeState(t,e){let o=this.states.get(t);if(!o)return Promise.reject(new p(`State ${t} not found.`));this.context.previousStates.push(this.currentState?.name??this.initialState),this.currentState=o;let i=await o.onEntered?.(this.context);if(i)return this.changeState(i,e);let n=await this.prepareMessageOptions(o),r=e.replied||e.deferred?await e.editReply({embeds:n.embeds,components:n.components,content:n.content}):await e.reply(n);return this.collector&&this.collector.stop(),this.collector=r.createMessageComponentCollector({time:o.timeout||12e4,filter:c(a=>a.user.id===e.user.id,"filter")}),this.collector.on("collect",this.handleCollect.bind(this)),!0}async handleCollect(t){let e=this.components.get(t.customId);if(!e)throw new p(`Couldn't find component with customId: ${t.customId}`);if(e.type===1||e.type===3){let i=typeof e.component=="function"?await e.component(this.context):e.component,n=typeof i.modal=="function"?await i.modal(t):i.modal;if(!n){await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let l=await this.getNewStateFromCallback(e)??this.currentState?.name;return l?void this.changeState(l,t):t.deleteReply()}let r=u.generate().toString();n.setCustomId(r),await t.showModal(n);let a=await t.awaitModalSubmit({time:3e5,filter:c(l=>l.user.id===t.user.id&&l.customId===r,"filter")}).catch(()=>null);if(!a)return;await a.deferUpdate(),this.collector?.stop(),this.context.interaction=a;let s=await this.getNewStateFromCallback(e,a)??this.currentState?.name;return s?void this.changeState(s,t):t.deleteReply()}await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let o=await this.getNewStateFromCallback(e)??this.currentState?.name;if(!o)return t.deleteReply();this.changeState(o,t)}async prepareMessageOptions(t){let e=typeof t.message=="object"?t.message:await t.message(this.context);return{components:await this.formatComponents(e),fetchReply:!0,flags:e.ephemeral?M.Ephemeral:0,content:typeof e.content=="function"?await e.content?.(this.context):e.content,embeds:Array.isArray(e.embeds)?e.embeds:await e.embeds(this.context)}}async getNewStateFromCallback(t,e){if(typeof t.callback=="string")return t.callback;if(t.type===1||t.type===3){if(!e)throw new p("No modal submit interaction found when required.");return t.callback(this.context,e)}return t.callback(this.context)}async formatComponents(t){let e=[],o=Array.isArray(t.components)?t.components:await t.components(this.context);this.components.clear();for(let i of o){let n=new x;for(let r of i){let a=typeof r.component=="function"?await r.component(this.context):r.component,s=u.generate().toString();"button"in a?(a.button.setCustomId(s),this.components.set(s,r),n.addComponents(a.button)):(a.setCustomId(s),this.components.set(s,r),n.addComponents(a))}e.push(n)}return e}};export{d as Prompt};
@@ -1,67 +0,0 @@
1
- import { RepliableInteraction, EmbedBuilder, ButtonInteraction, ButtonBuilder, StringSelectMenuInteraction, StringSelectMenuBuilder, ModalSubmitInteraction, ModalBuilder } from 'discord.js';
2
- import { MaybePromise } from './util.types.mjs';
3
-
4
- /** An enum containing the prompt component types that are supported */
5
- declare enum PromptComponentType {
6
- Button = 0,
7
- ModalButton = 1,
8
- SelectMenu = 2,
9
- ModalSelectMenu = 3
10
- }
11
- type PromptContext<Context extends object, T = RepliableInteraction> = Context & {
12
- interaction?: T;
13
- previousStates: string[];
14
- goBack: () => string;
15
- genericError?: string;
16
- };
17
- interface ModalComponentReturnType<T, Interaction> {
18
- button: T;
19
- modal: ModalBuilder | ((interaction: Interaction) => MaybePromise<ModalBuilder | null>);
20
- }
21
- interface PromptStateComponentBase<Context extends object, Interaction = RepliableInteraction> {
22
- callback: string | ((ctx: PromptContext<Context, Interaction>) => MaybePromise<string | undefined>);
23
- }
24
- interface PromptStateComponentBaseWithInteraction<Context extends object, Interaction = RepliableInteraction, AlternateInteraction = Interaction> {
25
- callback: string | ((ctx: PromptContext<Context, Interaction>, interaction: AlternateInteraction) => MaybePromise<string | undefined>);
26
- }
27
- /** A prompt state that uses a button component */
28
- interface PromptStateButtonComponent<T extends object> extends PromptStateComponentBase<T, ButtonInteraction> {
29
- type: PromptComponentType.Button;
30
- component: ButtonBuilder | ((ctx: PromptContext<T>) => MaybePromise<ButtonBuilder>);
31
- }
32
- /** A prompt state that contains a select menu */
33
- interface PromptStateSelectMenuComponent<T extends object> extends PromptStateComponentBase<T, StringSelectMenuInteraction> {
34
- type: PromptComponentType.SelectMenu;
35
- component: StringSelectMenuBuilder | ((ctx: PromptContext<T>) => MaybePromise<StringSelectMenuBuilder>);
36
- }
37
- /** A prompt state that uses a modal that is opened by a button */
38
- interface PromptStateModalButtonComponent<T extends object> extends PromptStateComponentBaseWithInteraction<T, ButtonInteraction, ModalSubmitInteraction> {
39
- type: PromptComponentType.ModalButton;
40
- component: ModalComponentReturnType<ButtonBuilder, ButtonInteraction> | ((ctx: PromptContext<T>) => MaybePromise<ModalComponentReturnType<ButtonBuilder, ButtonInteraction>>);
41
- }
42
- /** A prompt state that is a modal opened by a select menu component */
43
- interface PromptStateModalSelectMenuComponent<T extends object> extends PromptStateComponentBaseWithInteraction<T, StringSelectMenuInteraction, ModalSubmitInteraction | null> {
44
- type: PromptComponentType.ModalSelectMenu;
45
- component: ModalComponentReturnType<StringSelectMenuBuilder, StringSelectMenuInteraction> | ((ctx: PromptContext<T>) => MaybePromise<ModalComponentReturnType<StringSelectMenuBuilder, StringSelectMenuInteraction>>);
46
- }
47
- /** A type representing a prompt state component, used when defining the components added for a prompt state */
48
- type PromptStateComponent<T extends object> = PromptStateButtonComponent<T> | PromptStateSelectMenuComponent<T> | PromptStateModalSelectMenuComponent<T> | PromptStateModalButtonComponent<T>;
49
- /** A prompt state message callback */
50
- interface PromptStateMessageCallback<T extends object> {
51
- ephemeral: boolean;
52
- content?: string | ((ctx: PromptContext<T>) => MaybePromise<string | undefined>);
53
- embeds: EmbedBuilder[] | ((ctx: PromptContext<T>) => MaybePromise<EmbedBuilder[]>);
54
- components: PromptStateComponent<T>[][] | ((ctx: PromptContext<T>) => MaybePromise<PromptStateComponent<T>[][]>);
55
- }
56
- /**
57
- * A type representing a prompt state that is possible
58
- * @param T The type of the prompt context
59
- */
60
- interface PromptState<T extends object> {
61
- name: string;
62
- timeout?: number;
63
- onEntered?: (ctx: PromptContext<T>) => MaybePromise<string | undefined>;
64
- message: PromptStateMessageCallback<T> | ((ctx: PromptContext<T>) => MaybePromise<PromptStateMessageCallback<T>>);
65
- }
66
-
67
- export { PromptComponentType, type PromptContext, type PromptState, type PromptStateButtonComponent, type PromptStateComponent, type PromptStateComponentBase, type PromptStateComponentBaseWithInteraction, type PromptStateMessageCallback, type PromptStateModalButtonComponent, type PromptStateModalSelectMenuComponent, type PromptStateSelectMenuComponent };
@@ -1,67 +0,0 @@
1
- import { RepliableInteraction, EmbedBuilder, ButtonInteraction, ButtonBuilder, StringSelectMenuInteraction, StringSelectMenuBuilder, ModalSubmitInteraction, ModalBuilder } from 'discord.js';
2
- import { MaybePromise } from './util.types.js';
3
-
4
- /** An enum containing the prompt component types that are supported */
5
- declare enum PromptComponentType {
6
- Button = 0,
7
- ModalButton = 1,
8
- SelectMenu = 2,
9
- ModalSelectMenu = 3
10
- }
11
- type PromptContext<Context extends object, T = RepliableInteraction> = Context & {
12
- interaction?: T;
13
- previousStates: string[];
14
- goBack: () => string;
15
- genericError?: string;
16
- };
17
- interface ModalComponentReturnType<T, Interaction> {
18
- button: T;
19
- modal: ModalBuilder | ((interaction: Interaction) => MaybePromise<ModalBuilder | null>);
20
- }
21
- interface PromptStateComponentBase<Context extends object, Interaction = RepliableInteraction> {
22
- callback: string | ((ctx: PromptContext<Context, Interaction>) => MaybePromise<string | undefined>);
23
- }
24
- interface PromptStateComponentBaseWithInteraction<Context extends object, Interaction = RepliableInteraction, AlternateInteraction = Interaction> {
25
- callback: string | ((ctx: PromptContext<Context, Interaction>, interaction: AlternateInteraction) => MaybePromise<string | undefined>);
26
- }
27
- /** A prompt state that uses a button component */
28
- interface PromptStateButtonComponent<T extends object> extends PromptStateComponentBase<T, ButtonInteraction> {
29
- type: PromptComponentType.Button;
30
- component: ButtonBuilder | ((ctx: PromptContext<T>) => MaybePromise<ButtonBuilder>);
31
- }
32
- /** A prompt state that contains a select menu */
33
- interface PromptStateSelectMenuComponent<T extends object> extends PromptStateComponentBase<T, StringSelectMenuInteraction> {
34
- type: PromptComponentType.SelectMenu;
35
- component: StringSelectMenuBuilder | ((ctx: PromptContext<T>) => MaybePromise<StringSelectMenuBuilder>);
36
- }
37
- /** A prompt state that uses a modal that is opened by a button */
38
- interface PromptStateModalButtonComponent<T extends object> extends PromptStateComponentBaseWithInteraction<T, ButtonInteraction, ModalSubmitInteraction> {
39
- type: PromptComponentType.ModalButton;
40
- component: ModalComponentReturnType<ButtonBuilder, ButtonInteraction> | ((ctx: PromptContext<T>) => MaybePromise<ModalComponentReturnType<ButtonBuilder, ButtonInteraction>>);
41
- }
42
- /** A prompt state that is a modal opened by a select menu component */
43
- interface PromptStateModalSelectMenuComponent<T extends object> extends PromptStateComponentBaseWithInteraction<T, StringSelectMenuInteraction, ModalSubmitInteraction | null> {
44
- type: PromptComponentType.ModalSelectMenu;
45
- component: ModalComponentReturnType<StringSelectMenuBuilder, StringSelectMenuInteraction> | ((ctx: PromptContext<T>) => MaybePromise<ModalComponentReturnType<StringSelectMenuBuilder, StringSelectMenuInteraction>>);
46
- }
47
- /** A type representing a prompt state component, used when defining the components added for a prompt state */
48
- type PromptStateComponent<T extends object> = PromptStateButtonComponent<T> | PromptStateSelectMenuComponent<T> | PromptStateModalSelectMenuComponent<T> | PromptStateModalButtonComponent<T>;
49
- /** A prompt state message callback */
50
- interface PromptStateMessageCallback<T extends object> {
51
- ephemeral: boolean;
52
- content?: string | ((ctx: PromptContext<T>) => MaybePromise<string | undefined>);
53
- embeds: EmbedBuilder[] | ((ctx: PromptContext<T>) => MaybePromise<EmbedBuilder[]>);
54
- components: PromptStateComponent<T>[][] | ((ctx: PromptContext<T>) => MaybePromise<PromptStateComponent<T>[][]>);
55
- }
56
- /**
57
- * A type representing a prompt state that is possible
58
- * @param T The type of the prompt context
59
- */
60
- interface PromptState<T extends object> {
61
- name: string;
62
- timeout?: number;
63
- onEntered?: (ctx: PromptContext<T>) => MaybePromise<string | undefined>;
64
- message: PromptStateMessageCallback<T> | ((ctx: PromptContext<T>) => MaybePromise<PromptStateMessageCallback<T>>);
65
- }
66
-
67
- export { PromptComponentType, type PromptContext, type PromptState, type PromptStateButtonComponent, type PromptStateComponent, type PromptStateComponentBase, type PromptStateComponentBaseWithInteraction, type PromptStateMessageCallback, type PromptStateModalButtonComponent, type PromptStateModalSelectMenuComponent, type PromptStateSelectMenuComponent };
@@ -1 +0,0 @@
1
- "use strict";var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var p=(n,e)=>{for(var o in e)r(n,o,{get:e[o],enumerable:!0})},u=(n,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of m(e))!l.call(n,t)&&t!==o&&r(n,t,{get:()=>e[t],enumerable:!(a=c(e,t))||a.enumerable});return n};var d=n=>u(r({},"__esModule",{value:!0}),n);var s={};p(s,{PromptComponentType:()=>i});module.exports=d(s);var i=(t=>(t[t.Button=0]="Button",t[t.ModalButton=1]="ModalButton",t[t.SelectMenu=2]="SelectMenu",t[t.ModalSelectMenu=3]="ModalSelectMenu",t))(i||{});0&&(module.exports={PromptComponentType});
@@ -1 +0,0 @@
1
- var e=(t=>(t[t.Button=0]="Button",t[t.ModalButton=1]="ModalButton",t[t.SelectMenu=2]="SelectMenu",t[t.ModalSelectMenu=3]="ModalSelectMenu",t))(e||{});export{e as PromptComponentType};
@@ -1,3 +0,0 @@
1
- type MaybePromise<T> = T | Promise<T>;
2
-
3
- export type { MaybePromise };
@@ -1,3 +0,0 @@
1
- type MaybePromise<T> = T | Promise<T>;
2
-
3
- export type { MaybePromise };
@@ -1 +0,0 @@
1
- "use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var y=(o,e,m,T)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of s(e))!t.call(o,r)&&r!==m&&i(o,r,{get:()=>e[r],enumerable:!(T=p(e,r))||T.enumerable});return o};var P=o=>y(i({},"__esModule",{value:!0}),o);var a={};module.exports=P(a);
File without changes
@@ -1,8 +0,0 @@
1
- declare class PromptError extends Error {
2
- constructor(message: string);
3
- }
4
- declare class UserError extends Error {
5
- constructor(message: string);
6
- }
7
-
8
- export { PromptError, UserError };
@@ -1,8 +0,0 @@
1
- declare class PromptError extends Error {
2
- constructor(message: string);
3
- }
4
- declare class UserError extends Error {
5
- constructor(message: string);
6
- }
7
-
8
- export { PromptError, UserError };
@@ -1 +0,0 @@
1
- "use strict";var e=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var a=(t,r)=>e(t,"name",{value:r,configurable:!0});var d=(t,r)=>{for(var c in r)e(t,c,{get:r[c],enumerable:!0})},g=(t,r,c,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of i(r))!x.call(t,s)&&s!==c&&e(t,s,{get:()=>r[s],enumerable:!(u=p(r,s))||u.enumerable});return t};var h=t=>g(e({},"__esModule",{value:!0}),t);var k={};d(k,{PromptError:()=>o,UserError:()=>n});module.exports=h(k);var o=class t extends Error{static{a(this,"PromptError")}constructor(r){super(r),Error.captureStackTrace?.(this,t)}},n=class t extends Error{static{a(this,"UserError")}constructor(r){super(r),Error.captureStackTrace?.(this,t)}};0&&(module.exports={PromptError,UserError});
@@ -1 +0,0 @@
1
- var a=Object.defineProperty;var s=(r,t)=>a(r,"name",{value:t,configurable:!0});var c=class r extends Error{static{s(this,"PromptError")}constructor(t){super(t),Error.captureStackTrace?.(this,r)}},e=class r extends Error{static{s(this,"UserError")}constructor(t){super(t),Error.captureStackTrace?.(this,r)}};export{c as PromptError,e as UserError};
@@ -1,46 +0,0 @@
1
- import { RepliableInteraction } from 'discord.js';
2
- import { PromptState } from './prompt.types.mjs';
3
-
4
- declare class PromptError extends Error {
5
- constructor(message: string);
6
- }
7
- /**
8
- * A prompt that allows you to create a sequence of states that a user can go through
9
- * with discord.js buttons and select menus.
10
- *
11
- * @example
12
- * ```ts
13
- * const prompt = new Prompt<ContextType>(defaults, initialState.name, [...]);
14
- * await prompt.start(interaction);
15
- * ```
16
- */
17
- declare class Prompt<T extends object> {
18
- initialState: string;
19
- /** The current context of this prompt */
20
- private context;
21
- /** The current state */
22
- private currentState?;
23
- /** All components for this prompt */
24
- private components;
25
- /** The interaction collector */
26
- private collector?;
27
- /** The states represented in a map */
28
- states: Map<string, PromptState<T>>;
29
- /** Creates the prompt with a given set of states */
30
- constructor(defaults: T, initialState: string, states: PromptState<T>[]);
31
- /**
32
- * Starts the prompt with a given interaction
33
- * @param interaction The interaction starting off the sequence
34
- * @returns {boolean} If true, the prompt started successfully
35
- */
36
- start(interaction: RepliableInteraction): Promise<boolean>;
37
- private changeState;
38
- private handleCollect;
39
- private prepareMessageOptions;
40
- private getNewStateFromCallback;
41
- private registerComponents;
42
- private unwrap;
43
- private replyOrEdit;
44
- }
45
-
46
- export { Prompt, PromptError };
@@ -1,46 +0,0 @@
1
- import { RepliableInteraction } from 'discord.js';
2
- import { PromptState } from './prompt.types.js';
3
-
4
- declare class PromptError extends Error {
5
- constructor(message: string);
6
- }
7
- /**
8
- * A prompt that allows you to create a sequence of states that a user can go through
9
- * with discord.js buttons and select menus.
10
- *
11
- * @example
12
- * ```ts
13
- * const prompt = new Prompt<ContextType>(defaults, initialState.name, [...]);
14
- * await prompt.start(interaction);
15
- * ```
16
- */
17
- declare class Prompt<T extends object> {
18
- initialState: string;
19
- /** The current context of this prompt */
20
- private context;
21
- /** The current state */
22
- private currentState?;
23
- /** All components for this prompt */
24
- private components;
25
- /** The interaction collector */
26
- private collector?;
27
- /** The states represented in a map */
28
- states: Map<string, PromptState<T>>;
29
- /** Creates the prompt with a given set of states */
30
- constructor(defaults: T, initialState: string, states: PromptState<T>[]);
31
- /**
32
- * Starts the prompt with a given interaction
33
- * @param interaction The interaction starting off the sequence
34
- * @returns {boolean} If true, the prompt started successfully
35
- */
36
- start(interaction: RepliableInteraction): Promise<boolean>;
37
- private changeState;
38
- private handleCollect;
39
- private prepareMessageOptions;
40
- private getNewStateFromCallback;
41
- private registerComponents;
42
- private unwrap;
43
- private replyOrEdit;
44
- }
45
-
46
- export { Prompt, PromptError };
package/dist/v2/Prompt.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var d=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var s=(a,t)=>d(a,"name",{value:t,configurable:!0});var y=(a,t)=>{for(var e in t)d(a,e,{get:t[e],enumerable:!0})},M=(a,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of g(t))!I.call(a,n)&&n!==e&&d(a,n,{get:()=>t[n],enumerable:!(o=h(t,n))||o.enumerable});return a};var x=a=>M(d({},"__esModule",{value:!0}),a);var T={};y(T,{Prompt:()=>P,PromptError:()=>c});module.exports=x(T);var S=require("util"),r=require("discord.js");var b=require("discord.js");var m=class extends b.ButtonBuilder{static{s(this,"PromptButtonBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}},C=class extends b.StringSelectMenuBuilder{static{s(this,"PromptSelectMenuBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}};var c=class a extends Error{static{s(this,"PromptError")}constructor(t){super(t),Error.captureStackTrace?.(this,a)}},P=class{constructor(t,e,o){this.initialState=e;let n=[],l=s(()=>this.context.previousStates.pop()??this.initialState,"goBack");this.context={...t,previousStates:n,goBack:l},this.states=new Map(o.map(i=>[i.name,i]))}static{s(this,"Prompt")}context;currentState;components=new r.Collection;collector;states;async start(t){return this.context.interaction=t,this.changeState(this.initialState,t)}async changeState(t,e){let o=this.states.get(t);if(!o)return Promise.reject(new c(`State ${t} not found.`));this.context.previousStates.push(this.currentState?.name??this.initialState),this.currentState=o;let n=await o.onEntered?.(this.context);if(n)return this.changeState(n,e);this.components.clear();let l=await this.prepareMessageOptions(o),i=await this.replyOrEdit(e,l);return this.collector&&this.collector.stop(),this.collector=i.createMessageComponentCollector({time:o.timeout||12e4,filter:s(u=>u.user.id===e.user.id,"filter")}),this.collector.on("collect",this.handleCollect.bind(this)),!0}async handleCollect(t){let e=this.components.get(t.customId);if(!e)throw new c(`Couldn't find component with customId: ${t.customId}`);if(e.modal){let n=await this.unwrap(e.modal,t);if(!n){await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let p=await this.getNewStateFromCallback(e)??this.currentState?.name;return p?void this.changeState(p,t):t.deleteReply()}let l=r.SnowflakeUtil.generate().toString();n.setCustomId(l),await t.showModal(n);let i=await t.awaitModalSubmit({time:3e5,filter:s(p=>p.user.id===t.user.id&&p.customId===l,"filter")}).catch(()=>null);if(!i)return;await i.deferUpdate(),this.collector?.stop(),this.context.interaction=i;let u=await this.getNewStateFromCallback(e,i)??this.currentState?.name;return u?void this.changeState(u,t):t.deleteReply()}await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let o=await this.getNewStateFromCallback(e)??this.currentState?.name;if(!o)return t.deleteReply();this.changeState(o,t)}async prepareMessageOptions(t){let e=await this.unwrap(t.message,this.context),o=await this.unwrap(e.components,this.context);return this.registerComponents(o),console.log((0,S.inspect)(o,{depth:null})),{components:o,fetchReply:!0,flags:(e.ephemeral?r.MessageFlags.Ephemeral:0)|r.MessageFlags.IsComponentsV2}}async getNewStateFromCallback(t,e){if(t.callback){if(typeof t.callback=="string")return t.callback;if(t.modal){if(!e)throw new c("No modal submit interaction found when required.");return t.callback(this.context,e)}return t.callback(this.context)}}registerComponents(t){for(let e of t)if(e instanceof m){let o=r.SnowflakeUtil.generate().toString();e.setCustomId(o),this.components.set(o,{...e.toJSON(),custom_id:o,callback:e.getCallback(),modal:e.getModal()})}else if(e instanceof C){let o=r.SnowflakeUtil.generate().toString();e.setCustomId(o),this.components.set(o,{...e.toJSON(),custom_id:o,callback:e.getCallback(),modal:e.getModal()})}else if(e instanceof r.SectionBuilder&&e.accessory instanceof m){let o=r.SnowflakeUtil.generate().toString();e.accessory.setCustomId(o),this.components.set(o,{...e.accessory.toJSON(),custom_id:o,callback:e.accessory.getCallback(),modal:e.accessory.getModal()})}else"components"in e&&Array.isArray(e.components)&&this.registerComponents(e.components)}async unwrap(t,...e){return typeof t=="function"?t(...e):t}async replyOrEdit(t,e){return t.replied||t.deferred?t.editReply({components:e.components}):t.reply(e)}};0&&(module.exports={Prompt,PromptError});
@@ -1 +0,0 @@
1
- var P=Object.defineProperty;var r=(i,t)=>P(i,"name",{value:t,configurable:!0});import{inspect as g}from"util";import{Collection as I,MessageFlags as C,SectionBuilder as y,SnowflakeUtil as d}from"discord.js";import{ButtonBuilder as S,StringSelectMenuBuilder as h}from"discord.js";var c=class extends S{static{r(this,"PromptButtonBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}},u=class extends h{static{r(this,"PromptSelectMenuBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}};var p=class i extends Error{static{r(this,"PromptError")}constructor(t){super(t),Error.captureStackTrace?.(this,i)}},b=class{constructor(t,e,o){this.initialState=e;let n=[],s=r(()=>this.context.previousStates.pop()??this.initialState,"goBack");this.context={...t,previousStates:n,goBack:s},this.states=new Map(o.map(a=>[a.name,a]))}static{r(this,"Prompt")}context;currentState;components=new I;collector;states;async start(t){return this.context.interaction=t,this.changeState(this.initialState,t)}async changeState(t,e){let o=this.states.get(t);if(!o)return Promise.reject(new p(`State ${t} not found.`));this.context.previousStates.push(this.currentState?.name??this.initialState),this.currentState=o;let n=await o.onEntered?.(this.context);if(n)return this.changeState(n,e);this.components.clear();let s=await this.prepareMessageOptions(o),a=await this.replyOrEdit(e,s);return this.collector&&this.collector.stop(),this.collector=a.createMessageComponentCollector({time:o.timeout||12e4,filter:r(m=>m.user.id===e.user.id,"filter")}),this.collector.on("collect",this.handleCollect.bind(this)),!0}async handleCollect(t){let e=this.components.get(t.customId);if(!e)throw new p(`Couldn't find component with customId: ${t.customId}`);if(e.modal){let n=await this.unwrap(e.modal,t);if(!n){await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let l=await this.getNewStateFromCallback(e)??this.currentState?.name;return l?void this.changeState(l,t):t.deleteReply()}let s=d.generate().toString();n.setCustomId(s),await t.showModal(n);let a=await t.awaitModalSubmit({time:3e5,filter:r(l=>l.user.id===t.user.id&&l.customId===s,"filter")}).catch(()=>null);if(!a)return;await a.deferUpdate(),this.collector?.stop(),this.context.interaction=a;let m=await this.getNewStateFromCallback(e,a)??this.currentState?.name;return m?void this.changeState(m,t):t.deleteReply()}await t.deferUpdate(),this.collector?.stop(),this.context.interaction=t;let o=await this.getNewStateFromCallback(e)??this.currentState?.name;if(!o)return t.deleteReply();this.changeState(o,t)}async prepareMessageOptions(t){let e=await this.unwrap(t.message,this.context),o=await this.unwrap(e.components,this.context);return this.registerComponents(o),console.log(g(o,{depth:null})),{components:o,fetchReply:!0,flags:(e.ephemeral?C.Ephemeral:0)|C.IsComponentsV2}}async getNewStateFromCallback(t,e){if(t.callback){if(typeof t.callback=="string")return t.callback;if(t.modal){if(!e)throw new p("No modal submit interaction found when required.");return t.callback(this.context,e)}return t.callback(this.context)}}registerComponents(t){for(let e of t)if(e instanceof c){let o=d.generate().toString();e.setCustomId(o),this.components.set(o,{...e.toJSON(),custom_id:o,callback:e.getCallback(),modal:e.getModal()})}else if(e instanceof u){let o=d.generate().toString();e.setCustomId(o),this.components.set(o,{...e.toJSON(),custom_id:o,callback:e.getCallback(),modal:e.getModal()})}else if(e instanceof y&&e.accessory instanceof c){let o=d.generate().toString();e.accessory.setCustomId(o),this.components.set(o,{...e.accessory.toJSON(),custom_id:o,callback:e.accessory.getCallback(),modal:e.accessory.getModal()})}else"components"in e&&Array.isArray(e.components)&&this.registerComponents(e.components)}async unwrap(t,...e){return typeof t=="function"?t(...e):t}async replyOrEdit(t,e){return t.replied||t.deferred?t.editReply({components:e.components}):t.reply(e)}};export{b as Prompt,p as PromptError};
@@ -1 +0,0 @@
1
- "use strict";var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var r=(e,t)=>l(e,"name",{value:t,configurable:!0});var b=(e,t)=>{for(var n in t)l(e,n,{get:t[n],enumerable:!0})},d=(e,t,n,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of s(t))!u.call(e,o)&&o!==n&&l(e,o,{get:()=>t[o],enumerable:!(p=m(t,o))||p.enumerable});return e};var C=e=>d(l({},"__esModule",{value:!0}),e);var P={};b(P,{PromptButtonBuilder:()=>i,PromptSelectMenuBuilder:()=>c});module.exports=C(P);var a=require("discord.js");var i=class extends a.ButtonBuilder{static{r(this,"PromptButtonBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}},c=class extends a.StringSelectMenuBuilder{static{r(this,"PromptSelectMenuBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}};0&&(module.exports={PromptButtonBuilder,PromptSelectMenuBuilder});
@@ -1 +0,0 @@
1
- var a=Object.defineProperty;var o=(e,t)=>a(e,"name",{value:t,configurable:!0});import{ButtonBuilder as r,StringSelectMenuBuilder as i}from"discord.js";var n=class extends r{static{o(this,"PromptButtonBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}},l=class extends i{static{o(this,"PromptSelectMenuBuilder")}callback;modal;setCallback(t){return this.callback=t,this}getCallback(){return this.callback}setModal(t){return this.modal=t,this}getModal(){return this.modal}};export{n as PromptButtonBuilder,l as PromptSelectMenuBuilder};