@pikokr/command.ts 5.5.0 → 5.6.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.eslintrc.js +19 -0
  2. package/.github/workflows/docs.yml +22 -6
  3. package/.github/workflows/lint.yml +41 -0
  4. package/.github/workflows/release.yml +49 -0
  5. package/.vscode/settings.json +6 -3
  6. package/dist/index.d.ts +48 -46
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/package.json +20 -3
  10. package/publish-version.js +1 -23
  11. package/scripts/docs.ts +8 -8
  12. package/src/applicationCommand/ApplicationCommand.ts +1 -9
  13. package/src/applicationCommand/ApplicationCommandExtension.ts +14 -17
  14. package/src/applicationCommand/ApplicationCommandOption.ts +1 -9
  15. package/src/applicationCommand/group.ts +2 -1
  16. package/src/applicationCommand/index.ts +4 -12
  17. package/src/core/components/BaseComponent.ts +3 -11
  18. package/src/core/components/ComponentArgument.ts +1 -9
  19. package/src/core/components/ComponentArgumentDecorator.ts +0 -8
  20. package/src/core/components/decoratorCreator.ts +4 -12
  21. package/src/core/components/index.ts +5 -13
  22. package/src/core/converter/index.ts +8 -15
  23. package/src/core/extensions/CTSExtension.ts +0 -8
  24. package/src/core/extensions/Extension.ts +5 -13
  25. package/src/core/extensions/index.ts +0 -8
  26. package/src/core/hooks/componentHook.ts +4 -11
  27. package/src/core/hooks/index.ts +3 -11
  28. package/src/core/hooks/moduleHook.ts +2 -9
  29. package/src/core/index.ts +0 -8
  30. package/src/core/listener/index.ts +0 -8
  31. package/src/core/structures/CommandClient.ts +7 -12
  32. package/src/core/structures/Registry.ts +8 -16
  33. package/src/core/structures/index.ts +0 -8
  34. package/src/core/symbols.ts +6 -14
  35. package/src/core/utils/checks.ts +5 -12
  36. package/src/core/utils/errors.ts +0 -8
  37. package/src/core/utils/index.ts +3 -11
  38. package/src/index.ts +3 -11
  39. package/src/textCommand/TextCommand.ts +0 -8
  40. package/src/textCommand/TextCommandExtension.ts +11 -32
  41. package/src/textCommand/index.ts +0 -8
  42. package/src/textCommand/parameters.ts +6 -14
  43. package/src/utils/types.ts +1 -0
  44. package/test/index.ts +5 -4
  45. package/tsup.config.ts +8 -8
  46. package/.github/workflows/publish.stable.yml +0 -18
  47. package/.github/workflows/publish.yml +0 -20
  48. package/.yarn/releases/yarn-3.2.3.cjs +0 -783
  49. package/.yarn/sdks/integrations.yml +0 -5
  50. package/.yarn/sdks/prettier/index.js +0 -20
  51. package/.yarn/sdks/prettier/package.json +0 -6
  52. package/.yarn/sdks/typescript/bin/tsc +0 -20
  53. package/.yarn/sdks/typescript/bin/tsserver +0 -20
  54. package/.yarn/sdks/typescript/lib/tsc.js +0 -20
  55. package/.yarn/sdks/typescript/lib/tsserver.js +0 -196
  56. package/.yarn/sdks/typescript/lib/tsserverlibrary.js +0 -196
  57. package/.yarn/sdks/typescript/lib/typescript.js +0 -20
  58. package/.yarn/sdks/typescript/package.json +0 -6
  59. package/.yarnrc.yml +0 -1
package/.eslintrc.js ADDED
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ env: {
3
+ es2021: true,
4
+ node: true,
5
+ },
6
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
7
+ overrides: [],
8
+ parser: '@typescript-eslint/parser',
9
+ parserOptions: {
10
+ ecmaVersion: 'latest',
11
+ sourceType: 'module',
12
+ },
13
+ plugins: ['@typescript-eslint', 'prettier'],
14
+ rules: {
15
+ 'prettier/prettier': 'error',
16
+ '@typescript-eslint/consistent-type-imports': 'error',
17
+ '@typescript-eslint/no-unused-vars': 'error',
18
+ },
19
+ }
@@ -20,17 +20,33 @@ jobs:
20
20
  - name: Checkout repository
21
21
  uses: actions/checkout@v3
22
22
 
23
- - name: Install node.js v16
23
+ - name: Install node.js v18
24
24
  uses: actions/setup-node@v3
25
25
  with:
26
- node-version: 16
27
- cache: 'yarn'
28
- cache-dependency-path: yarn.lock
26
+ node-version: 18
27
+
28
+ - name: Enable corepack
29
+ run: corepack enable
30
+
31
+ - name: Get pnpm store directory
32
+ id: pnpm-cache
33
+ shell: bash
34
+ run: |
35
+ echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
36
+
37
+ - uses: actions/cache@v3
38
+ name: Setup pnpm cache
39
+ with:
40
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
41
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
42
+ restore-keys: |
43
+ ${{ runner.os }}-pnpm-store-
44
+
29
45
  - name: Install dependencies
30
- run: yarn --immutable
46
+ run: pnpm i --frozen-lockfile
31
47
 
32
48
  - name: Build docs
33
- run: yarn docs
49
+ run: pnpm run docs
34
50
 
35
51
  - name: Upload artifacts
36
52
  uses: actions/upload-artifact@v3
@@ -0,0 +1,41 @@
1
+ name: Lint
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'dev'
7
+ pull_request:
8
+
9
+ jobs:
10
+ eslint:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v3
16
+ - name: Setup node
17
+ uses: actions/setup-node@v3
18
+ with:
19
+ node-version: 18
20
+ - name: Enable corepack
21
+ run: corepack enable
22
+
23
+ - name: Get pnpm store directory
24
+ id: pnpm-cache
25
+ shell: bash
26
+ run: |
27
+ echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
28
+
29
+ - uses: actions/cache@v3
30
+ name: Setup pnpm cache
31
+ with:
32
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
33
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
34
+ restore-keys: |
35
+ ${{ runner.os }}-pnpm-store-
36
+
37
+ - name: Install dependencies
38
+ run: pnpm i --frozen-lockfile
39
+
40
+ - name: Lint
41
+ run: pnpm run lint --max-warnings=0
@@ -0,0 +1,49 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'dev'
7
+ - 'stable'
8
+
9
+ jobs:
10
+ release:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v3
16
+ - name: Setup node
17
+ uses: actions/setup-node@v3
18
+ with:
19
+ node-version: 18
20
+ - name: Enable corepack
21
+ run: corepack enable
22
+
23
+ - name: Remove packageManager entry
24
+ run: |
25
+ sudo apt install -y jq
26
+ cat package.json | jq "del(.packageManager)" | tee package.json
27
+
28
+ - name: Get pnpm store directory
29
+ id: pnpm-cache
30
+ shell: bash
31
+ run: |
32
+ echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
33
+
34
+ - uses: actions/cache@v3
35
+ name: Setup pnpm cache
36
+ with:
37
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
38
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39
+ restore-keys: |
40
+ ${{ runner.os }}-pnpm-store-
41
+
42
+ - name: Install dependencies
43
+ run: pnpm i --frozen-lockfile
44
+
45
+ - name: Semantic release
46
+ run: pnpm run semantic-release
47
+ env:
48
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -11,7 +11,10 @@
11
11
  "**/.yarn": true,
12
12
  "**/.pnp.*": true
13
13
  },
14
- "prettier.prettierPath": ".yarn/sdks/prettier/index.js",
15
- "typescript.tsdk": ".yarn/sdks/typescript/lib",
16
- "typescript.enablePromptUseWorkspaceTsdk": true
14
+ "prettier.prettierPath": "node_modules/prettier/index.js",
15
+ "typescript.tsdk": "node_modules/typescript/lib",
16
+ "typescript.enablePromptUseWorkspaceTsdk": true,
17
+ "editor.codeActionsOnSave": {
18
+ "source.fixAll": true
19
+ }
17
20
  }
package/dist/index.d.ts CHANGED
@@ -4,14 +4,16 @@ import EventEmitter from 'events';
4
4
  import * as tslog from 'tslog';
5
5
  import { Logger, ISettingsParam } from 'tslog';
6
6
 
