@moody-djs/prompts 1.0.1 → 1.0.2

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.
@@ -0,0 +1,3 @@
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';
@@ -0,0 +1,3 @@
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';
@@ -0,0 +1 @@
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});
@@ -0,0 +1 @@
1
+ var P=Object.defineProperty;var a=(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{a(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{a(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{a(this,"PromptError")}constructor(t){super(t),Error.captureStackTrace?.(this,i)}},b=class{constructor(t,e,o){this.initialState=e;let n=[],s=a(()=>this.context.previousStates.pop()??this.initialState,"goBack");this.context={...t,previousStates:n,goBack:s},this.states=new Map(o.map(r=>[r.name,r]))}static{a(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),r=await this.replyOrEdit(e,s);return this.collector&&this.collector.stop(),this.collector=r.createMessageComponentCollector({time:o.timeout||12e4,filter:a(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 r=await t.awaitModalSubmit({time:3e5,filter:a(l=>l.user.id===t.user.id&&l.customId===s,"filter")}).catch(()=>null);if(!r)return;await r.deferUpdate(),this.collector?.stop(),this.context.interaction=r;let m=await this.getNewStateFromCallback(e,r)??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,c as PromptButtonBuilder,p as PromptError,u as PromptSelectMenuBuilder};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moody-djs/prompts",
3
3
  "description": "A simple library for creating state based prompts in discord.js",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "tsc --noEmit --skipLibCheck",