@pikokr/command.ts 5.0.7 → 5.1.1-dev.7a85ff9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +52 -40
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/applicationCommand/ApplicationCommand.ts +21 -4
- package/src/applicationCommand/ApplicationCommandExtension.ts +144 -28
- package/src/applicationCommand/group.ts +33 -0
- package/src/applicationCommand/index.ts +9 -8
- package/src/core/components/BaseComponent.ts +11 -19
- package/src/core/components/decoratorCreator.ts +19 -21
- package/src/core/converter/index.ts +20 -11
- package/src/core/extensions/Extension.ts +10 -11
- package/src/core/listener/index.ts +20 -22
- package/src/core/structures/Registry.ts +7 -7
- package/src/textCommand/TextCommand.ts +6 -2
- package/src/textCommand/TextCommandExtension.ts +1 -1
- package/test/index.ts +20 -1
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as discord_js from 'discord.js';
|
2
|
-
import { Collection, Snowflake, Interaction, ChatInputCommandInteraction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, Message, Client, UserApplicationCommandData, MessageApplicationCommandData,
|
2
|
+
import { Collection, Snowflake, Interaction, ChatInputCommandInteraction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, Message, Client, APIApplicationCommandSubcommandOption, ChatInputApplicationCommandData, UserApplicationCommandData, MessageApplicationCommandData, ApplicationCommandType, APIApplicationCommandOption } from 'discord.js';
|
3
3
|
import EventEmitter from 'events';
|
4
4
|
import * as tslog from 'tslog';
|
5
5
|
import { Logger } from 'tslog';
|
@@ -24,13 +24,11 @@ declare class ComponentArgument {
|
|
24
24
|
constructor(type: unknown);
|
25
25
|
}
|
26
26
|
|
27
|
-
declare class BaseComponent
|
28
|
-
options: Options;
|
27
|
+
declare class BaseComponent {
|
29
28
|
method: Function;
|
30
29
|
hooks: ComponentHookStore;
|
31
30
|
argTypes: Collection<number, ComponentArgument>;
|
32
|
-
|
33
|
-
convertOptions(options: OptionsArg): Options;
|
31
|
+
_init(method: Function, argTypes: unknown[]): void;
|
34
32
|
executeHook(target: object, name: string, args: unknown[]): Promise<void>;
|
35
33
|
execute(target: object, args: unknown[], beforeCallArgs?: unknown[]): Promise<any>;
|
36
34
|
}
|
@@ -38,27 +36,26 @@ declare class BaseComponent<Options = unknown, OptionsArg = Options> {
|
|
38
36
|
declare type ComponentStore = Collection<string | symbol, BaseComponent>;
|
39
37
|
declare type ComponentArgumentStore = Collection<number, ComponentArgumentDecorator>;
|
40
38
|
declare const getComponentStore: (target: object) => ComponentStore;
|
41
|
-
declare const getComponent: (target: object, key: string | symbol) => BaseComponent
|
42
|
-
declare const createComponentDecorator:
|
43
|
-
new (options: OptionArgs, method: Function, argTypes: unknown[]): BaseComponent<Options, OptionArgs>;
|
44
|
-
}) => (options: OptionArgs) => MethodDecorator;
|
39
|
+
declare const getComponent: (target: object, key: string | symbol) => BaseComponent | undefined;
|
40
|
+
declare const createComponentDecorator: (component: BaseComponent) => MethodDecorator;
|
45
41
|
declare const getComponentArgumentStore: (target: object, key: string | symbol) => ComponentArgumentStore;
|
46
42
|
declare const createArgumentDecorator: <Options>(type: {
|
47
43
|
new (options: Partial<Options>): ComponentArgumentDecorator<Options>;
|
48
44
|
}) => (options: Options) => ParameterDecorator;
|
49
45
|
|
50
|
-
declare type Options = {
|
51
|
-
component:
|
46
|
+
declare type Options$2 = {
|
47
|
+
component: unknown;
|
52
48
|
type: Function;
|
53
49
|
parameterless: boolean;
|
54
50
|
};
|
55
|
-
declare
|
51
|
+
declare type OptionsArg$1 = Omit<Options$2, 'parameterless'> & {
|
56
52
|
parameterless?: boolean;
|
57
|
-
}
|
53
|
+
};
|
54
|
+
declare class ConverterComponent extends BaseComponent {
|
55
|
+
options: Options$2;
|
56
|
+
constructor(options: OptionsArg$1);
|
58
57
|
}
|
59
|
-
declare const argConverter: (options:
|
60
|
-
parameterless?: boolean | undefined;
|
61
|
-
}) => MethodDecorator;
|
58
|
+
declare const argConverter: (options: OptionsArg$1) => MethodDecorator;
|
62
59
|
|
63
60
|
declare const createCheckDecorator: (fn: ComponentHookFn) => MethodDecorator;
|
64
61
|
declare const ownerOnly: MethodDecorator;
|
@@ -66,29 +63,26 @@ declare const ownerOnly: MethodDecorator;
|
|
66
63
|
declare class OwnerOnlyError {
|
67
64
|
}
|
68
65
|
|
69
|
-
declare
|
66
|
+
declare type Options$1 = {
|
70
67
|
emitter: string;
|
71
68
|
event: string;
|
72
|
-
}
|
69
|
+
};
|
70
|
+
declare type OptionsArg = {
|
73
71
|
emitter?: string;
|
74
72
|
event: string;
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
declare const listener: (options: {
|
82
|
-
emitter?: string | undefined;
|
83
|
-
event: string;
|
84
|
-
}) => MethodDecorator;
|
73
|
+
};
|
74
|
+
declare class ListenerComponent extends BaseComponent {
|
75
|
+
options: Options$1;
|
76
|
+
constructor(options: OptionsArg);
|
77
|
+
}
|
78
|
+
declare const listener: (options: OptionsArg) => MethodDecorator;
|
85
79
|
|
86
80
|
declare class Extension {
|
87
81
|
protected get commandClient(): CommandClient;
|
88
82
|
protected get client(): discord_js.Client<boolean>;
|
89
83
|
protected _logger?: Logger;
|
90
84
|
protected get logger(): Logger;
|
91
|
-
protected convertArguments(component:
|
85
|
+
protected convertArguments(component: unknown, argList: unknown[], args: Collection<number, ComponentArgument>, getConverterArgs: (arg: ComponentArgument, index: number, converter: ConverterComponent) => unknown[] | Promise<unknown[]>): Promise<void>;
|
92
86
|
}
|
93
87
|
|
94
88
|
declare class CTSExtension extends Extension {
|
@@ -102,11 +96,11 @@ declare class ApplicationCommandExtension extends CTSExtension {
|
|
102
96
|
config: ApplicationCommandExtensionConfig;
|
103
97
|
constructor(config: ApplicationCommandExtensionConfig);
|
104
98
|
interactionCreate(i: Interaction): Promise<void>;
|
105
|
-
load(): Promise<void>;
|
106
99
|
sync(): Promise<void>;
|
107
100
|
chatInteraction(i: ChatInputCommandInteraction): Promise<ChatInputCommandInteraction<discord_js.CacheType>>;
|
108
101
|
messageInteraction(i: MessageContextMenuCommandInteraction): Promise<MessageContextMenuCommandInteraction<discord_js.CacheType>>;
|
109
102
|
userInteraction(i: UserContextMenuCommandInteraction): Promise<UserContextMenuCommandInteraction<discord_js.CacheType>>;
|
103
|
+
commandInteraction(i: UserContextMenuCommandInteraction): Promise<UserContextMenuCommandInteraction<discord_js.CacheType>>;
|
110
104
|
}
|
111
105
|
|
112
106
|
declare type TextCommandOptions = {
|
@@ -114,7 +108,9 @@ declare type TextCommandOptions = {
|
|
114
108
|
aliases?: string[];
|
115
109
|
description?: string;
|
116
110
|
};
|
117
|
-
declare class TextCommandComponent extends BaseComponent
|
111
|
+
declare class TextCommandComponent extends BaseComponent {
|
112
|
+
options: TextCommandOptions;
|
113
|
+
constructor(options: TextCommandOptions);
|
118
114
|
}
|
119
115
|
declare const command: (options: TextCommandOptions) => MethodDecorator;
|
120
116
|
|
@@ -146,8 +142,8 @@ declare class Registry {
|
|
146
142
|
emitters: Collection<string, EventEmitter>;
|
147
143
|
logger: Logger;
|
148
144
|
constructor(logger: Logger, client: CommandClient);
|
149
|
-
getComponentsWithTypeGlobal<T
|
150
|
-
getComponentsWithType<T
|
145
|
+
getComponentsWithTypeGlobal<T>(type: unknown): T[];
|
146
|
+
getComponentsWithType<T>(ext: object, type: unknown): T[];
|
151
147
|
registerEventListeners(ext: object): void;
|
152
148
|
unregisterEventListeners(ext: object): void;
|
153
149
|
loadAllModulesInDirectory(dir: string): Promise<object[]>;
|
@@ -163,16 +159,32 @@ declare class Registry {
|
|
163
159
|
registerEventEmitter(name: string, emitter: EventEmitter): void;
|
164
160
|
}
|
165
161
|
|
166
|
-
declare class
|
162
|
+
declare class SubCommandGroup {
|
163
|
+
options: Omit<APIApplicationCommandSubcommandOption, 'type'>;
|
164
|
+
guilds?: string[] | undefined;
|
165
|
+
constructor(options: Omit<APIApplicationCommandSubcommandOption, 'type'>, guilds?: string[] | undefined);
|
166
|
+
command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator;
|
167
|
+
createChild(options: Omit<APIApplicationCommandSubcommandOption, 'type'>): SubCommandGroupChild;
|
168
|
+
}
|
169
|
+
declare class SubCommandGroupChild {
|
170
|
+
options: Omit<APIApplicationCommandSubcommandOption, 'type'>;
|
171
|
+
parent: SubCommandGroup;
|
172
|
+
constructor(options: Omit<APIApplicationCommandSubcommandOption, 'type'>, parent: SubCommandGroup);
|
173
|
+
command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator;
|
174
|
+
}
|
175
|
+
|
176
|
+
declare type Options = (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & {
|
167
177
|
type: ApplicationCommandType;
|
168
178
|
guilds?: Snowflake[];
|
169
|
-
}
|
179
|
+
};
|
180
|
+
declare class ApplicationCommandComponent extends BaseComponent {
|
181
|
+
options: Options;
|
182
|
+
subcommandGroup?: SubCommandGroup;
|
183
|
+
subcommandGroupChild?: SubCommandGroupChild;
|
184
|
+
constructor(options: UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>);
|
170
185
|
}
|
171
|
-
declare const applicationCommand: (options:
|
172
|
-
type: ApplicationCommandType;
|
173
|
-
guilds?: string[] | undefined;
|
174
|
-
}) => MethodDecorator;
|
186
|
+
declare const applicationCommand: (options: Options) => MethodDecorator;
|
175
187
|
|
176
188
|
declare const option: (options: APIApplicationCommandOption) => ParameterDecorator;
|
177
189
|
|
178
|
-
export { ApplicationCommandComponent, BaseComponent, CommandClient, ComponentArgument, ComponentArgumentDecorator, ComponentHookStore, ConverterComponent, Extension, ListenerComponent, OwnerOnlyError, Registry, TextCommandComponent, TextCommandConfig, TextCommandRestOption, applicationCommand, argConverter, command, createArgumentDecorator, createCheckDecorator, createComponentDecorator, createComponentHook, getComponent, getComponentArgumentStore, getComponentStore, getModuleHookStore, listener, moduleHook, option, ownerOnly, rest };
|
190
|
+
export { ApplicationCommandComponent, Options as ApplicationCommandComponentOptions, BaseComponent, CommandClient, ComponentArgument, ComponentArgumentDecorator, ComponentHookStore, ConverterComponent, Extension, ListenerComponent, OwnerOnlyError, Registry, SubCommandGroup, SubCommandGroupChild, TextCommandComponent, TextCommandConfig, TextCommandRestOption, applicationCommand, argConverter, command, createArgumentDecorator, createCheckDecorator, createComponentDecorator, createComponentHook, getComponent, getComponentArgumentStore, getComponentStore, getModuleHookStore, listener, moduleHook, option, ownerOnly, rest };
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var Yt=Object.create;var B=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var c=(n,t)=>B(n,"name",{value:t,configurable:!0});var m=(n,t)=>()=>(n&&(t=n(n=0)),t);var Tt=(n,t)=>{for(var e in t)B(n,e,{get:t[e],enumerable:!0})},Ht=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ee(t))!re.call(n,r)&&r!==e&&B(n,r,{get:()=>t[r],enumerable:!(o=te(t,r))||o.enumerable});return n};var x=(n,t,e)=>(e=n!=null?Yt(oe(n)):{},Ht(t||!n||!n.__esModule?B(e,"default",{value:n,enumerable:!0}):e,n)),ne=n=>Ht(B({},"__esModule",{value:!0}),n);var z,fe,pt,X,lt,Y,E=m(()=>{"use strict";z=Symbol(),fe=Symbol(),pt=Symbol(),X=Symbol(),lt=Symbol(),Y=Symbol()});var jt,ft,tt,ut=m(()=>{"use strict";jt=require("discord.js");E();ft=c((n,t)=>{let e=Reflect.getMetadata(lt,n,t);return e||(e=new jt.Collection,Reflect.defineMetadata(lt,e,n,t)),e},"getComponentHookStore"),tt=c((n,t)=>(e,o)=>{let r=ft(e,o),s=r.get(n);s||(s=[],r.set(n,s)),s.push(t)},"createComponentHook")});var dt,U,se,w,gt,Z,W=m(()=>{"use strict";dt=require("discord.js");ut();E();U=c(n=>{let t=Reflect.getMetadata(z,n);return t||(t=new dt.Collection,Reflect.defineMetadata(z,t,n)),t},"getComponentStore"),se=c((n,t)=>U(n).get(t),"getComponent"),w=c(n=>t=>(e,o)=>{var r=new n(t,Reflect.get(e,o),Reflect.getMetadata("design:paramtypes",e,o));let s=ft(e,o);r.hooks=s;let i=U(e);gt(e,o).forEach((l,u)=>{var f;(f=r.argTypes.get(u))==null||f.decorators.push(l)}),i.set(o,r)},"createComponentDecorator"),gt=c((n,t)=>{let e=Reflect.getMetadata(z,n,t);return e||(e=new dt.Collection,Reflect.defineMetadata(z,e,n,t)),e},"getComponentArgumentStore"),Z=c(n=>t=>(e,o,r)=>{var s=new n(t);gt(e,o).set(r,s)},"createArgumentDecorator")});var $,ht=m(()=>{"use strict";$=class{constructor(t){this.type=t,this.decorators=[]}};c($,"ComponentArgument")});var It,R,Lt=m(()=>{"use strict";It=x(require("lodash")),R=class{constructor(t){typeof t=="object"?this.options=It.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};c(R,"ComponentArgumentDecorator")});var d,ie,yt=m(()=>{"use strict";W();A();d=class extends g{};c(d,"ApplicationCommandComponent");ie=w(d)});var H,Ot,xt=m(()=>{"use strict";D();H=class extends R{};c(H,"ApplicationCommandOption");Ot=Z(H)});var Et,et,Ct,Wt=m(()=>{"use strict";Et=require("discord.js");E();et=c(n=>{let t=Reflect.getMetadata(pt,n);return t||(t=new Et.Collection,Reflect.defineMetadata(pt,t,n)),t},"getModuleHookStore"),Ct=c(n=>(t,e)=>{let o=et(t),r=o.get(n);r||(r=[],o.set(n,r)),r.push(Reflect.get(t,e))},"moduleHook")});var J=m(()=>{"use strict";Wt();ut()});var k,K,Q=m(()=>{"use strict";A();W();k=class extends g{defaultOptions(){return{emitter:"discord"}}constructor(t,e,o){super({event:t.event,emitter:t.emitter??"discord"},e,o)}};c(k,"ListenerComponent");K=w(k)});var ot,$t,At,Dt,Pt,P,wt=m(()=>{"use strict";ot=x(require("chalk")),$t=require("discord.js"),At=x(require("lodash"));bt();J();Q();E();Dt=x(require("walk-sync")),Pt=x(require("path")),P=class{constructor(t,e){this.client=e,this.extensions=[],this.emitters=new $t.Collection,this.logger=t.getChildLogger({prefix:[ot.default.green("[Registry]")]})}getComponentsWithTypeGlobal(t){let e=[];for(let o of this.extensions)e.push(...this.getComponentsWithType(o,t));return e}getComponentsWithType(t,e){let o=U(t);return Array.from(o.filter(r=>r.constructor===e).values())}registerEventListeners(t){let e=this.getComponentsWithType(t,k);for(let o of e){let r=this.emitters.get(o.options.emitter);if(r){let s=o.method.bind(t);Reflect.defineMetadata("bound",s,o),r.addListener(o.options.event,s)}}}unregisterEventListeners(t){let e=this.getComponentsWithType(t,k);for(let o of e){let r=this.emitters.get(o.options.emitter),s=Reflect.getMetadata("bound",o);r&&s&&r.removeListener(o.options.event,s)}}async loadAllModulesInDirectory(t){let e=[],o=(0,Dt.default)(t).filter(r=>r.endsWith(".ts")||r.endsWith(".js"));for(let r of o)if(!r.endsWith(".d.ts"))try{let s=Pt.default.join(t,r),i=require(s);if(typeof i.setup!="function")continue;let a=await i.setup();e.push(...await this.registerModules(a,s))}catch{this.logger.error(`Failed to load ${r}`)}return e}async registerModules(t,e){let o=[];if(t instanceof Array)for(let r of t)await this.registerModule(r),Reflect.defineMetadata(Y,e,r),o.push(r);else await this.registerModule(t),Reflect.defineMetadata(Y,e,t),o.push(t);return o}async reloadModules(){let t=[],e=new Set;for(let o of this.extensions){let r=Reflect.getMetadata(Y,o);!r||(e.add(r),await this.unregisterModule(o),delete require.cache[require.resolve(r)])}for(let o of e)try{let r=require(o);if(typeof r.setup!="function")continue;let s=await r.setup(this.client);await this.registerModules(s,o),t.push({file:o,result:!0})}catch(r){t.push({file:o,result:!1,error:r})}return t}async registerModule(t){Reflect.defineMetadata(X,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${ot.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),At.default.remove(this.extensions,e=>e===t),this.logger.info(`Module unregistered: ${ot.default.green(t.constructor.name)}`)}runModuleHook(t,e,...o){let s=et(t).get(e);if(s)for(let i of s)i.call(t,...o)}registerEventEmitter(t,e){this.emitters.set(t,e)}};c(P,"Registry")});var rt=m(()=>{"use strict";wt();Mt()});var j,b,nt=m(()=>{"use strict";A();W();j=class extends g{};c(j,"ConverterComponent");b=w(j)});var Nt,Gt,N,St=m(()=>{"use strict";Nt=x(require("chalk")),Gt=require("discord.js");nt();rt();N=class{get commandClient(){return M.getFromModule(this)}get client(){return this.commandClient.discord}get logger(){return this._logger||(this._logger=this.commandClient.logger.getChildLogger({prefix:[Nt.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}async convertArguments(t,e,o,r){let s=new Gt.Collection;for(let i of this.commandClient.registry.extensions)for(let a of this.commandClient.registry.getComponentsWithType(i,j))a.options.component==t&&s.set(a.options.type,{component:a,ext:i});for(let[i,a]of o){let l=s.get(a.type);if(!l){e[i]=void 0;continue}let u=await r(a,i,l.component);e[i]=await l.component.execute(l.ext,u)}}};c(N,"Extension")});var qt,I,vt=m(()=>{"use strict";qt=x(require("chalk"));St();I=class extends N{get logger(){return this._logger||(this._logger=this.commandClient.ctsLogger.getChildLogger({prefix:[qt.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}};c(I,"CTSExtension")});var F,p,V,C,h,Bt=m(()=>{"use strict";F=x(require("chalk")),p=require("discord.js");yt();xt();J();Q();rt();nt();vt();V=function(n,t,e,o){var r=arguments.length,s=r<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,t,e,o);else for(var a=n.length-1;a>=0;a--)(i=n[a])&&(s=(r<3?i(s):r>3?i(t,e,s):i(t,e))||s);return r>3&&s&&Object.defineProperty(t,e,s),s},C=function(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)},h=class extends I{constructor(t){super(),this.config=t}async interactionCreate(t){var s;if(t.type!==p.InteractionType.ApplicationCommand)return;let e=null,o=null,r=this.commandClient.registry.extensions;for(let i of r){let a=this.commandClient.registry.getComponentsWithType(i,d);for(let l of a)l.options.name===t.commandName&&(o=i,e=l)}if(e&&o){let i=[];await this.convertArguments(d,i,e.argTypes,()=>[t]);for(let[a,l]of e.argTypes){let u=null;for(let f of l.decorators)if(f instanceof H){if([p.ApplicationCommandOptionType.Subcommand,p.ApplicationCommandOptionType.SubcommandGroup].includes(f.options.type)&&t.isChatInputCommand()){if(f.options.type===p.ApplicationCommandOptionType.Subcommand){u=t.options.getSubcommand()===f.options.name;break}if(f.options.type===p.ApplicationCommandOptionType.SubcommandGroup){u=t.options.getSubcommandGroup()===f.options.name;break}}u=(s=t.options.get(f.options.name,!1))==null?void 0:s.value;break}u&&(i[a]=u)}try{await e.execute(o,i,[t])}catch(a){this.commandClient.emit("applicationCommandInvokeError",a,t)}}}async load(){}async sync(){let t=M.getFromModule(this);this.logger.info("Trying to sync commands...");let e=[],o=new p.Collection;for(let r of t.registry.getComponentsWithTypeGlobal(d)){let s={...r.options};if(s.type===p.ApplicationCommandType.ChatInput){s.options=[];for(let[,i]of r.argTypes){let a=i.decorators.find(l=>l.constructor===H);a&&s.options.push(a.options)}}if(r.options.guilds){for(let i of r.options.guilds){let a=o.get(i);a||(a=[],o.set(i,a)),a.push(s)}continue}if(this.config.guilds){for(let i of this.config.guilds){let a=o.get(i);a||(a=[],o.set(i,a)),a.push(s)}continue}e.push(s)}if(o.size)for(let[r,s]of o){this.logger.info(`Processing ${F.default.green(s.length)} commands(${s.map(i=>F.default.blue(i.name)).join(", ")})`);try{let i=await this.client.guilds.fetch(r);await i.fetch(),this.logger.info(`Registering commands for guild ${F.default.green(i.name)}(${F.default.blue(i.id)})`),await i.commands.set(s),this.logger.info(`Successfully registered commands for guild ${F.default.green(i.name)}(${F.default.blue(i.id)})`)}catch(i){this.logger.error(`Failed to register commands to guild ${F.default.green(r)}: ${i.message}`)}}if(e.length)try{this.logger.info("Registering commands globally..."),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}};c(h,"ApplicationCommandExtension");V([K({event:"interactionCreate"}),C("design:type",Function),C("design:paramtypes",[typeof p.Interaction>"u"?Object:p.Interaction])],h.prototype,"interactionCreate",null);V([Ct("load"),C("design:type",Function),C("design:paramtypes",[])],h.prototype,"load",null);V([b({component:d,parameterless:!0,type:p.ChatInputCommandInteraction}),C("design:type",Function),C("design:paramtypes",[typeof p.ChatInputCommandInteraction>"u"?Object:p.ChatInputCommandInteraction])],h.prototype,"chatInteraction",null);V([b({component:d,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),C("design:type",Function),C("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction>"u"?Object:p.MessageContextMenuCommandInteraction])],h.prototype,"messageInteraction",null);V([b({component:d,parameterless:!0,type:p.UserContextMenuCommandInteraction}),C("design:type",Function),C("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],h.prototype,"userInteraction",null)});var y,ce,Rt=m(()=>{"use strict";W();A();y=class extends g{};c(y,"TextCommandComponent");ce=w(y)});var L,ae,kt=m(()=>{"use strict";D();D();L=class extends R{};c(L,"TextCommandRestOption");ae=Z(L)});var G,st,_,S,zt=m(()=>{"use strict";Q();G=require("discord.js");vt();Rt();kt();D();st=function(n,t,e,o){var r=arguments.length,s=r<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,t,e,o);else for(var a=n.length-1;a>=0;a--)(i=n[a])&&(s=(r<3?i(s):r>3?i(t,e,s):i(t,e))||s);return r>3&&s&&Object.defineProperty(t,e,s),s},_=function(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)},S=class extends I{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 r=o.find(s=>e.startsWith(s));return r?r.length:null}return null}async messageCreate(t){let e=await this.processPrefix(t);if(!e)return;let o=t.content.slice(e),r=[],s=new Map;for(let v of this.commandClient.registry.extensions)for(let O of this.commandClient.registry.getComponentsWithType(v,y))r.push(O),s.set(O,v);let i=0,a=r.find(v=>{let O=[v.options.name];v.options.aliases&&O.push(...v.options.aliases);for(let T of O)if(o.startsWith(T))return o.length===T.length?(i=T.length,!0):(i=T.length,o.startsWith(T+" "));return!1});if(!a)return;let l=s.get(a);if(!l)return;let u=[],f=o.slice(i+1).split(/ /g);await this.convertArguments(y,u,a.argTypes,async(v,O,T)=>{if(T.options.parameterless)return[t];if(v.decorators.find(mt=>mt.constructor===L)){let mt=f.join(" ");return f=[],[mt,t]}return[f.shift(),t]}),await a.execute(l,u,[t])}async mesage(t){return t}async str(t){return t}async num(t){return Number(t)}};c(S,"TextCommandExtension");st([K({event:"messageCreate",emitter:"discord"}),_("design:type",Function),_("design:paramtypes",[typeof G.Message>"u"?Object:G.Message])],S.prototype,"messageCreate",null);st([b({component:y,type:G.Message,parameterless:!0}),_("design:type",Function),_("design:paramtypes",[typeof G.Message>"u"?Object:G.Message])],S.prototype,"mesage",null);st([b({component:y,type:String}),_("design:type",Function),_("design:paramtypes",[String])],S.prototype,"str",null);st([b({component:y,type:Number}),_("design:type",Function),_("design:paramtypes",[String])],S.prototype,"num",null)});var Jt={};Tt(Jt,{CommandClient:()=>M});var it,ct,Ut,Zt,M,Mt=m(()=>{"use strict";it=x(require("chalk")),ct=require("discord.js"),Ut=x(require("events")),Zt=require("tslog");Bt();zt();E();wt();M=class extends Ut.default{constructor(t,e=new Zt.Logger({dateTimeTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone})){super(),this.discord=t,this.logger=e,this.owners=new Set,this.ctsLogger=e.getChildLogger({prefix:[it.default.blue("[command.ts]")],displayFilePath:"hidden",displayFunctionName:!1}),this.registry=new P(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}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,r]of t.members)this.owners.add(o),e.push(r.user.tag);this.ctsLogger.info(`Fetched ${it.default.green(e.length)} owners(${e.map(o=>it.default.blue(o)).join(", ")})`)}async enableApplicationCommandsExtension(t){await this.registry.registerModule(new h(t)),this.ctsLogger.info("Application command extension enabled.")}async enableTextCommandsExtension(t){await this.registry.registerModule(new S(t)),this.ctsLogger.info("Text command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===h)}static getFromModule(t){return Reflect.getMetadata(X,t)}};c(M,"CommandClient")});var Ft,g,A=m(()=>{"use strict";Ft=require("discord.js");ht();g=class{hooks=new Ft.Collection;argTypes=new Ft.Collection;constructor(t,e,o){this.options=this.convertOptions(t),this.method=e;for(let r=0;r<o.length;r++){let s=o[r];this.argTypes.set(r,new $(s))}}convertOptions(t){return t}async executeHook(t,e,o){let r=this.hooks.get(e);if(!r)return;let{CommandClient:s}=await Promise.resolve().then(()=>(Mt(),Jt));for(let i of r)await i.call(null,s.getFromModule(t),...o)}async execute(t,e,o=e){await this.executeHook(t,"beforeCall",o);let r;try{r=await this.method.call(t,...e)}catch(s){throw await this.executeHook(t,"invokeError",[s]),s}return await this.executeHook(t,"afterCall",[r]),r}};c(g,"BaseComponent")});var So,bt=m(()=>{"use strict";So=require("reflect-metadata");W();ht();Lt();A()});var q,_t=m(()=>{"use strict";q=class{};c(q,"OwnerOnlyError")});var at,Kt,me,Qt=m(()=>{"use strict";at=require("discord.js");J();_t();Kt=c(n=>tt("beforeCall",n),"createCheckDecorator"),me=Kt(async(n,t)=>{let e=!1;if(t instanceof at.BaseInteraction?e=n.owners.has(t.user.id):t instanceof at.Message&&(e=n.owners.has(t.author.id)),!e)throw new q})});var Vt=m(()=>{"use strict";Qt();_t()});var Xt=m(()=>{"use strict";St()});var D=m(()=>{"use strict";bt();J();nt();Vt();Q();rt();Xt()});var pe={};Tt(pe,{ApplicationCommandComponent:()=>d,BaseComponent:()=>g,CommandClient:()=>M,ComponentArgument:()=>$,ComponentArgumentDecorator:()=>R,ConverterComponent:()=>j,Extension:()=>N,ListenerComponent:()=>k,OwnerOnlyError:()=>q,Registry:()=>P,TextCommandComponent:()=>y,TextCommandRestOption:()=>L,applicationCommand:()=>ie,argConverter:()=>b,command:()=>ce,createArgumentDecorator:()=>Z,createCheckDecorator:()=>Kt,createComponentDecorator:()=>w,createComponentHook:()=>tt,getComponent:()=>se,getComponentArgumentStore:()=>gt,getComponentStore:()=>U,getModuleHookStore:()=>et,listener:()=>K,moduleHook:()=>Ct,option:()=>Ot,ownerOnly:()=>me,rest:()=>ae});module.exports=ne(pe);D();yt();xt();Rt();kt();0&&(module.exports={ApplicationCommandComponent,BaseComponent,CommandClient,ComponentArgument,ComponentArgumentDecorator,ConverterComponent,Extension,ListenerComponent,OwnerOnlyError,Registry,TextCommandComponent,TextCommandRestOption,applicationCommand,argConverter,command,createArgumentDecorator,createCheckDecorator,createComponentDecorator,createComponentHook,getComponent,getComponentArgumentStore,getComponentStore,getModuleHookStore,listener,moduleHook,option,ownerOnly,rest});
|
1
|
+
"use strict";var oe=Object.create;var B=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var a=(n,t)=>B(n,"name",{value:t,configurable:!0});var l=(n,t)=>()=>(n&&(t=n(n=0)),t);var Gt=(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 re(t))!ie.call(n,s)&&s!==e&&B(n,s,{get:()=>t[s],enumerable:!(o=ne(t,s))||o.enumerable});return n};var b=(n,t,e)=>(e=n!=null?oe(se(n)):{},jt(t||!n||!n.__esModule?B(e,"default",{value:n,enumerable:!0}):e,n)),ae=n=>jt(B({},"__esModule",{value:!0}),n);var z,he,ft,X,ut,Y,A=l(()=>{"use strict";z=Symbol(),he=Symbol(),ft=Symbol(),X=Symbol(),ut=Symbol(),Y=Symbol()});var Ht,dt,tt,gt=l(()=>{"use strict";Ht=require("discord.js");A();dt=a((n,t)=>{let e=Reflect.getMetadata(ut,n,t);return e||(e=new Ht.Collection,Reflect.defineMetadata(ut,e,n,t)),e},"getComponentHookStore"),tt=a((n,t)=>(e,o)=>{let s=dt(e,o),r=s.get(n);r||(r=[],s.set(n,r)),r.push(t)},"createComponentHook")});var ht,U,ce,y,yt,Z,E=l(()=>{"use strict";ht=require("discord.js");gt();A();U=a(n=>{let t=Reflect.getMetadata(z,n);return t||(t=new ht.Collection,Reflect.defineMetadata(z,t,n)),t},"getComponentStore"),ce=a((n,t)=>U(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=U(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"),Z=a(n=>t=>(e,o,s)=>{var r=new n(t);yt(e,o).set(s,r)},"createArgumentDecorator")});var O,xt=l(()=>{"use strict";O=class{constructor(t){this.type=t,this.decorators=[]}};a(O,"ComponentArgument")});var Lt,R,$t=l(()=>{"use strict";Lt=b(require("lodash")),R=class{constructor(t){typeof t=="object"?this.options=Lt.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};a(R,"ComponentArgumentDecorator")});var g,me,et=l(()=>{"use strict";E();W();g=class extends x{constructor(t){super(),this.options=t}};a(g,"ApplicationCommandComponent");me=a(n=>y(new g(n)),"applicationCommand")});var F,At,bt=l(()=>{"use strict";G();F=class extends R{};a(F,"ApplicationCommandOption");At=Z(F)});var Et,I,J,K=l(()=>{"use strict";Et=b(require("lodash"));W();E();I=class extends x{constructor(t){super(),this.options=Et.default.merge({emitter:"discord"},t)}};a(I,"ListenerComponent");J=a(n=>y(new I(n)),"listener")});var j,S,ot=l(()=>{"use strict";W();E();j=class extends x{constructor(t){super(),this.options=t}};a(j,"ConverterComponent");S=a(n=>y(new j(n)),"argConverter")});var Ot,nt,pe,Wt=l(()=>{"use strict";Ot=require("discord.js");A();nt=a(n=>{let t=Reflect.getMetadata(ft,n);return t||(t=new Ot.Collection,Reflect.defineMetadata(ft,t,n)),t},"getModuleHookStore"),pe=a(n=>(t,e)=>{let o=nt(t),s=o.get(n);s||(s=[],o.set(n,s)),s.push(Reflect.get(t,e))},"moduleHook")});var rt=l(()=>{"use strict";Wt();gt()});var st,Dt,Pt,Nt,qt,D,Ct=l(()=>{"use strict";st=b(require("chalk")),Dt=require("discord.js"),Pt=b(require("lodash"));wt();rt();K();A();Nt=b(require("walk-sync")),qt=b(require("path")),D=class{constructor(t,e){this.client=e,this.extensions=[],this.emitters=new Dt.Collection,this.logger=t.getChildLogger({prefix:[st.default.green("[Registry]")]})}getComponentsWithTypeGlobal(t){let e=[];for(let o of this.extensions)e.push(...this.getComponentsWithType(o,t));return e}getComponentsWithType(t,e){let o=U(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 r=o.method.bind(t);Reflect.defineMetadata("bound",r,o),s.addListener(o.options.event,r)}}}unregisterEventListeners(t){let e=this.getComponentsWithType(t,I);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,Nt.default)(t).filter(s=>s.endsWith(".ts")||s.endsWith(".js"));for(let s of o)if(!s.endsWith(".d.ts"))try{let r=qt.default.join(t,s),c=require(r);if(typeof c.setup!="function")continue;let i=await c.setup();e.push(...await this.registerModules(i,r))}catch{this.logger.error(`Failed to load ${s}`)}return e}async registerModules(t,e){let o=[];if(t instanceof Array)for(let s of t)await this.registerModule(s),Reflect.defineMetadata(Y,e,s),o.push(s);else await this.registerModule(t),Reflect.defineMetadata(Y,e,t),o.push(t);return o}async reloadModules(){let t=[],e=new Set;for(let o of this.extensions){let s=Reflect.getMetadata(Y,o);!s||(e.add(s),await this.unregisterModule(o),delete require.cache[require.resolve(s)])}for(let o of e)try{let s=require(o);if(typeof s.setup!="function")continue;let r=await s.setup(this.client);await this.registerModules(r,o),t.push({file:o,result:!0})}catch(s){t.push({file:o,result:!1,error:s})}return t}async registerModule(t){Reflect.defineMetadata(X,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${st.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),Pt.default.remove(this.extensions,e=>e===t),this.logger.info(`Module unregistered: ${st.default.green(t.constructor.name)}`)}runModuleHook(t,e,...o){let r=nt(t).get(e);if(r)for(let c of r)c.call(t,...o)}registerEventEmitter(t,e){this.emitters.set(t,e)}};a(D,"Registry")});var St=l(()=>{"use strict";Ct();Mt()});var Bt,zt,P,vt=l(()=>{"use strict";Bt=b(require("chalk")),zt=require("discord.js");ot();St();P=class{get commandClient(){return H.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,j))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(P,"Extension")});var Ut,L,kt=l(()=>{"use strict";Ut=b(require("chalk"));vt();L=class extends P{get logger(){return this._logger||(this._logger=this.commandClient.ctsLogger.getChildLogger({prefix:[Ut.default.green(`[${this.constructor.name}]`)],displayFunctionName:!1})),this._logger}};a(L,"CTSExtension")});var M,p,Q,v,C,Zt=l(()=>{"use strict";M=b(require("chalk")),p=require("discord.js");et();bt();K();ot();kt();Q=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)},C=class extends L{constructor(t){super(),this.config=t}async interactionCreate(t){var i;if(t.type!==p.InteractionType.ApplicationCommand)return;let e=null,o=null,s=this.commandClient.registry.extensions,r=null,c=null;t.commandType===p.ApplicationCommandType.ChatInput&&(r=t.options.getSubcommand(!1),c=t.options.getSubcommandGroup(!1));t:for(let m of s){let u=this.commandClient.registry.getComponentsWithType(m,g);if(r){for(let f of u)if(!(!f.subcommandGroup&&!f.subcommandGroupChild)){if(f.subcommandGroupChild&&f.subcommandGroupChild.parent.options.name===t.commandName&&f.subcommandGroupChild.options.name===c&&f.options.name===r){o=m,e=f;break t}if(f.subcommandGroup&&!c&&f.subcommandGroup.options.name===t.commandName&&f.options.name===r){o=m,e=f;break t}}}else for(let f of u)if(f.options.name===t.commandName){o=m,e=f;break t}}if(e&&o){let m=[];await this.convertArguments(g,m,e.argTypes,()=>[t]);for(let[u,f]of e.argTypes){let d=null;for(let h of f.decorators)if(h instanceof F){if([p.ApplicationCommandOptionType.Subcommand,p.ApplicationCommandOptionType.SubcommandGroup].includes(h.options.type)&&t.isChatInputCommand()){if(h.options.type===p.ApplicationCommandOptionType.Subcommand){d=t.options.getSubcommand()===h.options.name;break}if(h.options.type===p.ApplicationCommandOptionType.SubcommandGroup){d=t.options.getSubcommandGroup()===h.options.name;break}}d=(i=t.options.get(h.options.name,!1))==null?void 0:i.value;break}d&&(m[u]=d)}try{await e.execute(o,m,[t])}catch(u){this.commandClient.emit("applicationCommandInvokeError",u,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(g)){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 m of r.subcommandGroup.guilds){let u=o.get(m);u||(u=[],o.set(m,u))}else e.push(i);s.set(r.subcommandGroup.options.name,i)}i.options||(i.options=[]),i.options.push({...r.options,type:p.ApplicationCommandOptionType.Subcommand});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 f of i.guilds){let d=o.get(f);d||(d=[],o.set(f,d))}else e.push(m);s.set(i.options.name,m)}m.options||(m.options=[]);let u=m.options.find(f=>f.name===r.subcommandGroupChild.options.name);u||(u={type:p.ApplicationCommandOptionType.SubcommandGroup,...r.subcommandGroupChild.options},m.options.push(u)),u.options||(u.options=[]),u.options.push({...r.options,type:p.ApplicationCommandOptionType.Subcommand});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===F);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))}continue}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 ${M.default.green(c.length)} commands(${c.map(m=>M.default.blue(m.name)).join(", ")}) for guild ${M.default.green(i.name)}(${M.default.blue(i.id)})`),await i.commands.set(c),this.logger.info(`Successfully registered commands for guild ${M.default.green(i.name)}(${M.default.blue(i.id)})`)}catch(i){this.logger.error(`Failed to register commands to guild ${M.default.green(r)}: ${i.message}`)}if(e.length)try{this.logger.info(`Processing ${M.default.green(e.length)} commands(${e.map(r=>M.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(C,"ApplicationCommandExtension");Q([J({event:"interactionCreate"}),v("design:type",Function),v("design:paramtypes",[typeof p.Interaction>"u"?Object:p.Interaction])],C.prototype,"interactionCreate",null);Q([S({component:g,parameterless:!0,type:p.ChatInputCommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.ChatInputCommandInteraction>"u"?Object:p.ChatInputCommandInteraction])],C.prototype,"chatInteraction",null);Q([S({component:g,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction>"u"?Object:p.MessageContextMenuCommandInteraction])],C.prototype,"messageInteraction",null);Q([S({component:g,parameterless:!0,type:p.UserContextMenuCommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],C.prototype,"userInteraction",null);Q([S({component:g,parameterless:!0,type:p.CommandInteraction}),v("design:type",Function),v("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],C.prototype,"commandInteraction",null)});var w,le,Rt=l(()=>{"use strict";E();W();w=class extends x{constructor(t){super(),this.options=t}};a(w,"TextCommandComponent");le=a(n=>y(new w(n)),"command")});var $,fe,It=l(()=>{"use strict";G();G();$=class extends R{};a($,"TextCommandRestOption");fe=Z($)});var N,it,_,k,Jt=l(()=>{"use strict";K();N=require("discord.js");kt();Rt();It();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)},k=class extends L{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){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 h of this.commandClient.registry.getComponentsWithType(d,w))s.push(h),r.set(h,d);let c=0,i=s.find(d=>{let h=[d.options.name];d.options.aliases&&h.push(...d.options.aliases);for(let T of h)if(o.startsWith(T))return o.length===T.length?(c=T.length,!0):(c=T.length,o.startsWith(T+" "));return!1});if(!i)return;let m=r.get(i);if(!m)return;let u=[],f=o.slice(c+1).split(/ /g);await this.convertArguments(w,u,i.argTypes,async(d,h,T)=>{if(T.options.parameterless)return[t];if(d.decorators.find(lt=>lt.constructor===$)){let lt=f.join(" ");return f=[],[lt,t]}return[f.shift(),t]}),await i.execute(m,u,[t])}async mesage(t){return t}async str(t){return t}async num(t){return Number(t)}};a(k,"TextCommandExtension");it([J({event:"messageCreate",emitter:"discord"}),_("design:type",Function),_("design:paramtypes",[typeof N.Message>"u"?Object:N.Message])],k.prototype,"messageCreate",null);it([S({component:w,type:N.Message,parameterless:!0}),_("design:type",Function),_("design:paramtypes",[typeof N.Message>"u"?Object:N.Message])],k.prototype,"mesage",null);it([S({component:w,type:String}),_("design:type",Function),_("design:paramtypes",[String])],k.prototype,"str",null);it([S({component:w,type:Number}),_("design:type",Function),_("design:paramtypes",[String])],k.prototype,"num",null)});var Vt={};Gt(Vt,{CommandClient:()=>H});var at,ct,Kt,Qt,H,Mt=l(()=>{"use strict";at=b(require("chalk")),ct=require("discord.js"),Kt=b(require("events")),Qt=require("tslog");Zt();Jt();A();Ct();H=class extends Kt.default{constructor(t,e=new Qt.Logger({dateTimeTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone})){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}),this.registry=new D(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}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 C(t)),this.ctsLogger.info("Application command extension enabled.")}async enableTextCommandsExtension(t){await this.registry.registerModule(new k(t)),this.ctsLogger.info("Text command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===C)}static getFromModule(t){return Reflect.getMetadata(X,t)}};a(H,"CommandClient")});var _t,x,W=l(()=>{"use strict";_t=require("discord.js");xt();x=class{hooks=new _t.Collection;argTypes=new _t.Collection;_init(t,e){this.method=t;for(let o=0;o<e.length;o++){let s=e[o];this.argTypes.set(o,new O(s))}}async executeHook(t,e,o){let s=this.hooks.get(e);if(!s)return;let{CommandClient:r}=await Promise.resolve().then(()=>(Mt(),Vt));for(let c of s)await c.call(null,r.getFromModule(t),...o)}async execute(t,e,o=e){await this.executeHook(t,"beforeCall",o);let s;try{s=await this.method.call(t,...e)}catch(r){throw await this.executeHook(t,"invokeError",[r]),r}return await this.executeHook(t,"afterCall",[s]),s}};a(x,"BaseComponent")});var ko,wt=l(()=>{"use strict";ko=require("reflect-metadata");E();xt();$t();W()});var q,Tt=l(()=>{"use strict";q=class{};a(q,"OwnerOnlyError")});var mt,Xt,ue,Yt=l(()=>{"use strict";mt=require("discord.js");rt();Tt();Xt=a(n=>tt("beforeCall",n),"createCheckDecorator"),ue=Xt(async(n,t)=>{let e=!1;if(t instanceof mt.BaseInteraction?e=n.owners.has(t.user.id):t instanceof mt.Message&&(e=n.owners.has(t.author.id)),!e)throw new q})});var te=l(()=>{"use strict";Yt();Tt()});var ee=l(()=>{"use strict";vt()});var G=l(()=>{"use strict";wt();rt();ot();te();K();St();ee()});var de={};Gt(de,{ApplicationCommandComponent:()=>g,BaseComponent:()=>x,CommandClient:()=>H,ComponentArgument:()=>O,ComponentArgumentDecorator:()=>R,ConverterComponent:()=>j,Extension:()=>P,ListenerComponent:()=>I,OwnerOnlyError:()=>q,Registry:()=>D,SubCommandGroup:()=>pt,SubCommandGroupChild:()=>V,TextCommandComponent:()=>w,TextCommandRestOption:()=>$,applicationCommand:()=>me,argConverter:()=>S,command:()=>le,createArgumentDecorator:()=>Z,createCheckDecorator:()=>Xt,createComponentDecorator:()=>y,createComponentHook:()=>tt,getComponent:()=>ce,getComponentArgumentStore:()=>yt,getComponentStore:()=>U,getModuleHookStore:()=>nt,listener:()=>J,moduleHook:()=>pe,option:()=>At,ownerOnly:()=>ue,rest:()=>fe});module.exports=ae(de);G();et();bt();var Ft=require("discord.js");G();et();var pt=class{constructor(t,e){this.options=t,this.guilds=e}command(t){let e=new g({type:Ft.ApplicationCommandType.ChatInput,...t});return e.subcommandGroup=this,y(e)}createChild(t){return new V(t,this)}};a(pt,"SubCommandGroup");var V=class{constructor(t,e){this.options=t,this.parent=e}command(t){let e=new g({type:Ft.ApplicationCommandType.ChatInput,...t});return e.subcommandGroupChild=this,y(e)}};a(V,"SubCommandGroupChild");Rt();It();0&&(module.exports={ApplicationCommandComponent,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,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/hooks/moduleHook.ts","../src/core/hooks/index.ts","../src/core/listener/index.ts","../src/core/structures/Registry.ts","../src/core/structures/index.ts","../src/core/converter/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/index.ts","../src/core/extensions/index.ts","../src/core/index.ts","../src/index.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","/*\r\n* File: componentHook.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 { 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.push(fn)\n }\n}\n","/*\r\n* File: decoratorCreator.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 { 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\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 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}\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'\n\nexport class ApplicationCommandComponent extends BaseComponent<\n (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & { type: ApplicationCommandType; guilds?: Snowflake[] }\n> {}\n\nexport const applicationCommand = createComponentDecorator(ApplicationCommandComponent)\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","/*\r\n* File: moduleHook.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 { Collection } from 'discord.js'\nimport { ModuleHookStoreSymbol } from '../symbols'\n\ntype 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 } from './componentHook'\r\nexport type { ComponentHookStore } from './componentHook'\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\nimport { BaseComponent } from '../components/BaseComponent'\nimport { createComponentDecorator } from '../components/decoratorCreator'\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","/*\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 type { BaseComponent } 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'\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 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 try {\n const p = path.join(dir, file)\n const mod = require(p)\n\n if (typeof mod.setup !== 'function') continue\n\n const modules = await mod.setup()\n\n results.push(...(await this.registerModules(modules, p)))\n } catch (e) {\n this.logger.error(`Failed to load ${file}`)\n }\n }\n\n return results\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 }[] = []\n const paths = new Set<string>()\n for (const module of this.extensions) {\n const file = Reflect.getMetadata(FilePathSymbol, module)\n if (!file) continue\n\n paths.add(file)\n\n await this.unregisterModule(module)\n delete require.cache[require.resolve(file)]\n }\n\n for (const path of paths) {\n try {\n const mod = require(path)\n\n if (typeof mod.setup !== 'function') continue\n\n const modules = await mod.setup(this.client)\n\n await this.registerModules(modules, path)\n\n result.push({\n file: path,\n result: true,\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","/*\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 { BaseComponent } from '../components/BaseComponent'\nimport { createComponentDecorator } from '../components/decoratorCreator'\n\ntype Options = { component: typeof BaseComponent<unknown>; type: Function; parameterless: boolean }\n\nexport class ConverterComponent extends BaseComponent<Options, Omit<Options, 'parameterless'> & { parameterless?: boolean }> {}\n\nexport const argConverter = createComponentDecorator(ConverterComponent)\n","/*\r\n* File: Extension.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 { 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, 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(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 ApplicationCommandData,\n ApplicationCommandOptionType,\n ApplicationCommandType,\n ChatInputCommandInteraction,\n Collection,\n Interaction,\n InteractionType,\n MessageContextMenuCommandInteraction,\n Snowflake,\n UserContextMenuCommandInteraction,\n} from 'discord.js'\nimport { ApplicationCommandComponent } from './ApplicationCommand'\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 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.execute(ext, argList, [i])\n } catch (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 const guildCommands = new Collection<Snowflake, 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 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 if (this.config.guilds) {\n for (const guild of this.config.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 commands.push(cmd)\n }\n\n if (guildCommands.size) {\n for (const [guild, commands] of guildCommands) {\n this.logger.info(`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')})`)\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 }\n if (commands.length) {\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","/*\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\ntype TextCommandOptions = {\n name: string\n aliases?: string[]\n description?: string\n}\n\nexport class TextCommandComponent extends BaseComponent<TextCommandOptions> {}\n\nexport const command = createComponentDecorator(TextCommandComponent)\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\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 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(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 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 }\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","/*\r\n* File: CommandClient.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 { Client, Snowflake, Team, User } from 'discord.js'\nimport EventEmitter from 'events'\nimport { 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(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 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","/*\r\n* File: BaseComponent.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 { Collection } from 'discord.js'\nimport _ from 'lodash'\nimport type { ComponentHookStore } from '../hooks'\nimport { ComponentArgument } from './ComponentArgument'\n\nexport class BaseComponent<Options = unknown, OptionsArg = Options> {\n options: Options\n\n method: Function\n\n hooks: ComponentHookStore = new Collection()\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 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 for (const fn of hook) {\n await fn.call(null, CommandClient.getFromModule(target), ...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 } catch (e) {\n await this.executeHook(target, 'invokeError', [e])\n throw e\n }\n await this.executeHook(target, 'afterCall', [result])\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","/*\r\n* File: checks.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 { 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 isOwner = client.owners.has(i.user.id)\n } else if (i instanceof Message) {\n isOwner = client.owners.has(i.author.id)\n }\n\n if (!isOwner) throw new OwnerOnlyError()\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'\nexport * from './errors'\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"],"mappings":"+pBAAA,mBAAA,6FCAA,OAuBS,GAWH,GAlCN,0BAoB0B,0BAGxB,AAAO,GAAI,GAAA,EAAA,IAAA,CACZ,GAAA,GAAA,QAAA,YAAA,GAAA,EAAA,CAAA,EAED,MAAO,IACL,GAAQ,GAAM,eACZ,QAAM,eAAQ,GAA8B,EAAI,EAAA,CAAA,GAIhD,GATS,yBAWP,GAAsB,GAAA,EAAA,IACvB,CAAA,EAAA,IAAA,CAED,GAAM,GAAQ,GAAA,EAAA,CAAA,EACf,EAAA,EAAA,IAAA,CAAA,EACF,AAAA,gCAL2B,yBClC5B,OA2BS,EAWL,GAOE,EAsBG,GAWJ,EA9EL,yBAsBiB,+BAKf,AAAO,EAAM,EAAA,GAAA,CACd,GAAA,GAAA,QAAA,YAAA,EAAA,CAAA,EAED,MAAO,IACL,GAAW,GAAG,eAEd,QAAY,eAAS,EAAA,EAAA,CAAA,GAGhB,GATQ,qBAWX,GAAmB,GAAA,EAAK,IAClB,EAAwD,CAAC,EAE7D,IAAM,CAAA,EAHW,gBAOjB,EAAc,EAAA,GAEd,GAEA,CAAA,EAAW,IAAO,IAChB,GAAU,GAAA,GAAS,EAAQ,QAAW,IAAI,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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/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","/*\r\n* File: componentHook.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 { 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.push(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\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 = (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","/*\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","/*\r\n* File: moduleHook.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 { Collection } from 'discord.js'\nimport { ModuleHookStoreSymbol } from '../symbols'\n\ntype 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 } 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 type { BaseComponent } 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'\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>(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 try {\n const p = path.join(dir, file)\n const mod = require(p)\n\n if (typeof mod.setup !== 'function') continue\n\n const modules = await mod.setup()\n\n results.push(...(await this.registerModules(modules, p)))\n } catch (e) {\n this.logger.error(`Failed to load ${file}`)\n }\n }\n\n return results\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 }[] = []\n const paths = new Set<string>()\n for (const module of this.extensions) {\n const file = Reflect.getMetadata(FilePathSymbol, module)\n if (!file) continue\n\n paths.add(file)\n\n await this.unregisterModule(module)\n delete require.cache[require.resolve(file)]\n }\n\n for (const path of paths) {\n try {\n const mod = require(path)\n\n if (typeof mod.setup !== 'function') continue\n\n const modules = await mod.setup(this.client)\n\n await this.registerModules(modules, path)\n\n result.push({\n file: path,\n result: true,\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 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 @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 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.execute(ext, argList, [i])\n } catch (e) {\n this.commandClient.emit('applicationCommandInvokeError', e, i)\n }\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 group.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand } 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 child.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand } 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 }\n continue\n }\n\n commands.push(cmd)\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\ntype 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\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 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 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 }\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","/*\r\n* File: CommandClient.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 { Client, Snowflake, Team, User } from 'discord.js'\nimport EventEmitter from 'events'\nimport { 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(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 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 for (const fn of hook) {\n await fn.call(null, CommandClient.getFromModule(target), ...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 } catch (e) {\n await this.executeHook(target, 'invokeError', [e])\n throw e\n }\n await this.executeHook(target, 'afterCall', [result])\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","/*\r\n* File: checks.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 { 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 isOwner = client.owners.has(i.user.id)\n } else if (i instanceof Message) {\n isOwner = client.owners.has(i.author.id)\n }\n\n if (!isOwner) throw new OwnerOnlyError()\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'\nexport * from './errors'\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,mBAAA,6FCAA,OAuBS,GAWH,GAlCN,0BAoB0B,0BAGxB,AAAO,GAAI,GAAA,EAAA,IAAA,CACZ,GAAA,GAAA,QAAA,YAAA,GAAA,EAAA,CAAA,EAED,MAAO,IACL,GAAQ,GAAM,eACZ,QAAM,eAAQ,GAA8B,EAAI,EAAA,CAAA,GAIhD,GATS,yBAWP,GAAsB,GAAA,EAAA,IACvB,CAAA,EAAA,IAAA,CAED,GAAM,GAAQ,GAAA,EAAA,CAAA,EACf,EAAA,EAAA,IAAA,CAAA,EACF,AAAA,gCAL2B,yBClC5B,GAQA,IAUa,EAYA,GAMA,EAoBA,GAY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AC3F,GAAM,GAAM,GAAI,GAA4B,CAC1C,KAAM,0BAAuB,UAC7B,GAAG,EACJ,EACD,SAAI,qBAAuB,KACpB,EAAyB,CAAG,IAT1B","names":[]}
|
package/package.json
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pikokr/command.ts",
|
3
3
|
"description": "Discord.js command framework for typescript.",
|
4
|
-
"version": "5.
|
4
|
+
"version": "5.1.1-dev.7a85ff9",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
7
7
|
"license": "MIT",
|
8
8
|
"devDependencies": {
|
9
9
|
"@discordjs/ts-docgen": "0.4.1",
|
10
|
-
"@swc/core": "1.2.
|
10
|
+
"@swc/core": "1.2.222",
|
11
11
|
"@types/chalk": "2.2.0",
|
12
12
|
"@types/lodash": "4.14.182",
|
13
13
|
"all-contributors-cli": "6.20.0",
|
14
|
-
"discord.js": "14.
|
14
|
+
"discord.js": "14.1.2",
|
15
15
|
"dotenv": "16.0.1",
|
16
16
|
"prettier": "2.7.1",
|
17
17
|
"rimraf": "3.0.2",
|
18
18
|
"ts-node": "10.9.1",
|
19
|
-
"tsup": "6.2.
|
20
|
-
"typedoc": "0.23.
|
19
|
+
"tsup": "6.2.1",
|
20
|
+
"typedoc": "0.23.10",
|
21
21
|
"typescript": "4.7.4"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
@@ -43,4 +43,4 @@
|
|
43
43
|
"peerDependencies": {
|
44
44
|
"discord.js": "^14.0.1"
|
45
45
|
}
|
46
|
-
}
|
46
|
+
}
|
@@ -9,9 +9,26 @@
|
|
9
9
|
import type { ApplicationCommandType, ChatInputApplicationCommandData, MessageApplicationCommandData, Snowflake, UserApplicationCommandData } from 'discord.js'
|
10
10
|
import { createComponentDecorator } from '../core/components/decoratorCreator'
|
11
11
|
import { BaseComponent } from '../core/components/BaseComponent'
|
12
|
+
import { SubCommandGroup, SubCommandGroupChild } from './group'
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
type Options = (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & {
|
15
|
+
type: ApplicationCommandType
|
16
|
+
guilds?: Snowflake[]
|
17
|
+
}
|
16
18
|
|
17
|
-
export
|
19
|
+
export class ApplicationCommandComponent extends BaseComponent {
|
20
|
+
options: Options
|
21
|
+
|
22
|
+
subcommandGroup?: SubCommandGroup
|
23
|
+
subcommandGroupChild?: SubCommandGroupChild
|
24
|
+
|
25
|
+
constructor(options: UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) {
|
26
|
+
super()
|
27
|
+
|
28
|
+
this.options = options as Options
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
export const applicationCommand = (options: Options) => createComponentDecorator(new ApplicationCommandComponent(options))
|
33
|
+
|
34
|
+
export type { Options as ApplicationCommandComponentOptions }
|
@@ -8,11 +8,16 @@
|
|
8
8
|
|
9
9
|
import chalk from 'chalk'
|
10
10
|
import {
|
11
|
+
APIApplicationCommandSubcommandGroupOption,
|
12
|
+
APIApplicationCommandSubcommandOption,
|
11
13
|
ApplicationCommandData,
|
12
14
|
ApplicationCommandOptionType,
|
15
|
+
ApplicationCommandSubCommandData,
|
13
16
|
ApplicationCommandType,
|
17
|
+
ChatInputApplicationCommandData,
|
14
18
|
ChatInputCommandInteraction,
|
15
19
|
Collection,
|
20
|
+
CommandInteraction,
|
16
21
|
Interaction,
|
17
22
|
InteractionType,
|
18
23
|
MessageContextMenuCommandInteraction,
|
@@ -21,9 +26,7 @@ import {
|
|
21
26
|
} from 'discord.js'
|
22
27
|
import { ApplicationCommandComponent } from './ApplicationCommand'
|
23
28
|
import { ApplicationCommandOption } from './ApplicationCommandOption'
|
24
|
-
import { moduleHook } from '../core/hooks'
|
25
29
|
import { listener } from '../core/listener'
|
26
|
-
import { CommandClient } from '../core/structures'
|
27
30
|
import { argConverter } from '../core/converter'
|
28
31
|
import { CTSExtension } from '../core/extensions/CTSExtension'
|
29
32
|
|
@@ -45,13 +48,44 @@ export class ApplicationCommandExtension extends CTSExtension {
|
|
45
48
|
|
46
49
|
const extensions = this.commandClient.registry.extensions
|
47
50
|
|
48
|
-
|
49
|
-
|
51
|
+
let subcommand: string | null = null
|
52
|
+
let subcommandGroup: string | null = null
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
if (i.commandType === ApplicationCommandType.ChatInput) {
|
55
|
+
subcommand = i.options.getSubcommand(false)
|
56
|
+
subcommandGroup = i.options.getSubcommandGroup(false)
|
57
|
+
}
|
58
|
+
|
59
|
+
extLoop: for (const extension of extensions) {
|
60
|
+
const components = this.commandClient.registry.getComponentsWithType<ApplicationCommandComponent>(extension, ApplicationCommandComponent)
|
61
|
+
|
62
|
+
if (subcommand) {
|
63
|
+
for (const command of components) {
|
64
|
+
if (!command.subcommandGroup && !command.subcommandGroupChild) continue
|
65
|
+
|
66
|
+
if (
|
67
|
+
command.subcommandGroupChild &&
|
68
|
+
command.subcommandGroupChild.parent.options.name === i.commandName &&
|
69
|
+
command.subcommandGroupChild.options.name === subcommandGroup &&
|
70
|
+
command.options.name === subcommand
|
71
|
+
) {
|
72
|
+
ext = extension
|
73
|
+
cmd = command
|
74
|
+
break extLoop
|
75
|
+
}
|
76
|
+
if (command.subcommandGroup && !subcommandGroup && command.subcommandGroup.options.name === i.commandName && command.options.name === subcommand) {
|
77
|
+
ext = extension
|
78
|
+
cmd = command
|
79
|
+
break extLoop
|
80
|
+
}
|
81
|
+
}
|
82
|
+
} else {
|
83
|
+
for (const command of components) {
|
84
|
+
if (command.options.name === i.commandName) {
|
85
|
+
ext = extension
|
86
|
+
cmd = command
|
87
|
+
break extLoop
|
88
|
+
}
|
55
89
|
}
|
56
90
|
}
|
57
91
|
}
|
@@ -95,19 +129,88 @@ export class ApplicationCommandExtension extends CTSExtension {
|
|
95
129
|
}
|
96
130
|
}
|
97
131
|
|
98
|
-
@moduleHook('load')
|
99
|
-
async load() {}
|
100
|
-
|
101
132
|
async sync() {
|
102
|
-
const client =
|
133
|
+
const client = this.commandClient
|
103
134
|
|
104
135
|
this.logger.info('Trying to sync commands...')
|
105
136
|
|
106
|
-
|
137
|
+
let commands: ApplicationCommandData[] = []
|
107
138
|
|
108
139
|
const guildCommands = new Collection<Snowflake, ApplicationCommandData[]>()
|
109
140
|
|
110
|
-
|
141
|
+
const subcommandGroups = new Collection<string, ChatInputApplicationCommandData>()
|
142
|
+
|
143
|
+
for (const command of client.registry.getComponentsWithTypeGlobal<ApplicationCommandComponent>(ApplicationCommandComponent)) {
|
144
|
+
if (command.subcommandGroup) {
|
145
|
+
let group = subcommandGroups.get(command.subcommandGroup.options.name)
|
146
|
+
|
147
|
+
if (!group) {
|
148
|
+
group = {
|
149
|
+
...command.subcommandGroup.options,
|
150
|
+
type: ApplicationCommandType.ChatInput,
|
151
|
+
}
|
152
|
+
|
153
|
+
if (command.subcommandGroup.guilds) {
|
154
|
+
for (const guild of command.subcommandGroup.guilds) {
|
155
|
+
let commands = guildCommands.get(guild)
|
156
|
+
if (!commands) {
|
157
|
+
commands = []
|
158
|
+
guildCommands.set(guild, commands)
|
159
|
+
}
|
160
|
+
}
|
161
|
+
} else {
|
162
|
+
commands.push(group)
|
163
|
+
}
|
164
|
+
|
165
|
+
subcommandGroups.set(command.subcommandGroup.options.name, group)
|
166
|
+
}
|
167
|
+
|
168
|
+
if (!group.options) group.options = []
|
169
|
+
|
170
|
+
group.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand } as ApplicationCommandSubCommandData)
|
171
|
+
|
172
|
+
continue
|
173
|
+
} else if (command.subcommandGroupChild) {
|
174
|
+
const parent = command.subcommandGroupChild.parent
|
175
|
+
let group = subcommandGroups.get(parent.options.name)
|
176
|
+
|
177
|
+
if (!group) {
|
178
|
+
group = {
|
179
|
+
...parent.options,
|
180
|
+
type: ApplicationCommandType.ChatInput,
|
181
|
+
}
|
182
|
+
|
183
|
+
if (parent.guilds) {
|
184
|
+
for (const guild of parent.guilds) {
|
185
|
+
let commands = guildCommands.get(guild)
|
186
|
+
if (!commands) {
|
187
|
+
commands = []
|
188
|
+
guildCommands.set(guild, commands)
|
189
|
+
}
|
190
|
+
}
|
191
|
+
} else {
|
192
|
+
commands.push(group)
|
193
|
+
}
|
194
|
+
|
195
|
+
subcommandGroups.set(parent.options.name, group)
|
196
|
+
}
|
197
|
+
|
198
|
+
if (!group.options) group.options = []
|
199
|
+
|
200
|
+
let child = group.options.find((x) => x.name === command.subcommandGroupChild!.options.name) as APIApplicationCommandSubcommandGroupOption
|
201
|
+
|
202
|
+
if (!child) {
|
203
|
+
child = { type: ApplicationCommandOptionType.SubcommandGroup, ...(command.subcommandGroupChild.options as Omit<APIApplicationCommandSubcommandGroupOption, 'type'>) }
|
204
|
+
group.options.push(child)
|
205
|
+
}
|
206
|
+
|
207
|
+
if (!child.options) child.options = []
|
208
|
+
|
209
|
+
child.options.push({ ...command.options, type: ApplicationCommandOptionType.Subcommand } as APIApplicationCommandSubcommandOption)
|
210
|
+
|
211
|
+
continue
|
212
|
+
}
|
213
|
+
|
111
214
|
const cmd: ApplicationCommandData = { ...command.options }
|
112
215
|
|
113
216
|
if (cmd.type === ApplicationCommandType.ChatInput) {
|
@@ -122,6 +225,8 @@ export class ApplicationCommandExtension extends CTSExtension {
|
|
122
225
|
}
|
123
226
|
}
|
124
227
|
|
228
|
+
await command.executeHook(this, 'beforeSync', [cmd, command])
|
229
|
+
|
125
230
|
if (command.options.guilds) {
|
126
231
|
for (const guild of command.options.guilds) {
|
127
232
|
let commands = guildCommands.get(guild)
|
@@ -129,32 +234,34 @@ export class ApplicationCommandExtension extends CTSExtension {
|
|
129
234
|
commands = []
|
130
235
|
guildCommands.set(guild, commands)
|
131
236
|
}
|
132
|
-
commands.push(cmd)
|
133
237
|
}
|
134
238
|
continue
|
135
239
|
}
|
136
240
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
241
|
+
commands.push(cmd)
|
242
|
+
}
|
243
|
+
|
244
|
+
if (this.config.guilds) {
|
245
|
+
for (const guild of this.config.guilds) {
|
246
|
+
let g = guildCommands.get(guild)
|
247
|
+
if (!g) {
|
248
|
+
g = []
|
249
|
+
guildCommands.set(guild, g)
|
145
250
|
}
|
146
|
-
|
251
|
+
g.push(...commands)
|
147
252
|
}
|
148
|
-
|
253
|
+
|
254
|
+
commands = []
|
149
255
|
}
|
150
256
|
|
151
257
|
if (guildCommands.size) {
|
152
258
|
for (const [guild, commands] of guildCommands) {
|
153
|
-
this.logger.info(`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')})`)
|
154
259
|
try {
|
155
260
|
const g = await this.client.guilds.fetch(guild)
|
156
261
|
await g.fetch()
|
157
|
-
this.logger.info(
|
262
|
+
this.logger.info(
|
263
|
+
`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')}) for guild ${chalk.green(g.name)}(${chalk.blue(g.id)})`,
|
264
|
+
)
|
158
265
|
|
159
266
|
await g.commands.set(commands)
|
160
267
|
|
@@ -166,7 +273,7 @@ export class ApplicationCommandExtension extends CTSExtension {
|
|
166
273
|
}
|
167
274
|
if (commands.length) {
|
168
275
|
try {
|
169
|
-
this.logger.info(`
|
276
|
+
this.logger.info(`Processing ${chalk.green(commands.length)} commands(${commands.map((x) => chalk.blue(x.name)).join(', ')}) for application scope...`)
|
170
277
|
|
171
278
|
await this.client.application!.commands.set(commands)
|
172
279
|
|
@@ -203,4 +310,13 @@ export class ApplicationCommandExtension extends CTSExtension {
|
|
203
310
|
async userInteraction(i: UserContextMenuCommandInteraction) {
|
204
311
|
return i
|
205
312
|
}
|
313
|
+
|
314
|
+
@argConverter({
|
315
|
+
component: ApplicationCommandComponent,
|
316
|
+
parameterless: true,
|
317
|
+
type: CommandInteraction,
|
318
|
+
})
|
319
|
+
async commandInteraction(i: UserContextMenuCommandInteraction) {
|
320
|
+
return i
|
321
|
+
}
|
206
322
|
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { APIApplicationCommandSubcommandOption, ApplicationCommandType, ChatInputApplicationCommandData } from 'discord.js'
|
2
|
+
import { createComponentDecorator } from '../core'
|
3
|
+
import { ApplicationCommandComponent } from './ApplicationCommand'
|
4
|
+
|
5
|
+
export class SubCommandGroup {
|
6
|
+
constructor(public options: Omit<APIApplicationCommandSubcommandOption, 'type'>, public guilds?: string[]) {}
|
7
|
+
|
8
|
+
command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator {
|
9
|
+
const cmd = new ApplicationCommandComponent({
|
10
|
+
type: ApplicationCommandType.ChatInput,
|
11
|
+
...options,
|
12
|
+
})
|
13
|
+
cmd.subcommandGroup = this
|
14
|
+
return createComponentDecorator(cmd)
|
15
|
+
}
|
16
|
+
|
17
|
+
createChild(options: Omit<APIApplicationCommandSubcommandOption, 'type'>) {
|
18
|
+
return new SubCommandGroupChild(options, this)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
export class SubCommandGroupChild {
|
23
|
+
constructor(public options: Omit<APIApplicationCommandSubcommandOption, 'type'>, public parent: SubCommandGroup) {}
|
24
|
+
|
25
|
+
command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator {
|
26
|
+
const cmd = new ApplicationCommandComponent({
|
27
|
+
type: ApplicationCommandType.ChatInput,
|
28
|
+
...options,
|
29
|
+
})
|
30
|
+
cmd.subcommandGroupChild = this
|
31
|
+
return createComponentDecorator(cmd)
|
32
|
+
}
|
33
|
+
}
|
@@ -1,10 +1,11 @@
|
|
1
1
|
/*
|
2
|
-
* File: index.ts
|
3
|
-
*
|
4
|
-
* Copyright (c) 2022-2022 pikokr
|
5
|
-
*
|
6
|
-
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
-
*/
|
2
|
+
* File: index.ts
|
3
|
+
*
|
4
|
+
* Copyright (c) 2022-2022 pikokr
|
5
|
+
*
|
6
|
+
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
+
*/
|
8
8
|
|
9
|
-
export * from './ApplicationCommand'
|
10
|
-
export { option } from './ApplicationCommandOption'
|
9
|
+
export * from './ApplicationCommand'
|
10
|
+
export { option } from './ApplicationCommandOption'
|
11
|
+
export * from './group'
|
@@ -1,28 +1,24 @@
|
|
1
|
-
/*
|
2
|
-
* File: BaseComponent.ts
|
3
|
-
*
|
4
|
-
* Copyright (c) 2022-2022 pikokr
|
5
|
-
*
|
6
|
-
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
-
*/
|
8
|
-
|
1
|
+
/*
|
2
|
+
* File: BaseComponent.ts
|
3
|
+
*
|
4
|
+
* Copyright (c) 2022-2022 pikokr
|
5
|
+
*
|
6
|
+
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
+
*/
|
8
|
+
|
9
9
|
import { Collection } from 'discord.js'
|
10
10
|
import _ from 'lodash'
|
11
11
|
import type { ComponentHookStore } from '../hooks'
|
12
12
|
import { ComponentArgument } from './ComponentArgument'
|
13
13
|
|
14
|
-
export class BaseComponent
|
15
|
-
|
16
|
-
|
17
|
-
method: Function
|
14
|
+
export class BaseComponent {
|
15
|
+
method!: Function
|
18
16
|
|
19
17
|
hooks: ComponentHookStore = new Collection()
|
20
18
|
|
21
19
|
argTypes: Collection<number, ComponentArgument> = new Collection()
|
22
20
|
|
23
|
-
|
24
|
-
this.options = this.convertOptions(options)
|
25
|
-
|
21
|
+
_init(method: Function, argTypes: unknown[]) {
|
26
22
|
this.method = method
|
27
23
|
for (let i = 0; i < argTypes.length; i++) {
|
28
24
|
const element = argTypes[i]
|
@@ -30,10 +26,6 @@ export class BaseComponent<Options = unknown, OptionsArg = Options> {
|
|
30
26
|
}
|
31
27
|
}
|
32
28
|
|
33
|
-
convertOptions(options: OptionsArg): Options {
|
34
|
-
return options as unknown as Options
|
35
|
-
}
|
36
|
-
|
37
29
|
async executeHook(target: object, name: string, args: unknown[]) {
|
38
30
|
const hook = this.hooks.get(name)
|
39
31
|
|
@@ -1,11 +1,11 @@
|
|
1
|
-
/*
|
2
|
-
* File: decoratorCreator.ts
|
3
|
-
*
|
4
|
-
* Copyright (c) 2022-2022 pikokr
|
5
|
-
*
|
6
|
-
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
-
*/
|
8
|
-
|
1
|
+
/*
|
2
|
+
* File: decoratorCreator.ts
|
3
|
+
*
|
4
|
+
* Copyright (c) 2022-2022 pikokr
|
5
|
+
*
|
6
|
+
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
+
*/
|
8
|
+
|
9
9
|
import { Collection } from 'discord.js'
|
10
10
|
import { ComponentHookStore } from '../hooks'
|
11
11
|
import { getComponentHookStore } from '../hooks/componentHook'
|
@@ -34,25 +34,23 @@ export const getComponent = (target: object, key: string | symbol) => {
|
|
34
34
|
return store.get(key)
|
35
35
|
}
|
36
36
|
|
37
|
-
export const createComponentDecorator =
|
38
|
-
return (
|
39
|
-
|
40
|
-
var component: BaseComponent<Options, OptionArgs> = new type(options, Reflect.get(target, key), Reflect.getMetadata('design:paramtypes', target, key))
|
37
|
+
export const createComponentDecorator = (component: BaseComponent): MethodDecorator => {
|
38
|
+
return (target, key) => {
|
39
|
+
component._init(Reflect.get(target, key), Reflect.getMetadata('design:paramtypes', target, key))
|
41
40
|
|
42
|
-
|
41
|
+
const componentHookStore: ComponentHookStore = getComponentHookStore(target, key)
|
43
42
|
|
44
|
-
|
43
|
+
component.hooks = componentHookStore
|
45
44
|
|
46
|
-
|
45
|
+
const store = getComponentStore(target)
|
47
46
|
|
48
|
-
|
47
|
+
const decorators = getComponentArgumentStore(target, key)
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
decorators.forEach((x, i) => {
|
50
|
+
component.argTypes.get(i)?.decorators.push(x)
|
51
|
+
})
|
53
52
|
|
54
|
-
|
55
|
-
}
|
53
|
+
store.set(key, component)
|
56
54
|
}
|
57
55
|
}
|
58
56
|
|
@@ -1,16 +1,25 @@
|
|
1
|
-
/*
|
2
|
-
* File: index.ts
|
3
|
-
*
|
4
|
-
* Copyright (c) 2022-2022 pikokr
|
5
|
-
*
|
6
|
-
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
-
*/
|
8
|
-
|
1
|
+
/*
|
2
|
+
* File: index.ts
|
3
|
+
*
|
4
|
+
* Copyright (c) 2022-2022 pikokr
|
5
|
+
*
|
6
|
+
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
+
*/
|
8
|
+
|
9
9
|
import { BaseComponent } from '../components/BaseComponent'
|
10
10
|
import { createComponentDecorator } from '../components/decoratorCreator'
|
11
11
|
|
12
|
-
type Options = { component:
|
12
|
+
type Options = { component: unknown; type: Function; parameterless: boolean }
|
13
|
+
|
14
|
+
type OptionsArg = Omit<Options, 'parameterless'> & { parameterless?: boolean }
|
15
|
+
|
16
|
+
export class ConverterComponent extends BaseComponent {
|
17
|
+
options: Options
|
13
18
|
|
14
|
-
|
19
|
+
constructor(options: OptionsArg) {
|
20
|
+
super()
|
21
|
+
this.options = options as Options
|
22
|
+
}
|
23
|
+
}
|
15
24
|
|
16
|
-
export const argConverter = createComponentDecorator(ConverterComponent)
|
25
|
+
export const argConverter = (options: OptionsArg) => createComponentDecorator(new ConverterComponent(options))
|
@@ -1,15 +1,14 @@
|
|
1
|
-
/*
|
2
|
-
* File: Extension.ts
|
3
|
-
*
|
4
|
-
* Copyright (c) 2022-2022 pikokr
|
5
|
-
*
|
6
|
-
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
-
*/
|
8
|
-
|
1
|
+
/*
|
2
|
+
* File: Extension.ts
|
3
|
+
*
|
4
|
+
* Copyright (c) 2022-2022 pikokr
|
5
|
+
*
|
6
|
+
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
+
*/
|
8
|
+
|
9
9
|
import chalk from 'chalk'
|
10
10
|
import { Collection } from 'discord.js'
|
11
11
|
import { Logger } from 'tslog'
|
12
|
-
import { BaseComponent } from '../components'
|
13
12
|
import { ComponentArgument } from '../components/ComponentArgument'
|
14
13
|
import { ConverterComponent } from '../converter'
|
15
14
|
import { CommandClient } from '../structures'
|
@@ -31,7 +30,7 @@ export class Extension {
|
|
31
30
|
}
|
32
31
|
|
33
32
|
protected async convertArguments(
|
34
|
-
component:
|
33
|
+
component: unknown,
|
35
34
|
argList: unknown[],
|
36
35
|
args: Collection<number, ComponentArgument>,
|
37
36
|
getConverterArgs: (arg: ComponentArgument, index: number, converter: ConverterComponent) => unknown[] | Promise<unknown[]>,
|
@@ -39,7 +38,7 @@ export class Extension {
|
|
39
38
|
const items = new Collection<unknown, { ext: object; component: ConverterComponent }>()
|
40
39
|
|
41
40
|
for (const extension of this.commandClient.registry.extensions) {
|
42
|
-
for (const converter of this.commandClient.registry.getComponentsWithType(extension, ConverterComponent)) {
|
41
|
+
for (const converter of this.commandClient.registry.getComponentsWithType<ConverterComponent>(extension, ConverterComponent)) {
|
43
42
|
if (converter.options.component != component) continue
|
44
43
|
|
45
44
|
items.set(converter.options.type, { component: converter, ext: extension })
|
@@ -1,29 +1,27 @@
|
|
1
|
-
/*
|
2
|
-
* File: index.ts
|
3
|
-
*
|
4
|
-
* Copyright (c) 2022-2022 pikokr
|
5
|
-
*
|
6
|
-
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
-
*/
|
8
|
-
|
1
|
+
/*
|
2
|
+
* File: index.ts
|
3
|
+
*
|
4
|
+
* Copyright (c) 2022-2022 pikokr
|
5
|
+
*
|
6
|
+
* Licensed under MIT License. Please see more defails in LICENSE file.
|
7
|
+
*/
|
8
|
+
|
9
|
+
import _ from 'lodash'
|
9
10
|
import { BaseComponent } from '../components/BaseComponent'
|
10
11
|
import { createComponentDecorator } from '../components/decoratorCreator'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
type Options = { emitter: string; event: string }
|
14
|
+
|
15
|
+
type OptionsArg = { emitter?: string; event: string }
|
16
|
+
|
17
|
+
export class ListenerComponent extends BaseComponent {
|
18
|
+
options: Options
|
19
|
+
|
20
|
+
constructor(options: OptionsArg) {
|
21
|
+
super()
|
16
22
|
|
17
|
-
|
18
|
-
super(
|
19
|
-
{
|
20
|
-
event: options.event,
|
21
|
-
emitter: options.emitter ?? 'discord',
|
22
|
-
},
|
23
|
-
method,
|
24
|
-
argTypes,
|
25
|
-
)
|
23
|
+
this.options = _.merge({ emitter: 'discord' }, options)
|
26
24
|
}
|
27
25
|
}
|
28
26
|
|
29
|
-
export const listener = createComponentDecorator(ListenerComponent)
|
27
|
+
export const listener = (options: OptionsArg) => createComponentDecorator(new ListenerComponent(options))
|
@@ -33,24 +33,24 @@ export class Registry {
|
|
33
33
|
})
|
34
34
|
}
|
35
35
|
|
36
|
-
getComponentsWithTypeGlobal<T
|
37
|
-
const result:
|
36
|
+
getComponentsWithTypeGlobal<T>(type: unknown): T[] {
|
37
|
+
const result: T[] = []
|
38
38
|
|
39
39
|
for (const ext of this.extensions) {
|
40
|
-
result.push(...this.getComponentsWithType(ext, type))
|
40
|
+
result.push(...this.getComponentsWithType<T>(ext, type))
|
41
41
|
}
|
42
42
|
|
43
43
|
return result
|
44
44
|
}
|
45
45
|
|
46
|
-
getComponentsWithType<T
|
46
|
+
getComponentsWithType<T>(ext: object, type: unknown): T[] {
|
47
47
|
const componentStore = getComponentStore(ext)
|
48
48
|
|
49
|
-
return Array.from(componentStore.filter((x) => (x.constructor as unknown) === type).values() as Iterable<
|
49
|
+
return Array.from(componentStore.filter((x) => (x.constructor as unknown) === type).values() as Iterable<T>)
|
50
50
|
}
|
51
51
|
|
52
52
|
registerEventListeners(ext: object) {
|
53
|
-
const listeners = this.getComponentsWithType(ext, ListenerComponent)
|
53
|
+
const listeners = this.getComponentsWithType<ListenerComponent>(ext, ListenerComponent)
|
54
54
|
|
55
55
|
for (const listener of listeners) {
|
56
56
|
const emitter = this.emitters.get(listener.options.emitter)
|
@@ -66,7 +66,7 @@ export class Registry {
|
|
66
66
|
}
|
67
67
|
|
68
68
|
unregisterEventListeners(ext: object) {
|
69
|
-
const listeners = this.getComponentsWithType(ext, ListenerComponent)
|
69
|
+
const listeners = this.getComponentsWithType<ListenerComponent>(ext, ListenerComponent)
|
70
70
|
|
71
71
|
for (const listener of listeners) {
|
72
72
|
const emitter = this.emitters.get(listener.options.emitter)
|
@@ -15,6 +15,10 @@ type TextCommandOptions = {
|
|
15
15
|
description?: string
|
16
16
|
}
|
17
17
|
|
18
|
-
export class TextCommandComponent extends BaseComponent
|
18
|
+
export class TextCommandComponent extends BaseComponent {
|
19
|
+
constructor(public options: TextCommandOptions) {
|
20
|
+
super()
|
21
|
+
}
|
22
|
+
}
|
19
23
|
|
20
|
-
export const command = createComponentDecorator(TextCommandComponent)
|
24
|
+
export const command = (options: TextCommandOptions) => createComponentDecorator(new TextCommandComponent(options))
|
@@ -58,7 +58,7 @@ export class TextCommandExtension extends CTSExtension {
|
|
58
58
|
const extensions = new Map<TextCommandComponent, object>()
|
59
59
|
|
60
60
|
for (const ext of this.commandClient.registry.extensions) {
|
61
|
-
for (const cmd of this.commandClient.registry.getComponentsWithType(ext, TextCommandComponent)) {
|
61
|
+
for (const cmd of this.commandClient.registry.getComponentsWithType<TextCommandComponent>(ext, TextCommandComponent)) {
|
62
62
|
commands.push(cmd)
|
63
63
|
extensions.set(cmd, ext)
|
64
64
|
}
|
package/test/index.ts
CHANGED
@@ -7,11 +7,18 @@
|
|
7
7
|
*/
|
8
8
|
|
9
9
|
import { ApplicationCommandOptionType, ApplicationCommandType, ChatInputCommandInteraction, Client, Message } from 'discord.js'
|
10
|
-
import { applicationCommand, CommandClient, moduleHook, option, ownerOnly, listener, Extension, command, rest } from '../src'
|
10
|
+
import { applicationCommand, CommandClient, moduleHook, option, ownerOnly, listener, Extension, command, rest, SubCommandGroup } from '../src'
|
11
11
|
import 'dotenv/config'
|
12
12
|
import { Logger } from 'tslog'
|
13
13
|
import chalk from 'chalk'
|
14
14
|
|
15
|
+
const group = new SubCommandGroup({
|
16
|
+
name: 'hi',
|
17
|
+
description: 'sans',
|
18
|
+
})
|
19
|
+
|
20
|
+
const sub = group.createChild({ name: 'sub', description: 'wow this is subcommand group' })
|
21
|
+
|
15
22
|
class Test extends Extension {
|
16
23
|
@applicationCommand({
|
17
24
|
type: ApplicationCommandType.ChatInput,
|
@@ -46,6 +53,16 @@ class Test extends Extension {
|
|
46
53
|
this.logger.info('Load')
|
47
54
|
}
|
48
55
|
|
56
|
+
@group.command({ name: 'hi', description: 'Wow this is sans' })
|
57
|
+
hi(i: ChatInputCommandInteraction) {
|
58
|
+
i.reply('Hi this is subcommand')
|
59
|
+
}
|
60
|
+
|
61
|
+
@sub.command({ name: 'hi', description: 'Wow this is sans' })
|
62
|
+
subHi(i: ChatInputCommandInteraction) {
|
63
|
+
i.reply('Hi this is subcommand in subcommand group')
|
64
|
+
}
|
65
|
+
|
49
66
|
@moduleHook('unload')
|
50
67
|
unload() {
|
51
68
|
this.logger.info('Unload')
|
@@ -87,6 +104,8 @@ const run = async () => {
|
|
87
104
|
|
88
105
|
await client.login(process.env.TOKEN)
|
89
106
|
|
107
|
+
await client.application?.commands.set([])
|
108
|
+
|
90
109
|
await cc.getApplicationCommandsExtension()!.sync()
|
91
110
|
}
|
92
111
|
|