7
- declare type ModuleHookStore = Collection<string, Function[]>;
7
+ type AnyFunction = (...args: unknown[]) => unknown;
8
+
9
+ type ComponentHookFn<T extends unknown[]> = (...args: T) => void | Promise<void>;
10
+ type ComponentHookStore = Collection<string, ComponentHookFn<unknown[]>[]>;
11
+ declare const createComponentHook: <T extends unknown[]>(name: string, fn: ComponentHookFn<T>) => MethodDecorator;
12
+
13
+ type ModuleHookStore = Collection<string, ComponentHookFn<unknown[]>[]>;
8
14
  declare const getModuleHookStore: (target: object) => ModuleHookStore;
9
15
  declare const moduleHook: (name: string) => MethodDecorator;
10
16
 
11
- declare type ComponentHookFn = (...args: any[]) => void | Promise<void>;
12
- declare type ComponentHookStore = Collection<string, ComponentHookFn[]>;
13
- declare const createComponentHook: (name: string, fn: ComponentHookFn) => MethodDecorator;
14
-
15
17
  declare class ComponentArgumentDecorator<Options = unknown> {
16
18
  options: Options;
17
19
  constructor(options: Partial<Options>);
@@ -25,17 +27,17 @@ declare class ComponentArgument {
25
27
  }
26
28
 
27
29
  declare class BaseComponent {
28
- method: Function;
30
+ method: AnyFunction;
29
31
  hooks: ComponentHookStore;
30
32
  argTypes: Collection<number, ComponentArgument>;
31
- _init(method: Function, argTypes: unknown[]): void;
33
+ _init(method: AnyFunction, argTypes: unknown[]): void;
32
34
  executeGlobalHook(target: object, name: string, args: unknown[]): Promise<void>;
33
35
  executeHook(target: object, name: string, args: unknown[]): Promise<void>;
34
- execute(target: object, args: unknown[], beforeCallArgs?: unknown[]): Promise<any>;
36
+ execute(target: object, args: unknown[], beforeCallArgs?: unknown[]): Promise<unknown>;
35
37
  }
36
38
 
37
- declare type ComponentStore = Collection<string | symbol, BaseComponent>;
38
- declare type ComponentArgumentStore = Collection<number, ComponentArgumentDecorator>;
39
+ type ComponentStore = Collection<string | symbol, BaseComponent>;
40
+ type ComponentArgumentStore = Collection<number, ComponentArgumentDecorator>;
39
41
  declare const getComponentStore: (target: object) => ComponentStore;
40
42
  declare const getComponent: (target: object, key: string | symbol) => BaseComponent | undefined;
41
43
  declare const createComponentDecorator: (component: BaseComponent) => MethodDecorator;
@@ -44,55 +46,33 @@ declare const createArgumentDecorator: <Options>(type: {
44
46
  new (options: Partial<Options>): ComponentArgumentDecorator<Options>;
45
47
  }) => (options: Options) => ParameterDecorator;
46
48
 
47
- declare type Options$2 = {
49
+ type Options$2<T> = {
48
50
  component: unknown;
49
- type: Function;
51
+ type: T;
50
52
  parameterless: boolean;
51
53
  };
52
- declare type OptionsArg$1 = Omit<Options$2, 'parameterless'> & {
54
+ type OptionsArg$1<T> = Omit<Options$2<T>, 'parameterless'> & {
53
55
  parameterless?: boolean;
54
56
  };
55
- declare class ConverterComponent extends BaseComponent {
56
- options: Options$2;
57
- constructor(options: OptionsArg$1);
57
+ declare class ConverterComponent<T> extends BaseComponent {
58
+ options: Options$2<T>;
59
+ constructor(options: OptionsArg$1<T>);
58
60
  }
59
- declare const argConverter: (options: OptionsArg$1) => MethodDecorator;
60
-
61
- declare const createCheckDecorator: (fn: ComponentHookFn) => MethodDecorator;
62
- declare const ownerOnly: MethodDecorator;
63
-
64
- declare class OwnerOnlyError {
65
- }
66
-
67
- declare const mergeMethodDecorators: (decorators: MethodDecorator[]) => MethodDecorator;
68
-
69
- declare type Options$1 = {
70
- emitter: string;
71
- event: string;
72
- };
73
- declare type OptionsArg = {
74
- emitter?: string;
75
- event: string;
76
- };
77
- declare class ListenerComponent extends BaseComponent {
78
- options: Options$1;
79
- constructor(options: OptionsArg);
80
- }
81
- declare const listener: (options: OptionsArg) => MethodDecorator;
61
+ declare const argConverter: <T>(options: OptionsArg$1<T>) => MethodDecorator;
82
62
 
83
63
  declare class Extension {
84
64
  protected get commandClient(): CommandClient;
85
65
  protected get client(): discord_js.Client<boolean>;
86
66
  protected _logger?: Logger<unknown>;
87
67
  protected get logger(): Logger<unknown>;
88
- protected convertArguments(component: unknown, argList: unknown[], args: Collection<number, ComponentArgument>, getConverterArgs: (arg: ComponentArgument, index: number, converter: ConverterComponent) => unknown[] | Promise<unknown[]>): Promise<void>;
68
+ protected convertArguments(component: unknown, argList: unknown[], args: Collection<number, ComponentArgument>, getConverterArgs: (arg: ComponentArgument, index: number, converter: ConverterComponent<unknown>) => unknown[] | Promise<unknown[]>): Promise<void>;
89
69
  }
90
70
 
91
71
  declare class CTSExtension extends Extension {
92
72
  protected get logger(): tslog.Logger<unknown>;
93
73
  }
94
74
 
95
- declare type ApplicationCommandExtensionConfig = {
75
+ type ApplicationCommandExtensionConfig = {
96
76
  guilds?: Snowflake[];
97
77
  };
98
78
  declare class ApplicationCommandExtension extends CTSExtension {
@@ -112,7 +92,7 @@ declare class ApplicationCommandExtension extends CTSExtension {
112
92
  commandInteraction(i: UserContextMenuCommandInteraction): Promise<UserContextMenuCommandInteraction<discord_js.CacheType>>;
113
93
  }
114
94
 
115
- declare type TextCommandOptions = {
95
+ type TextCommandOptions = {
116
96
  name: string;
117
97
  aliases?: string[];
118
98
  description?: string;
@@ -123,7 +103,7 @@ declare class TextCommandComponent extends BaseComponent {
123
103
  }
124
104
  declare const command: (options: TextCommandOptions) => MethodDecorator;
125
105
 
126
- declare type TextCommandConfig = {
106
+ type TextCommandConfig = {
127
107
  prefix: string | string[] | ((msg: Message) => Promise<string | string[]> | string | string[]);
128
108
  };
129
109
  declare module 'discord.js' {
@@ -156,9 +136,9 @@ declare class Registry {
156
136
  extensions: object[];
157
137
  emitters: Collection<string, EventEmitter>;
158
138
  logger: Logger<unknown>;
159
- globalHooks: Record<string, ComponentHookFn[]>;
139
+ globalHooks: Record<string, ComponentHookFn<unknown[]>[]>;
160
140
  constructor(logger: Logger<unknown>, client: CommandClient);
161
- addGlobalHook(name: string, fn: ComponentHookFn): void;
141
+ addGlobalHook(name: string, fn: ComponentHookFn<unknown[]>): void;
162
142
  getComponentsWithTypeGlobal<T>(type: unknown): T[];
163
143
  getComponentsWithType<T>(ext: object, type: unknown): T[];
164
144
  registerEventListeners(ext: object): void;
@@ -178,6 +158,28 @@ declare class Registry {
178
158
  registerEventEmitter(name: string, emitter: EventEmitter): void;
179
159
  }
180
160
 
161
+ declare const createCheckDecorator: (fn: ComponentHookFn<[CommandClient, Interaction | Message]>) => MethodDecorator;
162
+ declare const ownerOnly: MethodDecorator;
163
+
164
+ declare class OwnerOnlyError {
165
+ }
166
+
167
+ declare const mergeMethodDecorators: (decorators: MethodDecorator[]) => MethodDecorator;
168
+
169
+ type Options$1 = {
170
+ emitter: string;
171
+ event: string;
172
+ };
173
+ type OptionsArg = {
174
+ emitter?: string;
175
+ event: string;
176
+ };
177
+ declare class ListenerComponent extends BaseComponent {
178
+ options: Options$1;
179
+ constructor(options: OptionsArg);
180
+ }
181
+ declare const listener: (options: OptionsArg) => MethodDecorator;
182
+
181
183
  declare class SubCommandGroup {
182
184
  options: Omit<APIApplicationCommandSubcommandOption, 'type'>;
183
185
  guilds?: string[] | undefined;
@@ -192,7 +194,7 @@ declare class SubCommandGroupChild {
192
194
  command(options: Omit<ChatInputApplicationCommandData, 'options' | 'type'>): MethodDecorator;
193
195
  }
194
196
 
195
- declare type Options = (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & {
197
+ type Options = (UserApplicationCommandData | MessageApplicationCommandData | Omit<ChatInputApplicationCommandData, 'options'>) & {
196
198
  type: ApplicationCommandType;
197
199
  guilds?: Snowflake[];
198
200
  };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var ne=Object.create;var B=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ae=Object.prototype.hasOwnProperty;var c=(r,t)=>B(r,"name",{value:t,configurable:!0});var f=(r,t)=>()=>(r&&(t=r(r=0)),t);var At=(r,t)=>{for(var e in t)B(r,e,{get:t[e],enumerable:!0})},Lt=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of se(t))!ae.call(r,s)&&s!==e&&B(r,s,{get:()=>t[s],enumerable:!(o=re(t,s))||o.enumerable});return r};var C=(r,t,e)=>(e=r!=null?ne(ie(r)):{},Lt(t||!r||!r.__esModule?B(e,"default",{value:r,enumerable:!0}):e,r)),ce=r=>Lt(B({},"__esModule",{value:!0}),r);var z,xe,ft,Y,ut,tt,F=f(()=>{"use strict";z=Symbol(),xe=Symbol(),ft=Symbol(),Y=Symbol(),ut=Symbol(),tt=Symbol()});var Et,dt,et,gt=f(()=>{"use strict";Et=require("discord.js");F();dt=c((r,t)=>{let e=Reflect.getMetadata(ut,r,t);return e||(e=new Et.Collection,Reflect.defineMetadata(ut,e,r,t)),e},"getComponentHookStore"),et=c((r,t)=>(e,o)=>{let s=dt(e,o),n=s.get(r);n||(n=[],s.set(r,n)),n.unshift(t)},"createComponentHook")});var ht,Z,me,y,yt,J,$=f(()=>{"use strict";ht=require("discord.js");gt();F();Z=c(r=>{let t=Reflect.getMetadata(z,r);return t||(t=new ht.Collection,Reflect.defineMetadata(z,t,r)),t},"getComponentStore"),me=c((r,t)=>Z(r).get(t),"getComponent"),y=c(r=>(t,e)=>{r._init(Reflect.get(t,e),Reflect.getMetadata("design:paramtypes",t,e));let o=dt(t,e);r.hooks=o;let s=Z(t);yt(t,e).forEach((a,i)=>{var m;(m=r.argTypes.get(i))==null||m.decorators.push(a)}),s.set(e,r)},"createComponentDecorator"),yt=c((r,t)=>{let e=Reflect.getMetadata(z,r,t);return e||(e=new ht.Collection,Reflect.defineMetadata(z,e,r,t)),e},"getComponentArgumentStore"),J=c(r=>t=>(e,o,s)=>{var n=new r(t);yt(e,o).set(s,n)},"createArgumentDecorator")});var O,xt=f(()=>{"use strict";O=class{constructor(t){this.type=t,this.decorators=[]}};c(O,"ComponentArgument")});var Ft,G,$t=f(()=>{"use strict";Ft=C(require("lodash")),G=class{constructor(t){typeof t=="object"?this.options=Ft.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};c(G,"ComponentArgumentDecorator")});var h,pe,ot=f(()=>{"use strict";$();W();h=class extends x{constructor(t){super(),this.options=t}};c(h,"ApplicationCommandComponent");pe=c(r=>y(new h(r)),"applicationCommand")});var H,Ot,bt=f(()=>{"use strict";T();H=class extends G{};c(H,"ApplicationCommandOption");Ot=J(H)});var Wt,I,K,Q=f(()=>{"use strict";Wt=C(require("lodash"));W();$();I=class extends x{constructor(t){super(),this.options=Wt.default.merge({emitter:"discord"},t)}};c(I,"ListenerComponent");K=c(r=>y(new I(r)),"listener")});var j,S,nt=f(()=>{"use strict";W();$();j=class extends x{constructor(t){super(),this.options=t}};c(j,"ConverterComponent");S=c(r=>y(new j(r)),"argConverter")});var Dt,rt,le,Pt=f(()=>{"use strict";Dt=require("discord.js");F();rt=c(r=>{let t=Reflect.getMetadata(ft,r);return t||(t=new Dt.Collection,Reflect.defineMetadata(ft,t,r)),t},"getModuleHookStore"),le=c(r=>(t,e)=>{let o=rt(t),s=o.get(r);s||(s=[],o.set(r,s)),s.push(Reflect.get(t,e))},"moduleHook")});var st=f(()=>{"use strict";Pt();gt()});var D,Nt,qt,Ut,Bt,P,Ct=f(()=>{"use strict";D=C(require("chalk")),Nt=require("discord.js"),qt=C(require("lodash"));wt();st();Q();F();Ut=C(require("walk-sync")),Bt=C(require("path")),P=class{constructor(t,e){this.client=e,this.extensions=[],this.emitters=new Nt.Collection,this.globalHooks={},this.logger=t.getSubLogger({name:D.default.green("Registry")})}addGlobalHook(t,e){let o=this.globalHooks[t];o||(o=[],this.globalHooks[t]=o),o.push(e)}getComponentsWithTypeGlobal(t){let e=[];for(let o of this.extensions)e.push(...this.getComponentsWithType(o,t));return e}getComponentsWithType(t,e){let o=Z(t);return Array.from(o.filter(s=>s.constructor===e).values())}registerEventListeners(t){let e=this.getComponentsWithType(t,I);for(let o of e){let s=this.emitters.get(o.options.emitter);if(s){let n=o.method.bind(t);Reflect.defineMetadata("bound",n,o),s.addListener(o.options.event,n)}}}unregisterEventListeners(t){let e=this.getComponentsWithType(t,I);for(let o of e){let s=this.emitters.get(o.options.emitter),n=Reflect.getMetadata("bound",o);s&&n&&s.removeListener(o.options.event,n)}}async loadAllModulesInDirectory(t,e){let o=[],s=(0,Ut.default)(t).filter(n=>(n.endsWith(".ts")||n.endsWith(".js"))&&(!e||e.test(n)));for(let n of s){if(n.endsWith(".d.ts"))continue;let a=Bt.default.join(t,n);o.push(...await this.loadModulesAtPath(a))}return o}async loadModulesAtPath(t){this.logger.info(`Loading module at path ${D.default.green(t)}`);let e=require.resolve(t),o=require(e);if(typeof o.setup!="function")throw new Error("Extension must have a setup function");let s=await o.setup(this.client);return this.registerModules(s,e)}async registerModules(t,e){let o=[];if(t instanceof Array)for(let s of t)await this.registerModule(s),Reflect.defineMetadata(tt,e,s),o.push(s);else await this.registerModule(t),Reflect.defineMetadata(tt,e,t),o.push(t);return o}async reloadModules(){let t=[],e=new Set,o=[...this.extensions];for(let s of o){let n=Reflect.getMetadata(tt,s);!n||(this.logger.info(`Unloading module: ${D.default.green(s.constructor.name)}`),e.add(n),await this.unregisterModule(s),delete require.cache[require.resolve(n)])}for(let s of e)try{let n=await this.loadModulesAtPath(s);t.push({file:s,result:!0,extensions:n})}catch(n){t.push({file:s,result:!1,error:n})}return t}async registerModule(t){Reflect.defineMetadata(Y,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${D.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),qt.default.remove(this.extensions,e=>e===t),this.logger.info(`Module unregistered: ${D.default.green(t.constructor.name)}`)}runModuleHook(t,e,...o){let n=rt(t).get(e);if(n)for(let a of n)a.call(t,...o)}registerEventEmitter(t,e){this.emitters.set(t,e)}};c(P,"Registry")});var St=f(()=>{"use strict";Ct();it()});var zt,Zt,N,Mt=f(()=>{"use strict";zt=C(require("chalk")),Zt=require("discord.js");nt();St();N=class{get commandClient(){return A.getFromModule(this)}get client(){return this.commandClient.discord}get logger(){return this._logger||(this._logger=this.commandClient.logger.getSubLogger({name:zt.default.green(`${this.constructor.name}`)})),this._logger}async convertArguments(t,e,o,s){let n=new Zt.Collection;for(let a of this.commandClient.registry.extensions)for(let i of this.commandClient.registry.getComponentsWithType(a,j))i.options.component==t&&n.set(i.options.type,{component:i,ext:a});for(let[a,i]of o){let m=n.get(i.type);if(!m){e[a]=void 0;continue}let u=await s(i,a,m.component);e[a]=await m.component.execute(m.ext,u)}}};c(N,"Extension")});var Jt,L,kt=f(()=>{"use strict";Jt=C(require("chalk"));Mt();L=class extends N{get logger(){return this._logger||(this._logger=this.commandClient.ctsLogger.getSubLogger({name:Jt.default.green(`${this.constructor.name}`)})),this._logger}};c(L,"CTSExtension")});var M,p,V,k,b,vt=f(()=>{"use strict";M=C(require("chalk")),p=require("discord.js");ot();bt();Q();nt();kt();V=function(r,t,e,o){var s=arguments.length,n=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,e,o);else for(var i=r.length-1;i>=0;i--)(a=r[i])&&(n=(s<3?a(n):s>3?a(t,e,n):a(t,e))||n);return s>3&&n&&Object.defineProperty(t,e,n),n},k=function(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)},b=class extends L{constructor(t){super(),this.config=t,this.unmanagedCommands=[]}registerUnmanagedCommand(t){this.unmanagedCommands.push(t)}async interactionCreate(t){var e;try{if(t.type!==p.InteractionType.ApplicationCommand)return;let o=null,s=null,n=this.commandClient.registry.extensions,a=null,i=null;t.commandType===p.ApplicationCommandType.ChatInput&&(a=t.options.getSubcommand(!1),i=t.options.getSubcommandGroup(!1));t:for(let m of n){let u=this.commandClient.registry.getComponentsWithType(m,h);if(a){for(let l of u)if(!(!l.subcommandGroup&&!l.subcommandGroupChild)){if(l.subcommandGroupChild&&l.subcommandGroupChild.parent.options.name===t.commandName&&l.subcommandGroupChild.options.name===i&&l.options.name===a){s=m,o=l;break t}if(l.subcommandGroup&&!i&&l.subcommandGroup.options.name===t.commandName&&l.options.name===a){s=m,o=l;break t}}}else for(let l of u)if(l.options.name===t.commandName){s=m,o=l;break t}}if(o&&s){let m=[];await this.convertArguments(h,m,o.argTypes,()=>[t]);for(let[u,l]of o.argTypes){let d=null;for(let g of l.decorators)if(g instanceof H){if([p.ApplicationCommandOptionType.Subcommand,p.ApplicationCommandOptionType.SubcommandGroup].includes(g.options.type)&&t.isChatInputCommand()){if(g.options.type===p.ApplicationCommandOptionType.Subcommand){d=t.options.getSubcommand()===g.options.name;break}if(g.options.type===p.ApplicationCommandOptionType.SubcommandGroup){d=t.options.getSubcommandGroup()===g.options.name;break}}d=(e=t.options.get(g.options.name,!1))==null?void 0:e.value;break}d&&(m[u]=d)}try{await o.executeGlobalHook(s,"beforeApplicationCommandCall",[t]),await o.execute(s,m,[t])}finally{await o.executeGlobalHook(s,"afterApplicationCommandCall",[t])}}}catch(o){this.commandClient.emit("applicationCommandInvokeError",o,t)}}async sync(){let t=this.commandClient;this.logger.info("Trying to sync commands...");let e=[],o=new p.Collection,s=new p.Collection;for(let n of t.registry.getComponentsWithTypeGlobal(h)){if(n.subcommandGroup){let i=s.get(n.subcommandGroup.options.name);if(!i){if(i={...n.subcommandGroup.options,type:p.ApplicationCommandType.ChatInput},n.subcommandGroup.guilds)for(let u of n.subcommandGroup.guilds){let l=o.get(u);l||(l=[],o.set(u,l))}else e.push(i);s.set(n.subcommandGroup.options.name,i)}i.options||(i.options=[]);let m=[];for(let[,u]of n.argTypes){let l=u.decorators.find(d=>d.constructor===H);l&&m.push(l.options)}i.options.push({...n.options,type:p.ApplicationCommandOptionType.Subcommand,options:m});continue}else if(n.subcommandGroupChild){let i=n.subcommandGroupChild.parent,m=s.get(i.options.name);if(!m){if(m={...i.options,type:p.ApplicationCommandType.ChatInput},i.guilds)for(let d of i.guilds){let g=o.get(d);g||(g=[],o.set(d,g))}else e.push(m);s.set(i.options.name,m)}m.options||(m.options=[]);let u=m.options.find(d=>d.name===n.subcommandGroupChild.options.name);u||(u={type:p.ApplicationCommandOptionType.SubcommandGroup,...n.subcommandGroupChild.options},m.options.push(u)),u.options||(u.options=[]);let l=[];for(let[,d]of n.argTypes){let g=d.decorators.find(v=>v.constructor===H);g&&l.push(g.options)}u.options.push({...n.options,type:p.ApplicationCommandOptionType.Subcommand,options:l});continue}let a={...n.options};if(a.type===p.ApplicationCommandType.ChatInput){a.options=[];for(let[,i]of n.argTypes){let m=i.decorators.find(u=>u.constructor===H);m&&a.options.push(m.options)}}if(await n.executeHook(this,"beforeSync",[a,n]),n.options.guilds){for(let i of n.options.guilds){let m=o.get(i);m||(m=[],o.set(i,m)),m.push(a)}continue}e.push(a)}for(let{guilds:n,...a}of this.unmanagedCommands)if(n){for(let i of n){let m=o.get(i);m||(m=[],o.set(i,m)),m.push(a)}continue}else e.push(a);if(this.config.guilds){for(let n of this.config.guilds){let a=o.get(n);a||(a=[],o.set(n,a)),a.push(...e)}e=[]}if(o.size)for(let[n,a]of o)try{let i=await this.client.guilds.fetch(n);await i.fetch(),this.logger.info(`Processing ${M.default.green(a.length)} commands(${a.map(m=>M.default.blue(m.name)).join(", ")}) for guild ${M.default.green(i.name)}(${M.default.blue(i.id)})`),await i.commands.set(a),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(n)}: ${i.message}`)}if(e.length)try{this.logger.info(`Processing ${M.default.green(e.length)} commands(${e.map(n=>M.default.blue(n.name)).join(", ")}) for application scope...`),await this.client.application.commands.set(e),this.logger.info("Successfully registered commands.")}catch(n){this.logger.error(`Failed to register commands to global: ${n.message}`)}}async chatInteraction(t){return t}async messageInteraction(t){return t}async userInteraction(t){return t}async commandInteraction(t){return t}};c(b,"ApplicationCommandExtension");V([K({event:"interactionCreate"}),k("design:type",Function),k("design:paramtypes",[typeof p.Interaction>"u"?Object:p.Interaction])],b.prototype,"interactionCreate",null);V([S({component:h,parameterless:!0,type:p.ChatInputCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.ChatInputCommandInteraction>"u"?Object:p.ChatInputCommandInteraction])],b.prototype,"chatInteraction",null);V([S({component:h,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction>"u"?Object:p.MessageContextMenuCommandInteraction])],b.prototype,"messageInteraction",null);V([S({component:h,parameterless:!0,type:p.UserContextMenuCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"userInteraction",null);V([S({component:h,parameterless:!0,type:p.CommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"commandInteraction",null)});var w,fe,Ht=f(()=>{"use strict";$();W();w=class extends x{constructor(t){super(),this.options=t}};c(w,"TextCommandComponent");fe=c(r=>y(new w(r)),"command")});var E,ue,Rt=f(()=>{"use strict";T();T();E=class extends G{};c(E,"TextCommandRestOption");ue=J(E)});var q,at,_,R,Kt=f(()=>{"use strict";Q();q=require("discord.js");kt();Ht();Rt();T();at=function(r,t,e,o){var s=arguments.length,n=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,e,o);else for(var i=r.length-1;i>=0;i--)(a=r[i])&&(n=(s<3?a(n):s>3?a(t,e,n):a(t,e))||n);return s>3&&n&&Object.defineProperty(t,e,n),n},_=function(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)},R=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(n=>e.startsWith(n));return s?s.length:null}return null}async messageCreate(t){try{let e=await this.processPrefix(t);if(e===null)return;let o=t.content.slice(e),s=[],n=new Map;for(let d of this.commandClient.registry.extensions)for(let g of this.commandClient.registry.getComponentsWithType(d,w))s.push(g),n.set(g,d);let a=0,i=s.find(d=>{let g=[d.options.name];d.options.aliases&&g.push(...d.options.aliases);for(let v of g)if(o.startsWith(v))return o.length===v.length?(a=v.length,!0):(a=v.length,o.startsWith(v+" "));return!1});if(!i)return;let m=n.get(i);if(!m)return;t.command=i;let u=[],l=o.slice(a+1).split(/ /g);await this.convertArguments(w,u,i.argTypes,async(d,g,v)=>{if(v.options.parameterless)return[t];if(d.decorators.find(lt=>lt.constructor===E)){let lt=l.join(" ");return l=[],[lt,t]}return[l.shift(),t]}),await i.execute(m,u,[t])}catch(e){this.commandClient.emit("textCommandInvokeError",e,t)}}async mesage(t){return t}async str(t){return t}async num(t){return Number(t)}};c(R,"TextCommandExtension");at([K({event:"messageCreate",emitter:"discord"}),_("design:type",Function),_("design:paramtypes",[typeof q.Message>"u"?Object:q.Message])],R.prototype,"messageCreate",null);at([S({component:w,type:q.Message,parameterless:!0}),_("design:type",Function),_("design:paramtypes",[typeof q.Message>"u"?Object:q.Message])],R.prototype,"mesage",null);at([S({component:w,type:String}),_("design:type",Function),_("design:paramtypes",[String])],R.prototype,"str",null);at([S({component:w,type:Number}),_("design:type",Function),_("design:paramtypes",[String])],R.prototype,"num",null)});var It={};At(It,{CommandClient:()=>A});var Gt,ct,Qt,Vt,A,it=f(()=>{"use strict";Gt=C(require("chalk")),ct=require("discord.js"),Qt=C(require("events")),Vt=require("tslog");vt();Kt();F();Ct();A=class extends Qt.default{constructor(t,e=new Vt.Logger({prettyLogTimeZone:"local"}),o={}){super(),this.discord=t,this.logger=e,this.owners=new Set,this.ctsLogger=e.getSubLogger({...o,name:"command.ts"}),this.registry=new P(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}async isOwner(t){return this.owners.has(t.id)}async fetchOwners(){if(!this.discord.application)throw new Error("The client is not logged in.");this.ctsLogger.info("Fetching owners..."),await this.discord.application.fetch();let t=this.discord.application.owner;if(!t)throw new Error("Cannot find application owner");let e=[];if(t instanceof ct.User)this.owners.add(t.id),e.push(t.tag);else if(t instanceof ct.Team)for(let[o,s]of t.members)this.owners.add(o),e.push(s.user.tag);this.ctsLogger.info(`Fetched ${Gt.default.green(e.length)} owners(${e.map(o=>Gt.default.blue(o)).join(", ")})`)}async enableApplicationCommandsExtension(t){await this.registry.registerModule(new b(t)),this.ctsLogger.info("Application command extension enabled.")}async enableTextCommandsExtension(t){await this.registry.registerModule(new R(t)),this.ctsLogger.info("Text command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===b)}static getFromModule(t){return Reflect.getMetadata(Y,t)}};c(A,"CommandClient")});var _t,x,W=f(()=>{"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 executeGlobalHook(t,e,o){let{CommandClient:s}=await Promise.resolve().then(()=>(it(),It)),n=s.getFromModule(t),a=n.registry.globalHooks[e];if(a)for(let i of a)await i.call(null,n,...o)}async executeHook(t,e,o){let s=this.hooks.get(e);if(!s)return;let{CommandClient:n}=await Promise.resolve().then(()=>(it(),It)),a=n.getFromModule(t),i=a.registry.globalHooks[e];i&&s.unshift(...i);for(let m of s)await m.call(null,a,...o)}async execute(t,e,o=e){await this.executeHook(t,"beforeCall",o);let s;try{s=await this.method.call(t,...e),await this.executeHook(t,"afterCall",[...o,s])}catch(n){throw await this.executeHook(t,"invokeError",[n,...o]),n}return s}};c(x,"BaseComponent")});var Ro,wt=f(()=>{"use strict";Ro=require("reflect-metadata");$();xt();$t();W()});var U,Tt=f(()=>{"use strict";U=class{};c(U,"OwnerOnlyError")});var mt,Xt,de,Yt=f(()=>{"use strict";mt=require("discord.js");st();Tt();Xt=c(r=>et("beforeCall",r),"createCheckDecorator"),de=Xt(async(r,t)=>{let e=!1;if(t instanceof mt.BaseInteraction?e=await r.isOwner(t.user):t instanceof mt.Message&&(e=await r.isOwner(t.author)),!e)throw new U})});var ge,te=f(()=>{"use strict";ge=c(r=>(t,e,o)=>{for(let s of r)s(t,e,o)},"mergeMethodDecorators")});var ee=f(()=>{"use strict";Yt();Tt();te()});var oe=f(()=>{"use strict";Mt()});var T=f(()=>{"use strict";wt();st();nt();ee();Q();St();oe()});var he={};At(he,{ApplicationCommandComponent:()=>h,ApplicationCommandExtension:()=>b,BaseComponent:()=>x,CommandClient:()=>A,ComponentArgument:()=>O,ComponentArgumentDecorator:()=>G,ConverterComponent:()=>j,Extension:()=>N,ListenerComponent:()=>I,OwnerOnlyError:()=>U,Registry:()=>P,SubCommandGroup:()=>pt,SubCommandGroupChild:()=>X,TextCommandComponent:()=>w,TextCommandRestOption:()=>E,applicationCommand:()=>pe,argConverter:()=>S,command:()=>fe,createArgumentDecorator:()=>J,createCheckDecorator:()=>Xt,createComponentDecorator:()=>y,createComponentHook:()=>et,getComponent:()=>me,getComponentArgumentStore:()=>yt,getComponentStore:()=>Z,getModuleHookStore:()=>rt,listener:()=>K,mergeMethodDecorators:()=>ge,moduleHook:()=>le,option:()=>Ot,ownerOnly:()=>de,rest:()=>ue});module.exports=ce(he);T();ot();bt();var jt=require("discord.js");T();ot();var pt=class{constructor(t,e){this.options=t,this.guilds=e}command(t){let e=new h({type:jt.ApplicationCommandType.ChatInput,...t});return e.subcommandGroup=this,y(e)}createChild(t){return new X(t,this)}};c(pt,"SubCommandGroup");var X=class{constructor(t,e){this.options=t,this.parent=e}command(t){let e=new h({type:jt.ApplicationCommandType.ChatInput,...t});return e.subcommandGroupChild=this,y(e)}};c(X,"SubCommandGroupChild");vt();Ht();Rt();0&&(module.exports={ApplicationCommandComponent,ApplicationCommandExtension,BaseComponent,CommandClient,ComponentArgument,ComponentArgumentDecorator,ConverterComponent,Extension,ListenerComponent,OwnerOnlyError,Registry,SubCommandGroup,SubCommandGroupChild,TextCommandComponent,TextCommandRestOption,applicationCommand,argConverter,command,createArgumentDecorator,createCheckDecorator,createComponentDecorator,createComponentHook,getComponent,getComponentArgumentStore,getComponentStore,getModuleHookStore,listener,mergeMethodDecorators,moduleHook,option,ownerOnly,rest});
1
+ "use strict";var no=Object.create;var B=Object.defineProperty;var ro=Object.getOwnPropertyDescriptor;var so=Object.getOwnPropertyNames;var io=Object.getPrototypeOf,ao=Object.prototype.hasOwnProperty;var c=(r,t)=>B(r,"name",{value:t,configurable:!0});var f=(r,t)=>()=>(r&&(t=r(r=0)),t);var At=(r,t)=>{for(var o in t)B(r,o,{get:t[o],enumerable:!0})},Lt=(r,t,o,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of so(t))!ao.call(r,s)&&s!==o&&B(r,s,{get:()=>t[s],enumerable:!(e=ro(t,s))||e.enumerable});return r};var C=(r,t,o)=>(o=r!=null?no(io(r)):{},Lt(t||!r||!r.__esModule?B(o,"default",{value:r,enumerable:!0}):o,r)),co=r=>Lt(B({},"__esModule",{value:!0}),r);var z,bo,ft,Y,ut,tt,F=f(()=>{"use strict";z=Symbol(),bo=Symbol(),ft=Symbol(),Y=Symbol(),ut=Symbol(),tt=Symbol()});var Et,dt,ot,gt=f(()=>{"use strict";Et=require("discord.js");F();dt=c((r,t)=>{let o=Reflect.getMetadata(ut,r,t);return o||(o=new Et.Collection,Reflect.defineMetadata(ut,o,r,t)),o},"getComponentHookStore"),ot=c((r,t)=>(o,e)=>{let s=dt(o,e),n=s.get(r);n||(n=[],s.set(r,n)),n.unshift(t)},"createComponentHook")});var ht,Z,mo,y,yt,J,$=f(()=>{"use strict";ht=require("discord.js");gt();F();Z=c(r=>{let t=Reflect.getMetadata(z,r);return t||(t=new ht.Collection,Reflect.defineMetadata(z,t,r)),t},"getComponentStore"),mo=c((r,t)=>Z(r).get(t),"getComponent"),y=c(r=>(t,o)=>{r._init(Reflect.get(t,o),Reflect.getMetadata("design:paramtypes",t,o));let e=dt(t,o);r.hooks=e;let s=Z(t);yt(t,o).forEach((a,i)=>{var m;(m=r.argTypes.get(i))==null||m.decorators.push(a)}),s.set(o,r)},"createComponentDecorator"),yt=c((r,t)=>{let o=Reflect.getMetadata(z,r,t);return o||(o=new ht.Collection,Reflect.defineMetadata(z,o,r,t)),o},"getComponentArgumentStore"),J=c(r=>t=>(o,e,s)=>{let n=new r(t);yt(o,e).set(s,n)},"createArgumentDecorator")});var O,xt=f(()=>{"use strict";O=class{constructor(t){this.type=t,this.decorators=[]}};c(O,"ComponentArgument")});var Ft,G,$t=f(()=>{"use strict";Ft=C(require("lodash")),G=class{constructor(t){typeof t=="object"?this.options=Ft.default.merge(this.defaultOptions(),t):this.options=t}defaultOptions(){return{}}};c(G,"ComponentArgumentDecorator")});var h,po,et=f(()=>{"use strict";$();W();h=class extends x{constructor(t){super(),this.options=t}};c(h,"ApplicationCommandComponent");po=c(r=>y(new h(r)),"applicationCommand")});var H,Ot,bt=f(()=>{"use strict";T();H=class extends G{};c(H,"ApplicationCommandOption");Ot=J(H)});var Wt,I,K,Q=f(()=>{"use strict";Wt=C(require("lodash"));W();$();I=class extends x{constructor(t){super(),this.options=Wt.default.merge({emitter:"discord"},t)}};c(I,"ListenerComponent");K=c(r=>y(new I(r)),"listener")});var j,S,nt=f(()=>{"use strict";W();$();j=class extends x{constructor(t){super(),this.options=t}};c(j,"ConverterComponent");S=c(r=>y(new j(r)),"argConverter")});var Dt,rt,lo,Pt=f(()=>{"use strict";Dt=require("discord.js");F();rt=c(r=>{let t=Reflect.getMetadata(ft,r);return t||(t=new Dt.Collection,Reflect.defineMetadata(ft,t,r)),t},"getModuleHookStore"),lo=c(r=>(t,o)=>{let e=rt(t),s=e.get(r);s||(s=[],e.set(r,s)),s.push(Reflect.get(t,o))},"moduleHook")});var st=f(()=>{"use strict";Pt();gt()});var D,Nt,Ut,qt,Bt,P,Ct=f(()=>{"use strict";D=C(require("chalk")),Nt=require("discord.js"),Ut=C(require("lodash"));wt();st();Q();F();qt=C(require("walk-sync")),Bt=C(require("path")),P=class{constructor(t,o){this.client=o,this.extensions=[],this.emitters=new Nt.Collection,this.globalHooks={},this.logger=t.getSubLogger({name:D.default.green("Registry")})}addGlobalHook(t,o){let e=this.globalHooks[t];e||(e=[],this.globalHooks[t]=e),e.push(o)}getComponentsWithTypeGlobal(t){let o=[];for(let e of this.extensions)o.push(...this.getComponentsWithType(e,t));return o}getComponentsWithType(t,o){let e=Z(t);return Array.from(e.filter(s=>s.constructor===o).values())}registerEventListeners(t){let o=this.getComponentsWithType(t,I);for(let e of o){let s=this.emitters.get(e.options.emitter);if(s){let n=e.method.bind(t);Reflect.defineMetadata("bound",n,e),s.addListener(e.options.event,n)}}}unregisterEventListeners(t){let o=this.getComponentsWithType(t,I);for(let e of o){let s=this.emitters.get(e.options.emitter),n=Reflect.getMetadata("bound",e);s&&n&&s.removeListener(e.options.event,n)}}async loadAllModulesInDirectory(t,o){let e=[],s=(0,qt.default)(t).filter(n=>(n.endsWith(".ts")||n.endsWith(".js"))&&(!o||o.test(n)));for(let n of s){if(n.endsWith(".d.ts"))continue;let a=Bt.default.join(t,n);e.push(...await this.loadModulesAtPath(a))}return e}async loadModulesAtPath(t){this.logger.info(`Loading module at path ${D.default.green(t)}`);let o=require.resolve(t),e=await import(o);if(typeof e.setup!="function")throw new Error("Extension must have a setup function");let s=await e.setup(this.client);return this.registerModules(s,o)}async registerModules(t,o){let e=[];if(t instanceof Array)for(let s of t)await this.registerModule(s),Reflect.defineMetadata(tt,o,s),e.push(s);else await this.registerModule(t),Reflect.defineMetadata(tt,o,t),e.push(t);return e}async reloadModules(){let t=[],o=new Set,e=[...this.extensions];for(let s of e){let n=Reflect.getMetadata(tt,s);!n||(this.logger.info(`Unloading module: ${D.default.green(s.constructor.name)}`),o.add(n),await this.unregisterModule(s),delete require.cache[require.resolve(n)])}for(let s of o)try{let n=await this.loadModulesAtPath(s);t.push({file:s,result:!0,extensions:n})}catch(n){t.push({file:s,result:!1,error:n})}return t}async registerModule(t){Reflect.defineMetadata(Y,this.client,t),this.registerEventListeners(t),await this.runModuleHook(t,"load"),this.extensions.push(t),this.logger.info(`Module registered: ${D.default.green(t.constructor.name)}`)}async unregisterModule(t){this.unregisterEventListeners(t),await this.runModuleHook(t,"unload"),Ut.default.remove(this.extensions,o=>o===t),this.logger.info(`Module unregistered: ${D.default.green(t.constructor.name)}`)}runModuleHook(t,o,...e){let n=rt(t).get(o);if(n)for(let a of n)a.call(t,...e)}registerEventEmitter(t,o){this.emitters.set(t,o)}};c(P,"Registry")});var St=f(()=>{"use strict";Ct();it()});var zt,Zt,N,Mt=f(()=>{"use strict";zt=C(require("chalk")),Zt=require("discord.js");nt();St();N=class{get commandClient(){return A.getFromModule(this)}get client(){return this.commandClient.discord}get logger(){return this._logger||(this._logger=this.commandClient.logger.getSubLogger({name:zt.default.green(`${this.constructor.name}`)})),this._logger}async convertArguments(t,o,e,s){let n=new Zt.Collection;for(let a of this.commandClient.registry.extensions)for(let i of this.commandClient.registry.getComponentsWithType(a,j))i.options.component==t&&n.set(i.options.type,{component:i,ext:a});for(let[a,i]of e){let m=n.get(i.type);if(!m){o[a]=void 0;continue}let d=await s(i,a,m.component);o[a]=await m.component.execute(m.ext,d)}}};c(N,"Extension")});var Jt,L,kt=f(()=>{"use strict";Jt=C(require("chalk"));Mt();L=class extends N{get logger(){return this._logger||(this._logger=this.commandClient.ctsLogger.getSubLogger({name:Jt.default.green(`${this.constructor.name}`)})),this._logger}};c(L,"CTSExtension")});var M,p,V,k,b,vt=f(()=>{"use strict";M=C(require("chalk")),p=require("discord.js");et();bt();Q();nt();kt();V=function(r,t,o,e){var s=arguments.length,n=s<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,o):e,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,o,e);else for(var i=r.length-1;i>=0;i--)(a=r[i])&&(n=(s<3?a(n):s>3?a(t,o,n):a(t,o))||n);return s>3&&n&&Object.defineProperty(t,o,n),n},k=function(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)},b=class extends L{constructor(t){super(),this.config=t,this.unmanagedCommands=[]}registerUnmanagedCommand(t){this.unmanagedCommands.push(t)}async interactionCreate(t){var o;try{if(t.type!==p.InteractionType.ApplicationCommand)return;let e=null,s=null,n=this.commandClient.registry.extensions,a=null,i=null;t.commandType===p.ApplicationCommandType.ChatInput&&(a=t.options.getSubcommand(!1),i=t.options.getSubcommandGroup(!1));t:for(let m of n){let d=this.commandClient.registry.getComponentsWithType(m,h);if(a){for(let l of d)if(!(!l.subcommandGroup&&!l.subcommandGroupChild)){if(l.subcommandGroupChild&&l.subcommandGroupChild.parent.options.name===t.commandName&&l.subcommandGroupChild.options.name===i&&l.options.name===a){s=m,e=l;break t}if(l.subcommandGroup&&!i&&l.subcommandGroup.options.name===t.commandName&&l.options.name===a){s=m,e=l;break t}}}else for(let l of d)if(l.options.name===t.commandName){s=m,e=l;break t}}if(e&&s){let m=[];await this.convertArguments(h,m,e.argTypes,()=>[t]);for(let[d,l]of e.argTypes){let g=null;for(let u of l.decorators)if(u instanceof H){if([p.ApplicationCommandOptionType.Subcommand,p.ApplicationCommandOptionType.SubcommandGroup].includes(u.options.type)&&t.isChatInputCommand()){if(u.options.type===p.ApplicationCommandOptionType.Subcommand){g=t.options.getSubcommand()===u.options.name;break}if(u.options.type===p.ApplicationCommandOptionType.SubcommandGroup){g=t.options.getSubcommandGroup()===u.options.name;break}}g=(o=t.options.get(u.options.name,!1))==null?void 0:o.value;break}g&&(m[d]=g)}try{await e.executeGlobalHook(s,"beforeApplicationCommandCall",[t]),await e.execute(s,m,[t])}finally{await e.executeGlobalHook(s,"afterApplicationCommandCall",[t])}}}catch(e){this.commandClient.emit("applicationCommandInvokeError",e,t)}}async sync(){let t=this.commandClient;this.logger.info("Trying to sync commands...");let o=[],e=new p.Collection,s=new p.Collection;for(let n of t.registry.getComponentsWithTypeGlobal(h)){if(n.subcommandGroup){let i=s.get(n.subcommandGroup.options.name);if(!i){if(i={...n.subcommandGroup.options,type:p.ApplicationCommandType.ChatInput},n.subcommandGroup.guilds)for(let d of n.subcommandGroup.guilds){let l=e.get(d);l||(l=[],e.set(d,l))}else o.push(i);s.set(n.subcommandGroup.options.name,i)}i.options||(i.options=[]);let m=[];for(let[,d]of n.argTypes){let l=d.decorators.find(g=>g.constructor===H);l&&m.push(l.options)}i.options.push({...n.options,type:p.ApplicationCommandOptionType.Subcommand,options:m});continue}else if(n.subcommandGroupChild){let i=n.subcommandGroupChild.parent,m=s.get(i.options.name);if(!m){if(m={...i.options,type:p.ApplicationCommandType.ChatInput},i.guilds)for(let g of i.guilds){let u=e.get(g);u||(u=[],e.set(g,u))}else o.push(m);s.set(i.options.name,m)}m.options||(m.options=[]);let d=m.options.find(g=>{var u;return g.name===((u=n.subcommandGroupChild)==null?void 0:u.options.name)});d||(d={type:p.ApplicationCommandOptionType.SubcommandGroup,...n.subcommandGroupChild.options},m.options.push(d)),d.options||(d.options=[]);let l=[];for(let[,g]of n.argTypes){let u=g.decorators.find(v=>v.constructor===H);u&&l.push(u.options)}d.options.push({...n.options,type:p.ApplicationCommandOptionType.Subcommand,options:l});continue}let a={...n.options};if(a.type===p.ApplicationCommandType.ChatInput){a.options=[];for(let[,i]of n.argTypes){let m=i.decorators.find(d=>d.constructor===H);m&&a.options.push(m.options)}}if(await n.executeHook(this,"beforeSync",[a,n]),n.options.guilds){for(let i of n.options.guilds){let m=e.get(i);m||(m=[],e.set(i,m)),m.push(a)}continue}o.push(a)}for(let{guilds:n,...a}of this.unmanagedCommands)if(n){for(let i of n){let m=e.get(i);m||(m=[],e.set(i,m)),m.push(a)}continue}else o.push(a);if(this.config.guilds){for(let n of this.config.guilds){let a=e.get(n);a||(a=[],e.set(n,a)),a.push(...o)}o=[]}if(e.size)for(let[n,a]of e)try{let i=await this.client.guilds.fetch(n);await i.fetch(),this.logger.info(`Processing ${M.default.green(a.length)} commands(${a.map(m=>M.default.blue(m.name)).join(", ")}) for guild ${M.default.green(i.name)}(${M.default.blue(i.id)})`),await i.commands.set(a),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(n)}: ${i.message}`)}if(o.length)try{this.logger.info(`Processing ${M.default.green(o.length)} commands(${o.map(n=>M.default.blue(n.name)).join(", ")}) for application scope...`),this.client.application?(await this.client.application.commands.set(o),this.logger.info("Successfully registered commands.")):this.logger.error("Client#application is not yet initialized.")}catch(n){this.logger.error(`Failed to register commands to global: ${n.message}`)}}async chatInteraction(t){return t}async messageInteraction(t){return t}async userInteraction(t){return t}async commandInteraction(t){return t}};c(b,"ApplicationCommandExtension");V([K({event:"interactionCreate"}),k("design:type",Function),k("design:paramtypes",[typeof Interaction>"u"?Object:Interaction])],b.prototype,"interactionCreate",null);V([S({component:h,parameterless:!0,type:p.ChatInputCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.ChatInputCommandInteraction>"u"?Object:p.ChatInputCommandInteraction])],b.prototype,"chatInteraction",null);V([S({component:h,parameterless:!0,type:p.MessageContextMenuCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.MessageContextMenuCommandInteraction>"u"?Object:p.MessageContextMenuCommandInteraction])],b.prototype,"messageInteraction",null);V([S({component:h,parameterless:!0,type:p.UserContextMenuCommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"userInteraction",null);V([S({component:h,parameterless:!0,type:p.CommandInteraction}),k("design:type",Function),k("design:paramtypes",[typeof p.UserContextMenuCommandInteraction>"u"?Object:p.UserContextMenuCommandInteraction])],b.prototype,"commandInteraction",null)});var w,fo,Ht=f(()=>{"use strict";$();W();w=class extends x{constructor(t){super(),this.options=t}};c(w,"TextCommandComponent");fo=c(r=>y(new w(r)),"command")});var E,uo,Rt=f(()=>{"use strict";T();T();E=class extends G{};c(E,"TextCommandRestOption");uo=J(E)});var U,at,_,R,Kt=f(()=>{"use strict";Q();U=require("discord.js");kt();Ht();Rt();T();at=function(r,t,o,e){var s=arguments.length,n=s<3?t:e===null?e=Object.getOwnPropertyDescriptor(t,o):e,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,o,e);else for(var i=r.length-1;i>=0;i--)(a=r[i])&&(n=(s<3?a(n):s>3?a(t,o,n):a(t,o))||n);return s>3&&n&&Object.defineProperty(t,o,n),n},_=function(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)},R=class extends L{constructor(t){super(),this.config=t}async processPrefix(t){let o=t.content,e=this.config.prefix;if(typeof e=="function"&&(e=await e(t)),typeof e=="string")return o.startsWith(e)?e.length:null;if(e instanceof Array){let s=e.find(n=>o.startsWith(n));return s?s.length:null}return null}async messageCreate(t){try{let o=await this.processPrefix(t);if(o===null)return;let e=t.content.slice(o),s=[],n=new Map;for(let g of this.commandClient.registry.extensions)for(let u of this.commandClient.registry.getComponentsWithType(g,w))s.push(u),n.set(u,g);let a=0,i=s.find(g=>{let u=[g.options.name];g.options.aliases&&u.push(...g.options.aliases);for(let v of u)if(e.startsWith(v))return e.length===v.length?(a=v.length,!0):(a=v.length,e.startsWith(v+" "));return!1});if(!i)return;let m=n.get(i);if(!m)return;t.command=i;let d=[],l=e.slice(a+1).split(/ /g);await this.convertArguments(w,d,i.argTypes,async(g,u,v)=>{if(v.options.parameterless)return[t];if(g.decorators.find(lt=>lt.constructor===E)){let lt=l.join(" ");return l=[],[lt,t]}return[l.shift(),t]}),await i.execute(m,d,[t])}catch(o){this.commandClient.emit("textCommandInvokeError",o,t)}}async mesage(t){return t}async str(t){return t}async num(t){return Number(t)}};c(R,"TextCommandExtension");at([K({event:"messageCreate",emitter:"discord"}),_("design:type",Function),_("design:paramtypes",[typeof U.Message>"u"?Object:U.Message])],R.prototype,"messageCreate",null);at([S({component:w,type:U.Message,parameterless:!0}),_("design:type",Function),_("design:paramtypes",[typeof U.Message>"u"?Object:U.Message])],R.prototype,"mesage",null);at([S({component:w,type:String}),_("design:type",Function),_("design:paramtypes",[String])],R.prototype,"str",null);at([S({component:w,type:Number}),_("design:type",Function),_("design:paramtypes",[String])],R.prototype,"num",null)});var It={};At(It,{CommandClient:()=>A});var Gt,ct,Qt,Vt,A,it=f(()=>{"use strict";Gt=C(require("chalk")),ct=require("discord.js"),Qt=C(require("events")),Vt=require("tslog");vt();Kt();F();Ct();A=class extends Qt.default{constructor(t,o=new Vt.Logger({prettyLogTimeZone:"local"}),e={}){super(),this.discord=t,this.logger=o,this.owners=new Set,this.ctsLogger=o.getSubLogger({...e,name:"command.ts"}),this.registry=new P(this.ctsLogger,this),this.registry.registerEventEmitter("cts",this),this.registry.registerEventEmitter("discord",this.discord)}async isOwner(t){return this.owners.has(t.id)}async fetchOwners(){if(!this.discord.application)throw new Error("The client is not logged in.");this.ctsLogger.info("Fetching owners..."),await this.discord.application.fetch();let t=this.discord.application.owner;if(!t)throw new Error("Cannot find application owner");let o=[];if(t instanceof ct.User)this.owners.add(t.id),o.push(t.tag);else if(t instanceof ct.Team)for(let[e,s]of t.members)this.owners.add(e),o.push(s.user.tag);this.ctsLogger.info(`Fetched ${Gt.default.green(o.length)} owners(${o.map(e=>Gt.default.blue(e)).join(", ")})`)}async enableApplicationCommandsExtension(t){await this.registry.registerModule(new b(t)),this.ctsLogger.info("Application command extension enabled.")}async enableTextCommandsExtension(t){await this.registry.registerModule(new R(t)),this.ctsLogger.info("Text command extension enabled.")}getApplicationCommandsExtension(){return this.registry.extensions.find(t=>t.constructor===b)}static getFromModule(t){return Reflect.getMetadata(Y,t)}};c(A,"CommandClient")});var _t,x,W=f(()=>{"use strict";_t=require("discord.js");xt();x=class{hooks=new _t.Collection;argTypes=new _t.Collection;_init(t,o){this.method=t;for(let e=0;e<o.length;e++){let s=o[e];this.argTypes.set(e,new O(s))}}async executeGlobalHook(t,o,e){let{CommandClient:s}=await Promise.resolve().then(()=>(it(),It)),n=s.getFromModule(t),a=n.registry.globalHooks[o];if(a)for(let i of a)await i.call(null,n,...e)}async executeHook(t,o,e){let s=this.hooks.get(o);if(!s)return;let{CommandClient:n}=await Promise.resolve().then(()=>(it(),It)),a=n.getFromModule(t),i=a.registry.globalHooks[o];i&&s.unshift(...i);for(let m of s)await m.call(null,a,...e)}async execute(t,o,e=o){await this.executeHook(t,"beforeCall",e);let s;try{s=await this.method.call(t,...o),await this.executeHook(t,"afterCall",[...e,s])}catch(n){throw await this.executeHook(t,"invokeError",[n,...e]),n}return s}};c(x,"BaseComponent")});var Re,wt=f(()=>{"use strict";Re=require("reflect-metadata");$();xt();$t();W()});var q,Tt=f(()=>{"use strict";q=class{};c(q,"OwnerOnlyError")});var mt,Xt,go,Yt=f(()=>{"use strict";mt=require("discord.js");st();Tt();Xt=c(r=>ot("beforeCall",r),"createCheckDecorator"),go=Xt(async(r,t)=>{let o=!1;if(t instanceof mt.BaseInteraction?o=await r.isOwner(t.user):t instanceof mt.Message&&(o=await r.isOwner(t.author)),!o)throw new q})});var ho,to=f(()=>{"use strict";ho=c(r=>(t,o,e)=>{for(let s of r)s(t,o,e)},"mergeMethodDecorators")});var oo=f(()=>{"use strict";Yt();Tt();to()});var eo=f(()=>{"use strict";Mt()});var T=f(()=>{"use strict";wt();st();nt();oo();Q();St();eo()});var yo={};At(yo,{ApplicationCommandComponent:()=>h,ApplicationCommandExtension:()=>b,BaseComponent:()=>x,CommandClient:()=>A,ComponentArgument:()=>O,ComponentArgumentDecorator:()=>G,ConverterComponent:()=>j,Extension:()=>N,ListenerComponent:()=>I,OwnerOnlyError:()=>q,Registry:()=>P,SubCommandGroup:()=>pt,SubCommandGroupChild:()=>X,TextCommandComponent:()=>w,TextCommandRestOption:()=>E,applicationCommand:()=>po,argConverter:()=>S,command:()=>fo,createArgumentDecorator:()=>J,createCheckDecorator:()=>Xt,createComponentDecorator:()=>y,createComponentHook:()=>ot,getComponent:()=>mo,getComponentArgumentStore:()=>yt,getComponentStore:()=>Z,getModuleHookStore:()=>rt,listener:()=>K,mergeMethodDecorators:()=>ho,moduleHook:()=>lo,option:()=>Ot,ownerOnly:()=>go,rest:()=>uo});module.exports=co(yo);T();et();bt();var jt=require("discord.js");T();et();var pt=class{constructor(t,o){this.options=t,this.guilds=o}command(t){let o=new h({type:jt.ApplicationCommandType.ChatInput,...t});return o.subcommandGroup=this,y(o)}createChild(t){return new X(t,this)}};c(pt,"SubCommandGroup");var X=class{constructor(t,o){this.options=t,this.parent=o}command(t){let o=new h({type:jt.ApplicationCommandType.ChatInput,...t});return o.subcommandGroupChild=this,y(o)}};c(X,"SubCommandGroupChild");vt();Ht();Rt();0&&(module.exports={ApplicationCommandComponent,ApplicationCommandExtension,BaseComponent,CommandClient,ComponentArgument,ComponentArgumentDecorator,ConverterComponent,Extension,ListenerComponent,OwnerOnlyError,Registry,SubCommandGroup,SubCommandGroupChild,TextCommandComponent,TextCommandRestOption,applicationCommand,argConverter,command,createArgumentDecorator,createCheckDecorator,createComponentDecorator,createComponentHook,getComponent,getComponentArgumentStore,getComponentStore,getModuleHookStore,listener,mergeMethodDecorators,moduleHook,option,ownerOnly,rest});
2
2
  //# sourceMappingURL=index.js.map