@pikokr/command.ts 5.0.0-dev.97799e9 → 5.0.0-dev.a935c89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as discord_js from 'discord.js';
2
2
  import { Collection, Snowflake, Interaction, ChatInputCommandInteraction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, Client, UserApplicationCommandData, MessageApplicationCommandData, ChatInputApplicationCommandData, ApplicationCommandType, APIApplicationCommandOption } from 'discord.js';
3
3
  import EventEmitter from 'events';
4
+ import * as tslog from 'tslog';
4
5
  import { Logger } from 'tslog';
5
6
 
6
7
  declare class ComponentArgumentDecorator<Options = unknown> {
@@ -39,15 +40,19 @@ declare const createArgumentDecorator: <Options>(type: {
39
40
  declare class Extension {
40
41
  protected get commandClient(): CommandClient;
41
42
  protected get client(): discord_js.Client<boolean>;
42
- private _logger?;
43
+ protected _logger?: Logger;
43
44
  protected get logger(): Logger;
44
45
  protected convertArguments(component: typeof BaseComponent<unknown>, argList: unknown[], args: Collection<number, ComponentArgument>, getConverterArgs: (arg: ComponentArgument, index: number) => unknown[] | Promise<unknown[]>): Promise<void>;
45
46
  }
46
47
 
48
+ declare class CTSExtension extends Extension {
49
+ protected get logger(): tslog.Logger;
50
+ }
51
+
47
52
  declare type ApplicationCommandExtensionConfig = {
48
53
  guilds?: Snowflake[];
49
54
  };
50
- declare class ApplicationCommandExtension extends Extension {
55
+ declare class ApplicationCommandExtension extends CTSExtension {
51
56
  config: ApplicationCommandExtensionConfig;
52
57
  constructor(config: ApplicationCommandExtensionConfig);
53
58
  interactionCreate(i: Interaction): Promise<void>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var it=Object.create;var v=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames,B=Object.getOwnPropertySymbols,at=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var z=(o,t,e)=>t in o?v(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,U=(o,t)=>{for(var e in t||(t={}))G.call(t,e)&&z(o,e,t[e]);if(B)for(var e of B(t))pt.call(t,e)&&z(o,e,t[e]);return o};var Z=o=>v(o,"__esModule",{value:!0}),i=(o,t)=>v(o,"name",{value:t,configurable:!0});var lt=(o,t)=>{for(var e in t)v(o,e,{get:t[e],enumerable:!0})},q=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of mt(t))!G.call(o,r)&&(e||r!=="default")&&v(o,r,{get:()=>t[r],enumerable:!(n=ct(t,r))||n.enumerable});return o},x=(o,t)=>q(Z(v(o!=null?it(at(o)):{},"default",!t&&o&&o.__esModule?{get:()=>o.default,enumerable:!0}:{value:o,enumerable:!0})),o),ft=(o=>(t,e)=>o&&o.get(t)||(e=q(Z({}),t,1),o&&o.set(t,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var ut={};lt(ut,{ApplicationCommandComponent:()=>l,BaseComponent:()=>u,CommandClient:()=>b,ConverterComponent:()=>w,Registry:()=>E,applicationCommand:()=>gt,argConverter:()=>I,createArgumentDecorator:()=>k,createComponentDecorator:()=>C,getComponent:()=>dt,getComponentArgumentStore:()=>W,getComponentStore:()=>T,getModuleHookStore:()=>O,moduleHook:()=>P,option:()=>tt});var wt=require("reflect-metadata");var J=require("discord.js");var A=class{constructor(t){this.type=t,this.decorators=[]}};i(A,"ComponentArgument");var u=class{argTypes=new J.Collection;constructor(t,e,n){this.options=this.convertOptions(t),this.method=e;for(let r=0;r<n.length;r++){let s=n[r];this.argTypes.set(r,new A(s))}}convertOptions(t){return t}execute(t,e){return this.method.call(t,...e)}};i(u,"BaseComponent");var D=require("discord.js");var R=Symbol(),bt=Symbol(),H=Symbol(),L=Symbol();var T=i(o=>{let t=Reflect.getMetadata(R,o);return t||(t=new D.Collection,Reflect.defineMetadata(R,t,o)),t},"getComponentStore"),dt=i((o,t)=>T(o).get(t),"getComponent"),C=i(o=>t=>(e,n)=>{var r=new o(t,Reflect.get(e,n),Reflect.getMetadata("design:paramtypes",e,n));let s=T(e);W(e,n).forEach((m,f)=>{var h;(h=r.argTypes.get(f))==null||h.decorators.push(m)}),s.set(n,r)},"createComponentDecorator"),W=i((o,t)=>{let e=Reflect.getMetadata(R,o,t);return e||(e=new D.Collection,Reflect.defineMetadata(R,e,o,t)),e},"getComponentArgumentStore"),k=i(o=>t=>(e,n,r)=>{var s=new o(t);W(e,n).set(r,s)},"createArgumentDecorator");var _=x(require("chalk")),V=require("discord.js"),X=x(require("lodash"));var K=require("discord.js");var O=i(o=>{let t=Reflect.getMetadata(H,o);return t||(t=new K.Collection,Reflect.defineMetadata(H,t,o)),t},"getModuleHookStore"),P=i(o=>(t,e)=>{let n=O(t),r=n.get(e);r||(r=[],n.set(e,r)),r.push(Reflect.get(t,e))},"moduleHook");var M=class extends u{defaultOptions(){return{emitter:"discord"}}constructor(t,e,n){super({event:t.event,emitter:(r=t.emitter)!=null?r:"discord"},e,n);var r}};i(M,"ListenerComponent");var Q=C(M);var E=class{constructor(t,e){this.client=e,this.extensions=[],this.emitters=new V.Collection,this.logger=t.getChildLogger({prefix:[_.default.green("[Registry]")]})}getComponentsWithTypeGlobal(t){let e=[];for(let n of this.extensions)e.push(...this.getComponentsWithType(n,t));return e}getComponentsWithType(t,e){let n=T(t);return Array.from(n.filter(r=>r.constructor===e).values())}registerEventListeners(t){let e=this.getComponentsWithType(t,M);for(let n of e){let r=this.emitters.get(n.options.emitter);if(r){let s=n.method.bind(t);Reflect.defineMetadata("bound",s,n),r.addListener(n.options.event,s)}}}unregisterEventListeners(t){let e=this.getComponentsWithType(t,M);for(let n of e){let r=this.emitters.get(n.options.emitter),s=Reflect.getMetadata("bound",n);r&&s&&r.removeListener(n.options.event,s)}}async registerModule(t){Reflect.defineMetadata(L,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${_.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),X.default.remove(this.extensions,e=>e===t),this.logger.info(`Module unregistered: ${_.default.green(t.constructor.name)}`)}runModuleHook(t,e,...n){let s=O(t).get(e);if(s)for(let c of s)c.call(t,...n)}registerEventEmitter(t,e){this.emitters.set(t,e)}};i(E,"Registry");var rt=x(require("chalk")),nt=x(require("events")),st=require("tslog");var y=x(require("chalk")),p=require("discord.js");var l=class extends u{};i(l,"ApplicationCommandComponent");var gt=C(l);var Y=x(require("lodash")),$=class{constructor(t){typeof t=="object"?this.options=Y.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};i($,"ComponentArgumentDecorator");var S=class extends ${};i(S,"ApplicationCommandOption");var tt=k(S);var et=x(require("chalk")),ot=require("discord.js");var w=class extends u{};i(w,"ConverterComponent");var I=C(w);var j=class{get commandClient(){return b.getFromModule(this)}get client(){return this.commandClient.discord}get logger(){return this._logger||(this._logger=this.commandClient.logger.getChildLogger({prefix:[et.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}async convertArguments(t,e,n,r){let s=new ot.Collection;for(let c of this.commandClient.registry.extensions)for(let m of this.commandClient.registry.getComponentsWithType(c,w))m.options.component==t&&s.set(m.options.type,{component:m,ext:c});for(let[c,m]of n){let f=s.get(m.type);if(!f){e[c]=void 0;continue}let h=await r(m,c);e[c]=await f.component.execute(f.ext,h)}}};i(j,"Extension");var F=function(o,t,e,n){var r=arguments.length,s=r<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(o,t,e,n);else for(var m=o.length-1;m>=0;m--)(c=o[m])&&(s=(r<3?c(s):r>3?c(t,e,s):c(t,e))||s);return r>3&&s&&Object.defineProperty(t,e,s),s},d=function(o,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,t)},g=class extends j{constructor(t){super();this.config=t}async interactionCreate(t){var s;if(t.type!==p.InteractionType.ApplicationCommand)return;let e=null,n=null,r=this.commandClient.registry.extensions;for(let c of r){let m=this.commandClient.registry.getComponentsWithType(c,l);for(let f of m)f.options.name===t.commandName&&(n=c,e=f)}if(e&&n){let c=[];await this.convertArguments(l,c,e.argTypes,()=>[t]);for(let[m,f]of e.argTypes){let h=null;for(let N of f.decorators)if(N instanceof S){h=(s=t.options.get(N.options.name,!1))==null?void 0:s.value;break}h&&(c[m]=h)}try{await e.execute(n,c)}catch(m){this.logger.error(m),this.commandClient.emit("applicationCommandInvokeError",m,t)}}}async load(){}async sync(){let t=b.getFromModule(this);this.logger.info("Trying to sync commands...");let e=[];for(let n of t.registry.getComponentsWithTypeGlobal(l)){let r=U({},n.options);if(r.type===p.ApplicationCommandType.ChatInput){r.options=[];for(let[,s]of n.argTypes){let c=s.decorators.find(m=>m.constructor===S);c&&r.options.push(c.options)}}e.push(r)}if(this.logger.info(`Processing ${y.default.green(e.length)} commands(${e.map(n=>y.default.blue(n.name)).join(", ")})`),this.config.guilds)for(let n of this.config.guilds)try{let r=await this.client.guilds.fetch(n);await r.fetch(),this.logger.info(`Registering commands for guild ${y.default.green(r.name)}(${y.default.blue(r.id)})`),await r.commands.set(e),this.logger.info(`Successfully registered commands for guild ${y.default.green(r.name)}(${y.default.blue(r.id)})`)}catch(r){this.logger.error(`Failed to register commands to guild ${y.default.green(n)}: ${r.message}`)}else try{this.logger.info("Registering commands globally..."),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}};i(g,"ApplicationCommandExtension");F([Q({event:"interactionCreate"}),d("design:type",Function),d("design:paramtypes",[typeof p.Interaction=="undefined"?Object:p.Interaction])],g.prototype,"interactionCreate",null);F([P("load"),d("design:type",Function),d("design:paramtypes",[])],g.prototype,"load",null);F([I({component:l,parameterless:!0,type:p.ChatInputCommandInteraction}),d("design:type",Function),d("design:paramtypes",[typeof p.ChatInputCommandInteraction=="undefined"?Object:p.ChatInputCommandInteraction])],g.prototype,"chatInteraction",null);F([I({component:l,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),d("design:type",Function),d("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction=="undefined"?Object:p.MessageContextMenuCommandInteraction])],g.prototype,"messageInteraction",null);F([I({component:l,parameterless:!0,type:p.UserContextMenuCommandInteraction}),d("design:type",Function),d("design:paramtypes",[typeof p.UserContextMenuCommandInteraction=="undefined"?Object:p.UserContextMenuCommandInteraction])],g.prototype,"userInteraction",null);var b=class extends nt.default{constructor(t,e=new st.Logger({dateTimeTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone})){super();this.discord=t,this.logger=e,this.ctsLogger=e.getChildLogger({prefix:[rt.default.blue("[command.ts]")],displayFilePath:"hidden",displayFunctionName:!1}),this.registry=new E(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}async enableApplicationCommandsExtension(t){await this.registry.registerModule(new g(t)),this.ctsLogger.info("Application command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===g)}static getFromModule(t){return Reflect.getMetadata(L,t)}};i(b,"CommandClient");module.exports=ft(ut);0&&(module.exports={ApplicationCommandComponent,BaseComponent,CommandClient,ConverterComponent,Registry,applicationCommand,argConverter,createArgumentDecorator,createComponentDecorator,getComponent,getComponentArgumentStore,getComponentStore,getModuleHookStore,moduleHook,option});
1
+ var mt=Object.create;var v=Object.defineProperty;var at=Object.getOwnPropertyDescriptor;var pt=Object.getOwnPropertyNames,G=Object.getOwnPropertySymbols,lt=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var U=(o,t,e)=>t in o?v(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,Z=(o,t)=>{for(var e in t||(t={}))z.call(t,e)&&U(o,e,t[e]);if(G)for(var e of G(t))ft.call(t,e)&&U(o,e,t[e]);return o};var q=o=>v(o,"__esModule",{value:!0}),s=(o,t)=>v(o,"name",{value:t,configurable:!0});var gt=(o,t)=>{for(var e in t)v(o,e,{get:t[e],enumerable:!0})},J=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of pt(t))!z.call(o,r)&&(e||r!=="default")&&v(o,r,{get:()=>t[r],enumerable:!(n=at(t,r))||n.enumerable});return o},y=(o,t)=>J(q(v(o!=null?mt(lt(o)):{},"default",!t&&o&&o.__esModule?{get:()=>o.default,enumerable:!0}:{value:o,enumerable:!0})),o),dt=(o=>(t,e)=>o&&o.get(t)||(e=J(q({}),t,1),o&&o.set(t,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var yt={};gt(yt,{ApplicationCommandComponent:()=>l,BaseComponent:()=>u,CommandClient:()=>b,ConverterComponent:()=>w,Registry:()=>E,applicationCommand:()=>ht,argConverter:()=>_,createArgumentDecorator:()=>N,createComponentDecorator:()=>C,getComponent:()=>ut,getComponentArgumentStore:()=>W,getComponentStore:()=>T,getModuleHookStore:()=>A,moduleHook:()=>P,option:()=>et});var Tt=require("reflect-metadata");var K=require("discord.js");var I=class{constructor(t){this.type=t,this.decorators=[]}};s(I,"ComponentArgument");var u=class{argTypes=new K.Collection;constructor(t,e,n){this.options=this.convertOptions(t),this.method=e;for(let r=0;r<n.length;r++){let i=n[r];this.argTypes.set(r,new I(i))}}convertOptions(t){return t}execute(t,e){return this.method.call(t,...e)}};s(u,"BaseComponent");var D=require("discord.js");var R=Symbol(),Mt=Symbol(),k=Symbol(),L=Symbol();var T=s(o=>{let t=Reflect.getMetadata(R,o);return t||(t=new D.Collection,Reflect.defineMetadata(R,t,o)),t},"getComponentStore"),ut=s((o,t)=>T(o).get(t),"getComponent"),C=s(o=>t=>(e,n)=>{var r=new o(t,Reflect.get(e,n),Reflect.getMetadata("design:paramtypes",e,n));let i=T(e);W(e,n).forEach((m,f)=>{var h;(h=r.argTypes.get(f))==null||h.decorators.push(m)}),i.set(n,r)},"createComponentDecorator"),W=s((o,t)=>{let e=Reflect.getMetadata(R,o,t);return e||(e=new D.Collection,Reflect.defineMetadata(R,e,o,t)),e},"getComponentArgumentStore"),N=s(o=>t=>(e,n,r)=>{var i=new o(t);W(e,n).set(r,i)},"createArgumentDecorator");var O=y(require("chalk")),X=require("discord.js"),Y=y(require("lodash"));var Q=require("discord.js");var A=s(o=>{let t=Reflect.getMetadata(k,o);return t||(t=new Q.Collection,Reflect.defineMetadata(k,t,o)),t},"getModuleHookStore"),P=s(o=>(t,e)=>{let n=A(t),r=n.get(e);r||(r=[],n.set(e,r)),r.push(Reflect.get(t,e))},"moduleHook");var M=class extends u{defaultOptions(){return{emitter:"discord"}}constructor(t,e,n){super({event:t.event,emitter:(r=t.emitter)!=null?r:"discord"},e,n);var r}};s(M,"ListenerComponent");var V=C(M);var E=class{constructor(t,e){this.client=e,this.extensions=[],this.emitters=new X.Collection,this.logger=t.getChildLogger({prefix:[O.default.green("[Registry]")]})}getComponentsWithTypeGlobal(t){let e=[];for(let n of this.extensions)e.push(...this.getComponentsWithType(n,t));return e}getComponentsWithType(t,e){let n=T(t);return Array.from(n.filter(r=>r.constructor===e).values())}registerEventListeners(t){let e=this.getComponentsWithType(t,M);for(let n of e){let r=this.emitters.get(n.options.emitter);if(r){let i=n.method.bind(t);Reflect.defineMetadata("bound",i,n),r.addListener(n.options.event,i)}}}unregisterEventListeners(t){let e=this.getComponentsWithType(t,M);for(let n of e){let r=this.emitters.get(n.options.emitter),i=Reflect.getMetadata("bound",n);r&&i&&r.removeListener(n.options.event,i)}}async registerModule(t){Reflect.defineMetadata(L,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${O.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),Y.default.remove(this.extensions,e=>e===t),this.logger.info(`Module unregistered: ${O.default.green(t.constructor.name)}`)}runModuleHook(t,e,...n){let i=A(t).get(e);if(i)for(let c of i)c.call(t,...n)}registerEventEmitter(t,e){this.emitters.set(t,e)}};s(E,"Registry");var st=y(require("chalk")),it=y(require("events")),ct=require("tslog");var x=y(require("chalk")),p=require("discord.js");var l=class extends u{};s(l,"ApplicationCommandComponent");var ht=C(l);var tt=y(require("lodash")),$=class{constructor(t){typeof t=="object"?this.options=tt.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};s($,"ComponentArgumentDecorator");var S=class extends ${};s(S,"ApplicationCommandOption");var et=N(S);var w=class extends u{};s(w,"ConverterComponent");var _=C(w);var nt=y(require("chalk"));var ot=y(require("chalk")),rt=require("discord.js");var j=class{get commandClient(){return b.getFromModule(this)}get client(){return this.commandClient.discord}get logger(){return this._logger||(this._logger=this.commandClient.logger.getChildLogger({prefix:[ot.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}async convertArguments(t,e,n,r){let i=new rt.Collection;for(let c of this.commandClient.registry.extensions)for(let m of this.commandClient.registry.getComponentsWithType(c,w))m.options.component==t&&i.set(m.options.type,{component:m,ext:c});for(let[c,m]of n){let f=i.get(m.type);if(!f){e[c]=void 0;continue}let h=await r(m,c);e[c]=await f.component.execute(f.ext,h)}}};s(j,"Extension");var H=class extends j{get logger(){return this._logger||(this._logger=this.commandClient.ctsLogger.getChildLogger({prefix:[nt.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}};s(H,"CTSExtension");var F=function(o,t,e,n){var r=arguments.length,i=r<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(o,t,e,n);else for(var m=o.length-1;m>=0;m--)(c=o[m])&&(i=(r<3?c(i):r>3?c(t,e,i):c(t,e))||i);return r>3&&i&&Object.defineProperty(t,e,i),i},g=function(o,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,t)},d=class extends H{constructor(t){super();this.config=t}async interactionCreate(t){var i;if(t.type!==p.InteractionType.ApplicationCommand)return;let e=null,n=null,r=this.commandClient.registry.extensions;for(let c of r){let m=this.commandClient.registry.getComponentsWithType(c,l);for(let f of m)f.options.name===t.commandName&&(n=c,e=f)}if(e&&n){let c=[];await this.convertArguments(l,c,e.argTypes,()=>[t]);for(let[m,f]of e.argTypes){let h=null;for(let B of f.decorators)if(B instanceof S){h=(i=t.options.get(B.options.name,!1))==null?void 0:i.value;break}h&&(c[m]=h)}try{await e.execute(n,c)}catch(m){this.logger.error(m),this.commandClient.emit("applicationCommandInvokeError",m,t)}}}async load(){}async sync(){let t=b.getFromModule(this);this.logger.info("Trying to sync commands...");let e=[];for(let n of t.registry.getComponentsWithTypeGlobal(l)){let r=Z({},n.options);if(r.type===p.ApplicationCommandType.ChatInput){r.options=[];for(let[,i]of n.argTypes){let c=i.decorators.find(m=>m.constructor===S);c&&r.options.push(c.options)}}e.push(r)}if(this.logger.info(`Processing ${x.default.green(e.length)} commands(${e.map(n=>x.default.blue(n.name)).join(", ")})`),this.config.guilds)for(let n of this.config.guilds)try{let r=await this.client.guilds.fetch(n);await r.fetch(),this.logger.info(`Registering commands for guild ${x.default.green(r.name)}(${x.default.blue(r.id)})`),await r.commands.set(e),this.logger.info(`Successfully registered commands for guild ${x.default.green(r.name)}(${x.default.blue(r.id)})`)}catch(r){this.logger.error(`Failed to register commands to guild ${x.default.green(n)}: ${r.message}`)}else try{this.logger.info("Registering commands globally..."),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}};s(d,"ApplicationCommandExtension");F([V({event:"interactionCreate"}),g("design:type",Function),g("design:paramtypes",[typeof p.Interaction=="undefined"?Object:p.Interaction])],d.prototype,"interactionCreate",null);F([P("load"),g("design:type",Function),g("design:paramtypes",[])],d.prototype,"load",null);F([_({component:l,parameterless:!0,type:p.ChatInputCommandInteraction}),g("design:type",Function),g("design:paramtypes",[typeof p.ChatInputCommandInteraction=="undefined"?Object:p.ChatInputCommandInteraction])],d.prototype,"chatInteraction",null);F([_({component:l,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),g("design:type",Function),g("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction=="undefined"?Object:p.MessageContextMenuCommandInteraction])],d.prototype,"messageInteraction",null);F([_({component:l,parameterless:!0,type:p.UserContextMenuCommandInteraction}),g("design:type",Function),g("design:paramtypes",[typeof p.UserContextMenuCommandInteraction=="undefined"?Object:p.UserContextMenuCommandInteraction])],d.prototype,"userInteraction",null);var b=class extends it.default{constructor(t,e=new ct.Logger({dateTimeTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone})){super();this.discord=t,this.logger=e,this.ctsLogger=e.getChildLogger({prefix:[st.default.blue("[command.ts]")],displayFilePath:"hidden",displayFunctionName:!1}),this.registry=new E(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}async enableApplicationCommandsExtension(t){await this.registry.registerModule(new d(t)),this.ctsLogger.info("Application command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===d)}static getFromModule(t){return Reflect.getMetadata(L,t)}};s(b,"CommandClient");module.exports=dt(yt);0&&(module.exports={ApplicationCommandComponent,BaseComponent,CommandClient,ConverterComponent,Registry,applicationCommand,argConverter,createArgumentDecorator,createComponentDecorator,getComponent,getComponentArgumentStore,getComponentStore,getModuleHookStore,moduleHook,option});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/home/runner/work/command.ts/command.ts/src/index.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/index.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/BaseComponent.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/ComponentArgument.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/decoratorCreator.ts","../src/core/home/runner/work/command.ts/command.ts/src/core/symbols.ts","../src/core/structures/home/runner/work/command.ts/command.ts/src/core/structures/Registry.ts","../src/core/hooks/home/runner/work/command.ts/command.ts/src/core/hooks/moduleHook.ts","../src/core/listener/home/runner/work/command.ts/command.ts/src/core/listener/index.ts","../src/core/structures/home/runner/work/command.ts/command.ts/src/core/structures/CommandClient.ts","../src/applicationCommand/home/runner/work/command.ts/command.ts/src/applicationCommand/ApplicationCommandExtension.ts","../src/applicationCommand/home/runner/work/command.ts/command.ts/src/applicationCommand/ApplicationCommand.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/ComponentArgumentDecorator.ts","../src/applicationCommand/home/runner/work/command.ts/command.ts/src/applicationCommand/ApplicationCommandOption.ts","../src/core/extensions/home/runner/work/command.ts/command.ts/src/core/extensions/Extension.ts","../src/core/converter/home/runner/work/command.ts/command.ts/src/core/converter/index.ts"],"sourcesContent":["/*\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\nexport * from './core'\nexport * from './applicationCommand'\n","import 'reflect-metadata'\nexport * from './BaseComponent'\nexport * from './decoratorCreator'\n","import { Collection } from 'discord.js'\nimport _ from 'lodash'\nimport { ComponentArgument } from './ComponentArgument'\n\nexport class BaseComponent<Options = unknown, OptionsArg = Options> {\n options: Options\n\n method: Function\n\n argTypes: Collection<number, ComponentArgument> = new Collection()\n\n constructor(options: OptionsArg, method: Function, argTypes: unknown[]) {\n this.options = this.convertOptions(options)\n\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 convertOptions(options: OptionsArg): Options {\n return options as unknown as Options\n }\n\n execute(target: object, args: unknown[]) {\n return this.method.call(target, ...args)\n }\n}\n","import { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\nexport class ComponentArgument {\n decorators: ComponentArgumentDecorator[] = []\n\n constructor(public type: unknown) {}\n}\n","import { Collection } from 'discord.js'\nimport { ComponentStoreSymbol } from '../symbols'\nimport { BaseComponent } from './BaseComponent'\nimport { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\ntype ComponentStore = Collection<string | symbol, BaseComponent>\ntype 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 = <Options, OptionArgs>(type: typeof BaseComponent<Options, OptionArgs>) => {\n return (options: OptionArgs): MethodDecorator => {\n return (target, key) => {\n var component: BaseComponent<Options, OptionArgs> = new type(options, Reflect.get(target, key), Reflect.getMetadata('design:paramtypes', target, key))\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}\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","export const ComponentStoreSymbol = Symbol()\nexport const ComponentArgStoreSymbol = Symbol()\nexport const ModuleHookStoreSymbol = Symbol()\nexport const CommandClientSymbol = Symbol()\n","import chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport EventEmitter from 'events'\nimport _ from 'lodash'\nimport { Logger } from 'tslog'\nimport { BaseComponent, getComponentStore } from '../components'\nimport { getModuleHookStore } from '../hooks'\nimport { ListenerComponent } from '../listener'\nimport { CommandClientSymbol } from '../symbols'\nimport { CommandClient } from './CommandClient'\n\nexport class Registry {\n extensions: object[] = []\n\n emitters: Collection<string, EventEmitter> = new Collection()\n\n logger: Logger\n\n constructor(logger: Logger, public client: CommandClient) {\n this.logger = logger.getChildLogger({\n prefix: [chalk.green('[Registry]')],\n })\n }\n\n getComponentsWithTypeGlobal<T extends typeof BaseComponent<Config>, Config>(type: T): InstanceType<T>[] {\n const result: InstanceType<T>[] = []\n\n for (const ext of this.extensions) {\n result.push(...this.getComponentsWithType(ext, type))\n }\n\n return result\n }\n\n getComponentsWithType<T extends typeof BaseComponent<Config>, Config>(ext: object, type: T): InstanceType<T>[] {\n const componentStore = getComponentStore(ext)\n\n return Array.from(componentStore.filter((x) => (x.constructor as unknown) === type).values() as Iterable<InstanceType<T>>)\n }\n\n registerEventListeners(ext: object) {\n const listeners = this.getComponentsWithType(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(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 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","import { Collection } from 'discord.js'\nimport { ModuleHookStoreSymbol } from '../symbols'\n\ntype ModuleHookStore = Collection<string | symbol, 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(key)\n\n if (!v) {\n v = []\n store.set(key, v)\n }\n\n v.push(Reflect.get(target, key))\n }\n}\n","import { BaseComponent, createComponentDecorator } from '../components'\n\nexport class ListenerComponent extends BaseComponent<{ emitter: string; event: string }, { emitter?: string; event: string }> {\n defaultOptions() {\n return { emitter: 'discord' }\n }\n\n constructor(options: ListenerComponent['options'], method: Function, argTypes: unknown[]) {\n super(\n {\n event: options.event,\n emitter: options.emitter ?? 'discord',\n },\n method,\n argTypes,\n )\n }\n}\n\nexport const listener = createComponentDecorator(ListenerComponent)\n","import chalk from 'chalk'\nimport { Client } from 'discord.js'\nimport EventEmitter from 'events'\nimport { Logger } from 'tslog'\nimport { ApplicationCommandExtension, ApplicationCommandExtensionConfig } from '../../applicationCommand/ApplicationCommandExtension'\nimport { CommandClientSymbol } from '../symbols'\nimport { Registry } from './Registry'\n\nexport class CommandClient extends EventEmitter {\n ctsLogger: Logger\n registry: Registry\n\n constructor(public discord: Client, public logger: Logger = new Logger({ dateTimeTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone })) {\n super()\n\n this.ctsLogger = logger.getChildLogger({ prefix: [chalk.blue('[command.ts]')], displayFilePath: 'hidden', displayFunctionName: false })\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 enableApplicationCommandsExtension(config: ApplicationCommandExtensionConfig) {\n await this.registry.registerModule(new ApplicationCommandExtension(config))\n this.ctsLogger.info('Application 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","import chalk from 'chalk'\nimport {\n ApplicationCommandData,\n ApplicationCommandType,\n ChatInputCommandInteraction,\n GuildAuditLogs,\n Interaction,\n InteractionType,\n MessageContextMenuCommandInteraction,\n Snowflake,\n UserContextMenuCommandInteraction,\n} from 'discord.js'\nimport { ApplicationCommandComponent } from '.'\nimport { ApplicationCommandOption } from './ApplicationCommandOption'\nimport { moduleHook } from '../core/hooks'\nimport { listener } from '../core/listener'\nimport { CommandClient } from '../core/structures'\nimport { Extension } from '../core/extensions/Extension'\nimport { argConverter } from '../core/converter'\n\nexport type ApplicationCommandExtensionConfig = {\n guilds?: Snowflake[]\n}\n\nexport class ApplicationCommandExtension extends Extension {\n constructor(public config: ApplicationCommandExtensionConfig) {\n super()\n }\n\n @listener({ event: 'interactionCreate' })\n async interactionCreate(i: Interaction) {\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 for (const extension of extensions) {\n const components = this.commandClient.registry.getComponentsWithType(extension, ApplicationCommandComponent)\n\n for (const command of components) {\n if (command.options.name === i.commandName) {\n ext = extension\n cmd = command\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 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.execute(ext, argList)\n } catch (e) {\n this.logger.error(e)\n this.commandClient.emit('applicationCommandInvokeError', e, i)\n }\n }\n }\n\n @moduleHook('load')\n async load() {}\n\n async sync() {\n const client = CommandClient.getFromModule(this)\n\n this.logger.info('Trying to sync commands...')\n\n const commands: ApplicationCommandData[] = []\n\n for (const command of client.registry.getComponentsWithTypeGlobal(ApplicationCommandComponent)) {\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 commands.push(cmd)\n }\n\n this.logger.info(`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')})`)\n\n if (this.config.guilds) {\n for (const guild of this.config.guilds) {\n try {\n const g = await this.client.guilds.fetch(guild)\n await g.fetch()\n this.logger.info(`Registering commands for guild ${chalk.green(g.name)}(${chalk.blue(g.id)})`)\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 } else {\n try {\n this.logger.info(`Registering commands globally...`)\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","import { ApplicationCommandType, ChatInputApplicationCommandData, MessageApplicationCommandData, UserApplicationCommandData } from 'discord.js'\nimport { BaseComponent, createComponentDecorator } from '../core'\n\nexport class ApplicationCommandComponent extends BaseComponent<\n (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & { type: ApplicationCommandType }\n> {}\n\nexport const applicationCommand = createComponentDecorator(ApplicationCommandComponent)\n","import _ 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","import { APIApplicationCommandOption } from 'discord.js'\nimport { createArgumentDecorator } from '../core'\nimport { ComponentArgumentDecorator } from '../core/components/ComponentArgumentDecorator'\n\ntype Options = APIApplicationCommandOption\n\nexport class ApplicationCommandOption extends ComponentArgumentDecorator<Options> {}\n\nexport const option = createArgumentDecorator(ApplicationCommandOption)\n","import chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport { Logger } from 'tslog'\nimport { BaseComponent } from '../components'\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 private _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: typeof BaseComponent<unknown>,\n argList: unknown[],\n args: Collection<number, ComponentArgument>,\n getConverterArgs: (arg: ComponentArgument, index: number) => 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(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)\n\n argList[index] = await converter.component.execute(converter.ext, converterArgs)\n }\n }\n}\n","import { BaseComponent, createComponentDecorator } from '../components'\n\ntype Options = { component: typeof BaseComponent<unknown>; type: Function; parameterless: boolean }\n\nexport class ConverterComponent extends BaseComponent<Options, Options & { parameterless?: boolean }> {}\n\nexport const argConverter = createComponentDecorator(ConverterComponent)\n"],"mappings":"+/BAAA,mXCAA,OAAO,4BCAP,MAA2B,sBCEpB,WAAuB,CAG5B,YAAmB,EAAe,MAAf,KAAA,OAFnB,WAA2C,KADtC,yBDEA,WAAmB,CAKxB,SAAkD,GAAI,cAEtD,YAAY,EAAqB,EAAkB,EAAqB,CACtE,KAAK,QAAU,KAAK,eAAe,GAEnC,KAAK,OAAS,EACd,OAAS,GAAI,EAAG,EAAI,EAAS,OAAQ,IAAK,CACxC,GAAM,GAAU,EAAS,GACzB,KAAK,SAAS,IAAI,EAAG,GAAI,GAAkB,KAI/C,eAAe,EAA8B,CAC3C,MAAO,GAGT,QAAQ,EAAgB,EAAiB,CACvC,MAAO,MAAK,OAAO,KAAK,EAAM,GAAK,KAtBhC,qBEJP,MAA2B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vIJ,sCAKJ,EAAS,CAAE,MAAO,6EACQ,gBAAW,YAAA,OAAX,iBANhB,EAA2B,UAMhC,oBAAiB,SAgDtB,EAAW,6DAtDD,EAA2B,UAuDhC,OAAI,SAwDT,EAAa,CACZ,UAAW,EACX,cAAe,GACf,KAAM,uFAEiB,gCAA2B,YAAA,OAA3B,iCApHd,EAA2B,UAoHhC,kBAAe,SAIpB,EAAa,CACZ,UAAW,EACX,cAAe,GACf,KAAM,gGAEoB,yCAAoC,YAAA,OAApC,0CA7HjB,EAA2B,UA6HhC,qBAAkB,SAIvB,EAAa,CACZ,UAAW,EACX,cAAe,GACf,KAAM,6FAEiB,sCAAiC,YAAA,OAAjC,uCAtId,EAA2B,UAsIhC,kBAAe,MDtJhB,mBAA4B,WAAY,CAI7C,YAAmB,EAAwB,EAAiB,GAAI,WAAO,CAAE,iBAAkB,KAAK,iBAAiB,kBAAkB,WAAa,CAC9I,aADiB,QAAA,OAAwB,OAAA,EAGzC,KAAK,UAAY,EAAO,eAAe,CAAE,OAAQ,CAAC,WAAM,KAAK,iBAAkB,gBAAiB,SAAU,oBAAqB,KAE/H,KAAK,SAAW,GAAI,GAAS,KAAK,UAAW,MAE7C,KAAK,SAAS,qBAAqB,MAAO,MAC1C,KAAK,SAAS,qBAAqB,UAAW,KAAK,cAG/C,oCAAmC,EAA2C,CAClF,KAAM,MAAK,SAAS,eAAe,GAAI,GAA4B,IACnE,KAAK,UAAU,KAAK,0CAGtB,iCAAkC,CAChC,MAAO,MAAK,SAAS,WAAW,KAAK,AAAC,GAAM,EAAE,cAAgB,SAGzD,eAAc,EAA4B,CAC/C,MAAO,SAAQ,YAAY,EAAqB,KAzB7C","names":[]}
1
+ {"version":3,"sources":["../src/home/runner/work/command.ts/command.ts/src/index.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/index.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/BaseComponent.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/ComponentArgument.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/decoratorCreator.ts","../src/core/home/runner/work/command.ts/command.ts/src/core/symbols.ts","../src/core/structures/home/runner/work/command.ts/command.ts/src/core/structures/Registry.ts","../src/core/hooks/home/runner/work/command.ts/command.ts/src/core/hooks/moduleHook.ts","../src/core/listener/home/runner/work/command.ts/command.ts/src/core/listener/index.ts","../src/core/structures/home/runner/work/command.ts/command.ts/src/core/structures/CommandClient.ts","../src/applicationCommand/home/runner/work/command.ts/command.ts/src/applicationCommand/ApplicationCommandExtension.ts","../src/applicationCommand/home/runner/work/command.ts/command.ts/src/applicationCommand/ApplicationCommand.ts","../src/core/components/home/runner/work/command.ts/command.ts/src/core/components/ComponentArgumentDecorator.ts","../src/applicationCommand/home/runner/work/command.ts/command.ts/src/applicationCommand/ApplicationCommandOption.ts","../src/core/converter/home/runner/work/command.ts/command.ts/src/core/converter/index.ts","../src/core/extensions/home/runner/work/command.ts/command.ts/src/core/extensions/CTSExtension.ts","../src/core/extensions/home/runner/work/command.ts/command.ts/src/core/extensions/Extension.ts"],"sourcesContent":["/*\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\nexport * from './core'\nexport * from './applicationCommand'\n","import 'reflect-metadata'\nexport * from './BaseComponent'\nexport * from './decoratorCreator'\n","import { Collection } from 'discord.js'\nimport _ from 'lodash'\nimport { ComponentArgument } from './ComponentArgument'\n\nexport class BaseComponent<Options = unknown, OptionsArg = Options> {\n options: Options\n\n method: Function\n\n argTypes: Collection<number, ComponentArgument> = new Collection()\n\n constructor(options: OptionsArg, method: Function, argTypes: unknown[]) {\n this.options = this.convertOptions(options)\n\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 convertOptions(options: OptionsArg): Options {\n return options as unknown as Options\n }\n\n execute(target: object, args: unknown[]) {\n return this.method.call(target, ...args)\n }\n}\n","import { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\nexport class ComponentArgument {\n decorators: ComponentArgumentDecorator[] = []\n\n constructor(public type: unknown) {}\n}\n","import { Collection } from 'discord.js'\nimport { ComponentStoreSymbol } from '../symbols'\nimport { BaseComponent } from './BaseComponent'\nimport { ComponentArgumentDecorator } from './ComponentArgumentDecorator'\n\ntype ComponentStore = Collection<string | symbol, BaseComponent>\ntype 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 = <Options, OptionArgs>(type: typeof BaseComponent<Options, OptionArgs>) => {\n return (options: OptionArgs): MethodDecorator => {\n return (target, key) => {\n var component: BaseComponent<Options, OptionArgs> = new type(options, Reflect.get(target, key), Reflect.getMetadata('design:paramtypes', target, key))\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}\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","export const ComponentStoreSymbol = Symbol()\nexport const ComponentArgStoreSymbol = Symbol()\nexport const ModuleHookStoreSymbol = Symbol()\nexport const CommandClientSymbol = Symbol()\n","import chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport EventEmitter from 'events'\nimport _ from 'lodash'\nimport { Logger } from 'tslog'\nimport { BaseComponent, getComponentStore } from '../components'\nimport { getModuleHookStore } from '../hooks'\nimport { ListenerComponent } from '../listener'\nimport { CommandClientSymbol } from '../symbols'\nimport { CommandClient } from './CommandClient'\n\nexport class Registry {\n extensions: object[] = []\n\n emitters: Collection<string, EventEmitter> = new Collection()\n\n logger: Logger\n\n constructor(logger: Logger, public client: CommandClient) {\n this.logger = logger.getChildLogger({\n prefix: [chalk.green('[Registry]')],\n })\n }\n\n getComponentsWithTypeGlobal<T extends typeof BaseComponent<Config>, Config>(type: T): InstanceType<T>[] {\n const result: InstanceType<T>[] = []\n\n for (const ext of this.extensions) {\n result.push(...this.getComponentsWithType(ext, type))\n }\n\n return result\n }\n\n getComponentsWithType<T extends typeof BaseComponent<Config>, Config>(ext: object, type: T): InstanceType<T>[] {\n const componentStore = getComponentStore(ext)\n\n return Array.from(componentStore.filter((x) => (x.constructor as unknown) === type).values() as Iterable<InstanceType<T>>)\n }\n\n registerEventListeners(ext: object) {\n const listeners = this.getComponentsWithType(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(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 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","import { Collection } from 'discord.js'\nimport { ModuleHookStoreSymbol } from '../symbols'\n\ntype ModuleHookStore = Collection<string | symbol, 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(key)\n\n if (!v) {\n v = []\n store.set(key, v)\n }\n\n v.push(Reflect.get(target, key))\n }\n}\n","import { BaseComponent, createComponentDecorator } from '../components'\n\nexport class ListenerComponent extends BaseComponent<{ emitter: string; event: string }, { emitter?: string; event: string }> {\n defaultOptions() {\n return { emitter: 'discord' }\n }\n\n constructor(options: ListenerComponent['options'], method: Function, argTypes: unknown[]) {\n super(\n {\n event: options.event,\n emitter: options.emitter ?? 'discord',\n },\n method,\n argTypes,\n )\n }\n}\n\nexport const listener = createComponentDecorator(ListenerComponent)\n","import chalk from 'chalk'\nimport { Client } from 'discord.js'\nimport EventEmitter from 'events'\nimport { Logger } from 'tslog'\nimport { ApplicationCommandExtension, ApplicationCommandExtensionConfig } from '../../applicationCommand/ApplicationCommandExtension'\nimport { CommandClientSymbol } from '../symbols'\nimport { Registry } from './Registry'\n\nexport class CommandClient extends EventEmitter {\n ctsLogger: Logger\n registry: Registry\n\n constructor(public discord: Client, public logger: Logger = new Logger({ dateTimeTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone })) {\n super()\n\n this.ctsLogger = logger.getChildLogger({ prefix: [chalk.blue('[command.ts]')], displayFilePath: 'hidden', displayFunctionName: false })\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 enableApplicationCommandsExtension(config: ApplicationCommandExtensionConfig) {\n await this.registry.registerModule(new ApplicationCommandExtension(config))\n this.ctsLogger.info('Application 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","import chalk from 'chalk'\nimport {\n ApplicationCommandData,\n ApplicationCommandType,\n ChatInputCommandInteraction,\n GuildAuditLogs,\n Interaction,\n InteractionType,\n MessageContextMenuCommandInteraction,\n Snowflake,\n UserContextMenuCommandInteraction,\n} from 'discord.js'\nimport { ApplicationCommandComponent } from '.'\nimport { ApplicationCommandOption } from './ApplicationCommandOption'\nimport { moduleHook } from '../core/hooks'\nimport { listener } from '../core/listener'\nimport { CommandClient } from '../core/structures'\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 @listener({ event: 'interactionCreate' })\n async interactionCreate(i: Interaction) {\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 for (const extension of extensions) {\n const components = this.commandClient.registry.getComponentsWithType(extension, ApplicationCommandComponent)\n\n for (const command of components) {\n if (command.options.name === i.commandName) {\n ext = extension\n cmd = command\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 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.execute(ext, argList)\n } catch (e) {\n this.logger.error(e)\n this.commandClient.emit('applicationCommandInvokeError', e, i)\n }\n }\n }\n\n @moduleHook('load')\n async load() {}\n\n async sync() {\n const client = CommandClient.getFromModule(this)\n\n this.logger.info('Trying to sync commands...')\n\n const commands: ApplicationCommandData[] = []\n\n for (const command of client.registry.getComponentsWithTypeGlobal(ApplicationCommandComponent)) {\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 commands.push(cmd)\n }\n\n this.logger.info(`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')})`)\n\n if (this.config.guilds) {\n for (const guild of this.config.guilds) {\n try {\n const g = await this.client.guilds.fetch(guild)\n await g.fetch()\n this.logger.info(`Registering commands for guild ${chalk.green(g.name)}(${chalk.blue(g.id)})`)\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 } else {\n try {\n this.logger.info(`Registering commands globally...`)\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","import { ApplicationCommandType, ChatInputApplicationCommandData, MessageApplicationCommandData, UserApplicationCommandData } from 'discord.js'\nimport { BaseComponent, createComponentDecorator } from '../core'\n\nexport class ApplicationCommandComponent extends BaseComponent<\n (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & { type: ApplicationCommandType }\n> {}\n\nexport const applicationCommand = createComponentDecorator(ApplicationCommandComponent)\n","import _ 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","import { APIApplicationCommandOption } from 'discord.js'\nimport { createArgumentDecorator } from '../core'\nimport { ComponentArgumentDecorator } from '../core/components/ComponentArgumentDecorator'\n\ntype Options = APIApplicationCommandOption\n\nexport class ApplicationCommandOption extends ComponentArgumentDecorator<Options> {}\n\nexport const option = createArgumentDecorator(ApplicationCommandOption)\n","import { BaseComponent, createComponentDecorator } from '../components'\n\ntype Options = { component: typeof BaseComponent<unknown>; type: Function; parameterless: boolean }\n\nexport class ConverterComponent extends BaseComponent<Options, Options & { parameterless?: boolean }> {}\n\nexport const argConverter = createComponentDecorator(ConverterComponent)\n","import 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","import chalk from 'chalk'\nimport { Collection } from 'discord.js'\nimport { Logger } from 'tslog'\nimport { BaseComponent } from '../components'\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: typeof BaseComponent<unknown>,\n argList: unknown[],\n args: Collection<number, ComponentArgument>,\n getConverterArgs: (arg: ComponentArgument, index: number) => 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(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)\n\n argList[index] = await converter.component.execute(converter.ext, converterArgs)\n }\n }\n}\n"],"mappings":"+/BAAA,mXCAA,OAAO,4BCAP,MAA2B,sBCEpB,WAAuB,CAG5B,YAAmB,EAAe,MAAf,KAAA,OAFnB,WAA2C,KADtC,yBDEA,WAAmB,CAKxB,SAAkD,GAAI,cAEtD,YAAY,EAAqB,EAAkB,EAAqB,CACtE,KAAK,QAAU,KAAK,eAAe,GAEnC,KAAK,OAAS,EACd,O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AAK,cAG/C,oCAAmC,EAA2C,CAClF,KAAM,MAAK,SAAS,eAAe,GAAI,GAA4B,IACnE,KAAK,UAAU,KAAK,0CAGtB,iCAAkC,CAChC,MAAO,MAAK,SAAS,WAAW,KAAK,AAAC,GAAM,EAAE,cAAgB,SAGzD,eAAc,EAA4B,CAC/C,MAAO,SAAQ,YAAY,EAAqB,KAzB7C","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.0.0-dev.97799e9",
4
+ "version": "5.0.0-dev.a935c89",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -15,14 +15,14 @@ import { ApplicationCommandOption } from './ApplicationCommandOption'
15
15
  import { moduleHook } from '../core/hooks'
16
16
  import { listener } from '../core/listener'
17
17
  import { CommandClient } from '../core/structures'
18
- import { Extension } from '../core/extensions/Extension'
19
18
  import { argConverter } from '../core/converter'
19
+ import { CTSExtension } from '../core/extensions/CTSExtension'
20
20
 
21
21
  export type ApplicationCommandExtensionConfig = {
22
22
  guilds?: Snowflake[]
23
23
  }
24
24
 
25
- export class ApplicationCommandExtension extends Extension {
25
+ export class ApplicationCommandExtension extends CTSExtension {
26
26
  constructor(public config: ApplicationCommandExtensionConfig) {
27
27
  super()
28
28
  }
@@ -0,0 +1,9 @@
1
+ import chalk from 'chalk'
2
+ import { Extension } from './Extension'
3
+
4
+ export class CTSExtension extends Extension {
5
+ protected get logger() {
6
+ if (!this._logger) this._logger = this.commandClient.ctsLogger.getChildLogger({ prefix: [chalk.green(`[${this.constructor.name}]`)], displayFunctionName: false })
7
+ return this._logger
8
+ }
9
+ }
@@ -15,7 +15,7 @@ export class Extension {
15
15
  return this.commandClient.discord
16
16
  }
17
17
 
18
- private _logger?: Logger
18
+ protected _logger?: Logger
19
19
 
20
20
  protected get logger() {
21
21
  if (!this._logger) this._logger = this.commandClient.logger.getChildLogger({ prefix: [chalk.green(`[${this.constructor.name}]`)], displayFunctionName: false })