@moody-djs/prompts 1.0.2 → 1.0.4

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.
@@ -1,3 +1,95 @@
1
- export { Prompt, PromptError } from './Prompt.mjs';
2
- export { APIPromptButtonComponent, APIPromptSelectMenuComponent, APIPromptTopLevelComponent, PromptButtonBuilder, PromptContext, PromptSelectMenuBuilder, PromptState, PromptStateMessageCallback, RegisterComponentsOptions } from './prompt.types.mjs';
3
- import 'discord.js';
1
+ import * as discord_js from 'discord.js';
2
+ import { RepliableInteraction, JSONEncodable, APIMessageTopLevelComponent, APIActionRowComponent, APIButtonComponentWithCustomId, ModalSubmitInteraction, ButtonInteraction, ModalBuilder, APIStringSelectComponent, StringSelectMenuInteraction, ButtonBuilder, StringSelectMenuBuilder } from 'discord.js';
3
+
4
+ type MaybePromise<T> = T | Promise<T>;
5
+ type PromptContext<Context extends object, T = RepliableInteraction> = Context & {
6
+ interaction?: T;
7
+ previousStates: string[];
8
+ goBack: () => string;
9
+ };
10
+ /** A prompt state message callback */
11
+ interface PromptStateMessageCallback<T extends object> {
12
+ ephemeral: boolean;
13
+ components: JSONEncodable<APIPromptTopLevelComponent<T>>[] | ((ctx: PromptContext<T>) => MaybePromise<JSONEncodable<APIPromptTopLevelComponent<T>>[]>);
14
+ }
15
+ /**
16
+ * A type representing a prompt state that is possible
17
+ * @param T The type of the prompt context
18
+ */
19
+ interface PromptState<T extends object> {
20
+ name: string;
21
+ timeout?: number;
22
+ onEntered?: (ctx: PromptContext<T>) => MaybePromise<string | undefined>;
23
+ message: PromptStateMessageCallback<T> | ((ctx: PromptContext<T>) => MaybePromise<PromptStateMessageCallback<T>>);
24
+ }
25
+ type PromptComponentCallback<Context extends object, Interaction> = string | ((ctx: PromptContext<Context, Interaction>, modalInteraction?: ModalSubmitInteraction) => MaybePromise<string | undefined>);
26
+ type APIPromptTopLevelComponent<T extends object> = APIMessageTopLevelComponent | APIActionRowComponent<APIPromptButtonComponent<T> | APIPromptSelectMenuComponent<T>>;
27
+ type APIPromptButtonComponent<T extends object> = APIButtonComponentWithCustomId & {
28
+ callback: PromptComponentCallback<T, ButtonInteraction>;
29
+ modal?: ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>);
30
+ };
31
+ type APIPromptSelectMenuComponent<T extends object> = APIStringSelectComponent & {
32
+ callback: PromptComponentCallback<T, StringSelectMenuInteraction>;
33
+ modal?: ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>);
34
+ };
35
+ type RegisterComponentsOptions<T extends object> = APIPromptTopLevelComponent<T> | APIPromptButtonComponent<T> | APIPromptSelectMenuComponent<T>;
36
+ declare class PromptButtonBuilder<Context extends object> extends ButtonBuilder {
37
+ callback?: PromptComponentCallback<Context, ButtonInteraction>;
38
+ modal?: ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>);
39
+ setCallback(callback: PromptComponentCallback<Context, ButtonInteraction>): this;
40
+ getCallback(): PromptComponentCallback<Context, ButtonInteraction<discord_js.CacheType>>;
41
+ setModal(modal: ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>)): this;
42
+ getModal(): ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>) | undefined;
43
+ }
44
+ declare class PromptSelectMenuBuilder<Context extends object> extends StringSelectMenuBuilder {
45
+ callback?: PromptComponentCallback<Context, StringSelectMenuInteraction>;
46
+ modal?: ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>);
47
+ setCallback(callback: PromptComponentCallback<Context, StringSelectMenuInteraction>): this;
48
+ getCallback(): PromptComponentCallback<Context, StringSelectMenuInteraction<discord_js.CacheType>>;
49
+ setModal(modal: ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>)): this;
50
+ getModal(): ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>) | undefined;
51
+ }
52
+
53
+ declare class PromptError extends Error {
54
+ constructor(message: string);
55
+ }
56
+ /**
57
+ * A prompt that allows you to create a sequence of states that a user can go through
58
+ * with discord.js buttons and select menus.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const prompt = new Prompt<ContextType>(defaults, initialState.name, [...]);
63
+ * await prompt.start(interaction);
64
+ * ```
65
+ */
66
+ declare class Prompt<T extends object> {
67
+ initialState: string;
68
+ /** The current context of this prompt */
69
+ private context;
70
+ /** The current state */
71
+ private currentState?;
72
+ /** All components for this prompt */
73
+ private components;
74
+ /** The interaction collector */
75
+ private collector?;
76
+ /** The states represented in a map */
77
+ states: Map<string, PromptState<T>>;
78
+ /** Creates the prompt with a given set of states */
79
+ constructor(defaults: T, initialState: string, states: PromptState<T>[]);
80
+ /**
81
+ * Starts the prompt with a given interaction
82
+ * @param interaction The interaction starting off the sequence
83
+ * @returns {boolean} If true, the prompt started successfully
84
+ */
85
+ start(interaction: RepliableInteraction): Promise<boolean>;
86
+ private changeState;
87
+ private handleCollect;
88
+ private prepareMessageOptions;
89
+ private getNewStateFromCallback;
90
+ private registerComponents;
91
+ private unwrap;
92
+ private replyOrEdit;
93
+ }
94
+
95
+ export { type APIPromptButtonComponent, type APIPromptSelectMenuComponent, type APIPromptTopLevelComponent, Prompt, PromptButtonBuilder, type PromptContext, PromptError, PromptSelectMenuBuilder, type PromptState, type PromptStateMessageCallback, type RegisterComponentsOptions };
@@ -1,3 +1,95 @@
1
- export { Prompt, PromptError } from './Prompt.js';
2
- export { APIPromptButtonComponent, APIPromptSelectMenuComponent, APIPromptTopLevelComponent, PromptButtonBuilder, PromptContext, PromptSelectMenuBuilder, PromptState, PromptStateMessageCallback, RegisterComponentsOptions } from './prompt.types.js';
3
- import 'discord.js';
1
+ import * as discord_js from 'discord.js';
2
+ import { RepliableInteraction, JSONEncodable, APIMessageTopLevelComponent, APIActionRowComponent, APIButtonComponentWithCustomId, ModalSubmitInteraction, ButtonInteraction, ModalBuilder, APIStringSelectComponent, StringSelectMenuInteraction, ButtonBuilder, StringSelectMenuBuilder } from 'discord.js';
3
+
4
+ type MaybePromise<T> = T | Promise<T>;
5
+ type PromptContext<Context extends object, T = RepliableInteraction> = Context & {
6
+ interaction?: T;
7
+ previousStates: string[];
8
+ goBack: () => string;
9
+ };
10
+ /** A prompt state message callback */
11
+ interface PromptStateMessageCallback<T extends object> {
12
+ ephemeral: boolean;
13
+ components: JSONEncodable<APIPromptTopLevelComponent<T>>[] | ((ctx: PromptContext<T>) => MaybePromise<JSONEncodable<APIPromptTopLevelComponent<T>>[]>);
14
+ }
15
+ /**
16
+ * A type representing a prompt state that is possible
17
+ * @param T The type of the prompt context
18
+ */
19
+ interface PromptState<T extends object> {
20
+ name: string;
21
+ timeout?: number;
22
+ onEntered?: (ctx: PromptContext<T>) => MaybePromise<string | undefined>;
23
+ message: PromptStateMessageCallback<T> | ((ctx: PromptContext<T>) => MaybePromise<PromptStateMessageCallback<T>>);
24
+ }
25
+ type PromptComponentCallback<Context extends object, Interaction> = string | ((ctx: PromptContext<Context, Interaction>, modalInteraction?: ModalSubmitInteraction) => MaybePromise<string | undefined>);
26
+ type APIPromptTopLevelComponent<T extends object> = APIMessageTopLevelComponent | APIActionRowComponent<APIPromptButtonComponent<T> | APIPromptSelectMenuComponent<T>>;
27
+ type APIPromptButtonComponent<T extends object> = APIButtonComponentWithCustomId & {
28
+ callback: PromptComponentCallback<T, ButtonInteraction>;
29
+ modal?: ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>);
30
+ };
31
+ type APIPromptSelectMenuComponent<T extends object> = APIStringSelectComponent & {
32
+ callback: PromptComponentCallback<T, StringSelectMenuInteraction>;
33
+ modal?: ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>);
34
+ };
35
+ type RegisterComponentsOptions<T extends object> = APIPromptTopLevelComponent<T> | APIPromptButtonComponent<T> | APIPromptSelectMenuComponent<T>;
36
+ declare class PromptButtonBuilder<Context extends object> extends ButtonBuilder {
37
+ callback?: PromptComponentCallback<Context, ButtonInteraction>;
38
+ modal?: ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>);
39
+ setCallback(callback: PromptComponentCallback<Context, ButtonInteraction>): this;
40
+ getCallback(): PromptComponentCallback<Context, ButtonInteraction<discord_js.CacheType>>;
41
+ setModal(modal: ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>)): this;
42
+ getModal(): ModalBuilder | ((interaction: ButtonInteraction) => MaybePromise<ModalBuilder | null>) | undefined;
43
+ }
44
+ declare class PromptSelectMenuBuilder<Context extends object> extends StringSelectMenuBuilder {
45
+ callback?: PromptComponentCallback<Context, StringSelectMenuInteraction>;
46
+ modal?: ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>);
47
+ setCallback(callback: PromptComponentCallback<Context, StringSelectMenuInteraction>): this;
48
+ getCallback(): PromptComponentCallback<Context, StringSelectMenuInteraction<discord_js.CacheType>>;
49
+ setModal(modal: ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>)): this;
50
+ getModal(): ModalBuilder | ((interaction: StringSelectMenuInteraction) => MaybePromise<ModalBuilder | null>) | undefined;
51
+ }
52
+
53
+ declare class PromptError extends Error {
54
+ constructor(message: string);
55
+ }
56
+ /**
57
+ * A prompt that allows you to create a sequence of states that a user can go through
58
+ * with discord.js buttons and select menus.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const prompt = new Prompt<ContextType>(defaults, initialState.name, [...]);
63
+ * await prompt.start(interaction);
64
+ * ```
65
+ */
66
+ declare class Prompt<T extends object> {
67
+ initialState: string;
68
+ /** The current context of this prompt */
69
+ private context;
70
+ /** The current state */
71
+ private currentState?;
72
+ /** All components for this prompt */
73
+ private components;
74
+ /** The interaction collector */
75
+ private collector?;
76
+ /** The states represented in a map */
77
+ states: Map<string, PromptState<T>>;
78
+ /** Creates the prompt with a given set of states */
79
+ constructor(defaults: T, initialState: string, states: PromptState<T>[]);
80
+ /**
81
+ * Starts the prompt with a given interaction
82
+ * @param interaction The interaction starting off the sequence
83
+ * @returns {boolean} If true, the prompt started successfully
84
+ */
85
+ start(interaction: RepliableInteraction): Promise<boolean>;
86
+ private changeState;
87
+ private handleCollect;
88
+ private prepareMessageOptions;
89
+ private getNewStateFromCallback;
90
+ private registerComponents;
91
+ private unwrap;
92
+ private replyOrEdit;
93
+ }
94
+
95
+ export { type APIPromptButtonComponent, type APIPromptSelectMenuComponent, type APIPromptTopLevelComponent, Prompt, PromptButtonBuilder, type PromptContext, PromptError, PromptSelectMenuBuilder, type PromptState, type PromptStateMessageCallback, type RegisterComponentsOptions };
package/dist/v2/index.js CHANGED
@@ -1 +1,253 @@
1
- "use strict";var C=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var s=(r,t)=>C(r,"name",{value:t,configurable:!0});var y=(r,t)=>{for(var e in t)C(r,e,{get:t[e],enumerable:!0})},M=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of g(t))!I.call(r,n)&&n!==e&&C(r,n,{get:()=>t[n],enumerable:!(o=h(t,n))||o.enumerable});return r};var x=r=>M(C({},"__esModule",{value:!0}),r);var T={};y(T,{Prompt:()=>P,PromptButtonBuilder:()=>c,PromptError:()=>p,PromptSelectMenuBuilder:()=>u});module.exports=x(T);var S=require("util"),a=require("discord.js");var b=require("discord.js");var c=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}},u=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 p=class r extends Error{static{s(this,"PromptError")}constructor(t){super(t),Error.captureStackTrace?.(this,r)}},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 a.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 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 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(d=>d.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 m=await this.getNewStateFromCallback(e)??this.currentState?.name;return m?void this.changeState(m,t):t.deleteReply()}let l=a.SnowflakeUtil.generate().toString();n.setCustomId(l),await t.showModal(n);let i=await t.awaitModalSubmit({time:3e5,filter:s(m=>m.user.id===t.user.id&&m.customId===l,"filter")}).catch(()=>null);if(!i)return;await i.deferUpdate(),this.collector?.stop(),this.context.interaction=i;let d=await this.getNewStateFromCallback(e,i)??this.currentState?.name;return d?void this.changeState(d,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?a.MessageFlags.Ephemeral:0)|a.MessageFlags.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=a.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 u){let o=a.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 a.SectionBuilder&&e.accessory instanceof c){let o=a.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,PromptButtonBuilder,PromptError,PromptSelectMenuBuilder});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/v2/index.ts
22
+ var v2_exports = {};
23
+ __export(v2_exports, {
24
+ Prompt: () => Prompt,
25
+ PromptButtonBuilder: () => PromptButtonBuilder,
26
+ PromptError: () => PromptError,
27
+ PromptSelectMenuBuilder: () => PromptSelectMenuBuilder
28
+ });
29
+ module.exports = __toCommonJS(v2_exports);
30
+
31
+ // src/v2/Prompt.ts
32
+ var import_discord2 = require("discord.js");
33
+
34
+ // src/v2/prompt.types.ts
35
+ var import_discord = require("discord.js");
36
+ var PromptButtonBuilder = class extends import_discord.ButtonBuilder {
37
+ static {
38
+ __name(this, "PromptButtonBuilder");
39
+ }
40
+ callback;
41
+ modal;
42
+ setCallback(callback) {
43
+ this.callback = callback;
44
+ return this;
45
+ }
46
+ getCallback() {
47
+ return this.callback;
48
+ }
49
+ setModal(modal) {
50
+ this.modal = modal;
51
+ return this;
52
+ }
53
+ getModal() {
54
+ return this.modal;
55
+ }
56
+ };
57
+ var PromptSelectMenuBuilder = class extends import_discord.StringSelectMenuBuilder {
58
+ static {
59
+ __name(this, "PromptSelectMenuBuilder");
60
+ }
61
+ callback;
62
+ modal;
63
+ setCallback(callback) {
64
+ this.callback = callback;
65
+ return this;
66
+ }
67
+ getCallback() {
68
+ return this.callback;
69
+ }
70
+ setModal(modal) {
71
+ this.modal = modal;
72
+ return this;
73
+ }
74
+ getModal() {
75
+ return this.modal;
76
+ }
77
+ };
78
+
79
+ // src/v2/Prompt.ts
80
+ var PromptError = class _PromptError extends Error {
81
+ static {
82
+ __name(this, "PromptError");
83
+ }
84
+ constructor(message) {
85
+ super(message);
86
+ Error.captureStackTrace?.(this, _PromptError);
87
+ }
88
+ };
89
+ var Prompt = class {
90
+ /** Creates the prompt with a given set of states */
91
+ constructor(defaults, initialState, states) {
92
+ this.initialState = initialState;
93
+ const previousStates = [];
94
+ const goBack = /* @__PURE__ */ __name(() => {
95
+ return this.context.previousStates.pop() ?? this.initialState;
96
+ }, "goBack");
97
+ this.context = { ...defaults, previousStates, goBack };
98
+ this.states = new Map(states.map((s) => [s.name, s]));
99
+ }
100
+ static {
101
+ __name(this, "Prompt");
102
+ }
103
+ /** The current context of this prompt */
104
+ context;
105
+ /** The current state */
106
+ currentState;
107
+ /** All components for this prompt */
108
+ components = new import_discord2.Collection();
109
+ /** The interaction collector */
110
+ collector;
111
+ /** The states represented in a map */
112
+ states;
113
+ /**
114
+ * Starts the prompt with a given interaction
115
+ * @param interaction The interaction starting off the sequence
116
+ * @returns {boolean} If true, the prompt started successfully
117
+ */
118
+ async start(interaction) {
119
+ this.context.interaction = interaction;
120
+ return this.changeState(this.initialState, interaction);
121
+ }
122
+ async changeState(newState, interaction) {
123
+ const state = this.states.get(newState);
124
+ if (!state) return Promise.reject(new PromptError(`State ${newState} not found.`));
125
+ this.context.previousStates.push(this.currentState?.name ?? this.initialState);
126
+ this.currentState = state;
127
+ const shouldChangeState = await state.onEntered?.(this.context);
128
+ if (shouldChangeState) return this.changeState(shouldChangeState, interaction);
129
+ this.components.clear();
130
+ const messageOptions = await this.prepareMessageOptions(state);
131
+ const msg = await this.replyOrEdit(interaction, messageOptions);
132
+ if (this.collector) this.collector.stop();
133
+ this.collector = msg.createMessageComponentCollector({
134
+ time: state.timeout || 12e4,
135
+ filter: /* @__PURE__ */ __name((i) => i.user.id === interaction.user.id, "filter")
136
+ });
137
+ this.collector.on("collect", this.handleCollect.bind(this));
138
+ return true;
139
+ }
140
+ async handleCollect(interaction) {
141
+ const component = this.components.get(interaction.customId);
142
+ if (!component) throw new PromptError(`Couldn't find component with customId: ${interaction.customId}`);
143
+ if (component.modal) {
144
+ const modal = await this.unwrap(component.modal, interaction);
145
+ if (!modal) {
146
+ await interaction.deferUpdate();
147
+ this.collector?.stop();
148
+ this.context.interaction = interaction;
149
+ const newState3 = await this.getNewStateFromCallback(component) ?? this.currentState?.name;
150
+ if (!newState3) return interaction.deleteReply();
151
+ return void this.changeState(newState3, interaction);
152
+ }
153
+ const snowflake = import_discord2.SnowflakeUtil.generate().toString();
154
+ modal.setCustomId(snowflake);
155
+ await interaction.showModal(modal);
156
+ const response = await interaction.awaitModalSubmit({
157
+ time: 3e5,
158
+ filter: /* @__PURE__ */ __name((i) => i.user.id === interaction.user.id && i.customId === snowflake, "filter")
159
+ }).catch(() => null);
160
+ if (!response) return;
161
+ await response.deferUpdate();
162
+ this.collector?.stop();
163
+ this.context.interaction = response;
164
+ const newState2 = await this.getNewStateFromCallback(component, response) ?? this.currentState?.name;
165
+ if (!newState2) return interaction.deleteReply();
166
+ return void this.changeState(newState2, interaction);
167
+ }
168
+ await interaction.deferUpdate();
169
+ this.collector?.stop();
170
+ this.context.interaction = interaction;
171
+ const newState = await this.getNewStateFromCallback(component) ?? this.currentState?.name;
172
+ if (!newState) return interaction.deleteReply();
173
+ return void this.changeState(newState, interaction);
174
+ }
175
+ async prepareMessageOptions(state) {
176
+ const messageData = await this.unwrap(state.message, this.context);
177
+ const components = await this.unwrap(messageData.components, this.context);
178
+ this.registerComponents(components);
179
+ const messageOptions = {
180
+ components,
181
+ fetchReply: true,
182
+ flags: (messageData.ephemeral ? import_discord2.MessageFlags.Ephemeral : 0) | import_discord2.MessageFlags.IsComponentsV2
183
+ };
184
+ return messageOptions;
185
+ }
186
+ async getNewStateFromCallback(component, modalInteraction) {
187
+ if (!component.callback) return void 0;
188
+ if (typeof component.callback === "string") return component.callback;
189
+ if (component.modal) {
190
+ if (!modalInteraction) throw new PromptError("No modal submit interaction found when required.");
191
+ return component.callback(
192
+ this.context,
193
+ modalInteraction
194
+ );
195
+ }
196
+ return component.callback(
197
+ this.context
198
+ );
199
+ }
200
+ registerComponents(components) {
201
+ for (const builder of components) {
202
+ if (builder instanceof PromptButtonBuilder) {
203
+ const id = import_discord2.SnowflakeUtil.generate().toString();
204
+ builder.setCustomId(id);
205
+ this.components.set(id, {
206
+ ...builder.toJSON(),
207
+ custom_id: id,
208
+ callback: builder.getCallback(),
209
+ modal: builder.getModal()
210
+ });
211
+ } else if (builder instanceof PromptSelectMenuBuilder) {
212
+ const id = import_discord2.SnowflakeUtil.generate().toString();
213
+ builder.setCustomId(id);
214
+ this.components.set(id, {
215
+ ...builder.toJSON(),
216
+ custom_id: id,
217
+ callback: builder.getCallback(),
218
+ modal: builder.getModal()
219
+ });
220
+ } else if (builder instanceof import_discord2.SectionBuilder && builder.accessory instanceof PromptButtonBuilder) {
221
+ const id = import_discord2.SnowflakeUtil.generate().toString();
222
+ builder.accessory.setCustomId(id);
223
+ this.components.set(id, {
224
+ ...builder.accessory.toJSON(),
225
+ custom_id: id,
226
+ callback: builder.accessory.getCallback(),
227
+ modal: builder.accessory.getModal()
228
+ });
229
+ } else if ("components" in builder && Array.isArray(builder.components)) {
230
+ this.registerComponents(builder.components);
231
+ }
232
+ }
233
+ }
234
+ async unwrap(value, ...args) {
235
+ if (typeof value === "function") {
236
+ return value(...args);
237
+ }
238
+ return value;
239
+ }
240
+ async replyOrEdit(interaction, options) {
241
+ if (interaction.replied || interaction.deferred) {
242
+ return interaction.editReply({ components: options.components });
243
+ }
244
+ return interaction.reply(options);
245
+ }
246
+ };
247
+ // Annotate the CommonJS export names for ESM import in node:
248
+ 0 && (module.exports = {
249
+ Prompt,
250
+ PromptButtonBuilder,
251
+ PromptError,
252
+ PromptSelectMenuBuilder
253
+ });