@pikokr/command.ts 5.3.0-dev.64b0ef9 → 5.3.1-dev.a03aefb

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ github:
2
+ - pikokr
package/dist/index.d.ts CHANGED
@@ -29,6 +29,7 @@ declare class BaseComponent {
29
29
  hooks: ComponentHookStore;
30
30
  argTypes: Collection<number, ComponentArgument>;
31
31
  _init(method: Function, argTypes: unknown[]): void;
32
+ executeGlobalHook(target: object, name: string, args: unknown[]): Promise<void>;
32
33
  executeHook(target: object, name: string, args: unknown[]): Promise<void>;
33
34
  execute(target: object, args: unknown[], beforeCallArgs?: unknown[]): Promise<any>;
34
35
  }
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var ne=Object.create;var B=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ae=Object.prototype.hasOwnProperty;var a=(n,t)=>B(n,"name",{value:t,configurable:!0});var f=(n,t)=>()=>(n&&(t=n(n=0)),t);var Ft=(n,t)=>{for(var e in t)B(n,e,{get:t[e],enumerable:!0})},jt=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of se(t))!ae.call(n,s)&&s!==e&&B(n,s,{get:()=>t[s],enumerable:!(o=re(t,s))||o.enumerable});return n};var C=(n,t,e)=>(e=n!=null?ne(ie(n)):{},jt(t||!n||!n.__esModule?B(e,"default",{value:n,enumerable:!0}):e,n)),ce=n=>jt(B({},"__esModule",{value:!0}),n);var z,xe,ft,Y,ut,tt,O=f(()=>{"use strict";z=Symbol(),xe=Symbol(),ft=Symbol(),Y=Symbol(),ut=Symbol(),tt=Symbol()});var Et,dt,et,gt=f(()=>{"use strict";Et=require("discord.js");O();dt=a((n,t)=>{let e=Reflect.getMetadata(ut,n,t);return e||(e=new Et.Collection,Reflect.defineMetadata(ut,e,n,t)),e},"getComponentHookStore"),et=a((n,t)=>(e,o)=>{let s=dt(e,o),r=s.get(n);r||(r=[],s.set(n,r)),r.unshift(t)},"createComponentHook")});var ht,Z,me,y,yt,J,$=f(()=>{"use strict";ht=require("discord.js");gt();O();Z=a(n=>{let t=Reflect.getMetadata(z,n);return t||(t=new ht.Collection,Reflect.defineMetadata(z,t,n)),t},"getComponentStore"),me=a((n,t)=>Z(n).get(t),"getComponent"),y=a(n=>(t,e)=>{n._init(Reflect.get(t,e),Reflect.getMetadata("design:paramtypes",t,e));let o=dt(t,e);n.hooks=o;let s=Z(t);yt(t,e).forEach((c,i)=>{var m;(m=n.argTypes.get(i))==null||m.decorators.push(c)}),s.set(e,n)},"createComponentDecorator"),yt=a((n,t)=>{let e=Reflect.getMetadata(z,n,t);return e||(e=new ht.Collection,Reflect.defineMetadata(z,e,n,t)),e},"getComponentArgumentStore"),J=a(n=>t=>(e,o,s)=>{var r=new n(t);yt(e,o).set(s,r)},"createArgumentDecorator")});var A,xt=f(()=>{"use strict";A=class{constructor(t){this.type=t,this.decorators=[]}};a(A,"ComponentArgument")});var Lt,H,Ot=f(()=>{"use strict";Lt=C(require("lodash")),H=class{constructor(t){typeof t=="object"?this.options=Lt.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};a(H,"ComponentArgumentDecorator")});var h,pe,ot=f(()=>{"use strict";$();W();h=class extends x{constructor(t){super(),this.options=t}};a(h,"ApplicationCommandComponent");pe=a(n=>y(new h(n)),"applicationCommand")});var R,$t,bt=f(()=>{"use strict";G();R=class extends H{};a(R,"ApplicationCommandOption");$t=J(R)});var At,T,K,Q=f(()=>{"use strict";At=C(require("lodash"));W();$();T=class extends x{constructor(t){super(),this.options=At.default.merge({emitter:"discord"},t)}};a(T,"ListenerComponent");K=a(n=>y(new T(n)),"listener")});var F,M,nt=f(()=>{"use strict";W();$();F=class extends x{constructor(t){super(),this.options=t}};a(F,"ConverterComponent");M=a(n=>y(new F(n)),"argConverter")});var Wt,rt,le,Dt=f(()=>{"use strict";Wt=require("discord.js");O();rt=a(n=>{let t=Reflect.getMetadata(ft,n);return t||(t=new Wt.Collection,Reflect.defineMetadata(ft,t,n)),t},"getModuleHookStore"),le=a(n=>(t,e)=>{let o=rt(t),s=o.get(n);s||(s=[],o.set(n,s)),s.push(Reflect.get(t,e))},"moduleHook")});var st=f(()=>{"use strict";Dt();gt()});var D,Pt,Nt,qt,Ut,P,Ct=f(()=>{"use strict";D=C(require("chalk")),Pt=require("discord.js"),Nt=C(require("lodash"));wt();st();Q();O();qt=C(require("walk-sync")),Ut=C(require("path")),P=class{constructor(t,e){this.client=e,this.extensions=[],this.emitters=new Pt.Collection,this.globalHooks={},this.logger=t.getChildLogger({prefix:[D.default.green("[Registry]")]})}addGlobalHook(t,e){let o=this.globalHooks[t];o||(o=[],this.globalHooks[t]=o),o.push(e)}getComponentsWithTypeGlobal(t){let e=[];for(let o of this.extensions)e.push(...this.getComponentsWithType(o,t));return e}getComponentsWithType(t,e){let o=Z(t);return Array.from(o.filter(s=>s.constructor===e).values())}registerEventListeners(t){let e=this.getComponentsWithType(t,T);for(let o of e){let s=this.emitters.get(o.options.emitter);if(s){let r=o.method.bind(t);Reflect.defineMetadata("bound",r,o),s.addListener(o.options.event,r)}}}unregisterEventListeners(t){let e=this.getComponentsWithType(t,T);for(let o of e){let s=this.emitters.get(o.options.emitter),r=Reflect.getMetadata("bound",o);s&&r&&s.removeListener(o.options.event,r)}}async loadAllModulesInDirectory(t){let e=[],o=(0,qt.default)(t).filter(s=>s.endsWith(".ts")||s.endsWith(".js"));for(let s of o){if(s.endsWith(".d.ts"))continue;let r=Ut.default.join(t,s);e.push(...await this.loadModulesAtPath(r))}return e}async loadModulesAtPath(t){this.logger.info(`Loading module at path ${D.default.green(t)}`);let e=require.resolve(t),o=require(e);if(typeof o.setup!="function")throw new Error("Extension must have a setup function");let s=await o.setup(this.client);return this.registerModules(s,e)}async registerModules(t,e){let o=[];if(t instanceof Array)for(let s of t)await this.registerModule(s),Reflect.defineMetadata(tt,e,s),o.push(s);else await this.registerModule(t),Reflect.defineMetadata(tt,e,t),o.push(t);return o}async reloadModules(){let t=[],e=new Set,o=[...this.extensions];for(let s of o){let r=Reflect.getMetadata(tt,s);!r||(this.logger.info(`Unloading module: ${D.default.green(s.constructor.name)}`),e.add(r),await this.unregisterModule(s),delete require.cache[require.resolve(r)])}for(let s of e)try{let r=await this.loadModulesAtPath(s);t.push({file:s,result:!0,extensions:r})}catch(r){t.push({file:s,result:!1,error:r})}return t}async registerModule(t){Reflect.defineMetadata(Y,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${D.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),Nt.default.remove(this.extensions,e=>e===t),this.logger.info(`Module unregistered: ${D.default.green(t.constructor.name)}`)}runModuleHook(t,e,...o){let r=rt(t).get(e);if(r)for(let c of r)c.call(t,...o)}registerEventEmitter(t,e){this.emitters.set(t,e)}};a(P,"Registry")});var Mt=f(()=>{"use strict";Ct();St()});var Bt,zt,N,vt=f(()=>{"use strict";Bt=C(require("chalk")),zt=require("discord.js");nt();Mt();N=class{get commandClient(){return j.getFromModule(this)}get client(){return this.commandClient.discord}get logger(){return this._logger||(this._logger=this.commandClient.logger.getChildLogger({prefix:[Bt.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}async convertArguments(t,e,o,s){let r=new zt.Collection;for(let c of this.commandClient.registry.extensions)for(let i of this.commandClient.registry.getComponentsWithType(c,F))i.options.component==t&&r.set(i.options.type,{component:i,ext:c});for(let[c,i]of o){let m=r.get(i.type);if(!m){e[c]=void 0;continue}let u=await s(i,c,m.component);e[c]=await m.component.execute(m.ext,u)}}};a(N,"Extension")});var Zt,E,kt=f(()=>{"use strict";Zt=C(require("chalk"));vt();E=class extends N{get logger(){return this._logger||(this._logger=this.commandClient.ctsLogger.getChildLogger({prefix:[Zt.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}};a(E,"CTSExtension")});var S,p,V,v,b,Rt=f(()=>{"use strict";S=C(require("chalk")),p=require("discord.js");ot();bt();Q();nt();kt();V=function(n,t,e,o){var s=arguments.length,r=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,t,e,o);else for(var i=n.length-1;i>=0;i--)(c=n[i])&&(r=(s<3?c(r):s>3?c(t,e,r):c(t,e))||r);return s>3&&r&&Object.defineProperty(t,e,r),r},v=function(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)},b=class extends E{constructor(t){super(),this.config=t,this.unmanagedCommands=[]}registerUnmanagedCommand(t){this.unmanagedCommands.push(t)}async interactionCreate(t){var e;try{if(t.type!==p.InteractionType.ApplicationCommand)return;let o=null,s=null,r=this.commandClient.registry.extensions,c=null,i=null;t.commandType===p.ApplicationCommandType.ChatInput&&(c=t.options.getSubcommand(!1),i=t.options.getSubcommandGroup(!1));t:for(let m of r){let u=this.commandClient.registry.getComponentsWithType(m,h);if(c){for(let l of u)if(!(!l.subcommandGroup&&!l.subcommandGroupChild)){if(l.subcommandGroupChild&&l.subcommandGroupChild.parent.options.name===t.commandName&&l.subcommandGroupChild.options.name===i&&l.options.name===c){s=m,o=l;break t}if(l.subcommandGroup&&!i&&l.subcommandGroup.options.name===t.commandName&&l.options.name===c){s=m,o=l;break t}}}else for(let l of u)if(l.options.name===t.commandName){s=m,o=l;break t}}if(o&&s){let m=[];await this.convertArguments(h,m,o.argTypes,()=>[t]);for(let[u,l]of o.argTypes){let d=null;for(let g of l.decorators)if(g instanceof R){if([p.ApplicationCommandOptionType.Subcommand,p.ApplicationCommandOptionType.SubcommandGroup].includes(g.options.type)&&t.isChatInputCommand()){if(g.options.type===p.ApplicationCommandOptionType.Subcommand){d=t.options.getSubcommand()===g.options.name;break}if(g.options.type===p.ApplicationCommandOptionType.SubcommandGroup){d=t.options.getSubcommandGroup()===g.options.name;break}}d=(e=t.options.get(g.options.name,!1))==null?void 0:e.value;break}d&&(m[u]=d)}await o.execute(s,m,[t])}}catch(o){this.commandClient.emit("applicationCommandInvokeError",o,t)}}async sync(){let t=this.commandClient;this.logger.info("Trying to sync commands...");let e=[],o=new p.Collection,s=new p.Collection;for(let r of t.registry.getComponentsWithTypeGlobal(h)){if(r.subcommandGroup){let i=s.get(r.subcommandGroup.options.name);if(!i){if(i={...r.subcommandGroup.options,type:p.ApplicationCommandType.ChatInput},r.subcommandGroup.guilds)for(let u of r.subcommandGroup.guilds){let l=o.get(u);l||(l=[],o.set(u,l))}else e.push(i);s.set(r.subcommandGroup.options.name,i)}i.options||(i.options=[]);let m=[];for(let[,u]of r.argTypes){let l=u.decorators.find(d=>d.constructor===R);l&&m.push(l.options)}i.options.push({...r.options,type:p.ApplicationCommandOptionType.Subcommand,options:m});continue}else if(r.subcommandGroupChild){let i=r.subcommandGroupChild.parent,m=s.get(i.options.name);if(!m){if(m={...i.options,type:p.ApplicationCommandType.ChatInput},i.guilds)for(let d of i.guilds){let g=o.get(d);g||(g=[],o.set(d,g))}else e.push(m);s.set(i.options.name,m)}m.options||(m.options=[]);let u=m.options.find(d=>d.name===r.subcommandGroupChild.options.name);u||(u={type:p.ApplicationCommandOptionType.SubcommandGroup,...r.subcommandGroupChild.options},m.options.push(u)),u.options||(u.options=[]);let l=[];for(let[,d]of r.argTypes){let g=d.decorators.find(k=>k.constructor===R);g&&l.push(g.options)}u.options.push({...r.options,type:p.ApplicationCommandOptionType.Subcommand,options:l});continue}let c={...r.options};if(c.type===p.ApplicationCommandType.ChatInput){c.options=[];for(let[,i]of r.argTypes){let m=i.decorators.find(u=>u.constructor===R);m&&c.options.push(m.options)}}if(await r.executeHook(this,"beforeSync",[c,r]),r.options.guilds){for(let i of r.options.guilds){let m=o.get(i);m||(m=[],o.set(i,m)),m.push(c)}continue}e.push(c)}for(let{guilds:r,...c}of this.unmanagedCommands)if(r){for(let i of r){let m=o.get(i);m||(m=[],o.set(i,m)),m.push(c)}continue}else e.push(c);if(this.config.guilds){for(let r of this.config.guilds){let c=o.get(r);c||(c=[],o.set(r,c)),c.push(...e)}e=[]}if(o.size)for(let[r,c]of o)try{let i=await this.client.guilds.fetch(r);await i.fetch(),this.logger.info(`Processing ${S.default.green(c.length)} commands(${c.map(m=>S.default.blue(m.name)).join(", ")}) for guild ${S.default.green(i.name)}(${S.default.blue(i.id)})`),await i.commands.set(c),this.logger.info(`Successfully registered commands for guild ${S.default.green(i.name)}(${S.default.blue(i.id)})`)}catch(i){this.logger.error(`Failed to register commands to guild ${S.default.green(r)}: ${i.message}`)}if(e.length)try{this.logger.info(`Processing ${S.default.green(e.length)} commands(${e.map(r=>S.default.blue(r.name)).join(", ")}) for application scope...`),await this.client.application.commands.set(e),this.logger.info("Successfully registered commands.")}catch(r){this.logger.error(`Failed to register commands to global: ${r.message}`)}}async chatInteraction(t){return t}async messageInteraction(t){return t}async userInteraction(t){return t}async commandInteraction(t){return t}};a(b,"ApplicationCommandExtension");V([K({event:"interactionCreate"}),v("design:type",Function),v("design:paramtypes",[typeof p.Interaction>"u"?Object:p.Interaction])],b.prototype,"interactionCreate",null);V([M({component:h,parameterless:!0,type:p.ChatInputCommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.ChatInputCommandInteraction>"u"?Object:p.ChatInputCommandInteraction])],b.prototype,"chatInteraction",null);V([M({component:h,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction>"u"?Object:p.MessageContextMenuCommandInteraction])],b.prototype,"messageInteraction",null);V([M({component:h,parameterless:!0,type:p.UserContextMenuCommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"userInteraction",null);V([M({component:h,parameterless:!0,type:p.CommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"commandInteraction",null)});var w,fe,It=f(()=>{"use strict";$();W();w=class extends x{constructor(t){super(),this.options=t}};a(w,"TextCommandComponent");fe=a(n=>y(new w(n)),"command")});var L,ue,Ht=f(()=>{"use strict";G();G();L=class extends H{};a(L,"TextCommandRestOption");ue=J(L)});var q,it,_,I,Jt=f(()=>{"use strict";Q();q=require("discord.js");kt();It();Ht();G();it=function(n,t,e,o){var s=arguments.length,r=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,t,e,o);else for(var i=n.length-1;i>=0;i--)(c=n[i])&&(r=(s<3?c(r):s>3?c(t,e,r):c(t,e))||r);return s>3&&r&&Object.defineProperty(t,e,r),r},_=function(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)},I=class extends E{constructor(t){super(),this.config=t}async processPrefix(t){let e=t.content,o=this.config.prefix;if(typeof o=="function"&&(o=await o(t)),typeof o=="string")return e.startsWith(o)?o.length:null;if(o instanceof Array){let s=o.find(r=>e.startsWith(r));return s?s.length:null}return null}async messageCreate(t){try{let e=await this.processPrefix(t);if(!e)return;let o=t.content.slice(e),s=[],r=new Map;for(let d of this.commandClient.registry.extensions)for(let g of this.commandClient.registry.getComponentsWithType(d,w))s.push(g),r.set(g,d);let c=0,i=s.find(d=>{let g=[d.options.name];d.options.aliases&&g.push(...d.options.aliases);for(let k of g)if(o.startsWith(k))return o.length===k.length?(c=k.length,!0):(c=k.length,o.startsWith(k+" "));return!1});if(!i)return;let m=r.get(i);if(!m)return;t.command=i;let u=[],l=o.slice(c+1).split(/ /g);await this.convertArguments(w,u,i.argTypes,async(d,g,k)=>{if(k.options.parameterless)return[t];if(d.decorators.find(lt=>lt.constructor===L)){let lt=l.join(" ");return l=[],[lt,t]}return[l.shift(),t]}),await i.execute(m,u,[t])}catch(e){this.commandClient.emit("textCommandInvokeError",e,t)}}async mesage(t){return t}async str(t){return t}async num(t){return Number(t)}};a(I,"TextCommandExtension");it([K({event:"messageCreate",emitter:"discord"}),_("design:type",Function),_("design:paramtypes",[typeof q.Message>"u"?Object:q.Message])],I.prototype,"messageCreate",null);it([M({component:w,type:q.Message,parameterless:!0}),_("design:type",Function),_("design:paramtypes",[typeof q.Message>"u"?Object:q.Message])],I.prototype,"mesage",null);it([M({component:w,type:String}),_("design:type",Function),_("design:paramtypes",[String])],I.prototype,"str",null);it([M({component:w,type:Number}),_("design:type",Function),_("design:paramtypes",[String])],I.prototype,"num",null)});var Vt={};Ft(Vt,{CommandClient:()=>j});var at,ct,Kt,Qt,j,St=f(()=>{"use strict";at=C(require("chalk")),ct=require("discord.js"),Kt=C(require("events")),Qt=require("tslog");Rt();Jt();O();Ct();j=class extends Kt.default{constructor(t,e=new Qt.Logger({dateTimeTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone}),o={}){super(),this.discord=t,this.logger=e,this.owners=new Set,this.ctsLogger=e.getChildLogger({prefix:[at.default.blue("[command.ts]")],displayFilePath:"hidden",displayFunctionName:!1,...o}),this.registry=new P(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}async isOwner(t){return this.owners.has(t.id)}async fetchOwners(){if(!this.discord.application)throw new Error("The client is not logged in.");this.ctsLogger.info("Fetching owners..."),await this.discord.application.fetch();let t=this.discord.application.owner;if(!t)throw new Error("Cannot find application owner");let e=[];if(t instanceof ct.User)this.owners.add(t.id),e.push(t.tag);else if(t instanceof ct.Team)for(let[o,s]of t.members)this.owners.add(o),e.push(s.user.tag);this.ctsLogger.info(`Fetched ${at.default.green(e.length)} owners(${e.map(o=>at.default.blue(o)).join(", ")})`)}async enableApplicationCommandsExtension(t){await this.registry.registerModule(new b(t)),this.ctsLogger.info("Application command extension enabled.")}async enableTextCommandsExtension(t){await this.registry.registerModule(new I(t)),this.ctsLogger.info("Text command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===b)}static getFromModule(t){return Reflect.getMetadata(Y,t)}};a(j,"CommandClient")});var Tt,x,W=f(()=>{"use strict";Tt=require("discord.js");xt();x=class{hooks=new Tt.Collection;argTypes=new Tt.Collection;_init(t,e){this.method=t;for(let o=0;o<e.length;o++){let s=e[o];this.argTypes.set(o,new A(s))}}async executeHook(t,e,o){let s=this.hooks.get(e);if(!s)return;let{CommandClient:r}=await Promise.resolve().then(()=>(St(),Vt)),c=r.getFromModule(t),i=c.registry.globalHooks[e];i&&s.unshift(...i);for(let m of s)await m.call(null,c,...o)}async execute(t,e,o=e){await this.executeHook(t,"beforeCall",o);let s;try{s=await this.method.call(t,...e),await this.executeHook(t,"afterCall",[...o,s])}catch(r){throw await this.executeHook(t,"invokeError",[r,...o]),r}return s}};a(x,"BaseComponent")});var Io,wt=f(()=>{"use strict";Io=require("reflect-metadata");$();xt();Ot();W()});var U,_t=f(()=>{"use strict";U=class{};a(U,"OwnerOnlyError")});var mt,Xt,de,Yt=f(()=>{"use strict";mt=require("discord.js");st();_t();Xt=a(n=>et("beforeCall",n),"createCheckDecorator"),de=Xt(async(n,t)=>{let e=!1;if(t instanceof mt.BaseInteraction?e=await n.isOwner(t.user):t instanceof mt.Message&&(e=await n.isOwner(t.author)),!e)throw new U})});var ge,te=f(()=>{"use strict";ge=a(n=>(t,e,o)=>{for(let s of n)s(t,e,o)},"mergeMethodDecorators")});var ee=f(()=>{"use strict";Yt();_t();te()});var oe=f(()=>{"use strict";vt()});var G=f(()=>{"use strict";wt();st();nt();ee();Q();Mt();oe()});var he={};Ft(he,{ApplicationCommandComponent:()=>h,ApplicationCommandExtension:()=>b,BaseComponent:()=>x,CommandClient:()=>j,ComponentArgument:()=>A,ComponentArgumentDecorator:()=>H,ConverterComponent:()=>F,Extension:()=>N,ListenerComponent:()=>T,OwnerOnlyError:()=>U,Registry:()=>P,SubCommandGroup:()=>pt,SubCommandGroupChild:()=>X,TextCommandComponent:()=>w,TextCommandRestOption:()=>L,applicationCommand:()=>pe,argConverter:()=>M,command:()=>fe,createArgumentDecorator:()=>J,createCheckDecorator:()=>Xt,createComponentDecorator:()=>y,createComponentHook:()=>et,getComponent:()=>me,getComponentArgumentStore:()=>yt,getComponentStore:()=>Z,getModuleHookStore:()=>rt,listener:()=>K,mergeMethodDecorators:()=>ge,moduleHook:()=>le,option:()=>$t,ownerOnly:()=>de,rest:()=>ue});module.exports=ce(he);G();ot();bt();var Gt=require("discord.js");G();ot();var pt=class{constructor(t,e){this.options=t,this.guilds=e}command(t){let e=new h({type:Gt.ApplicationCommandType.ChatInput,...t});return e.subcommandGroup=this,y(e)}createChild(t){return new X(t,this)}};a(pt,"SubCommandGroup");var X=class{constructor(t,e){this.options=t,this.parent=e}command(t){let e=new h({type:Gt.ApplicationCommandType.ChatInput,...t});return e.subcommandGroupChild=this,y(e)}};a(X,"SubCommandGroupChild");Rt();It();Ht();0&&(module.exports={ApplicationCommandComponent,ApplicationCommandExtension,BaseComponent,CommandClient,ComponentArgument,ComponentArgumentDecorator,ConverterComponent,Extension,ListenerComponent,OwnerOnlyError,Registry,SubCommandGroup,SubCommandGroupChild,TextCommandComponent,TextCommandRestOption,applicationCommand,argConverter,command,createArgumentDecorator,createCheckDecorator,createComponentDecorator,createComponentHook,getComponent,getComponentArgumentStore,getComponentStore,getModuleHookStore,listener,mergeMethodDecorators,moduleHook,option,ownerOnly,rest});
1
+ "use strict";var ne=Object.create;var B=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ae=Object.prototype.hasOwnProperty;var c=(r,t)=>B(r,"name",{value:t,configurable:!0});var f=(r,t)=>()=>(r&&(t=r(r=0)),t);var jt=(r,t)=>{for(var e in t)B(r,e,{get:t[e],enumerable:!0})},At=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of se(t))!ae.call(r,s)&&s!==e&&B(r,s,{get:()=>t[s],enumerable:!(o=re(t,s))||o.enumerable});return r};var C=(r,t,e)=>(e=r!=null?ne(ie(r)):{},At(t||!r||!r.__esModule?B(e,"default",{value:r,enumerable:!0}):e,r)),ce=r=>At(B({},"__esModule",{value:!0}),r);var z,xe,ut,Y,dt,tt,L=f(()=>{"use strict";z=Symbol(),xe=Symbol(),ut=Symbol(),Y=Symbol(),dt=Symbol(),tt=Symbol()});var Et,gt,et,ht=f(()=>{"use strict";Et=require("discord.js");L();gt=c((r,t)=>{let e=Reflect.getMetadata(dt,r,t);return e||(e=new Et.Collection,Reflect.defineMetadata(dt,e,r,t)),e},"getComponentHookStore"),et=c((r,t)=>(e,o)=>{let s=gt(e,o),n=s.get(r);n||(n=[],s.set(r,n)),n.unshift(t)},"createComponentHook")});var yt,Z,me,y,xt,J,O=f(()=>{"use strict";yt=require("discord.js");ht();L();Z=c(r=>{let t=Reflect.getMetadata(z,r);return t||(t=new yt.Collection,Reflect.defineMetadata(z,t,r)),t},"getComponentStore"),me=c((r,t)=>Z(r).get(t),"getComponent"),y=c(r=>(t,e)=>{r._init(Reflect.get(t,e),Reflect.getMetadata("design:paramtypes",t,e));let o=gt(t,e);r.hooks=o;let s=Z(t);xt(t,e).forEach((a,i)=>{var m;(m=r.argTypes.get(i))==null||m.decorators.push(a)}),s.set(e,r)},"createComponentDecorator"),xt=c((r,t)=>{let e=Reflect.getMetadata(z,r,t);return e||(e=new yt.Collection,Reflect.defineMetadata(z,e,r,t)),e},"getComponentArgumentStore"),J=c(r=>t=>(e,o,s)=>{var n=new r(t);xt(e,o).set(s,n)},"createArgumentDecorator")});var $,bt=f(()=>{"use strict";$=class{constructor(t){this.type=t,this.decorators=[]}};c($,"ComponentArgument")});var Lt,G,Ot=f(()=>{"use strict";Lt=C(require("lodash")),G=class{constructor(t){typeof t=="object"?this.options=Lt.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};c(G,"ComponentArgumentDecorator")});var h,pe,ot=f(()=>{"use strict";O();W();h=class extends x{constructor(t){super(),this.options=t}};c(h,"ApplicationCommandComponent");pe=c(r=>y(new h(r)),"applicationCommand")});var H,$t,Ct=f(()=>{"use strict";_();H=class extends G{};c(H,"ApplicationCommandOption");$t=J(H)});var Wt,I,K,Q=f(()=>{"use strict";Wt=C(require("lodash"));W();O();I=class extends x{constructor(t){super(),this.options=Wt.default.merge({emitter:"discord"},t)}};c(I,"ListenerComponent");K=c(r=>y(new I(r)),"listener")});var F,M,nt=f(()=>{"use strict";W();O();F=class extends x{constructor(t){super(),this.options=t}};c(F,"ConverterComponent");M=c(r=>y(new F(r)),"argConverter")});var Dt,rt,le,Pt=f(()=>{"use strict";Dt=require("discord.js");L();rt=c(r=>{let t=Reflect.getMetadata(ut,r);return t||(t=new Dt.Collection,Reflect.defineMetadata(ut,t,r)),t},"getModuleHookStore"),le=c(r=>(t,e)=>{let o=rt(t),s=o.get(r);s||(s=[],o.set(r,s)),s.push(Reflect.get(t,e))},"moduleHook")});var st=f(()=>{"use strict";Pt();ht()});var D,Nt,qt,Ut,Bt,P,wt=f(()=>{"use strict";D=C(require("chalk")),Nt=require("discord.js"),qt=C(require("lodash"));Mt();st();Q();L();Ut=C(require("walk-sync")),Bt=C(require("path")),P=class{constructor(t,e){this.client=e,this.extensions=[],this.emitters=new Nt.Collection,this.globalHooks={},this.logger=t.getChildLogger({prefix:[D.default.green("[Registry]")]})}addGlobalHook(t,e){let o=this.globalHooks[t];o||(o=[],this.globalHooks[t]=o),o.push(e)}getComponentsWithTypeGlobal(t){let e=[];for(let o of this.extensions)e.push(...this.getComponentsWithType(o,t));return e}getComponentsWithType(t,e){let o=Z(t);return Array.from(o.filter(s=>s.constructor===e).values())}registerEventListeners(t){let e=this.getComponentsWithType(t,I);for(let o of e){let s=this.emitters.get(o.options.emitter);if(s){let n=o.method.bind(t);Reflect.defineMetadata("bound",n,o),s.addListener(o.options.event,n)}}}unregisterEventListeners(t){let e=this.getComponentsWithType(t,I);for(let o of e){let s=this.emitters.get(o.options.emitter),n=Reflect.getMetadata("bound",o);s&&n&&s.removeListener(o.options.event,n)}}async loadAllModulesInDirectory(t){let e=[],o=(0,Ut.default)(t).filter(s=>s.endsWith(".ts")||s.endsWith(".js"));for(let s of o){if(s.endsWith(".d.ts"))continue;let n=Bt.default.join(t,s);e.push(...await this.loadModulesAtPath(n))}return e}async loadModulesAtPath(t){this.logger.info(`Loading module at path ${D.default.green(t)}`);let e=require.resolve(t),o=require(e);if(typeof o.setup!="function")throw new Error("Extension must have a setup function");let s=await o.setup(this.client);return this.registerModules(s,e)}async registerModules(t,e){let o=[];if(t instanceof Array)for(let s of t)await this.registerModule(s),Reflect.defineMetadata(tt,e,s),o.push(s);else await this.registerModule(t),Reflect.defineMetadata(tt,e,t),o.push(t);return o}async reloadModules(){let t=[],e=new Set,o=[...this.extensions];for(let s of o){let n=Reflect.getMetadata(tt,s);!n||(this.logger.info(`Unloading module: ${D.default.green(s.constructor.name)}`),e.add(n),await this.unregisterModule(s),delete require.cache[require.resolve(n)])}for(let s of e)try{let n=await this.loadModulesAtPath(s);t.push({file:s,result:!0,extensions:n})}catch(n){t.push({file:s,result:!1,error:n})}return t}async registerModule(t){Reflect.defineMetadata(Y,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${D.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),qt.default.remove(this.extensions,e=>e===t),this.logger.info(`Module unregistered: ${D.default.green(t.constructor.name)}`)}runModuleHook(t,e,...o){let n=rt(t).get(e);if(n)for(let a of n)a.call(t,...o)}registerEventEmitter(t,e){this.emitters.set(t,e)}};c(P,"Registry")});var St=f(()=>{"use strict";wt();it()});var zt,Zt,N,kt=f(()=>{"use strict";zt=C(require("chalk")),Zt=require("discord.js");nt();St();N=class{get commandClient(){return j.getFromModule(this)}get client(){return this.commandClient.discord}get logger(){return this._logger||(this._logger=this.commandClient.logger.getChildLogger({prefix:[zt.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}async convertArguments(t,e,o,s){let n=new Zt.Collection;for(let a of this.commandClient.registry.extensions)for(let i of this.commandClient.registry.getComponentsWithType(a,F))i.options.component==t&&n.set(i.options.type,{component:i,ext:a});for(let[a,i]of o){let m=n.get(i.type);if(!m){e[a]=void 0;continue}let u=await s(i,a,m.component);e[a]=await m.component.execute(m.ext,u)}}};c(N,"Extension")});var Jt,A,vt=f(()=>{"use strict";Jt=C(require("chalk"));kt();A=class extends N{get logger(){return this._logger||(this._logger=this.commandClient.ctsLogger.getChildLogger({prefix:[Jt.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}};c(A,"CTSExtension")});var S,p,V,k,b,Ht=f(()=>{"use strict";S=C(require("chalk")),p=require("discord.js");ot();Ct();Q();nt();vt();V=function(r,t,e,o){var s=arguments.length,n=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,e,o);else for(var i=r.length-1;i>=0;i--)(a=r[i])&&(n=(s<3?a(n):s>3?a(t,e,n):a(t,e))||n);return s>3&&n&&Object.defineProperty(t,e,n),n},k=function(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)},b=class extends A{constructor(t){super(),this.config=t,this.unmanagedCommands=[]}registerUnmanagedCommand(t){this.unmanagedCommands.push(t)}async interactionCreate(t){var e;try{if(t.type!==p.InteractionType.ApplicationCommand)return;let o=null,s=null,n=this.commandClient.registry.extensions,a=null,i=null;t.commandType===p.ApplicationCommandType.ChatInput&&(a=t.options.getSubcommand(!1),i=t.options.getSubcommandGroup(!1));t:for(let m of n){let u=this.commandClient.registry.getComponentsWithType(m,h);if(a){for(let l of u)if(!(!l.subcommandGroup&&!l.subcommandGroupChild)){if(l.subcommandGroupChild&&l.subcommandGroupChild.parent.options.name===t.commandName&&l.subcommandGroupChild.options.name===i&&l.options.name===a){s=m,o=l;break t}if(l.subcommandGroup&&!i&&l.subcommandGroup.options.name===t.commandName&&l.options.name===a){s=m,o=l;break t}}}else for(let l of u)if(l.options.name===t.commandName){s=m,o=l;break t}}if(o&&s){let m=[];await this.convertArguments(h,m,o.argTypes,()=>[t]);for(let[u,l]of o.argTypes){let d=null;for(let g of l.decorators)if(g instanceof H){if([p.ApplicationCommandOptionType.Subcommand,p.ApplicationCommandOptionType.SubcommandGroup].includes(g.options.type)&&t.isChatInputCommand()){if(g.options.type===p.ApplicationCommandOptionType.Subcommand){d=t.options.getSubcommand()===g.options.name;break}if(g.options.type===p.ApplicationCommandOptionType.SubcommandGroup){d=t.options.getSubcommandGroup()===g.options.name;break}}d=(e=t.options.get(g.options.name,!1))==null?void 0:e.value;break}d&&(m[u]=d)}try{await o.executeGlobalHook(s,"beforeApplicationCommandCall",[t]),await o.execute(s,m,[t])}finally{await o.executeGlobalHook(s,"afterApplicationCommandCall",[t])}}}catch(o){this.commandClient.emit("applicationCommandInvokeError",o,t)}}async sync(){let t=this.commandClient;this.logger.info("Trying to sync commands...");let e=[],o=new p.Collection,s=new p.Collection;for(let n of t.registry.getComponentsWithTypeGlobal(h)){if(n.subcommandGroup){let i=s.get(n.subcommandGroup.options.name);if(!i){if(i={...n.subcommandGroup.options,type:p.ApplicationCommandType.ChatInput},n.subcommandGroup.guilds)for(let u of n.subcommandGroup.guilds){let l=o.get(u);l||(l=[],o.set(u,l))}else e.push(i);s.set(n.subcommandGroup.options.name,i)}i.options||(i.options=[]);let m=[];for(let[,u]of n.argTypes){let l=u.decorators.find(d=>d.constructor===H);l&&m.push(l.options)}i.options.push({...n.options,type:p.ApplicationCommandOptionType.Subcommand,options:m});continue}else if(n.subcommandGroupChild){let i=n.subcommandGroupChild.parent,m=s.get(i.options.name);if(!m){if(m={...i.options,type:p.ApplicationCommandType.ChatInput},i.guilds)for(let d of i.guilds){let g=o.get(d);g||(g=[],o.set(d,g))}else e.push(m);s.set(i.options.name,m)}m.options||(m.options=[]);let u=m.options.find(d=>d.name===n.subcommandGroupChild.options.name);u||(u={type:p.ApplicationCommandOptionType.SubcommandGroup,...n.subcommandGroupChild.options},m.options.push(u)),u.options||(u.options=[]);let l=[];for(let[,d]of n.argTypes){let g=d.decorators.find(v=>v.constructor===H);g&&l.push(g.options)}u.options.push({...n.options,type:p.ApplicationCommandOptionType.Subcommand,options:l});continue}let a={...n.options};if(a.type===p.ApplicationCommandType.ChatInput){a.options=[];for(let[,i]of n.argTypes){let m=i.decorators.find(u=>u.constructor===H);m&&a.options.push(m.options)}}if(await n.executeHook(this,"beforeSync",[a,n]),n.options.guilds){for(let i of n.options.guilds){let m=o.get(i);m||(m=[],o.set(i,m)),m.push(a)}continue}e.push(a)}for(let{guilds:n,...a}of this.unmanagedCommands)if(n){for(let i of n){let m=o.get(i);m||(m=[],o.set(i,m)),m.push(a)}continue}else e.push(a);if(this.config.guilds){for(let n of this.config.guilds){let a=o.get(n);a||(a=[],o.set(n,a)),a.push(...e)}e=[]}if(o.size)for(let[n,a]of o)try{let i=await this.client.guilds.fetch(n);await i.fetch(),this.logger.info(`Processing ${S.default.green(a.length)} commands(${a.map(m=>S.default.blue(m.name)).join(", ")}) for guild ${S.default.green(i.name)}(${S.default.blue(i.id)})`),await i.commands.set(a),this.logger.info(`Successfully registered commands for guild ${S.default.green(i.name)}(${S.default.blue(i.id)})`)}catch(i){this.logger.error(`Failed to register commands to guild ${S.default.green(n)}: ${i.message}`)}if(e.length)try{this.logger.info(`Processing ${S.default.green(e.length)} commands(${e.map(n=>S.default.blue(n.name)).join(", ")}) for application scope...`),await this.client.application.commands.set(e),this.logger.info("Successfully registered commands.")}catch(n){this.logger.error(`Failed to register commands to global: ${n.message}`)}}async chatInteraction(t){return t}async messageInteraction(t){return t}async userInteraction(t){return t}async commandInteraction(t){return t}};c(b,"ApplicationCommandExtension");V([K({event:"interactionCreate"}),k("design:type",Function),k("design:paramtypes",[typeof p.Interaction>"u"?Object:p.Interaction])],b.prototype,"interactionCreate",null);V([M({component:h,parameterless:!0,type:p.ChatInputCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.ChatInputCommandInteraction>"u"?Object:p.ChatInputCommandInteraction])],b.prototype,"chatInteraction",null);V([M({component:h,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction>"u"?Object:p.MessageContextMenuCommandInteraction])],b.prototype,"messageInteraction",null);V([M({component:h,parameterless:!0,type:p.UserContextMenuCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"userInteraction",null);V([M({component:h,parameterless:!0,type:p.CommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"commandInteraction",null)});var w,fe,Rt=f(()=>{"use strict";O();W();w=class extends x{constructor(t){super(),this.options=t}};c(w,"TextCommandComponent");fe=c(r=>y(new w(r)),"command")});var E,ue,Gt=f(()=>{"use strict";_();_();E=class extends G{};c(E,"TextCommandRestOption");ue=J(E)});var q,at,T,R,Kt=f(()=>{"use strict";Q();q=require("discord.js");vt();Rt();Gt();_();at=function(r,t,e,o){var s=arguments.length,n=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,e,o);else for(var i=r.length-1;i>=0;i--)(a=r[i])&&(n=(s<3?a(n):s>3?a(t,e,n):a(t,e))||n);return s>3&&n&&Object.defineProperty(t,e,n),n},T=function(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)},R=class extends A{constructor(t){super(),this.config=t}async processPrefix(t){let e=t.content,o=this.config.prefix;if(typeof o=="function"&&(o=await o(t)),typeof o=="string")return e.startsWith(o)?o.length:null;if(o instanceof Array){let s=o.find(n=>e.startsWith(n));return s?s.length:null}return null}async messageCreate(t){try{let e=await this.processPrefix(t);if(e===null)return;let o=t.content.slice(e),s=[],n=new Map;for(let d of this.commandClient.registry.extensions)for(let g of this.commandClient.registry.getComponentsWithType(d,w))s.push(g),n.set(g,d);let a=0,i=s.find(d=>{let g=[d.options.name];d.options.aliases&&g.push(...d.options.aliases);for(let v of g)if(o.startsWith(v))return o.length===v.length?(a=v.length,!0):(a=v.length,o.startsWith(v+" "));return!1});if(!i)return;let m=n.get(i);if(!m)return;t.command=i;let u=[],l=o.slice(a+1).split(/ /g);await this.convertArguments(w,u,i.argTypes,async(d,g,v)=>{if(v.options.parameterless)return[t];if(d.decorators.find(ft=>ft.constructor===E)){let ft=l.join(" ");return l=[],[ft,t]}return[l.shift(),t]}),await i.execute(m,u,[t])}catch(e){this.commandClient.emit("textCommandInvokeError",e,t)}}async mesage(t){return t}async str(t){return t}async num(t){return Number(t)}};c(R,"TextCommandExtension");at([K({event:"messageCreate",emitter:"discord"}),T("design:type",Function),T("design:paramtypes",[typeof q.Message>"u"?Object:q.Message])],R.prototype,"messageCreate",null);at([M({component:w,type:q.Message,parameterless:!0}),T("design:type",Function),T("design:paramtypes",[typeof q.Message>"u"?Object:q.Message])],R.prototype,"mesage",null);at([M({component:w,type:String}),T("design:type",Function),T("design:paramtypes",[String])],R.prototype,"str",null);at([M({component:w,type:Number}),T("design:type",Function),T("design:paramtypes",[String])],R.prototype,"num",null)});var It={};jt(It,{CommandClient:()=>j});var ct,mt,Qt,Vt,j,it=f(()=>{"use strict";ct=C(require("chalk")),mt=require("discord.js"),Qt=C(require("events")),Vt=require("tslog");Ht();Kt();L();wt();j=class extends Qt.default{constructor(t,e=new Vt.Logger({dateTimeTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone}),o={}){super(),this.discord=t,this.logger=e,this.owners=new Set,this.ctsLogger=e.getChildLogger({prefix:[ct.default.blue("[command.ts]")],displayFilePath:"hidden",displayFunctionName:!1,...o}),this.registry=new P(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}async isOwner(t){return this.owners.has(t.id)}async fetchOwners(){if(!this.discord.application)throw new Error("The client is not logged in.");this.ctsLogger.info("Fetching owners..."),await this.discord.application.fetch();let t=this.discord.application.owner;if(!t)throw new Error("Cannot find application owner");let e=[];if(t instanceof mt.User)this.owners.add(t.id),e.push(t.tag);else if(t instanceof mt.Team)for(let[o,s]of t.members)this.owners.add(o),e.push(s.user.tag);this.ctsLogger.info(`Fetched ${ct.default.green(e.length)} owners(${e.map(o=>ct.default.blue(o)).join(", ")})`)}async enableApplicationCommandsExtension(t){await this.registry.registerModule(new b(t)),this.ctsLogger.info("Application command extension enabled.")}async enableTextCommandsExtension(t){await this.registry.registerModule(new R(t)),this.ctsLogger.info("Text command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===b)}static getFromModule(t){return Reflect.getMetadata(Y,t)}};c(j,"CommandClient")});var Tt,x,W=f(()=>{"use strict";Tt=require("discord.js");bt();x=class{hooks=new Tt.Collection;argTypes=new Tt.Collection;_init(t,e){this.method=t;for(let o=0;o<e.length;o++){let s=e[o];this.argTypes.set(o,new $(s))}}async executeGlobalHook(t,e,o){let{CommandClient:s}=await Promise.resolve().then(()=>(it(),It)),n=s.getFromModule(t),a=n.registry.globalHooks[e];if(a)for(let i of a)await i.call(null,n,...o)}async executeHook(t,e,o){let s=this.hooks.get(e);if(!s)return;let{CommandClient:n}=await Promise.resolve().then(()=>(it(),It)),a=n.getFromModule(t),i=a.registry.globalHooks[e];i&&s.unshift(...i);for(let m of s)await m.call(null,a,...o)}async execute(t,e,o=e){await this.executeHook(t,"beforeCall",o);let s;try{s=await this.method.call(t,...e),await this.executeHook(t,"afterCall",[...o,s])}catch(n){throw await this.executeHook(t,"invokeError",[n,...o]),n}return s}};c(x,"BaseComponent")});var Ro,Mt=f(()=>{"use strict";Ro=require("reflect-metadata");O();bt();Ot();W()});var U,_t=f(()=>{"use strict";U=class{};c(U,"OwnerOnlyError")});var pt,Xt,de,Yt=f(()=>{"use strict";pt=require("discord.js");st();_t();Xt=c(r=>et("beforeCall",r),"createCheckDecorator"),de=Xt(async(r,t)=>{let e=!1;if(t instanceof pt.BaseInteraction?e=await r.isOwner(t.user):t instanceof pt.Message&&(e=await r.isOwner(t.author)),!e)throw new U})});var ge,te=f(()=>{"use strict";ge=c(r=>(t,e,o)=>{for(let s of r)s(t,e,o)},"mergeMethodDecorators")});var ee=f(()=>{"use strict";Yt();_t();te()});var oe=f(()=>{"use strict";kt()});var _=f(()=>{"use strict";Mt();st();nt();ee();Q();St();oe()});var he={};jt(he,{ApplicationCommandComponent:()=>h,ApplicationCommandExtension:()=>b,BaseComponent:()=>x,CommandClient:()=>j,ComponentArgument:()=>$,ComponentArgumentDecorator:()=>G,ConverterComponent:()=>F,Extension:()=>N,ListenerComponent:()=>I,OwnerOnlyError:()=>U,Registry:()=>P,SubCommandGroup:()=>lt,SubCommandGroupChild:()=>X,TextCommandComponent:()=>w,TextCommandRestOption:()=>E,applicationCommand:()=>pe,argConverter:()=>M,command:()=>fe,createArgumentDecorator:()=>J,createCheckDecorator:()=>Xt,createComponentDecorator:()=>y,createComponentHook:()=>et,getComponent:()=>me,getComponentArgumentStore:()=>xt,getComponentStore:()=>Z,getModuleHookStore:()=>rt,listener:()=>K,mergeMethodDecorators:()=>ge,moduleHook:()=>le,option:()=>$t,ownerOnly:()=>de,rest:()=>ue});module.exports=ce(he);_();ot();Ct();var Ft=require("discord.js");_();ot();var lt=class{constructor(t,e){this.options=t,this.guilds=e}command(t){let e=new h({type:Ft.ApplicationCommandType.ChatInput,...t});return e.subcommandGroup=this,y(e)}createChild(t){return new X(t,this)}};c(lt,"SubCommandGroup");var X=class{constructor(t,e){this.options=t,this.parent=e}command(t){let e=new h({type:Ft.ApplicationCommandType.ChatInput,...t});return e.subcommandGroupChild=this,y(e)}};c(X,"SubCommandGroupChild");Ht();Rt();Gt();0&&(module.exports={ApplicationCommandComponent,ApplicationCommandExtension,BaseComponent,CommandClient,ComponentArgument,ComponentArgumentDecorator,ConverterComponent,Extension,ListenerComponent,OwnerOnlyError,Registry,SubCommandGroup,SubCommandGroupChild,TextCommandComponent,TextCommandRestOption,applicationCommand,argConverter,command,createArgumentDecorator,createCheckDecorator,createComponentDecorator,createComponentHook,getComponent,getComponentArgumentStore,getComponentStore,getModuleHookStore,listener,mergeMethodDecorators,moduleHook,option,ownerOnly,rest});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/symbols.ts","../src/core/hooks/componentHook.ts","../src/core/components/decoratorCreator.ts","../src/core/components/ComponentArgument.ts","../src/core/components/ComponentArgumentDecorator.ts","../src/applicationCommand/ApplicationCommand.ts","../src/applicationCommand/ApplicationCommandOption.ts","../src/core/listener/index.ts","../src/core/converter/index.ts","../src/core/hooks/moduleHook.ts","../src/core/hooks/index.ts","../src/core/structures/Registry.ts","../src/core/structures/index.ts","../src/core/extensions/Extension.ts","../src/core/extensions/CTSExtension.ts","../src/applicationCommand/ApplicationCommandExtension.ts","../src/textCommand/TextCommand.ts","../src/textCommand/parameters.ts","../src/textCommand/TextCommandExtension.ts","../src/core/structures/CommandClient.ts","../src/core/components/BaseComponent.ts","../src/core/components/index.ts","../src/core/utils/errors.ts","../src/core/utils/checks.ts","../src/core/utils/decorators.ts","../src/core/utils/index.ts","../src/core/extensions/index.ts","../src/core/index.ts","../src/index.ts","../src/applicationCommand/group.ts"],"sourcesContent":["/*\r\n * File: symbols.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nexport const ComponentStoreSymbol = Symbol()\r\nexport const ComponentArgStoreSymbol = Symbol()\r\nexport const ModuleHookStoreSymbol = Symbol()\r\nexport const CommandClientSymbol = Symbol()\r\nexport const ComponentHookSymbol = Symbol()\r\nexport const FilePathSymbol = Symbol()\r\n","/*\n * File: componentHook.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport { ComponentHookSymbol } from '../symbols'\n\nexport type ComponentHookFn = (...args: any[]) => void | Promise<void>\n\nexport type ComponentHookStore = Collection<string, ComponentHookFn[]>\n\nexport const getComponentHookStore = (target: object, property: string | symbol): ComponentHookStore => {\n let data = Reflect.getMetadata(ComponentHookSymbol, target, property) as ComponentHookStore\n\n if (!data) {\n data = new Collection()\n Reflect.defineMetadata(ComponentHookSymbol, data, target, property)\n }\n\n return data\n}\n\nexport const createComponentHook = (name: string, fn: ComponentHookFn): MethodDecorator => {\n return (target, key) => {\n const store = getComponentHookStore(target, key)\n\n let hooks = store.get(name)\n\n if (!hooks) {\n hooks = []\n store.set(name, hooks)\n }\n\n hooks.unshift(fn)\n }\n}\n","/*\n * File: decoratorCreator.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport { ComponentHookStore } from '../hooks'\nimport { getComponentHookStore } from '../hooks/componentHook'\nimport { ComponentStoreSymbol } from '../symbols'\nimport { BaseComponent } from './BaseComponent'\nimport { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\nexport type ComponentStore = Collection<string | symbol, BaseComponent>\nexport type ComponentArgumentStore = Collection<number, ComponentArgumentDecorator>\n\nexport const getComponentStore = (target: object): ComponentStore => {\n let result: ComponentStore | null = Reflect.getMetadata(ComponentStoreSymbol, target)\n\n if (!result) {\n result = new Collection()\n\n Reflect.defineMetadata(ComponentStoreSymbol, result, target)\n }\n\n return result\n}\n\nexport const getComponent = (target: object, key: string | symbol) => {\n const store = getComponentStore(target)\n\n return store.get(key)\n}\n\nexport const createComponentDecorator = (component: BaseComponent): MethodDecorator => {\n return (target, key) => {\n component._init(Reflect.get(target, key), Reflect.getMetadata('design:paramtypes', target, key))\n\n const componentHookStore: ComponentHookStore = getComponentHookStore(target, key)\n\n component.hooks = componentHookStore\n\n const store = getComponentStore(target)\n\n const decorators = getComponentArgumentStore(target, key)\n\n decorators.forEach((x, i) => {\n component.argTypes.get(i)?.decorators.push(x)\n })\n\n store.set(key, component)\n }\n}\n\nexport const getComponentArgumentStore = (target: object, key: string | symbol): ComponentArgumentStore => {\n let result: ComponentArgumentStore | null = Reflect.getMetadata(ComponentStoreSymbol, target, key)\n\n if (!result) {\n result = new Collection()\n\n Reflect.defineMetadata(ComponentStoreSymbol, result, target, key)\n }\n\n return result\n}\n\nexport const createArgumentDecorator = <Options>(type: typeof ComponentArgumentDecorator<Options>) => {\n return (options: Options): ParameterDecorator => {\n return (target, key, idx) => {\n var arg: ComponentArgumentDecorator<Options> = new type(options)\n\n const store = getComponentArgumentStore(target, key)\n\n store.set(idx, arg)\n }\n }\n}\n","/*\r\n* File: ComponentArgument.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\nexport class ComponentArgument {\n decorators: ComponentArgumentDecorator[] = []\n\n constructor(public type: unknown) {}\n}\n","/*\r\n* File: ComponentArgumentDecorator.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport _ from 'lodash'\n\nexport class ComponentArgumentDecorator<Options = unknown> {\n options: Options\n\n constructor(options: Partial<Options>) {\n if (typeof options === 'object') {\n this.options = _.merge(this.defaultOptions(), options)\n } else {\n this.options = options\n }\n }\n\n defaultOptions(): Options {\n return {} as unknown as Options\n }\n}\n","/*\n * File: ApplicationCommand.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport type { ApplicationCommandType, ChatInputApplicationCommandData, MessageApplicationCommandData, Snowflake, UserApplicationCommandData } from 'discord.js'\nimport { createComponentDecorator } from '../core/components/decoratorCreator'\nimport { BaseComponent } from '../core/components/BaseComponent'\nimport { SubCommandGroup, SubCommandGroupChild } from './group'\n\ntype Options = (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & {\n type: ApplicationCommandType\n guilds?: Snowflake[]\n}\n\nexport class ApplicationCommandComponent extends BaseComponent {\n options: Options\n\n subcommandGroup?: SubCommandGroup\n subcommandGroupChild?: SubCommandGroupChild\n\n constructor(options: UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) {\n super()\n\n this.options = options as Options\n }\n}\n\nexport const applicationCommand = (options: Options) => createComponentDecorator(new ApplicationCommandComponent(options))\n\nexport type { Options as ApplicationCommandComponentOptions }\n","/*\r\n* File: ApplicationCommandOption.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport { APIApplicationCommandOption } from 'discord.js'\nimport { createArgumentDecorator, ComponentArgumentDecorator } from '../core'\n\ntype Options = APIApplicationCommandOption\n\nexport class ApplicationCommandOption extends ComponentArgumentDecorator<Options> {}\n\nexport const option = createArgumentDecorator(ApplicationCommandOption)\n","/*\n * File: index.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport _ from 'lodash'\nimport { BaseComponent } from '../components/BaseComponent'\nimport { createComponentDecorator } from '../components/decoratorCreator'\n\ntype Options = { emitter: string; event: string }\n\ntype OptionsArg = { emitter?: string; event: string }\n\nexport class ListenerComponent extends BaseComponent {\n options: Options\n\n constructor(options: OptionsArg) {\n super()\n\n this.options = _.merge({ emitter: 'discord' }, options)\n }\n}\n\nexport const listener = (options: OptionsArg) => createComponentDecorator(new ListenerComponent(options))\n\nexport { Options as ListenerOptions, OptionsArg as ListenerOptionsArg }\n","/*\n * File: index.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { BaseComponent } from '../components/BaseComponent'\nimport { createComponentDecorator } from '../components/decoratorCreator'\n\ntype Options = { component: unknown; type: Function; parameterless: boolean }\n\ntype OptionsArg = Omit<Options, 'parameterless'> & { parameterless?: boolean }\n\nexport class ConverterComponent extends BaseComponent {\n options: Options\n\n constructor(options: OptionsArg) {\n super()\n this.options = options as Options\n }\n}\n\nexport const argConverter = (options: OptionsArg) => createComponentDecorator(new ConverterComponent(options))\n\nexport { Options as ArgumentConvertOptions, OptionsArg as ArgumentConvertOptionsArg }\n","/*\n * File: moduleHook.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport { ModuleHookStoreSymbol } from '../symbols'\n\nexport type ModuleHookStore = Collection<string, Function[]>\n\nexport const getModuleHookStore = (target: object) => {\n let result: ModuleHookStore | null = Reflect.getMetadata(ModuleHookStoreSymbol, target)\n\n if (!result) {\n result = new Collection()\n\n Reflect.defineMetadata(ModuleHookStoreSymbol, result, target)\n }\n\n return result\n}\n\nexport const moduleHook = (name: string): MethodDecorator => {\n return (target, key) => {\n const store = getModuleHookStore(target)\n\n let v = store.get(name)\n\n if (!v) {\n v = []\n store.set(name, v)\n }\n\n v.push(Reflect.get(target, key))\n }\n}\n","/*\r\n * File: index.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nexport * from './moduleHook'\r\nexport { createComponentHook, type ComponentHookFn } from './componentHook'\r\nexport type { ComponentHookStore } from './componentHook'\r\n","/*\n * File: Registry.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport EventEmitter from 'events'\nimport _, { result } from 'lodash'\nimport { Logger } from 'tslog'\nimport { getComponentStore } from '../components'\nimport { getModuleHookStore } from '../hooks'\nimport { ListenerComponent } from '../listener'\nimport { CommandClientSymbol, FilePathSymbol } from '../symbols'\nimport { CommandClient } from './CommandClient'\nimport walkSync from 'walk-sync'\nimport path from 'path'\nimport { ComponentHookFn } from '../hooks/componentHook'\n\nexport class Registry {\n extensions: object[] = []\n\n emitters: Collection<string, EventEmitter> = new Collection()\n\n logger: Logger\n\n globalHooks: Record<string, ComponentHookFn[]> = {}\n\n constructor(logger: Logger, public client: CommandClient) {\n this.logger = logger.getChildLogger({\n prefix: [chalk.green('[Registry]')],\n })\n }\n\n addGlobalHook(name: string, fn: ComponentHookFn) {\n let hooks = this.globalHooks[name]\n\n if (!hooks) {\n hooks = []\n this.globalHooks[name] = hooks\n }\n\n hooks.push(fn)\n }\n\n getComponentsWithTypeGlobal<T>(type: unknown): T[] {\n const result: T[] = []\n\n for (const ext of this.extensions) {\n result.push(...this.getComponentsWithType<T>(ext, type))\n }\n\n return result\n }\n\n getComponentsWithType<T>(ext: object, type: unknown): T[] {\n const componentStore = getComponentStore(ext)\n\n return Array.from(componentStore.filter((x) => (x.constructor as unknown) === type).values() as Iterable<T>)\n }\n\n registerEventListeners(ext: object) {\n const listeners = this.getComponentsWithType<ListenerComponent>(ext, ListenerComponent)\n\n for (const listener of listeners) {\n const emitter = this.emitters.get(listener.options.emitter)\n\n if (emitter) {\n const bound = listener.method.bind(ext)\n\n Reflect.defineMetadata('bound', bound, listener)\n\n emitter.addListener(listener.options.event, bound)\n }\n }\n }\n\n unregisterEventListeners(ext: object) {\n const listeners = this.getComponentsWithType<ListenerComponent>(ext, ListenerComponent)\n\n for (const listener of listeners) {\n const emitter = this.emitters.get(listener.options.emitter)\n const bound = Reflect.getMetadata('bound', listener)\n\n if (emitter && bound) {\n emitter.removeListener(listener.options.event, bound)\n }\n }\n }\n\n async loadAllModulesInDirectory(dir: string): Promise<object[]> {\n const results: object[] = []\n\n const files = walkSync(dir).filter((x) => x.endsWith('.ts') || x.endsWith('.js'))\n\n for (const file of files) {\n if (file.endsWith('.d.ts')) continue\n const p = path.join(dir, file)\n results.push(...(await this.loadModulesAtPath(p)))\n }\n\n return results\n }\n\n async loadModulesAtPath(file: string) {\n this.logger.info(`Loading module at path ${chalk.green(file)}`)\n\n const p = require.resolve(file)\n\n const mod = require(p)\n\n if (typeof mod.setup !== 'function') throw new Error('Extension must have a setup function')\n\n const modules = await mod.setup(this.client)\n\n return this.registerModules(modules, p)\n }\n\n private async registerModules(modules: object | object[], p: string) {\n const results: object[] = []\n if (modules instanceof Array) {\n for (const module of modules) {\n await this.registerModule(module)\n Reflect.defineMetadata(FilePathSymbol, p, module)\n results.push(module)\n }\n } else {\n await this.registerModule(modules)\n Reflect.defineMetadata(FilePathSymbol, p, modules)\n results.push(modules)\n }\n\n return results\n }\n\n async reloadModules() {\n const result: { file: string; result: boolean; error?: Error; extensions?: object[] }[] = []\n const paths = new Set<string>()\n const extensions = [...this.extensions]\n for (const module of extensions) {\n const file = Reflect.getMetadata(FilePathSymbol, module)\n if (!file) continue\n\n this.logger.info(`Unloading module: ${chalk.green(module.constructor.name)}`)\n\n paths.add(file)\n\n await this.unregisterModule(module)\n\n delete require.cache[require.resolve(file)]\n }\n\n for (const path of paths) {\n try {\n const extensions = await this.loadModulesAtPath(path)\n\n result.push({\n file: path,\n result: true,\n extensions,\n })\n } catch (e) {\n result.push({\n file: path,\n result: false,\n error: e as Error,\n })\n }\n }\n\n return result\n }\n\n async registerModule(ext: object) {\n Reflect.defineMetadata(CommandClientSymbol, this.client, ext)\n\n this.registerEventListeners(ext)\n await this.runModuleHook(ext, 'load')\n this.extensions.push(ext)\n this.logger.info(`Module registered: ${chalk.green(ext.constructor.name)}`)\n }\n\n async unregisterModule(ext: object) {\n this.unregisterEventListeners(ext)\n await this.runModuleHook(ext, 'unload')\n _.remove(this.extensions, (x) => x === ext)\n this.logger.info(`Module unregistered: ${chalk.green(ext.constructor.name)}`)\n }\n\n runModuleHook(ext: object, hookName: string, ...args: unknown[]) {\n const hooks = getModuleHookStore(ext)\n\n const functions = hooks.get(hookName)\n\n if (functions) {\n for (const fn of functions) {\n fn.call(ext, ...args)\n }\n }\n }\n\n registerEventEmitter(name: string, emitter: EventEmitter) {\n this.emitters.set(name, emitter)\n }\n}\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './Registry'\nexport * from './CommandClient'\n","/*\n * File: Extension.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport { Logger } from 'tslog'\nimport { ComponentArgument } from '../components/ComponentArgument'\nimport { ConverterComponent } from '../converter'\nimport { CommandClient } from '../structures'\n\nexport class Extension {\n protected get commandClient() {\n return CommandClient.getFromModule(this)\n }\n\n protected get client() {\n return this.commandClient.discord\n }\n\n protected _logger?: Logger\n\n protected get logger() {\n if (!this._logger) this._logger = this.commandClient.logger.getChildLogger({ prefix: [chalk.green(`[${this.constructor.name}]`)], displayFunctionName: false })\n return this._logger\n }\n\n protected async convertArguments(\n component: unknown,\n argList: unknown[],\n args: Collection<number, ComponentArgument>,\n getConverterArgs: (arg: ComponentArgument, index: number, converter: ConverterComponent) => unknown[] | Promise<unknown[]>,\n ) {\n const items = new Collection<unknown, { ext: object; component: ConverterComponent }>()\n\n for (const extension of this.commandClient.registry.extensions) {\n for (const converter of this.commandClient.registry.getComponentsWithType<ConverterComponent>(extension, ConverterComponent)) {\n if (converter.options.component != component) continue\n\n items.set(converter.options.type, { component: converter, ext: extension })\n }\n }\n\n for (const [index, arg] of args) {\n const converter = items.get(arg.type)\n\n if (!converter) {\n argList[index] = undefined\n continue\n }\n\n const converterArgs = await getConverterArgs(arg, index, converter.component)\n\n argList[index] = await converter.component.execute(converter.ext, converterArgs)\n }\n }\n}\n","/*\r\n* File: CTSExtension.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport chalk from 'chalk'\nimport { Extension } from './Extension'\n\nexport class CTSExtension extends Extension {\n protected get logger() {\n if (!this._logger) this._logger = this.commandClient.ctsLogger.getChildLogger({ prefix: [chalk.green(`[${this.constructor.name}]`)], displayFunctionName: false })\n return this._logger\n }\n}\n","/*\n * File: ApplicationCommandExtension.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport {\n APIApplicationCommandSubcommandGroupOption,\n APIApplicationCommandSubcommandOption,\n ApplicationCommandData,\n ApplicationCommandDataResolvable,\n ApplicationCommandOptionType,\n ApplicationCommandSubCommandData,\n ApplicationCommandType,\n ChatInputApplicationCommandData,\n ChatInputCommandInteraction,\n Collection,\n CommandInteraction,\n Interaction,\n InteractionType,\n MessageContextMenuCommandInteraction,\n Snowflake,\n UserContextMenuCommandInteraction,\n} from 'discord.js'\nimport { ApplicationCommandComponent } from './ApplicationCommand'\nimport { ApplicationCommandOption } from './ApplicationCommandOption'\nimport { listener } from '../core/listener'\nimport { argConverter } from '../core/converter'\nimport { CTSExtension } from '../core/extensions/CTSExtension'\n\nexport type ApplicationCommandExtensionConfig = {\n guilds?: Snowflake[]\n}\n\nexport class ApplicationCommandExtension extends CTSExtension {\n constructor(public config: ApplicationCommandExtensionConfig) {\n super()\n }\n\n unmanagedCommands: (ApplicationCommandData & { guilds?: Snowflake[] })[] = []\n\n registerUnmanagedCommand(command: ApplicationCommandData & { guilds?: Snowflake[] }) {\n this.unmanagedCommands.push(command)\n }\n\n @listener({ event: 'interactionCreate' })\n async interactionCreate(i: Interaction) {\n try {\n if (i.type !== InteractionType.ApplicationCommand) return\n\n let cmd: ApplicationCommandComponent | null = null\n let ext: object | null = null\n\n const extensions = this.commandClient.registry.extensions\n\n let subcommand: string | null = null\n let subcommandGroup: string | null = null\n\n if (i.commandType === ApplicationCommandType.ChatInput) {\n subcommand = i.options.getSubcommand(false)\n subcommandGroup = i.options.getSubcommandGroup(false)\n }\n\n extLoop: for (const extension of extensions) {\n const components = this.commandClient.registry.getComponentsWithType<ApplicationCommandComponent>(extension, ApplicationCommandComponent)\n\n if (subcommand) {\n for (const command of components) {\n if (!command.subcommandGroup && !command.subcommandGroupChild) continue\n\n if (\n command.subcommandGroupChild &&\n command.subcommandGroupChild.parent.options.name === i.commandName &&\n command.subcommandGroupChild.options.name === subcommandGroup &&\n command.options.name === subcommand\n ) {\n ext = extension\n cmd = command\n break extLoop\n }\n if (command.subcommandGroup && !subcommandGroup && command.subcommandGroup.options.name === i.commandName && command.options.name === subcommand) {\n ext = extension\n cmd = command\n break extLoop\n }\n }\n } else {\n for (const command of components) {\n if (command.options.name === i.commandName) {\n ext = extension\n cmd = command\n break extLoop\n }\n }\n }\n }\n\n if (cmd && ext) {\n const argList: unknown[] = []\n\n await this.convertArguments(ApplicationCommandComponent, argList, cmd.argTypes, () => [i])\n\n for (const [idx, arg] of cmd.argTypes) {\n let value: unknown = null\n\n for (const decorator of arg.decorators) {\n if (decorator instanceof ApplicationCommandOption) {\n if ([ApplicationCommandOptionType.Subcommand, ApplicationCommandOptionType.SubcommandGroup].includes(decorator.options.type) && i.isChatInputCommand()) {\n if (decorator.options.type === ApplicationCommandOptionType.Subcommand) {\n value = i.options.getSubcommand() === decorator.options.name\n break\n }\n if (decorator.options.type === ApplicationCommandOptionType.SubcommandGroup) {\n value = i.options.getSubcommandGroup() === decorator.options.name\n break\n }\n }\n\n value = i.options.get(decorator.options.name, false)?.value\n break\n }\n }\n\n if (value) {\n argList[idx] = value\n }\n }\n\n await cmd.execute(ext, argList, [i])\n }\n } catch (e) {\n this.commandClient.emit('applicationCommandInvokeError', e, i)\n }\n }\n\n async sync() {\n const client = this.commandClient\n\n this.logger.info('Trying to sync commands...')\n\n let commands: ApplicationCommandData[] = []\n\n const guildCommands = new Collection<Snowflake, ApplicationCommandData[]>()\n\n const subcommandGroups = new Collection<string, ChatInputApplicationCommandData>()\n\n for (const command of client.registry.getComponentsWithTypeGlobal<ApplicationCommandComponent>(ApplicationCommandComponent)) {\n if (command.subcommandGroup) {\n let group = subcommandGroups.get(command.subcommandGroup.options.name)\n\n if (!group) {\n group = {\n ...command.subcommandGroup.options,\n type: ApplicationCommandType.ChatInput,\n }\n\n if (command.subcommandGroup.guilds) {\n for (const guild of command.subcommandGroup.guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n }\n } else {\n commands.push(group)\n }\n\n subcommandGroups.set(command.subcommandGroup.options.name, group)\n }\n\n if (!group.options) group.options = []\n\n const options = []\n\n for (const [, arg] of command.argTypes) {\n const option = arg.decorators.find((x) => x.constructor === ApplicationCommandOption) as ApplicationCommandOption\n\n if (option) {\n options.push(option.options)\n }\n }\n\n group.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as ApplicationCommandSubCommandData)\n\n continue\n } else if (command.subcommandGroupChild) {\n const parent = command.subcommandGroupChild.parent\n let group = subcommandGroups.get(parent.options.name)\n\n if (!group) {\n group = {\n ...parent.options,\n type: ApplicationCommandType.ChatInput,\n }\n\n if (parent.guilds) {\n for (const guild of parent.guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n }\n } else {\n commands.push(group)\n }\n\n subcommandGroups.set(parent.options.name, group)\n }\n\n if (!group.options) group.options = []\n\n let child = group.options.find((x) => x.name === command.subcommandGroupChild!.options.name) as APIApplicationCommandSubcommandGroupOption\n\n if (!child) {\n child = { type: ApplicationCommandOptionType.SubcommandGroup, ...(command.subcommandGroupChild.options as Omit<APIApplicationCommandSubcommandGroupOption, 'type'>) }\n group.options.push(child)\n }\n\n if (!child.options) child.options = []\n\n const options = []\n\n for (const [, arg] of command.argTypes) {\n const option = arg.decorators.find((x) => x.constructor === ApplicationCommandOption) as ApplicationCommandOption\n\n if (option) {\n options.push(option.options)\n }\n }\n\n child.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as APIApplicationCommandSubcommandOption)\n\n continue\n }\n\n const cmd: ApplicationCommandData = { ...command.options }\n\n if (cmd.type === ApplicationCommandType.ChatInput) {\n cmd.options = []\n\n for (const [, arg] of command.argTypes) {\n const option = arg.decorators.find((x) => x.constructor === ApplicationCommandOption) as ApplicationCommandOption\n\n if (option) {\n cmd.options.push(option.options)\n }\n }\n }\n\n await command.executeHook(this, 'beforeSync', [cmd, command])\n\n if (command.options.guilds) {\n for (const guild of command.options.guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n commands.push(cmd)\n }\n continue\n }\n\n commands.push(cmd)\n }\n\n for (const { guilds, ...rest } of this.unmanagedCommands) {\n if (guilds) {\n for (const guild of guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n commands.push(rest)\n }\n continue\n } else {\n commands.push(rest)\n }\n }\n\n if (this.config.guilds) {\n for (const guild of this.config.guilds) {\n let g = guildCommands.get(guild)\n if (!g) {\n g = []\n guildCommands.set(guild, g)\n }\n g.push(...commands)\n }\n\n commands = []\n }\n\n if (guildCommands.size) {\n for (const [guild, commands] of guildCommands) {\n try {\n const g = await this.client.guilds.fetch(guild)\n await g.fetch()\n this.logger.info(\n `Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')}) for guild ${chalk.green(g.name)}(${chalk.blue(g.id)})`,\n )\n\n await g.commands.set(commands)\n\n this.logger.info(`Successfully registered commands for guild ${chalk.green(g.name)}(${chalk.blue(g.id)})`)\n } catch (e) {\n this.logger.error(`Failed to register commands to guild ${chalk.green(guild)}: ${(e as Error).message}`)\n }\n }\n }\n if (commands.length) {\n try {\n this.logger.info(`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')}) for application scope...`)\n\n await this.client.application!.commands.set(commands)\n\n this.logger.info('Successfully registered commands.')\n } catch (e) {\n this.logger.error(`Failed to register commands to global: ${(e as Error).message}`)\n }\n }\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: ChatInputCommandInteraction,\n })\n async chatInteraction(i: ChatInputCommandInteraction) {\n return i\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: MessageContextMenuCommandInteraction,\n })\n async messageInteraction(i: MessageContextMenuCommandInteraction) {\n return i\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: UserContextMenuCommandInteraction,\n })\n async userInteraction(i: UserContextMenuCommandInteraction) {\n return i\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: CommandInteraction,\n })\n async commandInteraction(i: UserContextMenuCommandInteraction) {\n return i\n }\n}\n","/*\n * File: TextCommand.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { createComponentDecorator } from '../core/components/decoratorCreator'\nimport { BaseComponent } from '../core/components/BaseComponent'\n\nexport type TextCommandOptions = {\n name: string\n aliases?: string[]\n description?: string\n}\n\nexport class TextCommandComponent extends BaseComponent {\n constructor(public options: TextCommandOptions) {\n super()\n }\n}\n\nexport const command = (options: TextCommandOptions) => createComponentDecorator(new TextCommandComponent(options))\n","/*\r\n * File: parameters.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nimport { ComponentArgumentDecorator } from '../core'\r\nimport { createArgumentDecorator } from '../core'\r\n\r\nexport class TextCommandRestOption extends ComponentArgumentDecorator<void> {}\r\n\r\nexport const rest = createArgumentDecorator(TextCommandRestOption)\r\n","/*\n * File: TextCommandExtension.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { listener } from '../core/listener'\nimport { Message } from 'discord.js'\nimport { CTSExtension } from '../core/extensions/CTSExtension'\nimport { TextCommandComponent } from './TextCommand'\nimport { TextCommandRestOption } from './parameters'\nimport { argConverter } from '../core'\n\nexport type TextCommandConfig = {\n prefix: string | string[] | ((msg: Message) => Promise<string | string[]> | string | string[])\n}\n\ndeclare module 'discord.js' {\n interface Message {\n command: TextCommandComponent\n }\n}\n\nexport class TextCommandExtension extends CTSExtension {\n constructor(private config: TextCommandConfig) {\n super()\n }\n\n private async processPrefix(msg: Message): Promise<number | null> {\n const content = msg.content\n let prefix = this.config.prefix\n\n if (typeof prefix === 'function') {\n prefix = await prefix(msg)\n }\n\n if (typeof prefix === 'string') {\n if (content.startsWith(prefix)) return prefix.length\n return null\n }\n\n if (prefix instanceof Array) {\n const p = prefix.find((x) => content.startsWith(x))\n\n if (p) return p.length\n return null\n }\n\n return null\n }\n\n @listener({ event: 'messageCreate', emitter: 'discord' })\n private async messageCreate(msg: Message) {\n try {\n const startIndex = await this.processPrefix(msg)\n\n if (!startIndex) return\n\n const content = msg.content.slice(startIndex)\n\n const commands: TextCommandComponent[] = []\n\n const extensions = new Map<TextCommandComponent, object>()\n\n for (const ext of this.commandClient.registry.extensions) {\n for (const cmd of this.commandClient.registry.getComponentsWithType<TextCommandComponent>(ext, TextCommandComponent)) {\n commands.push(cmd)\n extensions.set(cmd, ext)\n }\n }\n\n let commandNameLength = 0\n\n const command = commands.find((x) => {\n const names = [x.options.name]\n\n if (x.options.aliases) {\n names.push(...x.options.aliases)\n }\n\n for (const name of names) {\n if (content.startsWith(name)) {\n if (content.length === name.length) {\n commandNameLength = name.length\n return true\n }\n commandNameLength = name.length\n return content.startsWith(name + ' ')\n }\n }\n\n return false\n })\n\n if (!command) return\n\n const ext = extensions.get(command)\n\n if (!ext) return\n\n msg.command = command\n\n const args: unknown[] = []\n\n let argStrings = content.slice(commandNameLength + 1).split(/ /g)\n\n await this.convertArguments(TextCommandComponent, args, command.argTypes, async (arg, i, converter) => {\n if (converter.options.parameterless) return [msg]\n\n if (arg.decorators.find((x) => x.constructor === TextCommandRestOption)) {\n const text = argStrings.join(' ')\n argStrings = []\n return [text, msg]\n }\n return [argStrings.shift(), msg]\n })\n\n await command.execute(ext, args, [msg])\n } catch (e) {\n this.commandClient.emit('textCommandInvokeError', e, msg)\n }\n }\n\n @argConverter({ component: TextCommandComponent, type: Message, parameterless: true })\n async mesage(msg: Message) {\n return msg\n }\n\n @argConverter({ component: TextCommandComponent, type: String })\n async str(value: string) {\n return value\n }\n\n @argConverter({ component: TextCommandComponent, type: Number })\n async num(value: string) {\n return Number(value)\n }\n}\n","/*\n * File: CommandClient.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport { Client, Snowflake, Team, User } from 'discord.js'\nimport EventEmitter from 'events'\nimport { ISettingsParam, Logger } from 'tslog'\nimport { ApplicationCommandExtension, ApplicationCommandExtensionConfig } from '../../applicationCommand/ApplicationCommandExtension'\nimport { TextCommandConfig } from '../../textCommand'\nimport { TextCommandExtension } from '../../textCommand/TextCommandExtension'\nimport { CommandClientSymbol } from '../symbols'\nimport { Registry } from './Registry'\nexport class CommandClient extends EventEmitter {\n ctsLogger: Logger\n registry: Registry\n\n owners: Set<Snowflake> = new Set()\n\n constructor(\n public discord: Client,\n public logger: Logger = new Logger({ dateTimeTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone }),\n loggerOptions: ISettingsParam = {},\n ) {\n super()\n\n this.ctsLogger = logger.getChildLogger({ prefix: [chalk.blue('[command.ts]')], displayFilePath: 'hidden', displayFunctionName: false, ...loggerOptions })\n\n this.registry = new Registry(this.ctsLogger, this)\n\n this.registry.registerEventEmitter('cts', this)\n this.registry.registerEventEmitter('discord', this.discord)\n }\n\n async isOwner(user: User): Promise<boolean> {\n return this.owners.has(user.id)\n }\n\n async fetchOwners() {\n if (!this.discord.application) throw new Error('The client is not logged in.')\n\n this.ctsLogger.info('Fetching owners...')\n\n await this.discord.application.fetch()\n\n const owner = this.discord.application.owner\n\n if (!owner) throw new Error('Cannot find application owner')\n\n const owners: string[] = []\n\n if (owner instanceof User) {\n this.owners.add(owner.id)\n owners.push(owner.tag)\n } else if (owner instanceof Team) {\n for (const [id, member] of owner.members) {\n this.owners.add(id)\n owners.push(member.user.tag)\n }\n }\n\n this.ctsLogger.info(`Fetched ${chalk.green(owners.length)} owners(${owners.map((x) => chalk.blue(x)).join(', ')})`)\n }\n\n async enableApplicationCommandsExtension(config: ApplicationCommandExtensionConfig) {\n await this.registry.registerModule(new ApplicationCommandExtension(config))\n this.ctsLogger.info('Application command extension enabled.')\n }\n\n async enableTextCommandsExtension(config: TextCommandConfig) {\n await this.registry.registerModule(new TextCommandExtension(config))\n this.ctsLogger.info('Text command extension enabled.')\n }\n\n getApplicationCommandsExtension() {\n return this.registry.extensions.find((x) => x.constructor === ApplicationCommandExtension) as ApplicationCommandExtension | undefined\n }\n\n static getFromModule(ext: object): CommandClient {\n return Reflect.getMetadata(CommandClientSymbol, ext)\n }\n}\n","/*\n * File: BaseComponent.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport _ from 'lodash'\nimport type { ComponentHookStore } from '../hooks'\nimport { ComponentArgument } from './ComponentArgument'\n\nexport class BaseComponent {\n method!: Function\n\n hooks: ComponentHookStore = new Collection()\n\n argTypes: Collection<number, ComponentArgument> = new Collection()\n\n _init(method: Function, argTypes: unknown[]) {\n this.method = method\n for (let i = 0; i < argTypes.length; i++) {\n const element = argTypes[i]\n this.argTypes.set(i, new ComponentArgument(element))\n }\n }\n\n async executeHook(target: object, name: string, args: unknown[]) {\n const hook = this.hooks.get(name)\n\n if (!hook) return\n\n const { CommandClient } = await import('../structures/CommandClient')\n\n const client = CommandClient.getFromModule(target)\n\n const globalHooks = client.registry.globalHooks[name]\n\n if (globalHooks) {\n hook.unshift(...globalHooks)\n }\n\n for (const fn of hook) {\n await fn.call(null, client, ...args)\n }\n }\n\n async execute(target: object, args: unknown[], beforeCallArgs: unknown[] = args) {\n await this.executeHook(target, 'beforeCall', beforeCallArgs)\n let result\n try {\n result = await this.method.call(target, ...args)\n await this.executeHook(target, 'afterCall', [...beforeCallArgs, result])\n } catch (e) {\n await this.executeHook(target, 'invokeError', [e, ...beforeCallArgs])\n throw e\n }\n\n return result\n }\n}\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport 'reflect-metadata'\r\nexport * from './decoratorCreator'\r\nexport * from './ComponentArgument'\r\nexport * from './ComponentArgumentDecorator'\r\nexport * from './BaseComponent'\r\n","/*\r\n* File: errors.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport class OwnerOnlyError {}\n","/*\n * File: checks.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { BaseInteraction, Interaction, Message } from 'discord.js'\nimport { createComponentHook } from '../hooks'\nimport { ComponentHookFn } from '../hooks/componentHook'\nimport { CommandClient } from '../structures'\nimport { OwnerOnlyError } from './errors'\n\nexport const createCheckDecorator = (fn: ComponentHookFn) => createComponentHook('beforeCall', fn)\n\nexport const ownerOnly = createCheckDecorator(async (client: CommandClient, i: Interaction | Message) => {\n let isOwner = false\n\n if (i instanceof BaseInteraction) {\n client\n isOwner = await client.isOwner(i.user)\n } else if (i instanceof Message) {\n isOwner = await client.isOwner(i.author)\n }\n\n if (!isOwner) throw new OwnerOnlyError()\n})\n","export const mergeMethodDecorators = (decorators: MethodDecorator[]): MethodDecorator => {\n return (target, key, descriptor) => {\n for (const decorator of decorators) {\n decorator(target, key, descriptor)\n }\n }\n}\n","/*\r\n * File: index.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nexport * from './checks'\r\nexport * from './errors'\r\nexport * from './decorators'\r\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './Extension'\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './components'\nexport * from './hooks'\nexport * from './converter'\nexport * from './utils'\nexport * from './listener'\nexport * from './structures'\nexport * from './extensions'\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './core'\r\nexport * from './applicationCommand'\r\nexport * from './textCommand'\r\n","import { APIApplicationCommandSubcommandOption, ApplicationCommandType, ChatInputApplicationCommandData } from 'discord.js'\nimport { createComponentDecorator } from '../core'\nimport { ApplicationCommandComponent } from './ApplicationCommand'\n\nexport class SubCommandGroup {\n constructor(public options: Omit<APIApplicationCommandSubcommandOption, 'type'>, public guilds?: string[]) {}\n\n command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator {\n const cmd = new ApplicationCommandComponent({\n type: ApplicationCommandType.ChatInput,\n ...options,\n })\n cmd.subcommandGroup = this\n return createComponentDecorator(cmd)\n }\n\n createChild(options: Omit<APIApplicationCommandSubcommandOption, 'type'>) {\n return new SubCommandGroupChild(options, this)\n }\n}\n\nexport class SubCommandGroupChild {\n constructor(public options: Omit<APIApplicationCommandSubcommandOption, 'type'>, public parent: SubCommandGroup) {}\n\n command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator {\n const cmd = new ApplicationCommandComponent({\n type: ApplicationCommandType.ChatInput,\n ...options,\n })\n cmd.subcommandGroupChild = this\n return createComponentDecorator(cmd)\n }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O,IAAI,GAAqB,EAAS,IAAI,IAbpC,wBAiBN,GAAM,GAAN,KAA0B,CAC/B,YAAmB,EAAqE,EAAyB,MAA9F,QAAA,OAAqE,OAAA,EAExF,QAAQ,EAAqF,CAC3F,GAAM,GAAM,GAAI,GAA4B,CAC1C,KAAM,0BAAuB,UAC7B,GAAG,EACJ,EACD,SAAI,qBAAuB,KACpB,EAAyB,CAAG,IAT1B","names":[]}
1
+ {"version":3,"sources":["../src/core/symbols.ts","../src/core/hooks/componentHook.ts","../src/core/components/decoratorCreator.ts","../src/core/components/ComponentArgument.ts","../src/core/components/ComponentArgumentDecorator.ts","../src/applicationCommand/ApplicationCommand.ts","../src/applicationCommand/ApplicationCommandOption.ts","../src/core/listener/index.ts","../src/core/converter/index.ts","../src/core/hooks/moduleHook.ts","../src/core/hooks/index.ts","../src/core/structures/Registry.ts","../src/core/structures/index.ts","../src/core/extensions/Extension.ts","../src/core/extensions/CTSExtension.ts","../src/applicationCommand/ApplicationCommandExtension.ts","../src/textCommand/TextCommand.ts","../src/textCommand/parameters.ts","../src/textCommand/TextCommandExtension.ts","../src/core/structures/CommandClient.ts","../src/core/components/BaseComponent.ts","../src/core/components/index.ts","../src/core/utils/errors.ts","../src/core/utils/checks.ts","../src/core/utils/decorators.ts","../src/core/utils/index.ts","../src/core/extensions/index.ts","../src/core/index.ts","../src/index.ts","../src/applicationCommand/group.ts"],"sourcesContent":["/*\r\n * File: symbols.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nexport const ComponentStoreSymbol = Symbol()\r\nexport const ComponentArgStoreSymbol = Symbol()\r\nexport const ModuleHookStoreSymbol = Symbol()\r\nexport const CommandClientSymbol = Symbol()\r\nexport const ComponentHookSymbol = Symbol()\r\nexport const FilePathSymbol = Symbol()\r\n","/*\n * File: componentHook.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport { ComponentHookSymbol } from '../symbols'\n\nexport type ComponentHookFn = (...args: any[]) => void | Promise<void>\n\nexport type ComponentHookStore = Collection<string, ComponentHookFn[]>\n\nexport const getComponentHookStore = (target: object, property: string | symbol): ComponentHookStore => {\n let data = Reflect.getMetadata(ComponentHookSymbol, target, property) as ComponentHookStore\n\n if (!data) {\n data = new Collection()\n Reflect.defineMetadata(ComponentHookSymbol, data, target, property)\n }\n\n return data\n}\n\nexport const createComponentHook = (name: string, fn: ComponentHookFn): MethodDecorator => {\n return (target, key) => {\n const store = getComponentHookStore(target, key)\n\n let hooks = store.get(name)\n\n if (!hooks) {\n hooks = []\n store.set(name, hooks)\n }\n\n hooks.unshift(fn)\n }\n}\n","/*\n * File: decoratorCreator.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport { ComponentHookStore } from '../hooks'\nimport { getComponentHookStore } from '../hooks/componentHook'\nimport { ComponentStoreSymbol } from '../symbols'\nimport { BaseComponent } from './BaseComponent'\nimport { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\nexport type ComponentStore = Collection<string | symbol, BaseComponent>\nexport type ComponentArgumentStore = Collection<number, ComponentArgumentDecorator>\n\nexport const getComponentStore = (target: object): ComponentStore => {\n let result: ComponentStore | null = Reflect.getMetadata(ComponentStoreSymbol, target)\n\n if (!result) {\n result = new Collection()\n\n Reflect.defineMetadata(ComponentStoreSymbol, result, target)\n }\n\n return result\n}\n\nexport const getComponent = (target: object, key: string | symbol) => {\n const store = getComponentStore(target)\n\n return store.get(key)\n}\n\nexport const createComponentDecorator = (component: BaseComponent): MethodDecorator => {\n return (target, key) => {\n component._init(Reflect.get(target, key), Reflect.getMetadata('design:paramtypes', target, key))\n\n const componentHookStore: ComponentHookStore = getComponentHookStore(target, key)\n\n component.hooks = componentHookStore\n\n const store = getComponentStore(target)\n\n const decorators = getComponentArgumentStore(target, key)\n\n decorators.forEach((x, i) => {\n component.argTypes.get(i)?.decorators.push(x)\n })\n\n store.set(key, component)\n }\n}\n\nexport const getComponentArgumentStore = (target: object, key: string | symbol): ComponentArgumentStore => {\n let result: ComponentArgumentStore | null = Reflect.getMetadata(ComponentStoreSymbol, target, key)\n\n if (!result) {\n result = new Collection()\n\n Reflect.defineMetadata(ComponentStoreSymbol, result, target, key)\n }\n\n return result\n}\n\nexport const createArgumentDecorator = <Options>(type: typeof ComponentArgumentDecorator<Options>) => {\n return (options: Options): ParameterDecorator => {\n return (target, key, idx) => {\n var arg: ComponentArgumentDecorator<Options> = new type(options)\n\n const store = getComponentArgumentStore(target, key)\n\n store.set(idx, arg)\n }\n }\n}\n","/*\r\n* File: ComponentArgument.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\nexport class ComponentArgument {\n decorators: ComponentArgumentDecorator[] = []\n\n constructor(public type: unknown) {}\n}\n","/*\r\n* File: ComponentArgumentDecorator.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport _ from 'lodash'\n\nexport class ComponentArgumentDecorator<Options = unknown> {\n options: Options\n\n constructor(options: Partial<Options>) {\n if (typeof options === 'object') {\n this.options = _.merge(this.defaultOptions(), options)\n } else {\n this.options = options\n }\n }\n\n defaultOptions(): Options {\n return {} as unknown as Options\n }\n}\n","/*\n * File: ApplicationCommand.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport type { ApplicationCommandType, ChatInputApplicationCommandData, MessageApplicationCommandData, Snowflake, UserApplicationCommandData } from 'discord.js'\nimport { createComponentDecorator } from '../core/components/decoratorCreator'\nimport { BaseComponent } from '../core/components/BaseComponent'\nimport { SubCommandGroup, SubCommandGroupChild } from './group'\n\ntype Options = (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & {\n type: ApplicationCommandType\n guilds?: Snowflake[]\n}\n\nexport class ApplicationCommandComponent extends BaseComponent {\n options: Options\n\n subcommandGroup?: SubCommandGroup\n subcommandGroupChild?: SubCommandGroupChild\n\n constructor(options: UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) {\n super()\n\n this.options = options as Options\n }\n}\n\nexport const applicationCommand = (options: Options) => createComponentDecorator(new ApplicationCommandComponent(options))\n\nexport type { Options as ApplicationCommandComponentOptions }\n","/*\r\n* File: ApplicationCommandOption.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport { APIApplicationCommandOption } from 'discord.js'\nimport { createArgumentDecorator, ComponentArgumentDecorator } from '../core'\n\ntype Options = APIApplicationCommandOption\n\nexport class ApplicationCommandOption extends ComponentArgumentDecorator<Options> {}\n\nexport const option = createArgumentDecorator(ApplicationCommandOption)\n","/*\n * File: index.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport _ from 'lodash'\nimport { BaseComponent } from '../components/BaseComponent'\nimport { createComponentDecorator } from '../components/decoratorCreator'\n\ntype Options = { emitter: string; event: string }\n\ntype OptionsArg = { emitter?: string; event: string }\n\nexport class ListenerComponent extends BaseComponent {\n options: Options\n\n constructor(options: OptionsArg) {\n super()\n\n this.options = _.merge({ emitter: 'discord' }, options)\n }\n}\n\nexport const listener = (options: OptionsArg) => createComponentDecorator(new ListenerComponent(options))\n\nexport { Options as ListenerOptions, OptionsArg as ListenerOptionsArg }\n","/*\n * File: index.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { BaseComponent } from '../components/BaseComponent'\nimport { createComponentDecorator } from '../components/decoratorCreator'\n\ntype Options = { component: unknown; type: Function; parameterless: boolean }\n\ntype OptionsArg = Omit<Options, 'parameterless'> & { parameterless?: boolean }\n\nexport class ConverterComponent extends BaseComponent {\n options: Options\n\n constructor(options: OptionsArg) {\n super()\n this.options = options as Options\n }\n}\n\nexport const argConverter = (options: OptionsArg) => createComponentDecorator(new ConverterComponent(options))\n\nexport { Options as ArgumentConvertOptions, OptionsArg as ArgumentConvertOptionsArg }\n","/*\n * File: moduleHook.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport { ModuleHookStoreSymbol } from '../symbols'\n\nexport type ModuleHookStore = Collection<string, Function[]>\n\nexport const getModuleHookStore = (target: object) => {\n let result: ModuleHookStore | null = Reflect.getMetadata(ModuleHookStoreSymbol, target)\n\n if (!result) {\n result = new Collection()\n\n Reflect.defineMetadata(ModuleHookStoreSymbol, result, target)\n }\n\n return result\n}\n\nexport const moduleHook = (name: string): MethodDecorator => {\n return (target, key) => {\n const store = getModuleHookStore(target)\n\n let v = store.get(name)\n\n if (!v) {\n v = []\n store.set(name, v)\n }\n\n v.push(Reflect.get(target, key))\n }\n}\n","/*\r\n * File: index.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nexport * from './moduleHook'\r\nexport { createComponentHook, type ComponentHookFn } from './componentHook'\r\nexport type { ComponentHookStore } from './componentHook'\r\n","/*\n * File: Registry.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport EventEmitter from 'events'\nimport _, { result } from 'lodash'\nimport { Logger } from 'tslog'\nimport { getComponentStore } from '../components'\nimport { getModuleHookStore } from '../hooks'\nimport { ListenerComponent } from '../listener'\nimport { CommandClientSymbol, FilePathSymbol } from '../symbols'\nimport { CommandClient } from './CommandClient'\nimport walkSync from 'walk-sync'\nimport path from 'path'\nimport { ComponentHookFn } from '../hooks/componentHook'\n\nexport class Registry {\n extensions: object[] = []\n\n emitters: Collection<string, EventEmitter> = new Collection()\n\n logger: Logger\n\n globalHooks: Record<string, ComponentHookFn[]> = {}\n\n constructor(logger: Logger, public client: CommandClient) {\n this.logger = logger.getChildLogger({\n prefix: [chalk.green('[Registry]')],\n })\n }\n\n addGlobalHook(name: string, fn: ComponentHookFn) {\n let hooks = this.globalHooks[name]\n\n if (!hooks) {\n hooks = []\n this.globalHooks[name] = hooks\n }\n\n hooks.push(fn)\n }\n\n getComponentsWithTypeGlobal<T>(type: unknown): T[] {\n const result: T[] = []\n\n for (const ext of this.extensions) {\n result.push(...this.getComponentsWithType<T>(ext, type))\n }\n\n return result\n }\n\n getComponentsWithType<T>(ext: object, type: unknown): T[] {\n const componentStore = getComponentStore(ext)\n\n return Array.from(componentStore.filter((x) => (x.constructor as unknown) === type).values() as Iterable<T>)\n }\n\n registerEventListeners(ext: object) {\n const listeners = this.getComponentsWithType<ListenerComponent>(ext, ListenerComponent)\n\n for (const listener of listeners) {\n const emitter = this.emitters.get(listener.options.emitter)\n\n if (emitter) {\n const bound = listener.method.bind(ext)\n\n Reflect.defineMetadata('bound', bound, listener)\n\n emitter.addListener(listener.options.event, bound)\n }\n }\n }\n\n unregisterEventListeners(ext: object) {\n const listeners = this.getComponentsWithType<ListenerComponent>(ext, ListenerComponent)\n\n for (const listener of listeners) {\n const emitter = this.emitters.get(listener.options.emitter)\n const bound = Reflect.getMetadata('bound', listener)\n\n if (emitter && bound) {\n emitter.removeListener(listener.options.event, bound)\n }\n }\n }\n\n async loadAllModulesInDirectory(dir: string): Promise<object[]> {\n const results: object[] = []\n\n const files = walkSync(dir).filter((x) => x.endsWith('.ts') || x.endsWith('.js'))\n\n for (const file of files) {\n if (file.endsWith('.d.ts')) continue\n const p = path.join(dir, file)\n results.push(...(await this.loadModulesAtPath(p)))\n }\n\n return results\n }\n\n async loadModulesAtPath(file: string) {\n this.logger.info(`Loading module at path ${chalk.green(file)}`)\n\n const p = require.resolve(file)\n\n const mod = require(p)\n\n if (typeof mod.setup !== 'function') throw new Error('Extension must have a setup function')\n\n const modules = await mod.setup(this.client)\n\n return this.registerModules(modules, p)\n }\n\n private async registerModules(modules: object | object[], p: string) {\n const results: object[] = []\n if (modules instanceof Array) {\n for (const module of modules) {\n await this.registerModule(module)\n Reflect.defineMetadata(FilePathSymbol, p, module)\n results.push(module)\n }\n } else {\n await this.registerModule(modules)\n Reflect.defineMetadata(FilePathSymbol, p, modules)\n results.push(modules)\n }\n\n return results\n }\n\n async reloadModules() {\n const result: { file: string; result: boolean; error?: Error; extensions?: object[] }[] = []\n const paths = new Set<string>()\n const extensions = [...this.extensions]\n for (const module of extensions) {\n const file = Reflect.getMetadata(FilePathSymbol, module)\n if (!file) continue\n\n this.logger.info(`Unloading module: ${chalk.green(module.constructor.name)}`)\n\n paths.add(file)\n\n await this.unregisterModule(module)\n\n delete require.cache[require.resolve(file)]\n }\n\n for (const path of paths) {\n try {\n const extensions = await this.loadModulesAtPath(path)\n\n result.push({\n file: path,\n result: true,\n extensions,\n })\n } catch (e) {\n result.push({\n file: path,\n result: false,\n error: e as Error,\n })\n }\n }\n\n return result\n }\n\n async registerModule(ext: object) {\n Reflect.defineMetadata(CommandClientSymbol, this.client, ext)\n\n this.registerEventListeners(ext)\n await this.runModuleHook(ext, 'load')\n this.extensions.push(ext)\n this.logger.info(`Module registered: ${chalk.green(ext.constructor.name)}`)\n }\n\n async unregisterModule(ext: object) {\n this.unregisterEventListeners(ext)\n await this.runModuleHook(ext, 'unload')\n _.remove(this.extensions, (x) => x === ext)\n this.logger.info(`Module unregistered: ${chalk.green(ext.constructor.name)}`)\n }\n\n runModuleHook(ext: object, hookName: string, ...args: unknown[]) {\n const hooks = getModuleHookStore(ext)\n\n const functions = hooks.get(hookName)\n\n if (functions) {\n for (const fn of functions) {\n fn.call(ext, ...args)\n }\n }\n }\n\n registerEventEmitter(name: string, emitter: EventEmitter) {\n this.emitters.set(name, emitter)\n }\n}\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './Registry'\nexport * from './CommandClient'\n","/*\n * File: Extension.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport { Logger } from 'tslog'\nimport { ComponentArgument } from '../components/ComponentArgument'\nimport { ConverterComponent } from '../converter'\nimport { CommandClient } from '../structures'\n\nexport class Extension {\n protected get commandClient() {\n return CommandClient.getFromModule(this)\n }\n\n protected get client() {\n return this.commandClient.discord\n }\n\n protected _logger?: Logger\n\n protected get logger() {\n if (!this._logger) this._logger = this.commandClient.logger.getChildLogger({ prefix: [chalk.green(`[${this.constructor.name}]`)], displayFunctionName: false })\n return this._logger\n }\n\n protected async convertArguments(\n component: unknown,\n argList: unknown[],\n args: Collection<number, ComponentArgument>,\n getConverterArgs: (arg: ComponentArgument, index: number, converter: ConverterComponent) => unknown[] | Promise<unknown[]>,\n ) {\n const items = new Collection<unknown, { ext: object; component: ConverterComponent }>()\n\n for (const extension of this.commandClient.registry.extensions) {\n for (const converter of this.commandClient.registry.getComponentsWithType<ConverterComponent>(extension, ConverterComponent)) {\n if (converter.options.component != component) continue\n\n items.set(converter.options.type, { component: converter, ext: extension })\n }\n }\n\n for (const [index, arg] of args) {\n const converter = items.get(arg.type)\n\n if (!converter) {\n argList[index] = undefined\n continue\n }\n\n const converterArgs = await getConverterArgs(arg, index, converter.component)\n\n argList[index] = await converter.component.execute(converter.ext, converterArgs)\n }\n }\n}\n","/*\r\n* File: CTSExtension.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport chalk from 'chalk'\nimport { Extension } from './Extension'\n\nexport class CTSExtension extends Extension {\n protected get logger() {\n if (!this._logger) this._logger = this.commandClient.ctsLogger.getChildLogger({ prefix: [chalk.green(`[${this.constructor.name}]`)], displayFunctionName: false })\n return this._logger\n }\n}\n","/*\n * File: ApplicationCommandExtension.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport {\n APIApplicationCommandSubcommandGroupOption,\n APIApplicationCommandSubcommandOption,\n ApplicationCommandData,\n ApplicationCommandDataResolvable,\n ApplicationCommandOptionType,\n ApplicationCommandSubCommandData,\n ApplicationCommandType,\n ChatInputApplicationCommandData,\n ChatInputCommandInteraction,\n Collection,\n CommandInteraction,\n Interaction,\n InteractionType,\n MessageContextMenuCommandInteraction,\n Snowflake,\n UserContextMenuCommandInteraction,\n} from 'discord.js'\nimport { ApplicationCommandComponent } from './ApplicationCommand'\nimport { ApplicationCommandOption } from './ApplicationCommandOption'\nimport { listener } from '../core/listener'\nimport { argConverter } from '../core/converter'\nimport { CTSExtension } from '../core/extensions/CTSExtension'\n\nexport type ApplicationCommandExtensionConfig = {\n guilds?: Snowflake[]\n}\n\nexport class ApplicationCommandExtension extends CTSExtension {\n constructor(public config: ApplicationCommandExtensionConfig) {\n super()\n }\n\n unmanagedCommands: (ApplicationCommandData & { guilds?: Snowflake[] })[] = []\n\n registerUnmanagedCommand(command: ApplicationCommandData & { guilds?: Snowflake[] }) {\n this.unmanagedCommands.push(command)\n }\n\n @listener({ event: 'interactionCreate' })\n async interactionCreate(i: Interaction) {\n try {\n if (i.type !== InteractionType.ApplicationCommand) return\n\n let cmd: ApplicationCommandComponent | null = null\n let ext: object | null = null\n\n const extensions = this.commandClient.registry.extensions\n\n let subcommand: string | null = null\n let subcommandGroup: string | null = null\n\n if (i.commandType === ApplicationCommandType.ChatInput) {\n subcommand = i.options.getSubcommand(false)\n subcommandGroup = i.options.getSubcommandGroup(false)\n }\n\n extLoop: for (const extension of extensions) {\n const components = this.commandClient.registry.getComponentsWithType<ApplicationCommandComponent>(extension, ApplicationCommandComponent)\n\n if (subcommand) {\n for (const command of components) {\n if (!command.subcommandGroup && !command.subcommandGroupChild) continue\n\n if (\n command.subcommandGroupChild &&\n command.subcommandGroupChild.parent.options.name === i.commandName &&\n command.subcommandGroupChild.options.name === subcommandGroup &&\n command.options.name === subcommand\n ) {\n ext = extension\n cmd = command\n break extLoop\n }\n if (command.subcommandGroup && !subcommandGroup && command.subcommandGroup.options.name === i.commandName && command.options.name === subcommand) {\n ext = extension\n cmd = command\n break extLoop\n }\n }\n } else {\n for (const command of components) {\n if (command.options.name === i.commandName) {\n ext = extension\n cmd = command\n break extLoop\n }\n }\n }\n }\n\n if (cmd && ext) {\n const argList: unknown[] = []\n\n await this.convertArguments(ApplicationCommandComponent, argList, cmd.argTypes, () => [i])\n\n for (const [idx, arg] of cmd.argTypes) {\n let value: unknown = null\n\n for (const decorator of arg.decorators) {\n if (decorator instanceof ApplicationCommandOption) {\n if ([ApplicationCommandOptionType.Subcommand, ApplicationCommandOptionType.SubcommandGroup].includes(decorator.options.type) && i.isChatInputCommand()) {\n if (decorator.options.type === ApplicationCommandOptionType.Subcommand) {\n value = i.options.getSubcommand() === decorator.options.name\n break\n }\n if (decorator.options.type === ApplicationCommandOptionType.SubcommandGroup) {\n value = i.options.getSubcommandGroup() === decorator.options.name\n break\n }\n }\n\n value = i.options.get(decorator.options.name, false)?.value\n break\n }\n }\n\n if (value) {\n argList[idx] = value\n }\n }\n\n try {\n await cmd.executeGlobalHook(ext, 'beforeApplicationCommandCall', [i])\n await cmd.execute(ext, argList, [i])\n } finally {\n await cmd.executeGlobalHook(ext, 'afterApplicationCommandCall', [i])\n }\n }\n } catch (e) {\n this.commandClient.emit('applicationCommandInvokeError', e, i)\n }\n }\n\n async sync() {\n const client = this.commandClient\n\n this.logger.info('Trying to sync commands...')\n\n let commands: ApplicationCommandData[] = []\n\n const guildCommands = new Collection<Snowflake, ApplicationCommandData[]>()\n\n const subcommandGroups = new Collection<string, ChatInputApplicationCommandData>()\n\n for (const command of client.registry.getComponentsWithTypeGlobal<ApplicationCommandComponent>(ApplicationCommandComponent)) {\n if (command.subcommandGroup) {\n let group = subcommandGroups.get(command.subcommandGroup.options.name)\n\n if (!group) {\n group = {\n ...command.subcommandGroup.options,\n type: ApplicationCommandType.ChatInput,\n }\n\n if (command.subcommandGroup.guilds) {\n for (const guild of command.subcommandGroup.guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n }\n } else {\n commands.push(group)\n }\n\n subcommandGroups.set(command.subcommandGroup.options.name, group)\n }\n\n if (!group.options) group.options = []\n\n const options = []\n\n for (const [, arg] of command.argTypes) {\n const option = arg.decorators.find((x) => x.constructor === ApplicationCommandOption) as ApplicationCommandOption\n\n if (option) {\n options.push(option.options)\n }\n }\n\n group.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as ApplicationCommandSubCommandData)\n\n continue\n } else if (command.subcommandGroupChild) {\n const parent = command.subcommandGroupChild.parent\n let group = subcommandGroups.get(parent.options.name)\n\n if (!group) {\n group = {\n ...parent.options,\n type: ApplicationCommandType.ChatInput,\n }\n\n if (parent.guilds) {\n for (const guild of parent.guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n }\n } else {\n commands.push(group)\n }\n\n subcommandGroups.set(parent.options.name, group)\n }\n\n if (!group.options) group.options = []\n\n let child = group.options.find((x) => x.name === command.subcommandGroupChild!.options.name) as APIApplicationCommandSubcommandGroupOption\n\n if (!child) {\n child = { type: ApplicationCommandOptionType.SubcommandGroup, ...(command.subcommandGroupChild.options as Omit<APIApplicationCommandSubcommandGroupOption, 'type'>) }\n group.options.push(child)\n }\n\n if (!child.options) child.options = []\n\n const options = []\n\n for (const [, arg] of command.argTypes) {\n const option = arg.decorators.find((x) => x.constructor === ApplicationCommandOption) as ApplicationCommandOption\n\n if (option) {\n options.push(option.options)\n }\n }\n\n child.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand, options } as APIApplicationCommandSubcommandOption)\n\n continue\n }\n\n const cmd: ApplicationCommandData = { ...command.options }\n\n if (cmd.type === ApplicationCommandType.ChatInput) {\n cmd.options = []\n\n for (const [, arg] of command.argTypes) {\n const option = arg.decorators.find((x) => x.constructor === ApplicationCommandOption) as ApplicationCommandOption\n\n if (option) {\n cmd.options.push(option.options)\n }\n }\n }\n\n await command.executeHook(this, 'beforeSync', [cmd, command])\n\n if (command.options.guilds) {\n for (const guild of command.options.guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n commands.push(cmd)\n }\n continue\n }\n\n commands.push(cmd)\n }\n\n for (const { guilds, ...rest } of this.unmanagedCommands) {\n if (guilds) {\n for (const guild of guilds) {\n let commands = guildCommands.get(guild)\n if (!commands) {\n commands = []\n guildCommands.set(guild, commands)\n }\n commands.push(rest)\n }\n continue\n } else {\n commands.push(rest)\n }\n }\n\n if (this.config.guilds) {\n for (const guild of this.config.guilds) {\n let g = guildCommands.get(guild)\n if (!g) {\n g = []\n guildCommands.set(guild, g)\n }\n g.push(...commands)\n }\n\n commands = []\n }\n\n if (guildCommands.size) {\n for (const [guild, commands] of guildCommands) {\n try {\n const g = await this.client.guilds.fetch(guild)\n await g.fetch()\n this.logger.info(\n `Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')}) for guild ${chalk.green(g.name)}(${chalk.blue(g.id)})`,\n )\n\n await g.commands.set(commands)\n\n this.logger.info(`Successfully registered commands for guild ${chalk.green(g.name)}(${chalk.blue(g.id)})`)\n } catch (e) {\n this.logger.error(`Failed to register commands to guild ${chalk.green(guild)}: ${(e as Error).message}`)\n }\n }\n }\n if (commands.length) {\n try {\n this.logger.info(`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')}) for application scope...`)\n\n await this.client.application!.commands.set(commands)\n\n this.logger.info('Successfully registered commands.')\n } catch (e) {\n this.logger.error(`Failed to register commands to global: ${(e as Error).message}`)\n }\n }\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: ChatInputCommandInteraction,\n })\n async chatInteraction(i: ChatInputCommandInteraction) {\n return i\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: MessageContextMenuCommandInteraction,\n })\n async messageInteraction(i: MessageContextMenuCommandInteraction) {\n return i\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: UserContextMenuCommandInteraction,\n })\n async userInteraction(i: UserContextMenuCommandInteraction) {\n return i\n }\n\n @argConverter({\n component: ApplicationCommandComponent,\n parameterless: true,\n type: CommandInteraction,\n })\n async commandInteraction(i: UserContextMenuCommandInteraction) {\n return i\n }\n}\n","/*\n * File: TextCommand.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { createComponentDecorator } from '../core/components/decoratorCreator'\nimport { BaseComponent } from '../core/components/BaseComponent'\n\nexport type TextCommandOptions = {\n name: string\n aliases?: string[]\n description?: string\n}\n\nexport class TextCommandComponent extends BaseComponent {\n constructor(public options: TextCommandOptions) {\n super()\n }\n}\n\nexport const command = (options: TextCommandOptions) => createComponentDecorator(new TextCommandComponent(options))\n","/*\r\n * File: parameters.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nimport { ComponentArgumentDecorator } from '../core'\r\nimport { createArgumentDecorator } from '../core'\r\n\r\nexport class TextCommandRestOption extends ComponentArgumentDecorator<void> {}\r\n\r\nexport const rest = createArgumentDecorator(TextCommandRestOption)\r\n","/*\n * File: TextCommandExtension.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { listener } from '../core/listener'\nimport { Message } from 'discord.js'\nimport { CTSExtension } from '../core/extensions/CTSExtension'\nimport { TextCommandComponent } from './TextCommand'\nimport { TextCommandRestOption } from './parameters'\nimport { argConverter } from '../core'\n\nexport type TextCommandConfig = {\n prefix:\n | string\n | string[]\n | ((msg: Message) => Promise<string | string[]> | string | string[])\n}\n\ndeclare module 'discord.js' {\n interface Message {\n command: TextCommandComponent\n }\n}\n\nexport class TextCommandExtension extends CTSExtension {\n constructor(private config: TextCommandConfig) {\n super()\n }\n\n private async processPrefix(msg: Message): Promise<number | null> {\n const content = msg.content\n let prefix = this.config.prefix\n\n if (typeof prefix === 'function') {\n prefix = await prefix(msg)\n }\n\n if (typeof prefix === 'string') {\n if (content.startsWith(prefix)) return prefix.length\n return null\n }\n\n if (prefix instanceof Array) {\n const p = prefix.find((x) => content.startsWith(x))\n\n if (p) return p.length\n return null\n }\n\n return null\n }\n\n @listener({ event: 'messageCreate', emitter: 'discord' })\n private async messageCreate(msg: Message) {\n try {\n const startIndex = await this.processPrefix(msg)\n\n if (startIndex === null) return\n\n const content = msg.content.slice(startIndex)\n\n const commands: TextCommandComponent[] = []\n\n const extensions = new Map<TextCommandComponent, object>()\n\n for (const ext of this.commandClient.registry.extensions) {\n for (const cmd of this.commandClient.registry.getComponentsWithType<TextCommandComponent>(\n ext,\n TextCommandComponent\n )) {\n commands.push(cmd)\n extensions.set(cmd, ext)\n }\n }\n\n let commandNameLength = 0\n\n const command = commands.find((x) => {\n const names = [x.options.name]\n\n if (x.options.aliases) {\n names.push(...x.options.aliases)\n }\n\n for (const name of names) {\n if (content.startsWith(name)) {\n if (content.length === name.length) {\n commandNameLength = name.length\n return true\n }\n commandNameLength = name.length\n return content.startsWith(name + ' ')\n }\n }\n\n return false\n })\n\n if (!command) return\n\n const ext = extensions.get(command)\n\n if (!ext) return\n\n msg.command = command\n\n const args: unknown[] = []\n\n let argStrings = content.slice(commandNameLength + 1).split(/ /g)\n\n await this.convertArguments(\n TextCommandComponent,\n args,\n command.argTypes,\n async (arg, i, converter) => {\n if (converter.options.parameterless) return [msg]\n\n if (\n arg.decorators.find((x) => x.constructor === TextCommandRestOption)\n ) {\n const text = argStrings.join(' ')\n argStrings = []\n return [text, msg]\n }\n return [argStrings.shift(), msg]\n }\n )\n\n await command.execute(ext, args, [msg])\n } catch (e) {\n this.commandClient.emit('textCommandInvokeError', e, msg)\n }\n }\n\n @argConverter({\n component: TextCommandComponent,\n type: Message,\n parameterless: true,\n })\n async mesage(msg: Message) {\n return msg\n }\n\n @argConverter({ component: TextCommandComponent, type: String })\n async str(value: string) {\n return value\n }\n\n @argConverter({ component: TextCommandComponent, type: Number })\n async num(value: string) {\n return Number(value)\n }\n}\n","/*\n * File: CommandClient.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport chalk from 'chalk'\nimport { Client, Snowflake, Team, User } from 'discord.js'\nimport EventEmitter from 'events'\nimport { ISettingsParam, Logger } from 'tslog'\nimport { ApplicationCommandExtension, ApplicationCommandExtensionConfig } from '../../applicationCommand/ApplicationCommandExtension'\nimport { TextCommandConfig } from '../../textCommand'\nimport { TextCommandExtension } from '../../textCommand/TextCommandExtension'\nimport { CommandClientSymbol } from '../symbols'\nimport { Registry } from './Registry'\nexport class CommandClient extends EventEmitter {\n ctsLogger: Logger\n registry: Registry\n\n owners: Set<Snowflake> = new Set()\n\n constructor(\n public discord: Client,\n public logger: Logger = new Logger({ dateTimeTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone }),\n loggerOptions: ISettingsParam = {},\n ) {\n super()\n\n this.ctsLogger = logger.getChildLogger({ prefix: [chalk.blue('[command.ts]')], displayFilePath: 'hidden', displayFunctionName: false, ...loggerOptions })\n\n this.registry = new Registry(this.ctsLogger, this)\n\n this.registry.registerEventEmitter('cts', this)\n this.registry.registerEventEmitter('discord', this.discord)\n }\n\n async isOwner(user: User): Promise<boolean> {\n return this.owners.has(user.id)\n }\n\n async fetchOwners() {\n if (!this.discord.application) throw new Error('The client is not logged in.')\n\n this.ctsLogger.info('Fetching owners...')\n\n await this.discord.application.fetch()\n\n const owner = this.discord.application.owner\n\n if (!owner) throw new Error('Cannot find application owner')\n\n const owners: string[] = []\n\n if (owner instanceof User) {\n this.owners.add(owner.id)\n owners.push(owner.tag)\n } else if (owner instanceof Team) {\n for (const [id, member] of owner.members) {\n this.owners.add(id)\n owners.push(member.user.tag)\n }\n }\n\n this.ctsLogger.info(`Fetched ${chalk.green(owners.length)} owners(${owners.map((x) => chalk.blue(x)).join(', ')})`)\n }\n\n async enableApplicationCommandsExtension(config: ApplicationCommandExtensionConfig) {\n await this.registry.registerModule(new ApplicationCommandExtension(config))\n this.ctsLogger.info('Application command extension enabled.')\n }\n\n async enableTextCommandsExtension(config: TextCommandConfig) {\n await this.registry.registerModule(new TextCommandExtension(config))\n this.ctsLogger.info('Text command extension enabled.')\n }\n\n getApplicationCommandsExtension() {\n return this.registry.extensions.find((x) => x.constructor === ApplicationCommandExtension) as ApplicationCommandExtension | undefined\n }\n\n static getFromModule(ext: object): CommandClient {\n return Reflect.getMetadata(CommandClientSymbol, ext)\n }\n}\n","/*\n * File: BaseComponent.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { Collection } from 'discord.js'\nimport _ from 'lodash'\nimport type { ComponentHookStore } from '../hooks'\nimport { ComponentArgument } from './ComponentArgument'\n\nexport class BaseComponent {\n method!: Function\n\n hooks: ComponentHookStore = new Collection()\n\n argTypes: Collection<number, ComponentArgument> = new Collection()\n\n _init(method: Function, argTypes: unknown[]) {\n this.method = method\n for (let i = 0; i < argTypes.length; i++) {\n const element = argTypes[i]\n this.argTypes.set(i, new ComponentArgument(element))\n }\n }\n\n async executeGlobalHook(target: object, name: string, args: unknown[]) {\n const { CommandClient } = await import('../structures/CommandClient')\n\n const client = CommandClient.getFromModule(target)\n\n const globalHooks = client.registry.globalHooks[name]\n\n if (globalHooks) {\n for (const fn of globalHooks) {\n await fn.call(null, client, ...args)\n }\n }\n }\n\n async executeHook(target: object, name: string, args: unknown[]) {\n const hook = this.hooks.get(name)\n\n if (!hook) return\n\n const { CommandClient } = await import('../structures/CommandClient')\n\n const client = CommandClient.getFromModule(target)\n\n const globalHooks = client.registry.globalHooks[name]\n\n if (globalHooks) {\n hook.unshift(...globalHooks)\n }\n\n for (const fn of hook) {\n await fn.call(null, client, ...args)\n }\n }\n\n async execute(target: object, args: unknown[], beforeCallArgs: unknown[] = args) {\n await this.executeHook(target, 'beforeCall', beforeCallArgs)\n let result\n try {\n result = await this.method.call(target, ...args)\n await this.executeHook(target, 'afterCall', [...beforeCallArgs, result])\n } catch (e) {\n await this.executeHook(target, 'invokeError', [e, ...beforeCallArgs])\n throw e\n }\n\n return result\n }\n}\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nimport 'reflect-metadata'\r\nexport * from './decoratorCreator'\r\nexport * from './ComponentArgument'\r\nexport * from './ComponentArgumentDecorator'\r\nexport * from './BaseComponent'\r\n","/*\r\n* File: errors.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport class OwnerOnlyError {}\n","/*\n * File: checks.ts\n *\n * Copyright (c) 2022-2022 pikokr\n *\n * Licensed under MIT License. Please see more defails in LICENSE file.\n */\n\nimport { BaseInteraction, Interaction, Message } from 'discord.js'\nimport { createComponentHook } from '../hooks'\nimport { ComponentHookFn } from '../hooks/componentHook'\nimport { CommandClient } from '../structures'\nimport { OwnerOnlyError } from './errors'\n\nexport const createCheckDecorator = (fn: ComponentHookFn) => createComponentHook('beforeCall', fn)\n\nexport const ownerOnly = createCheckDecorator(async (client: CommandClient, i: Interaction | Message) => {\n let isOwner = false\n\n if (i instanceof BaseInteraction) {\n client\n isOwner = await client.isOwner(i.user)\n } else if (i instanceof Message) {\n isOwner = await client.isOwner(i.author)\n }\n\n if (!isOwner) throw new OwnerOnlyError()\n})\n","export const mergeMethodDecorators = (decorators: MethodDecorator[]): MethodDecorator => {\n return (target, key, descriptor) => {\n for (const decorator of decorators) {\n decorator(target, key, descriptor)\n }\n }\n}\n","/*\r\n * File: index.ts\r\n *\r\n * Copyright (c) 2022-2022 pikokr\r\n *\r\n * Licensed under MIT License. Please see more defails in LICENSE file.\r\n */\r\n\r\nexport * from './checks'\r\nexport * from './errors'\r\nexport * from './decorators'\r\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './Extension'\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './components'\nexport * from './hooks'\nexport * from './converter'\nexport * from './utils'\nexport * from './listener'\nexport * from './structures'\nexport * from './extensions'\n","/*\r\n* File: index.ts\r\n* \r\n* Copyright (c) 2022-2022 pikokr\r\n* \r\n* Licensed under MIT License. Please see more defails in LICENSE file.\r\n*/\r\n\r\nexport * from './core'\r\nexport * from './applicationCommand'\r\nexport * from './textCommand'\r\n","import { APIApplicationCommandSubcommandOption, ApplicationCommandType, ChatInputApplicationCommandData } from 'discord.js'\nimport { createComponentDecorator } from '../core'\nimport { ApplicationCommandComponent } from './ApplicationCommand'\n\nexport class SubCommandGroup {\n constructor(public options: Omit<APIApplicationCommandSubcommandOption, 'type'>, public guilds?: string[]) {}\n\n command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator {\n const cmd = new ApplicationCommandComponent({\n type: ApplicationCommandType.ChatInput,\n ...options,\n })\n cmd.subcommandGroup = this\n return createComponentDecorator(cmd)\n }\n\n createChild(options: Omit<APIApplicationCommandSubcommandOption, 'type'>) {\n return new SubCommandGroupChild(options, this)\n }\n}\n\nexport class SubCommandGroupChild {\n constructor(public options: Omit<APIApplicationCommandSubcommandOption, 'type'>, public parent: SubCommandGroup) {}\n\n command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator {\n const cmd = new ApplicationCommandComponent({\n type: ApplicationCommandType.ChatInput,\n ...options,\n })\n cmd.subcommandGroupChild = this\n return createComponentDecorator(cmd)\n }\n}\n"],"mappings":"+pBAAA,oBAAA,8FCAA,GAQA,IAOa,GAWA,GA1Bb,uBAQA,GAA2B,sBAC3B,IAMO,AAAM,GAAwB,GAAC,EAAgB,IAAkD,CACtG,GAAI,GAAO,QAAQ,YAAY,GAAqB,EAAQ,CAAQ,EAEpE,MAAK,IACH,GAAO,GAAI,eACX,QAAQ,eAAe,GAAqB,EAAM,EAAQ,CAAQ,GAG7D,GAR4B,yBAWxB,GAAsB,GAAC,EAAc,IACzC,CAAC,EAAQ,IAAQ,CACtB,GAAM,GAAQ,GAAsB,EAAQ,CAAG,EAE3C,EAAQ,EAAM,IAAI,CAAI,EAE1B,AAAK,GACH,GAAQ,CAAA,EACR,EAAM,IAAI,EAAM,CAAK,GAGvB,EAAM,QAAQ,CAAE,GAXe,yBC1BnC,GAQA,IAUa,EAYA,GAMA,EAoBA,GAYA,EApEb,sBAQA,GAA2B,sBAE3B,KACA,IAOO,AAAM,EAAoB,EAAC,GAAmC,CACnE,GAAI,GAAgC,QAAQ,YAAY,EAAsB,CAAM,EAEpF,MAAK,IACH,GAAS,GAAI,eAEb,QAAQ,eAAe,EAAsB,EAAQ,CAAM,GAGtD,GATwB,qBAYpB,GAAe,GAAC,EAAgB,IAGpC,AAFO,EAAkB,CAAM,EAEzB,IAAI,CAAG,EAHM,gBAMf,EAA2B,EAAC,GAChC,CAAC,EAAQ,IAAQ,CACtB,EAAU,MAAM,QAAQ,IAAI,EAAQ,CAAG,EAAG,QAAQ,Y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AAqB,MAAO,EAAuB,IAA6B,CACvG,GAAI,GAAU,GASd,GAPA,AAAI,YAAa,oBAEf,EAAU,KAAM,GAAO,QAAQ,EAAE,IAAI,EAC5B,YAAa,aACtB,GAAU,KAAM,GAAO,QAAQ,EAAE,MAAM,GAGrC,CAAC,EAAS,KAAM,IAAI,GACzB,IC3BD,GAAa,IAAb,uBAAO,AAAM,GAAwB,EAAC,GAC7B,CAAC,EAAQ,EAAK,IAAe,CAClC,OAAW,KAAa,GACtB,EAAU,EAAQ,EAAK,CAAU,GAHF,2BCArC,4CCAA,kCCAA,0BAcA,oCCdA,0yBCAA,OAA+G,sBAC/G,IACA,KAEO,GAAM,IAAN,KAAqB,CAC1B,YAAmB,EAAqE,EAAmB,MAAxF,QAAA,OAAqE,OAAA,EAExF,QAAQ,EAAqF,CAC3F,GAAM,GAAM,GAAI,GAA4B,CAC1C,KAAM,0BAAuB,UAC7B,GAAG,EACJ,EACD,SAAI,gBAAkB,KACf,EAAyB,CAAG,EAGrC,YAAY,EAA8D,CACxE,MAAO,IAAI,GAAqB,EAAS,IAAI,IAbpC,wBAiBN,GAAM,GAAN,KAA0B,CAC/B,YAAmB,EAAqE,EAAyB,MAA9F,QAAA,OAAqE,OAAA,EAExF,QAAQ,EAAqF,CAC3F,GAAM,GAAM,GAAI,GAA4B,CAC1C,KAAM,0BAAuB,UAC7B,GAAG,EACJ,EACD,SAAI,qBAAuB,KACpB,EAAyB,CAAG,IAT1B","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikokr/command.ts",
3
3
  "description": "Discord.js command framework for typescript.",
4
- "version": "5.3.0-dev.64b0ef9",
4
+ "version": "5.3.1-dev.a03aefb",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -129,7 +129,12 @@ export class ApplicationCommandExtension extends CTSExtension {
129
129
  }
130
130
  }
131
131
 
132
- await cmd.execute(ext, argList, [i])
132
+ try {
133
+ await cmd.executeGlobalHook(ext, 'beforeApplicationCommandCall', [i])
134
+ await cmd.execute(ext, argList, [i])
135
+ } finally {
136
+ await cmd.executeGlobalHook(ext, 'afterApplicationCommandCall', [i])
137
+ }
133
138
  }
134
139
  } catch (e) {
135
140
  this.commandClient.emit('applicationCommandInvokeError', e, i)
@@ -26,6 +26,20 @@ export class BaseComponent {
26
26
  }
27
27
  }
28
28
 
29
+ async executeGlobalHook(target: object, name: string, args: unknown[]) {
30
+ const { CommandClient } = await import('../structures/CommandClient')
31
+
32
+ const client = CommandClient.getFromModule(target)
33
+
34
+ const globalHooks = client.registry.globalHooks[name]
35
+
36
+ if (globalHooks) {
37
+ for (const fn of globalHooks) {
38
+ await fn.call(null, client, ...args)
39
+ }
40
+ }
41
+ }
42
+
29
43
  async executeHook(target: object, name: string, args: unknown[]) {
30
44
  const hook = this.hooks.get(name)
31
45
 
@@ -14,7 +14,10 @@ import { TextCommandRestOption } from './parameters'
14
14
  import { argConverter } from '../core'
15
15
 
16
16
  export type TextCommandConfig = {
17
- prefix: string | string[] | ((msg: Message) => Promise<string | string[]> | string | string[])
17
+ prefix:
18
+ | string
19
+ | string[]
20
+ | ((msg: Message) => Promise<string | string[]> | string | string[])
18
21
  }
19
22
 
20
23
  declare module 'discord.js' {
@@ -56,7 +59,7 @@ export class TextCommandExtension extends CTSExtension {
56
59
  try {
57
60
  const startIndex = await this.processPrefix(msg)
58
61
 
59
- if (!startIndex) return
62
+ if (startIndex === null) return
60
63
 
61
64
  const content = msg.content.slice(startIndex)
62
65
 
@@ -65,7 +68,10 @@ export class TextCommandExtension extends CTSExtension {
65
68
  const extensions = new Map<TextCommandComponent, object>()
66
69
 
67
70
  for (const ext of this.commandClient.registry.extensions) {
68
- for (const cmd of this.commandClient.registry.getComponentsWithType<TextCommandComponent>(ext, TextCommandComponent)) {
71
+ for (const cmd of this.commandClient.registry.getComponentsWithType<TextCommandComponent>(
72
+ ext,
73
+ TextCommandComponent
74
+ )) {
69
75
  commands.push(cmd)
70
76
  extensions.set(cmd, ext)
71
77
  }
@@ -106,16 +112,23 @@ export class TextCommandExtension extends CTSExtension {
106
112
 
107
113
  let argStrings = content.slice(commandNameLength + 1).split(/ /g)
108
114
 
109
- await this.convertArguments(TextCommandComponent, args, command.argTypes, async (arg, i, converter) => {
110
- if (converter.options.parameterless) return [msg]
111
-
112
- if (arg.decorators.find((x) => x.constructor === TextCommandRestOption)) {
113
- const text = argStrings.join(' ')
114
- argStrings = []
115
- return [text, msg]
115
+ await this.convertArguments(
116
+ TextCommandComponent,
117
+ args,
118
+ command.argTypes,
119
+ async (arg, i, converter) => {
120
+ if (converter.options.parameterless) return [msg]
121
+
122
+ if (
123
+ arg.decorators.find((x) => x.constructor === TextCommandRestOption)
124
+ ) {
125
+ const text = argStrings.join(' ')
126
+ argStrings = []
127
+ return [text, msg]
128
+ }
129
+ return [argStrings.shift(), msg]
116
130
  }
117
- return [argStrings.shift(), msg]
118
- })
131
+ )
119
132
 
120
133
  await command.execute(ext, args, [msg])
121
134
  } catch (e) {
@@ -123,7 +136,11 @@ export class TextCommandExtension extends CTSExtension {
123
136
  }
124
137
  }
125
138
 
126
- @argConverter({ component: TextCommandComponent, type: Message, parameterless: true })
139
+ @argConverter({
140
+ component: TextCommandComponent,
141
+ type: Message,
142
+ parameterless: true,
143
+ })
127
144
  async mesage(msg: Message) {
128
145
  return msg
129
146
  }