commandkit 1.0.0-dev.20250528020139 → 1.0.0-dev.20250528125253
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/cli/information.js +1 -1
- package/dist/cli/information.js.map +1 -1
- package/dist/cli/init.js +1 -1
- package/dist/cli/init.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ declare module 'commandkit' {
|
|
|
12
12
|
}
|
|
13
13
|
export {};
|
|
14
14
|
`,t=(0,we.join)(process.cwd(),"node_modules","commandkit-types");if(!(0,Ei.existsSync)(t))return;let o=(0,we.join)(t,"command.d.ts");await(0,Me.writeFile)(o,e,{encoding:"utf-8"})}var Me,we,Ei,Bt=g(()=>{"use strict";l();Me=require("fs/promises"),we=require("path");ve();Ei=require("fs");i(ot,"generateTypesPackage");i(wi,"rewriteCommandDeclaration")});var N,ks,Ts,jo,Ot,Ho=g(()=>{"use strict";l();N=require("discord.js");Io();Do();ke();ko();fe();vi();ve();Bt();ye();ks={command:i(n=>n instanceof N.SlashCommandBuilder||n instanceof N.ContextMenuCommandBuilder||n&&typeof n=="object","command"),chatInput:i(n=>typeof n=="function","chatInput"),autocomplete:i(n=>typeof n=="function","autocomplete"),message:i(n=>typeof n=="function","message"),messageContextMenu:i(n=>typeof n=="function","messageContextMenu"),userContextMenu:i(n=>typeof n=="function","userContextMenu")},Ts={beforeExecute:i(n=>typeof n=="function","beforeExecute"),afterExecute:i(n=>typeof n=="function","afterExecute")},jo=class jo{constructor(e){this.commandkit=e;this.registrar=new Kt(this.commandkit)}loadedCommands=new N.Collection;loadedMiddlewares=new N.Collection;commandNameToId=new Map;subcommandPathToId=new Map;registrar;onInteraction=null;onMessageCreate=null;commandRunner=new ln(this);externalCommandData=new N.Collection;externalMiddlewareData=new N.Collection;printBanner(){let e=crypto.randomUUID(),t=this.getCommandsArray().reduce((u,d)=>{let p=d.command.category||e;return u[p]=u[p]||[],u[p].push(d),u},{});console.log(C.green(`Loaded ${C.magenta(this.loadedCommands.size.toString())} commands:`));let o=Object.keys(t).sort(),r={};o.forEach(u=>{if(u!==e&&u.includes(":")){let d=u.split(":"),p=null;for(let b=d.length-1;b>0;b--){let y=d.slice(0,b).join(":");if(o.includes(y)){p=y;break}}p&&(r[p]=r[p]||[],r[p].push(u))}});let a=new Set,s=i((u,d="",p=!1,b="")=>{if(a.has(u))return;a.add(u);let y=t[u],E=r[u]&&r[u].length>0,S=p?"\u2514\u2500":"\u251C\u2500",P=b+(p?" ":"\u2502 ");if(u!==e){let w=u.includes(":")?u.split(":").pop():u;console.log(C.cyan(`${d}${S} ${C.bold(w)}`))}if(y.forEach((w,K)=>{let st=K===y.length-1&&!E?"\u2514\u2500":"\u251C\u2500",Fa=u!==e?P:d,Na=w.data.command.name,Ua=w.command.middlewares.length>0?C.magenta(" (\u03BB)"):"";console.log(`${C.green(`${Fa}${st}`)} ${C.yellow(Na)}${Ua}`)}),E){let w=r[u].sort();w.forEach((K,De)=>{let st=De===w.length-1;s(K,P,st,P)})}},"printCategory"),m=o.filter(u=>{if(u===e)return!0;if(u.includes(":")){let d=u.split(":");for(let p=1;p<d.length;p++){let b=d.slice(0,p).join(":");if(o.includes(b))return!1}return!0}return!0}).sort();m.forEach((u,d)=>{let p=d===m.length-1;s(u,"",p)})}getCommandsArray(){return Array.from(this.loadedCommands.values())}registerCommandHandler(){this.onInteraction??=async e=>{if(await this.commandkit.plugins.execute(async(a,s)=>s.onBeforeInteraction(a,e))||!(e.isCommand()||e.isAutocomplete()||e.isUserContextMenuCommand()||e.isMessageContextMenuCommand()))return;let r=await this.prepareCommandRun(e);if(r)return this.commandRunner.runCommand(r,e)},this.onMessageCreate??=async e=>{if(await this.commandkit.plugins.execute(async(r,a)=>a.onBeforeMessageCommand(r,e))||e.author.bot)return;let o=await this.prepareCommandRun(e);if(o)return this.commandRunner.runCommand(o,e)},this.commandkit.client.on(N.Events.InteractionCreate,this.onInteraction),this.commandkit.client.on(N.Events.MessageCreate,this.onMessageCreate)}async prepareCommandRun(e,t){var m;let o;if(!t)if(e instanceof N.Message){if(e.author.bot)return null;let u=await this.commandkit.config.getMessageCommandPrefix(e);o=new Rt(e,Array.isArray(u)?u:[u],d=>{var E,S;let p=this.commandNameToId.get(d);if(!p)return null;let b=this.loadedCommands.get(p);return!b||e.guildId&&((E=b.guilds)!=null&&E.length)&&!b.guilds.includes(e.guildId)?null:((S=("toJSON"in b.data.command?b.data.command.toJSON():b.data.command).options)==null?void 0:S.reduce((P,w)=>(P[w.name]=w.type,P),{}))??{}});try{t=o.getFullCommand().split(" ")[0]}catch(d){return Z(d,k.InvalidCommandPrefix)||M.error(d),null}}else{if(!(e.isChatInputCommand()||e.isAutocomplete()||e.isContextMenuCommand()))return null;t=e.commandName}let r=this.commandNameToId.get(t);if(!r)return null;let a=this.loadedCommands.get(r);if(!a||(e instanceof N.CommandInteraction||e instanceof N.AutocompleteInteraction)&&e.guildId&&((m=a.guilds)!=null&&m.length)&&!a.guilds.includes(e.guildId))return null;let s=[];for(let u of a.command.middlewares){let d=this.loadedMiddlewares.get(u);d&&s.push(d)}return{command:a,middlewares:s,messageCommandParser:o}}async reloadCommands(){this.loadedCommands.clear(),this.loadedMiddlewares.clear(),this.commandNameToId.clear(),this.subcommandPathToId.clear(),this.externalCommandData.clear(),this.externalMiddlewareData.clear(),await this.loadCommands()}async addExternalMiddleware(e){for(let t of e)t.id&&this.externalMiddlewareData.set(t.id,t)}async addExternalCommands(e){for(let t of e)t.id&&this.externalCommandData.set(t.id,t)}async registerExternalLoadedMiddleware(e){for(let t of e)this.loadedMiddlewares.set(t.middleware.id,t)}async registerExternalLoadedCommands(e){for(let t of e)this.loadedCommands.set(t.command.id,t),this.commandNameToId.set(t.command.name,t.command.id)}async loadCommands(){await this.commandkit.plugins.execute((s,m)=>m.onBeforeCommandsLoad(s));let e=this.commandkit.commandsRouter;if(!e)throw new Error("Commands router has not yet initialized");let{commands:t,middlewares:o}=e.getData(),r=this.externalCommandData.size?t.concat(this.externalCommandData):t,a=this.externalMiddlewareData.size?o.concat(this.externalMiddlewareData):o;for(let[s,m]of a)await this.loadMiddleware(s,m);for(let[s,m]of r)await this.loadCommand(s,m);W&&await wi(`type CommandTypeData = ${Array.from(this.loadedCommands.mapValues(s=>JSON.stringify(s.command.name)).values()).join(" | ")}`),await this.commandkit.plugins.execute((s,m)=>m.onAfterCommandsLoad(s))}async loadMiddleware(e,t){try{let o=await import(`${Pt(t.path)}?t=${Date.now()}`),r=0;for(let[a,s]of Object.entries(Ts)){if(o[a]&&!await s(o[a]))throw new Error(`Invalid export for middleware ${e}: ${a} does not match expected value`);o[a]&&r++}if(r===0)throw new Error(`Invalid export for middleware ${e}: at least one handler function must be provided`);this.loadedMiddlewares.set(e,{middleware:t,data:o})}catch(o){M.error(`Failed to load middleware ${e}`,o)}}async loadCommand(e,t){try{if(t.path===null){this.loadedCommands.set(e,{command:t,data:{command:{name:t.name,description:`${t.name} commands`,type:1}}});return}let o=await import(`${Pt(t.path)}?t=${Date.now()}`);if(!o.command)throw new Error(`Invalid export for command ${t.name}: no command definition found`);let r=0;for(let[s,m]of Object.entries(ks))if(s!=="command"&&o[s]&&r++,o[s]&&!await m(o[s]))throw new Error(`Invalid export for command ${t.name}: ${s} does not match expected value`);if(r===0)throw new Error(`Invalid export for command ${t.name}: at least one handler function must be provided`);let a=o.command;await this.commandkit.plugins.execute(async(s,m)=>{let u=await m.prepareCommand(s,a);u&&(a=u)}),this.loadedCommands.set(e,{command:t,guilds:o.guilds,data:{...o,command:"toJSON"in a?a.toJSON():a}}),this.commandNameToId.set(t.name,e)}catch(o){M.error(`Failed to load command ${t.name} (${e})`,o)}}};i(jo,"AppCommandHandler");Ot=jo});var Go,Ii,_o,J,As,Mi,Si,Bs,Os,Vo,Lt,Pi=g(()=>{"use strict";l();Go=require("discord.js"),Ii=require("fs"),_o=require("fs/promises"),J=require("path"),As=/^\+middleware\.(m|c)?(j|t)sx?$/,Mi=/^\+([^+().][^().]*)\.middleware\.(m|c)?(j|t)sx?$/,Si=/^\+global-middleware\.(m|c)?(j|t)sx?$/,Bs=/^([^+().][^().]*)\.(m|c)?(j|t)sx?$/,Os=/^\(.+\)$/,Vo=class Vo{constructor(e){this.options=e}commands=new Go.Collection;middlewares=new Go.Collection;populate(e){for(let[t,o]of Object.entries(e.commands))this.commands.set(t,o);for(let[t,o]of Object.entries(e.middlewares))this.middlewares.set(t,o)}isValidPath(){return(0,Ii.existsSync)(this.options.entrypoint)}isCommand(e){return Bs.test(e)}isMiddleware(e){return As.test(e)||Si.test(e)||Mi.test(e)}isCategory(e){return Os.test(e)}clear(){this.commands.clear(),this.middlewares.clear()}async scan(){let e=await(0,_o.readdir)(this.options.entrypoint,{withFileTypes:!0});for(let t of e){if(t.name.startsWith("_"))continue;let o=(0,J.join)(this.options.entrypoint,t.name);if(t.isDirectory()){let r=this.isCategory(t.name)?t.name.slice(1,-1):null;await this.traverse(o,r)}else await this.handle(t)}return await this.applyMiddlewares(),this.toJSON()}getData(){return{commands:this.commands,middlewares:this.middlewares}}toJSON(){return{commands:Object.fromEntries(this.commands.entries()),middlewares:Object.fromEntries(this.middlewares.entries())}}async traverse(e,t){let o=await(0,_o.readdir)(e,{withFileTypes:!0});for(let r of o)if(!r.name.startsWith("_")){if(r.isFile())(this.isCommand(r.name)||this.isMiddleware(r.name))&&await this.handle(r,t);else if(r.isDirectory()&&this.isCategory(r.name)&&t){let a=this.isCategory(r.name)?`${t}:${r.name.slice(1,-1)}`:null;await this.traverse((0,J.join)(e,r.name),a)}}}async handle(e,t=null){let o=e.name,r=(0,J.join)(e.parentPath,e.name);if(this.isCommand(o)){let a={id:crypto.randomUUID(),name:(0,J.basename)(r,(0,J.extname)(r)),path:r,category:t,parentPath:e.parentPath,relativePath:this.replaceEntrypoint(r),middlewares:[]};this.commands.set(a.id,a)}else if(this.isMiddleware(o)){let a={id:crypto.randomUUID(),name:(0,J.basename)(r,(0,J.extname)(r)),path:r,relativePath:this.replaceEntrypoint(r),parentPath:e.parentPath,global:Si.test(o),command:Mi.test(o)&&o.split(".")[0]||null};this.middlewares.set(a.id,a)}}applyMiddlewares(){this.commands.forEach(e=>{let t=e.parentPath,o=Array.from(this.middlewares.values()).filter(r=>r.global?!0:r.command?r.command===e.name:r.parentPath===t).map(r=>r.id);e.middlewares=Array.from(new Set([...e.middlewares,...o]))})}replaceEntrypoint(e){return(0,J.normalize)(e).replace(this.options.entrypoint,"")}};i(Vo,"CommandsRouter");Lt=Vo});var Ri,Di,Wo,mn,qo,$t,Ki=g(()=>{"use strict";l();Ri=require("discord.js"),Di=require("fs"),Wo=require("fs/promises"),mn=require("path"),qo=class qo{constructor(e){this.options=e;var t;if(e.entrypoints&&(e.entrypoints=Array.from(new Set(e.entrypoints))),!((t=e.entrypoints)!=null&&t.length))throw new Error("Entrypoint directory must be provided")}events=new Ri.Collection;addEntrypoints(e){this.options.entrypoints=Array.from(new Set([...this.options.entrypoints,...e]))}match(e){return this.events.get(e)??null}get entrypoints(){return this.options.entrypoints}isValidPath(){return this.entrypoints.every(e=>(0,Di.existsSync)(e))}clear(){this.events.clear()}async reload(){return this.clear(),this.scan()}async scan(){for(let e of this.entrypoints){let t=await(0,Wo.readdir)(e,{withFileTypes:!0});for(let o of t)if(o.isDirectory()){let r=(0,mn.join)(e,o.name);await this.scanEvent(o.name,r,null,[],!0)}}return Object.fromEntries(this.events)}toJSON(){return Object.fromEntries(this.events)}async scanEvent(e,t,o=null,r=[],a=!1){let s=await(0,Wo.readdir)(t,{withFileTypes:!0}),m=a&&/^\(.+\)$/.test(e),u=m?e.slice(1,-1):o??null;s.sort((d,p)=>d.name.localeCompare(p.name));for(let d of s)if(!d.name.startsWith("_")){if(d.isDirectory()){let p=(0,mn.join)(t,d.name);await this.scanEvent(d.name,p,u,r);continue}d.isFile()&&/\.(m|c)?(j|t)sx?$/.test(d.name)&&r.push((0,mn.join)(d.parentPath,d.name))}if(!m){let d=this.events.get(e);if(d){d.listeners=Array.from(new Set([...d.listeners,...r]));return}this.events.set(e,{event:e,path:t,listeners:r,namespace:u})}}};i(qo,"EventsRouter");$t=qo});var Jo=g(()=>{"use strict";l();Pi();Ki()});var ki,zo,un,Ti=g(()=>{"use strict";l();ki=require("discord.js");fe();Io();It();Mt();zo=class zo{constructor(e){this.commandkit=e}loadedEvents=new ki.Collection;getEvents(){return this.loadedEvents.size===0?[]:this.loadedEvents.toJSON().map(t=>({name:t.name,namespace:t.namespace,onceListeners:t.listeners.filter(o=>o.once).length,regularListeners:t.listeners.filter(o=>!o.once).length,metadata:t.event}))}async reloadEvents(){this.unregisterAll(),await this.loadEvents()}async loadEvents(){await this.commandkit.plugins.execute((o,r)=>r.onBeforeEventsLoad(o));let t=await this.commandkit.eventsRouter.scan();for(let o of Object.values(t)){let r=[];for(let m of o.listeners){let u=await import(Pt(m,!0));(!u.default||typeof u.default!="function")&&M.error(`Event handler for ${o.event}${o.namespace?` of namespace ${o.namespace}`:""} does not have a default export or is not a function`),r.push({handler:u.default,once:!!u.once})}let a=r.length;a||M.warn(`Event ${o.event}${o.namespace?` of namespace ${o.namespace}`:""} does not have any listeners`);let s=`${o.namespace?`${o.namespace}:`:""}${o.event}`;this.loadedEvents.set(s,{name:o.event,namespace:o.namespace,event:o,listeners:r}),M.info(`\u2728 Loaded event ${o.event}${o.namespace?` of namespace ${o.namespace}`:""} with ${a} listener${a===1?"":"s"}`)}this.registerAllClientEvents(),await this.commandkit.plugins.execute((o,r)=>r.onAfterEventsLoad(o))}unregisterAll(){this.unregisterAllClientListeners(),this.loadedEvents.clear()}registerAllClientEvents(){let e=this.commandkit.client;for(let[t,o]of this.loadedEvents.entries()){let{name:r,listeners:a,namespace:s}=o,m=a.filter(y=>y.once),u=a.filter(y=>!y.once),d=new Set,p=i(async(...y)=>{let E=!1,S={name:r,args:y,namespace:s??null,once:!1,metadata:o.event,accept(){E||(E=!0)}};await this.commandkit.plugins.execute(async(P,w)=>{var K;if(!E)return(K=w.willEmitEvent)==null?void 0:K.call(w,P,S)}).catch(Object),await tn({event:r,namespace:s??null,data:o.event,commandkit:this.commandkit,arguments:y},async()=>{for(let P of u)try{await P.handler(...y)}catch(w){if(w instanceof Ee){M.debug(`Event propagation stopped for ${r}${s?` of namespace ${s}`:""}`);break}M.error(`Error handling event ${r}${s?` of namespace ${s}`:""}`,w)}})},"mainHandler"),b=i(async(...y)=>{let E=!1,S=!1,P={name:r,args:y,namespace:s??null,once:!0,metadata:o.event,accept(){S||(S=!0)}};await this.commandkit.plugins.execute(async(w,K)=>{var De;if(!S)return(De=K.willEmitEvent)==null?void 0:De.call(K,w,P)}).catch(Object);for(let w of m){if(E)break;await tn({event:r,namespace:s??null,data:o.event,commandkit:this.commandkit,arguments:y},async()=>{try{if(d.has(w.handler))return;await w.handler(...y),d.add(w.handler)}catch(K){K instanceof Ee&&(M.debug(`Event propagation stopped for ${r}${s?` of namespace ${s}`:""}`),E=!0),M.error(`Error handling event ${r}${s?` of namespace ${s}`:""}`,K)}})}d.size===m.length&&u.length===0&&(this.loadedEvents.delete(t),M.info(`\u{1F9F9} Cleaned up completed once-only event ${r}${s?` of namespace ${s}`:""}`))},"onceHandler");this.loadedEvents.set(t,{...o,mainListener:u.length>0?{handler:p,once:!1}:void 0,executedOnceListeners:d}),s?(u.length>0&&this.commandkit.events.on(s,r,p),m.length>0&&this.commandkit.events.once(s,r,b)):(u.length>0&&e.on(r,p),m.length>0&&e.once(r,b)),M.info(`\u{1F50C} Registered event ${r}${s?` of namespace ${s}`:""} (${u.length} regular, ${m.length} once-only)`)}}unregisterAllClientListeners(){let e=this.commandkit.client;for(let[t,{name:o,mainListener:r,namespace:a}]of this.loadedEvents.entries())r?a?this.commandkit.events.off(a,o,r.handler):e.off(o,r.handler):a?this.commandkit.events.removeAllListeners(a,o):e.removeAllListeners(o),this.loadedEvents.delete(t),M.info(`\u{1F5D1}\uFE0F Unregistered event ${o}${a?` of namespace ${a}`:""}`)}};i(zo,"AppEventsHandler");un=zo});function $s(n){process.stdout.write(n),process.stdout.write(`
|
|
15
|
-
`)}function dn(n){let e=(0,ge.join)(n,"sharding-manager.js");return te.default.existsSync(e)?e:(0,ge.join)(n,"index.js")}function Se(n){$s(C.red(`Error: ${n}`)),process.exit(1)}async function Fs(n){return/\.(c|m)?tsx?$/.test(n)?(process.features.typescript||await Yo(),!0):!1}function Ns(){if(rt)return rt;let n={"yarn.lock":"yarn","pnpm-lock.yaml":"pnpm","package-lock.json":"npm","bun.lock":"bun","bun.lockb":"bun"};for(let[e,t]of Object.entries(n))if(te.default.existsSync((0,ge.join)(process.cwd(),e))){rt=t;break}return rt||(rt="npm"),rt}async function Yo(n){if(Q)return Q;try{Q=await import("typescript")}catch(e){if(e instanceof Error&&"code"in e&&e.code==="MODULE_NOT_FOUND")try{let t=Ns();return(0,Ai.execSync)(`${t} add typescript`,{stdio:"inherit",cwd:process.cwd()}),console.log(C.cyan("TypeScript has been installed automatically, restarting...")),Q=await import("typescript"),Q}catch{Se("TypeScript is not installed and could not be installed automatically. Please install it manually.")}Se(e||"TypeScript must be installed to use TypeScript config files.")}return Q}async function Bi(n){if(await Us(n),await Fs(n)&&Q){let{transpileModule:o}=Q,r=te.default.readFileSync(n,"utf8"),{outputText:a}=o(r,{compilerOptions:{module:Q.ModuleKind.ESNext,target:Q.ScriptTarget.ESNext,moduleResolution:Q.ModuleResolutionKind.NodeNext},fileName:n}),s=await ot(),m=(0,ge.join)(s,"compiled-commandkit.config.mjs");te.default.writeFileSync(m,a),n=m}return await import(`file://${n}`).then(o=>o.default||o)}async function Us(n){if(!te.default.existsSync(n))throw new Error(`File not found: ${n}`)}async function Oi(n,e){let t=(0,ge.join)(process.cwd(),n),o=(0,ge.join)(process.cwd(),e),r=["app/locales"],a=r.map(m=>(0,ge.join)(t,m)),s=r.map(m=>(0,ge.join)(o,m));for(let m of a){if(!te.default.existsSync(m))continue;let u=s[a.indexOf(m)];te.default.existsSync(u)||te.default.promises.mkdir(u,{recursive:!0}),await te.default.promises.cp(m,u,{recursive:!0,force:!0})}}var Ls,ge,te,Ai,Q,rt,Ie=g(()=>{"use strict";l();Ls=require("rimraf"),ge=require("path"),te=q(require("fs"));ye();Bt();Ai=require("child_process");i($s,"write");i(dn,"findEntrypoint");i(Se,"panic");i(Fs,"ensureTypeScript");i(Ns,"detectPackageManager");i(Yo,"loadTypeScript");i(Bi,"loadConfigFileFromPath");i(Us,"ensureExists");i(Oi,"copyLocaleFiles")});function Qo(n){return js.map(e=>(0,$i.join)(n,e))}function Hs(n){let e=Qo(n);for(let t of e)if((0,Li.existsSync)(t))return{path:t,isTypeScript:/\.ts$/.test(t)};return null}async function Ce(n=process.cwd()){if(Xo)return Xo;let e=Hs(n);if(!e)return qe();let t=await Bi(e.path);return Xo=t,t}var Li,$i,js,Xo,Ft=g(()=>{"use strict";l();Li=require("fs"),$i=require("path");Ie();en();js=["commandkit.config.js","commandkit.config.mjs","commandkit.config.cjs","commandkit.config.ts"];i(Qo,"getPossibleConfigPaths");i(Hs,"findConfigFile");Xo=null;i(Ce,"loadConfigFile")});function Fi(n){W&&process.on("message",async e=>{if(typeof e!="object"||e===null)return;let{event:t,path:o,id:r}=e;if(!t)return;process.env.COMMANDKIT_DEBUG_HMR==="true"&&M.info(`Received HMR event: ${t}${o?` for ${o}`:""}`);let a=!1,s=!1,m=!1,u={accept(){a=!0},preventDefault(){s=!0},path:o,event:t};try{if(await n.plugins.execute(async(d,p)=>{var b;a||await((b=p.performHMR)==null?void 0:b.call(p,d,u))}),s)return;switch(t){case Y.ReloadCommands:n.commandHandler.reloadCommands(),m=!0;break;case Y.ReloadEvents:n.eventHandler.reloadEvents(),m=!0;break;case Y.Unknown:m=!1;break;default:break}}finally{r&&process.send&&process.send({type:"commandkit-hmr-ack",id:r,handled:m||a})}})}var Ni=g(()=>{"use strict";l();fe();ve();i(Fi,"registerDevHooks")});var Ui,Zo,pn,ji=g(()=>{"use strict";l();Ui=q(require("events")),Zo=class Zo{constructor(e){this.commandkit=e}emitter=new Ui.default;to(e){return{on:this.on.bind(this,e),off:this.off.bind(this,e),once:this.once.bind(this,e),emit:this.emit.bind(this,e),removeAllListeners:this.removeAllListeners.bind(this,e)}}on(e,t,o){this.emitter.on(`${e}:${t}`,o)}off(e,t,o){this.emitter.off(`${e}:${t}`,o)}once(e,t,o){this.emitter.once(`${e}:${t}`,o)}emit(e,t,...o){return this.emitter.emit(`${e}:${t}`,...o)}removeAllListeners(e,t){t?this.emitter.removeAllListeners(`${e}:${t}`):this.emitter.removeAllListeners(e)}};i(Zo,"CommandKitEventsChannel");pn=Zo});var Hi,er,fn,Gi=g(()=>{"use strict";l();Hi=require("discord.js"),er=class er extends Hi.Collection{};i(er,"FlagStore");fn=er});function Gs(n){hn.add(n)}function _s(n){gn.add(n)}var _i,Cn,tr,Vi,Wi,hn,gn,it,z,qi,Ji,zi,Yi,Xi,ne,Te,jt=g(()=>{"use strict";l();_i=q(require("events"));ye();io();ro();Cn=require("discord.js");It();tr=require("path");Ho();Jo();Ti();go();Ft();ve();Ni();Vi=require("fs");ji();he();Bt();fe();Gi();hn=new Set,gn=new Set;i(Gs,"onBootstrap");i(_s,"onApplicationBootstrap");ne=class ne extends _i.default{constructor(t){if(ne.instance&&process.emitWarning("CommandKit instance already exists. Having multiple instance in same project is discouraged and it may lead to unexpected behavior.",{code:"MultiInstanceWarning"}),!t.client)throw new Error(C.red('"client" is required when instantiating CommandKit.'));super();this.options=t;x(this,z);x(this,it,!1);I(this,"eventInterceptor");I(this,"config",{defaultLocale:Cn.Locale.EnglishUS,getMessageCommandPrefix:i(()=>"!","getMessageCommandPrefix")});I(this,"store",new Map);I(this,"flags",new fn);I(this,"commandsRouter");I(this,"eventsRouter");I(this,"commandHandler",new Ot(this));I(this,"eventHandler",new un(this));I(this,"plugins");I(this,"events",new pn(this));this.plugins=new Et(this),ne.instance||(ne.instance=this),Wi=ne.instance,v(this,z,qi).call(this)}async start(t){if(!c(this,it)){if(!this.options.client)throw new Error(C.red('"client" is required when starting CommandKit.'));if(this.eventInterceptor=new xt(this.client),W)try{Fi(this),await ot()}catch(o){process.env.COMMANDKIT_DEBUG_TYPEGEN&&M.error(o)}if(await this.loadPlugins(),await v(this,z,zi).call(this),this.commandHandler.registerCommandHandler(),this.incrementClientListenersCount(),t!==!1&&!this.options.client.isReady()){this.client.once(Cn.Events.ClientReady,async()=>{await this.commandHandler.registrar.register()}),await this.plugins.execute((r,a)=>{var s;return(s=a.onBeforeClientLogin)==null?void 0:s.call(a,r)});let o=t??this.options.client.token??process.env.TOKEN??process.env.DISCORD_TOKEN;await this.options.client.login(o),await this.plugins.execute((r,a)=>{var s;return(s=a.onAfterClientLogin)==null?void 0:s.call(a,r)})}else this.options.client.isReady()&&await this.commandHandler.registrar.register();h(this,it,!0),await v(this,z,Ji).call(this)}}async loadPlugins(){let o=(await Ce()).plugins.flat(2).filter(r=>mo(r));if(o.length)for(let r of o)await this.plugins.softRegisterPlugin(r)}get started(){return c(this,it)}setPrefixResolver(t){return this.config.getMessageCommandPrefix=t,this}setDefaultLocale(t){return this.config.defaultLocale=t,this}get client(){return this.options.client}async reloadCommands(){await this.commandHandler.reloadCommands()}async reloadEvents(){await this.eventHandler.reloadEvents()}incrementClientListenersCount(){this.options.client.setMaxListeners(this.options.client.getMaxListeners()+1)}decrementClientListenersCount(){this.options.client.setMaxListeners(this.options.client.getMaxListeners()-1)}getAppDirectory(){return hi()}getPath(t){let o=this.getAppDirectory();if(!o)return null;switch(t){case"commands":return(0,tr.join)(o,"commands");case"events":return(0,tr.join)(o,"events");default:return t}}};it=new WeakMap,z=new WeakSet,qi=i(async function(){for(let t of hn)try{await t(this)}catch(o){M.error("Error while executing bootstrap hook: ",o)}finally{hn.delete(t)}hn.clear()},"#bootstrapHooks"),Ji=i(async function(){for(let t of gn)try{await t(this)}catch(o){M.error("Error while executing application bootstrap hook: ",o)}finally{gn.delete(t)}gn.clear()},"#applicationBootstrapHooks"),zi=i(async function(){if(!this.getAppDirectory())return;let o=this.getPath("commands"),r=this.getPath("events");this.commandsRouter=new Lt({entrypoint:o}),await this.plugins.execute((a,s)=>s.onCommandsRouterInit(a)),this.eventsRouter=new $t({entrypoints:[r]}),await this.plugins.execute((a,s)=>s.onEventsRouterInit(a)),await v(this,z,Xi).call(this),await v(this,z,Yi).call(this)},"#init"),Yi=i(async function(){if(this.commandsRouter.isValidPath()){let t=await this.commandsRouter.scan();W&&(0,Vi.writeFileSync)("./.commandkit/commands.json",JSON.stringify(t,null,2))}await this.commandHandler.loadCommands(),this.commandHandler.printBanner()},"#initCommands"),Xi=i(async function(){this.eventsRouter.isValidPath()&&await this.eventsRouter.scan(),await this.eventHandler.loadEvents()},"#initEvents"),i(ne,"CommandKit"),I(ne,"createElement",no),I(ne,"Fragment",to),I(ne,"instance");Te=ne});var ea={};Qe(ea,{version:()=>yn});var yn,xn=g(()=>{"use strict";l();yn="1.0.0-dev.20250528020139"});function vn(n=!1){let e={NODE_ENV:"development",COMMANDKIT_IS_DEV:"true"};return n?Object.assign({},e):Object.assign({},process.env,e)}function En(n=!1){let e={NODE_ENV:"production",COMMANDKIT_IS_DEV:"false"};return n?Object.assign({},e):Object.assign({},process.env,e)}var ta,Ws,qs,na,oa,rr=g(()=>{"use strict";l();i(vn,"DevEnv");i(En,"ProdEnv");ta=[".env",".env.local"],Ws=[".env.development",".env.development.local"],qs=[".env.production",".env.production.local"],na=[...ta,...Ws],oa=[...ta,...qs]});function Js(n){return n?["pipe","pipe","pipe","ipc"]:["pipe","pipe","pipe"]}function wn(n,e,t){var a,s;(0,aa.existsSync)((0,ia.join)(e,n))||Se(`Could not locate the entrypoint file: ${n}`);let o=Js(t),r=(0,ra.spawn)("node",[`--title="CommandKit ${t?"Development":"Production"}"`,"--enable-source-maps",n],{cwd:e,windowsHide:!0,env:t?vn():En(),stdio:o});return(a=r.stdout)==null||a.pipe(process.stdout),(s=r.stderr)==null||s.pipe(process.stderr),r}var ra,ia,aa,ir=g(()=>{"use strict";l();ra=require("child_process");rr();ia=require("path"),aa=require("fs");Ie();i(Js,"getStdio");i(wn,"createAppProcess")});function Ys(n,e,t){let o=n.flattenDiagnosticMessageText(e.messageText,`
|
|
15
|
+
`)}function dn(n){let e=(0,ge.join)(n,"sharding-manager.js");return te.default.existsSync(e)?e:(0,ge.join)(n,"index.js")}function Se(n){$s(C.red(`Error: ${n}`)),process.exit(1)}async function Fs(n){return/\.(c|m)?tsx?$/.test(n)?(process.features.typescript||await Yo(),!0):!1}function Ns(){if(rt)return rt;let n={"yarn.lock":"yarn","pnpm-lock.yaml":"pnpm","package-lock.json":"npm","bun.lock":"bun","bun.lockb":"bun"};for(let[e,t]of Object.entries(n))if(te.default.existsSync((0,ge.join)(process.cwd(),e))){rt=t;break}return rt||(rt="npm"),rt}async function Yo(n){if(Q)return Q;try{Q=await import("typescript")}catch(e){if(e instanceof Error&&"code"in e&&e.code==="MODULE_NOT_FOUND")try{let t=Ns();return(0,Ai.execSync)(`${t} add typescript`,{stdio:"inherit",cwd:process.cwd()}),console.log(C.cyan("TypeScript has been installed automatically, restarting...")),Q=await import("typescript"),Q}catch{Se("TypeScript is not installed and could not be installed automatically. Please install it manually.")}Se(e||"TypeScript must be installed to use TypeScript config files.")}return Q}async function Bi(n){if(await Us(n),await Fs(n)&&Q){let{transpileModule:o}=Q,r=te.default.readFileSync(n,"utf8"),{outputText:a}=o(r,{compilerOptions:{module:Q.ModuleKind.ESNext,target:Q.ScriptTarget.ESNext,moduleResolution:Q.ModuleResolutionKind.NodeNext},fileName:n}),s=await ot(),m=(0,ge.join)(s,"compiled-commandkit.config.mjs");te.default.writeFileSync(m,a),n=m}return await import(`file://${n}`).then(o=>o.default||o)}async function Us(n){if(!te.default.existsSync(n))throw new Error(`File not found: ${n}`)}async function Oi(n,e){let t=(0,ge.join)(process.cwd(),n),o=(0,ge.join)(process.cwd(),e),r=["app/locales"],a=r.map(m=>(0,ge.join)(t,m)),s=r.map(m=>(0,ge.join)(o,m));for(let m of a){if(!te.default.existsSync(m))continue;let u=s[a.indexOf(m)];te.default.existsSync(u)||te.default.promises.mkdir(u,{recursive:!0}),await te.default.promises.cp(m,u,{recursive:!0,force:!0})}}var Ls,ge,te,Ai,Q,rt,Ie=g(()=>{"use strict";l();Ls=require("rimraf"),ge=require("path"),te=q(require("fs"));ye();Bt();Ai=require("child_process");i($s,"write");i(dn,"findEntrypoint");i(Se,"panic");i(Fs,"ensureTypeScript");i(Ns,"detectPackageManager");i(Yo,"loadTypeScript");i(Bi,"loadConfigFileFromPath");i(Us,"ensureExists");i(Oi,"copyLocaleFiles")});function Qo(n){return js.map(e=>(0,$i.join)(n,e))}function Hs(n){let e=Qo(n);for(let t of e)if((0,Li.existsSync)(t))return{path:t,isTypeScript:/\.ts$/.test(t)};return null}async function Ce(n=process.cwd()){if(Xo)return Xo;let e=Hs(n);if(!e)return qe();let t=await Bi(e.path);return Xo=t,t}var Li,$i,js,Xo,Ft=g(()=>{"use strict";l();Li=require("fs"),$i=require("path");Ie();en();js=["commandkit.config.js","commandkit.config.mjs","commandkit.config.cjs","commandkit.config.ts"];i(Qo,"getPossibleConfigPaths");i(Hs,"findConfigFile");Xo=null;i(Ce,"loadConfigFile")});function Fi(n){W&&process.on("message",async e=>{if(typeof e!="object"||e===null)return;let{event:t,path:o,id:r}=e;if(!t)return;process.env.COMMANDKIT_DEBUG_HMR==="true"&&M.info(`Received HMR event: ${t}${o?` for ${o}`:""}`);let a=!1,s=!1,m=!1,u={accept(){a=!0},preventDefault(){s=!0},path:o,event:t};try{if(await n.plugins.execute(async(d,p)=>{var b;a||await((b=p.performHMR)==null?void 0:b.call(p,d,u))}),s)return;switch(t){case Y.ReloadCommands:n.commandHandler.reloadCommands(),m=!0;break;case Y.ReloadEvents:n.eventHandler.reloadEvents(),m=!0;break;case Y.Unknown:m=!1;break;default:break}}finally{r&&process.send&&process.send({type:"commandkit-hmr-ack",id:r,handled:m||a})}})}var Ni=g(()=>{"use strict";l();fe();ve();i(Fi,"registerDevHooks")});var Ui,Zo,pn,ji=g(()=>{"use strict";l();Ui=q(require("events")),Zo=class Zo{constructor(e){this.commandkit=e}emitter=new Ui.default;to(e){return{on:this.on.bind(this,e),off:this.off.bind(this,e),once:this.once.bind(this,e),emit:this.emit.bind(this,e),removeAllListeners:this.removeAllListeners.bind(this,e)}}on(e,t,o){this.emitter.on(`${e}:${t}`,o)}off(e,t,o){this.emitter.off(`${e}:${t}`,o)}once(e,t,o){this.emitter.once(`${e}:${t}`,o)}emit(e,t,...o){return this.emitter.emit(`${e}:${t}`,...o)}removeAllListeners(e,t){t?this.emitter.removeAllListeners(`${e}:${t}`):this.emitter.removeAllListeners(e)}};i(Zo,"CommandKitEventsChannel");pn=Zo});var Hi,er,fn,Gi=g(()=>{"use strict";l();Hi=require("discord.js"),er=class er extends Hi.Collection{};i(er,"FlagStore");fn=er});function Gs(n){hn.add(n)}function _s(n){gn.add(n)}var _i,Cn,tr,Vi,Wi,hn,gn,it,z,qi,Ji,zi,Yi,Xi,ne,Te,jt=g(()=>{"use strict";l();_i=q(require("events"));ye();io();ro();Cn=require("discord.js");It();tr=require("path");Ho();Jo();Ti();go();Ft();ve();Ni();Vi=require("fs");ji();he();Bt();fe();Gi();hn=new Set,gn=new Set;i(Gs,"onBootstrap");i(_s,"onApplicationBootstrap");ne=class ne extends _i.default{constructor(t){if(ne.instance&&process.emitWarning("CommandKit instance already exists. Having multiple instance in same project is discouraged and it may lead to unexpected behavior.",{code:"MultiInstanceWarning"}),!t.client)throw new Error(C.red('"client" is required when instantiating CommandKit.'));super();this.options=t;x(this,z);x(this,it,!1);I(this,"eventInterceptor");I(this,"config",{defaultLocale:Cn.Locale.EnglishUS,getMessageCommandPrefix:i(()=>"!","getMessageCommandPrefix")});I(this,"store",new Map);I(this,"flags",new fn);I(this,"commandsRouter");I(this,"eventsRouter");I(this,"commandHandler",new Ot(this));I(this,"eventHandler",new un(this));I(this,"plugins");I(this,"events",new pn(this));this.plugins=new Et(this),ne.instance||(ne.instance=this),Wi=ne.instance,v(this,z,qi).call(this)}async start(t){if(!c(this,it)){if(!this.options.client)throw new Error(C.red('"client" is required when starting CommandKit.'));if(this.eventInterceptor=new xt(this.client),W)try{Fi(this),await ot()}catch(o){process.env.COMMANDKIT_DEBUG_TYPEGEN&&M.error(o)}if(await this.loadPlugins(),await v(this,z,zi).call(this),this.commandHandler.registerCommandHandler(),this.incrementClientListenersCount(),t!==!1&&!this.options.client.isReady()){this.client.once(Cn.Events.ClientReady,async()=>{await this.commandHandler.registrar.register()}),await this.plugins.execute((r,a)=>{var s;return(s=a.onBeforeClientLogin)==null?void 0:s.call(a,r)});let o=t??this.options.client.token??process.env.TOKEN??process.env.DISCORD_TOKEN;await this.options.client.login(o),await this.plugins.execute((r,a)=>{var s;return(s=a.onAfterClientLogin)==null?void 0:s.call(a,r)})}else this.options.client.isReady()&&await this.commandHandler.registrar.register();h(this,it,!0),await v(this,z,Ji).call(this)}}async loadPlugins(){let o=(await Ce()).plugins.flat(2).filter(r=>mo(r));if(o.length)for(let r of o)await this.plugins.softRegisterPlugin(r)}get started(){return c(this,it)}setPrefixResolver(t){return this.config.getMessageCommandPrefix=t,this}setDefaultLocale(t){return this.config.defaultLocale=t,this}get client(){return this.options.client}async reloadCommands(){await this.commandHandler.reloadCommands()}async reloadEvents(){await this.eventHandler.reloadEvents()}incrementClientListenersCount(){this.options.client.setMaxListeners(this.options.client.getMaxListeners()+1)}decrementClientListenersCount(){this.options.client.setMaxListeners(this.options.client.getMaxListeners()-1)}getAppDirectory(){return hi()}getPath(t){let o=this.getAppDirectory();if(!o)return null;switch(t){case"commands":return(0,tr.join)(o,"commands");case"events":return(0,tr.join)(o,"events");default:return t}}};it=new WeakMap,z=new WeakSet,qi=i(async function(){for(let t of hn)try{await t(this)}catch(o){M.error("Error while executing bootstrap hook: ",o)}finally{hn.delete(t)}hn.clear()},"#bootstrapHooks"),Ji=i(async function(){for(let t of gn)try{await t(this)}catch(o){M.error("Error while executing application bootstrap hook: ",o)}finally{gn.delete(t)}gn.clear()},"#applicationBootstrapHooks"),zi=i(async function(){if(!this.getAppDirectory())return;let o=this.getPath("commands"),r=this.getPath("events");this.commandsRouter=new Lt({entrypoint:o}),await this.plugins.execute((a,s)=>s.onCommandsRouterInit(a)),this.eventsRouter=new $t({entrypoints:[r]}),await this.plugins.execute((a,s)=>s.onEventsRouterInit(a)),await v(this,z,Xi).call(this),await v(this,z,Yi).call(this)},"#init"),Yi=i(async function(){if(this.commandsRouter.isValidPath()){let t=await this.commandsRouter.scan();W&&(0,Vi.writeFileSync)("./.commandkit/commands.json",JSON.stringify(t,null,2))}await this.commandHandler.loadCommands(),this.commandHandler.printBanner()},"#initCommands"),Xi=i(async function(){this.eventsRouter.isValidPath()&&await this.eventsRouter.scan(),await this.eventHandler.loadEvents()},"#initEvents"),i(ne,"CommandKit"),I(ne,"createElement",no),I(ne,"Fragment",to),I(ne,"instance");Te=ne});var ea={};Qe(ea,{version:()=>yn});var yn,xn=g(()=>{"use strict";l();yn="1.0.0-dev.20250528125253"});function vn(n=!1){let e={NODE_ENV:"development",COMMANDKIT_IS_DEV:"true"};return n?Object.assign({},e):Object.assign({},process.env,e)}function En(n=!1){let e={NODE_ENV:"production",COMMANDKIT_IS_DEV:"false"};return n?Object.assign({},e):Object.assign({},process.env,e)}var ta,Ws,qs,na,oa,rr=g(()=>{"use strict";l();i(vn,"DevEnv");i(En,"ProdEnv");ta=[".env",".env.local"],Ws=[".env.development",".env.development.local"],qs=[".env.production",".env.production.local"],na=[...ta,...Ws],oa=[...ta,...qs]});function Js(n){return n?["pipe","pipe","pipe","ipc"]:["pipe","pipe","pipe"]}function wn(n,e,t){var a,s;(0,aa.existsSync)((0,ia.join)(e,n))||Se(`Could not locate the entrypoint file: ${n}`);let o=Js(t),r=(0,ra.spawn)("node",[`--title="CommandKit ${t?"Development":"Production"}"`,"--enable-source-maps",n],{cwd:e,windowsHide:!0,env:t?vn():En(),stdio:o});return(a=r.stdout)==null||a.pipe(process.stdout),(s=r.stderr)==null||s.pipe(process.stderr),r}var ra,ia,aa,ir=g(()=>{"use strict";l();ra=require("child_process");rr();ia=require("path"),aa=require("fs");Ie();i(Js,"getStdio");i(wn,"createAppProcess")});function Ys(n,e,t){let o=n.flattenDiagnosticMessageText(e.messageText,`
|
|
16
16
|
`);if(!e.file)return`${C.red("error")}: ${o}`;let{line:r,character:a}=n.getLineAndCharacterOfPosition(e.file,e.start),s=(0,Mn.relative)(t,e.file.fileName),m=`${r+1}:${a+1}`,u=e.code?`TS${e.code}`:"";return[`${C.bold(C.cyan(s))}:${C.bold(C.yellow(m))} - ${C.red("error")} ${C.gray(u)}`,`${o}`].join(`
|
|
17
17
|
`)}async function la(n){let e=(0,Mn.join)(n,"tsconfig.json");if(!(0,sa.existsSync)(e))return;let t=await Yo(zs),o={getCanonicalFileName:i(u=>u,"getCanonicalFileName"),getCurrentDirectory:t.sys.getCurrentDirectory,getNewLine:i(()=>t.sys.newLine,"getNewLine")},r=t.readConfigFile(e,t.sys.readFile);r.error&&(console.error(C.red(`Error reading tsconfig.json: ${t.formatDiagnostic(r.error,o)}`)),process.exit(1));let a=t.parseJsonConfigFileContent(r.config,t.sys,n);a.options.noEmit=!0;let s=t.createProgram({rootNames:a.fileNames,options:a.options,projectReferences:a.projectReferences}),m=[...s.getOptionsDiagnostics(),...s.getGlobalDiagnostics(),...s.getSyntacticDiagnostics(),...s.getSemanticDiagnostics()];if(m.length>0){console.log(""),console.error(C.bold(C.red("Type checking failed with the following errors:"))),console.log("");let u=new Map;for(let b of m){let y=b.file?b.file.fileName:"Global";u.has(y)||u.set(y,[]),u.get(y).push(b)}let d=m.length,p=0;for(let[b,y]of u)for(let E of y)p++,console.log(Ys(t,E,n)),p<d&&console.log("");console.log(""),console.error(C.bold(C.red(`Found ${d} error${d>1?"s":""}`))),console.log(""),process.exit(1)}console.log(C.green("\u2713 Type checking completed successfully."))}var sa,Mn,zs,ca=g(()=>{"use strict";l();sa=require("fs");Ie();Mn=require("path");ye();zs="TypeScript must be installed in order to use the type checker. Please install it using `npm install typescript` or `yarn add typescript`";i(Ys,"formatDiagnostic");i(la,"performTypeCheck")});async function Sn({plugins:n,esbuildPlugins:e,isDev:t,configPath:o}){var m;let r=await Ce(o);!t&&!((m=r==null?void 0:r.typescript)!=null&&m.ignoreBuildErrors)&&await la(o||process.cwd());let a=new wt(n||[]),s=a.isEmpty()?[]:[a.toEsbuildPlugin()];e!=null&&e.length&&s.push(...e.map(Co));try{let u=t?".commandkit":r.distDir;await(0,ga.rimraf)(u),await(0,pa.build)({esbuildPlugins:s,watch:!1,banner:{js:t?"":"/* Optimized production build generated by commandkit */"},cjsInterop:!0,dts:!1,clean:!0,format:["esm"],shims:!0,keepNames:!0,minify:!1,esbuildOptions:i(d=>(d.jsx="automatic",d.jsxImportSource="commandkit",d),"esbuildOptions"),minifyIdentifiers:!1,minifySyntax:!1,silent:!!t,splitting:!0,skipNodeModulesBundle:!0,name:"CommandKit",sourcemap:!0,target:"node16",outDir:u,env:t?vn(!0):En(!0),entry:["src",`!${r.distDir}`,"!.commandkit","!**/*.test.*","!**/*.spec.*"]}),await Oi("src",u),await Qs(o||process.cwd(),!!t,r.distDir)}catch(u){console.error("Build failed:",u),u instanceof Error&&console.error("Error details:",u.stack),process.exit(1)}finally{await a.cleanup()}}async function Qs(n,e,t){let o=`/* Entrypoint File Generated By CommandKit */
|
|
18
18
|
${e?`
|