necord 3.0.6 → 3.0.7-dev.1640434883.bbae86b

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 (69) hide show
  1. package/dist/context/index.d.ts +4 -4
  2. package/dist/context/index.js +16 -16
  3. package/dist/context/necord-arguments-host.d.ts +11 -11
  4. package/dist/context/necord-arguments-host.js +19 -19
  5. package/dist/context/necord-execution-context.d.ts +8 -8
  6. package/dist/context/necord-execution-context.js +19 -19
  7. package/dist/context/necord-params.factory.d.ts +5 -5
  8. package/dist/context/necord-params.factory.js +25 -25
  9. package/dist/context/necord-paramtype.enum.d.ts +6 -6
  10. package/dist/context/necord-paramtype.enum.js +10 -10
  11. package/dist/decorators/commands.decorator.d.ts +10 -10
  12. package/dist/decorators/commands.decorator.js +7 -7
  13. package/dist/decorators/components.decorator.d.ts +2 -2
  14. package/dist/decorators/components.decorator.js +6 -6
  15. package/dist/decorators/groups.decorator.d.ts +3 -3
  16. package/dist/decorators/groups.decorator.js +9 -9
  17. package/dist/decorators/index.d.ts +6 -6
  18. package/dist/decorators/index.js +18 -18
  19. package/dist/decorators/listeners.decorator.d.ts +2 -2
  20. package/dist/decorators/listeners.decorator.js +6 -6
  21. package/dist/decorators/options.decorator.d.ts +37 -37
  22. package/dist/decorators/options.decorator.js +13 -13
  23. package/dist/decorators/params.decorator.d.ts +4 -4
  24. package/dist/decorators/params.decorator.js +16 -16
  25. package/dist/index.d.ts +4 -4
  26. package/dist/index.js +16 -16
  27. package/dist/interfaces/command-metadata.interface.d.ts +6 -6
  28. package/dist/interfaces/command-metadata.interface.js +2 -2
  29. package/dist/interfaces/component-metadata.interface.d.ts +5 -5
  30. package/dist/interfaces/component-metadata.interface.js +2 -2
  31. package/dist/interfaces/index.d.ts +5 -5
  32. package/dist/interfaces/index.js +17 -17
  33. package/dist/interfaces/listener-metadata.interface.d.ts +5 -5
  34. package/dist/interfaces/listener-metadata.interface.js +2 -2
  35. package/dist/interfaces/module-options.interface.d.ts +16 -16
  36. package/dist/interfaces/module-options.interface.js +2 -2
  37. package/dist/interfaces/option-metadata.interface.d.ts +7 -7
  38. package/dist/interfaces/option-metadata.interface.js +2 -2
  39. package/dist/necord.constants.d.ts +8 -8
  40. package/dist/necord.constants.js +12 -12
  41. package/dist/necord.module.d.ts +14 -14
  42. package/dist/necord.module.js +116 -116
  43. package/dist/necord.update.d.ts +7 -7
  44. package/dist/necord.update.js +69 -69
  45. package/dist/services/commands.service.d.ts +19 -19
  46. package/dist/services/commands.service.js +170 -170
  47. package/dist/services/components.service.d.ts +13 -13
  48. package/dist/services/components.service.js +51 -51
  49. package/dist/services/explorer.service.d.ts +17 -17
  50. package/dist/services/explorer.service.js +54 -54
  51. package/dist/services/index.d.ts +5 -5
  52. package/dist/services/index.js +17 -17
  53. package/dist/services/listeners.service.d.ts +12 -12
  54. package/dist/services/listeners.service.js +47 -47
  55. package/dist/services/metadata-accessor.service.d.ts +13 -13
  56. package/dist/services/metadata-accessor.service.js +44 -44
  57. package/dist/utils/create-necord-commands.util.d.ts +4 -4
  58. package/dist/utils/create-necord-commands.util.js +9 -9
  59. package/dist/utils/create-necord-components.util.d.ts +2 -2
  60. package/dist/utils/create-necord-components.util.js +9 -9
  61. package/dist/utils/create-necord-listeners.util.d.ts +3 -3
  62. package/dist/utils/create-necord-listeners.util.js +12 -12
  63. package/dist/utils/create-necord-options.util.d.ts +2 -2
  64. package/dist/utils/create-necord-options.util.js +15 -15
  65. package/dist/utils/create-necord-params.util.d.ts +4 -4
  66. package/dist/utils/create-necord-params.util.js +24 -24
  67. package/dist/utils/index.d.ts +5 -5
  68. package/dist/utils/index.js +17 -17
  69. package/package.json +3 -4
@@ -1,69 +1,69 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var NecordUpdate_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.NecordUpdate = void 0;
17
- const common_1 = require("@nestjs/common");
18
- const decorators_1 = require("./decorators");
19
- let NecordUpdate = NecordUpdate_1 = class NecordUpdate {
20
- constructor() {
21
- this.logger = new common_1.Logger(NecordUpdate_1.name);
22
- }
23
- onWarn(message) {
24
- if (!NecordUpdate_1.isDebugMode()) {
25
- return;
26
- }
27
- return this.logger.warn(message);
28
- }
29
- onError(error) {
30
- if (!NecordUpdate_1.isDebugMode()) {
31
- return;
32
- }
33
- return this.logger.error(error);
34
- }
35
- onDebug(message) {
36
- if (!NecordUpdate_1.isDebugMode()) {
37
- return;
38
- }
39
- return this.logger.debug(message);
40
- }
41
- static isDebugMode() {
42
- return !!process.env.NEST_DEBUG;
43
- }
44
- };
45
- __decorate([
46
- (0, decorators_1.On)('warn'),
47
- __param(0, (0, decorators_1.Context)()),
48
- __metadata("design:type", Function),
49
- __metadata("design:paramtypes", [String]),
50
- __metadata("design:returntype", void 0)
51
- ], NecordUpdate.prototype, "onWarn", null);
52
- __decorate([
53
- (0, decorators_1.On)('error'),
54
- __param(0, (0, decorators_1.Context)()),
55
- __metadata("design:type", Function),
56
- __metadata("design:paramtypes", [Error]),
57
- __metadata("design:returntype", void 0)
58
- ], NecordUpdate.prototype, "onError", null);
59
- __decorate([
60
- (0, decorators_1.On)('debug'),
61
- __param(0, (0, decorators_1.Context)()),
62
- __metadata("design:type", Function),
63
- __metadata("design:paramtypes", [String]),
64
- __metadata("design:returntype", void 0)
65
- ], NecordUpdate.prototype, "onDebug", null);
66
- NecordUpdate = NecordUpdate_1 = __decorate([
67
- (0, common_1.Injectable)()
68
- ], NecordUpdate);
69
- exports.NecordUpdate = NecordUpdate;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var NecordUpdate_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.NecordUpdate = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const decorators_1 = require("./decorators");
19
+ let NecordUpdate = NecordUpdate_1 = class NecordUpdate {
20
+ constructor() {
21
+ this.logger = new common_1.Logger(NecordUpdate_1.name);
22
+ }
23
+ onWarn(message) {
24
+ if (!NecordUpdate_1.isDebugMode()) {
25
+ return;
26
+ }
27
+ return this.logger.warn(message);
28
+ }
29
+ onError(error) {
30
+ if (!NecordUpdate_1.isDebugMode()) {
31
+ return;
32
+ }
33
+ return this.logger.error(error);
34
+ }
35
+ onDebug(message) {
36
+ if (!NecordUpdate_1.isDebugMode()) {
37
+ return;
38
+ }
39
+ return this.logger.debug(message);
40
+ }
41
+ static isDebugMode() {
42
+ return !!process.env.NEST_DEBUG;
43
+ }
44
+ };
45
+ __decorate([
46
+ (0, decorators_1.On)('warn'),
47
+ __param(0, (0, decorators_1.Context)()),
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", [String]),
50
+ __metadata("design:returntype", void 0)
51
+ ], NecordUpdate.prototype, "onWarn", null);
52
+ __decorate([
53
+ (0, decorators_1.On)('error'),
54
+ __param(0, (0, decorators_1.Context)()),
55
+ __metadata("design:type", Function),
56
+ __metadata("design:paramtypes", [Error]),
57
+ __metadata("design:returntype", void 0)
58
+ ], NecordUpdate.prototype, "onError", null);
59
+ __decorate([
60
+ (0, decorators_1.On)('debug'),
61
+ __param(0, (0, decorators_1.Context)()),
62
+ __metadata("design:type", Function),
63
+ __metadata("design:paramtypes", [String]),
64
+ __metadata("design:returntype", void 0)
65
+ ], NecordUpdate.prototype, "onDebug", null);
66
+ NecordUpdate = NecordUpdate_1 = __decorate([
67
+ (0, common_1.Injectable)()
68
+ ], NecordUpdate);
69
+ exports.NecordUpdate = NecordUpdate;
@@ -1,19 +1,19 @@
1
- import { OnModuleInit } from '@nestjs/common';
2
- import { ExplorerService } from './explorer.service';
3
- import { ApplicationCommandMetadata, NecordModuleOptions } from '../interfaces';
4
- import { MetadataAccessorService } from './metadata-accessor.service';
5
- import { Client } from 'discord.js';
6
- export declare class CommandsService implements OnModuleInit {
7
- private readonly explorerService;
8
- private readonly metadataAccessor;
9
- private readonly client;
10
- private readonly options;
11
- private readonly logger;
12
- private readonly commands;
13
- constructor(explorerService: ExplorerService<ApplicationCommandMetadata>, metadataAccessor: MetadataAccessorService, client: Client, options: NecordModuleOptions);
14
- onModuleInit(): Promise<void>;
15
- private onReadyRegistration;
16
- private registerContextMenuHandler;
17
- private registerSlashCommandHandler;
18
- private static getCommandKey;
19
- }
1
+ import { OnModuleInit } from '@nestjs/common';
2
+ import { ExplorerService } from './explorer.service';
3
+ import { ApplicationCommandMetadata, NecordModuleOptions } from '../interfaces';
4
+ import { MetadataAccessorService } from './metadata-accessor.service';
5
+ import { Client } from 'discord.js';
6
+ export declare class CommandsService implements OnModuleInit {
7
+ private readonly explorerService;
8
+ private readonly metadataAccessor;
9
+ private readonly client;
10
+ private readonly options;
11
+ private readonly logger;
12
+ private readonly commands;
13
+ constructor(explorerService: ExplorerService<ApplicationCommandMetadata>, metadataAccessor: MetadataAccessorService, client: Client, options: NecordModuleOptions);
14
+ onModuleInit(): Promise<void>;
15
+ private onReadyRegistration;
16
+ private registerContextMenuHandler;
17
+ private registerSlashCommandHandler;
18
+ private static getCommandKey;
19
+ }
@@ -1,170 +1,170 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- var __rest = (this && this.__rest) || function (s, e) {
24
- var t = {};
25
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
26
- t[p] = s[p];
27
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
28
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
29
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
30
- t[p[i]] = s[p[i]];
31
- }
32
- return t;
33
- };
34
- var CommandsService_1;
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.CommandsService = void 0;
37
- const common_1 = require("@nestjs/common");
38
- const explorer_service_1 = require("./explorer.service");
39
- const metadata_accessor_service_1 = require("./metadata-accessor.service");
40
- const discord_js_1 = require("discord.js");
41
- const decorators_1 = require("../decorators");
42
- const necord_constants_1 = require("../necord.constants");
43
- let CommandsService = CommandsService_1 = class CommandsService {
44
- constructor(explorerService, metadataAccessor, client, options) {
45
- this.explorerService = explorerService;
46
- this.metadataAccessor = metadataAccessor;
47
- this.client = client;
48
- this.options = options;
49
- this.logger = new common_1.Logger(CommandsService_1.name);
50
- this.commands = [];
51
- }
52
- onModuleInit() {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const commands = this.explorerService.explore((instance, prototype, method) => {
55
- const command = this.metadataAccessor.getApplicationCommandMetadata(instance, method);
56
- if (!command)
57
- return;
58
- return Object.assign(Object.assign({}, command), { instance,
59
- prototype,
60
- method });
61
- });
62
- commands.forEach((_a) => {
63
- var { instance, prototype, method } = _a, command = __rest(_a, ["instance", "prototype", "method"]);
64
- const options = this.metadataAccessor.getOptionsMetadata(instance, method);
65
- let group = this.metadataAccessor.getCommandGroupMetadata(instance, method);
66
- let subGroup = this.metadataAccessor.getCommandSubGroupMetadata(instance, method);
67
- if (command.type !== 1 /* CHAT_INPUT */) {
68
- this.commands.push(command);
69
- this.registerContextMenuHandler(command, command.execute);
70
- return;
71
- }
72
- else if (!group && subGroup) {
73
- subGroup = undefined;
74
- }
75
- command.options = Object.values(options);
76
- this.registerSlashCommandHandler(group === null || group === void 0 ? void 0 : group.name, subGroup === null || subGroup === void 0 ? void 0 : subGroup.name, command, options, command.execute);
77
- if (!group && !subGroup) {
78
- this.commands.push(command);
79
- return;
80
- }
81
- const cachedGroup = this.commands.find(c => c.type === 1 /* CHAT_INPUT */ && c.name === group.name);
82
- group = cachedGroup !== null && cachedGroup !== void 0 ? cachedGroup : group;
83
- if (!subGroup) {
84
- group.options.push(command);
85
- return;
86
- }
87
- else {
88
- const cachedSubGroup = group.options.find(s => s.type === 2 /* SUB_COMMAND_GROUP */ && s.name === (subGroup === null || subGroup === void 0 ? void 0 : subGroup.name));
89
- subGroup = cachedSubGroup !== null && cachedSubGroup !== void 0 ? cachedSubGroup : subGroup;
90
- subGroup.options.push(command);
91
- !cachedSubGroup && group.options.push(subGroup);
92
- }
93
- !cachedGroup && this.commands.push(group);
94
- });
95
- });
96
- }
97
- onReadyRegistration() {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- if (!this.options.registerApplicationCommands) {
100
- return;
101
- }
102
- if (this.client.application.partial) {
103
- yield this.client.application.fetch();
104
- }
105
- this.logger.log(`Started refreshing application commands.`);
106
- yield this.client.application.commands.set(this.commands, typeof this.options.registerApplicationCommands === 'string'
107
- ? this.options.registerApplicationCommands
108
- : undefined);
109
- this.logger.log(`Successfully reloaded application commands.`);
110
- });
111
- }
112
- registerContextMenuHandler(command, execute) {
113
- this.client.on('interactionCreate', interaction => interaction.isContextMenu() &&
114
- interaction.targetType === (command.type === 2 /* USER */ ? 'USER' : 'MESSAGE') &&
115
- interaction.commandName === command.name &&
116
- execute(interaction, interaction.targetType === 'USER'
117
- ? {
118
- user: interaction.options.getUser('user'),
119
- member: interaction.options.getMember('user')
120
- }
121
- : { message: interaction.options.getMessage('message') }));
122
- }
123
- registerSlashCommandHandler(group, subGroup, command, options, execute) {
124
- this.client.on('interactionCreate', (interaction) => __awaiter(this, void 0, void 0, function* () {
125
- if (!interaction.isCommand())
126
- return;
127
- const rootCommand = interaction.commandName;
128
- const groupCommand = interaction.options.getSubcommandGroup(false);
129
- const subCommandGroup = interaction.options.getSubcommand(false);
130
- if (CommandsService_1.getCommandKey(rootCommand, groupCommand, subCommandGroup) !==
131
- CommandsService_1.getCommandKey(group, subGroup, command.name))
132
- return;
133
- const DTO = Object.entries(options).reduce((prev, [parameter, option]) => {
134
- const resolve = interaction.options[option.methodName];
135
- prev[parameter] = resolve.call(interaction.options, option.name, !!option.required);
136
- return prev;
137
- }, {});
138
- return execute(interaction, DTO);
139
- }));
140
- }
141
- static getCommandKey(group, subGroup, command) {
142
- let commandKey;
143
- if (!!group) {
144
- if (!!subGroup) {
145
- commandKey = `${group}-${subGroup}-${command}`;
146
- }
147
- else {
148
- commandKey = `${group}-null-${command}`;
149
- }
150
- }
151
- else {
152
- commandKey = `${command}-null-null`;
153
- }
154
- return commandKey;
155
- }
156
- };
157
- __decorate([
158
- (0, decorators_1.On)('ready'),
159
- __metadata("design:type", Function),
160
- __metadata("design:paramtypes", []),
161
- __metadata("design:returntype", Promise)
162
- ], CommandsService.prototype, "onReadyRegistration", null);
163
- CommandsService = CommandsService_1 = __decorate([
164
- (0, common_1.Injectable)(),
165
- __param(3, (0, common_1.Inject)(necord_constants_1.NECORD_MODULE_OPTIONS)),
166
- __metadata("design:paramtypes", [explorer_service_1.ExplorerService,
167
- metadata_accessor_service_1.MetadataAccessorService,
168
- discord_js_1.Client, Object])
169
- ], CommandsService);
170
- exports.CommandsService = CommandsService;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __rest = (this && this.__rest) || function (s, e) {
24
+ var t = {};
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
26
+ t[p] = s[p];
27
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
28
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
29
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
30
+ t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ };
34
+ var CommandsService_1;
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CommandsService = void 0;
37
+ const common_1 = require("@nestjs/common");
38
+ const explorer_service_1 = require("./explorer.service");
39
+ const metadata_accessor_service_1 = require("./metadata-accessor.service");
40
+ const discord_js_1 = require("discord.js");
41
+ const decorators_1 = require("../decorators");
42
+ const necord_constants_1 = require("../necord.constants");
43
+ let CommandsService = CommandsService_1 = class CommandsService {
44
+ constructor(explorerService, metadataAccessor, client, options) {
45
+ this.explorerService = explorerService;
46
+ this.metadataAccessor = metadataAccessor;
47
+ this.client = client;
48
+ this.options = options;
49
+ this.logger = new common_1.Logger(CommandsService_1.name);
50
+ this.commands = [];
51
+ }
52
+ onModuleInit() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const commands = this.explorerService.explore((instance, prototype, method) => {
55
+ const command = this.metadataAccessor.getApplicationCommandMetadata(instance, method);
56
+ if (!command)
57
+ return;
58
+ return Object.assign(Object.assign({}, command), { instance,
59
+ prototype,
60
+ method });
61
+ });
62
+ commands.forEach((_a) => {
63
+ var { instance, prototype, method } = _a, command = __rest(_a, ["instance", "prototype", "method"]);
64
+ const options = this.metadataAccessor.getOptionsMetadata(instance, method);
65
+ let group = this.metadataAccessor.getCommandGroupMetadata(instance, method);
66
+ let subGroup = this.metadataAccessor.getCommandSubGroupMetadata(instance, method);
67
+ if (command.type !== 1 /* CHAT_INPUT */) {
68
+ this.commands.push(command);
69
+ this.registerContextMenuHandler(command, command.execute);
70
+ return;
71
+ }
72
+ else if (!group && subGroup) {
73
+ subGroup = undefined;
74
+ }
75
+ command.options = Object.values(options);
76
+ this.registerSlashCommandHandler(group === null || group === void 0 ? void 0 : group.name, subGroup === null || subGroup === void 0 ? void 0 : subGroup.name, command, options, command.execute);
77
+ if (!group && !subGroup) {
78
+ this.commands.push(command);
79
+ return;
80
+ }
81
+ const cachedGroup = this.commands.find(c => c.type === 1 /* CHAT_INPUT */ && c.name === group.name);
82
+ group = cachedGroup !== null && cachedGroup !== void 0 ? cachedGroup : group;
83
+ if (!subGroup) {
84
+ group.options.push(command);
85
+ return;
86
+ }
87
+ else {
88
+ const cachedSubGroup = group.options.find(s => s.type === 2 /* SUB_COMMAND_GROUP */ && s.name === (subGroup === null || subGroup === void 0 ? void 0 : subGroup.name));
89
+ subGroup = cachedSubGroup !== null && cachedSubGroup !== void 0 ? cachedSubGroup : subGroup;
90
+ subGroup.options.push(command);
91
+ !cachedSubGroup && group.options.push(subGroup);
92
+ }
93
+ !cachedGroup && this.commands.push(group);
94
+ });
95
+ });
96
+ }
97
+ onReadyRegistration() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ if (!this.options.registerApplicationCommands) {
100
+ return;
101
+ }
102
+ if (this.client.application.partial) {
103
+ yield this.client.application.fetch();
104
+ }
105
+ this.logger.log(`Started refreshing application commands.`);
106
+ yield this.client.application.commands.set(this.commands, typeof this.options.registerApplicationCommands === 'string'
107
+ ? this.options.registerApplicationCommands
108
+ : undefined);
109
+ this.logger.log(`Successfully reloaded application commands.`);
110
+ });
111
+ }
112
+ registerContextMenuHandler(command, execute) {
113
+ this.client.on('interactionCreate', interaction => interaction.isContextMenu() &&
114
+ interaction.targetType === (command.type === 2 /* USER */ ? 'USER' : 'MESSAGE') &&
115
+ interaction.commandName === command.name &&
116
+ execute(interaction, interaction.targetType === 'USER'
117
+ ? {
118
+ user: interaction.options.getUser('user'),
119
+ member: interaction.options.getMember('user')
120
+ }
121
+ : { message: interaction.options.getMessage('message') }));
122
+ }
123
+ registerSlashCommandHandler(group, subGroup, command, options, execute) {
124
+ this.client.on('interactionCreate', (interaction) => __awaiter(this, void 0, void 0, function* () {
125
+ if (!interaction.isCommand())
126
+ return;
127
+ const rootCommand = interaction.commandName;
128
+ const groupCommand = interaction.options.getSubcommandGroup(false);
129
+ const subCommandGroup = interaction.options.getSubcommand(false);
130
+ if (CommandsService_1.getCommandKey(rootCommand, groupCommand, subCommandGroup) !==
131
+ CommandsService_1.getCommandKey(group, subGroup, command.name))
132
+ return;
133
+ const DTO = Object.entries(options).reduce((prev, [parameter, option]) => {
134
+ const resolve = interaction.options[option.methodName];
135
+ prev[parameter] = resolve.call(interaction.options, option.name, !!option.required);
136
+ return prev;
137
+ }, {});
138
+ return execute(interaction, DTO);
139
+ }));
140
+ }
141
+ static getCommandKey(group, subGroup, command) {
142
+ let commandKey;
143
+ if (!!group) {
144
+ if (!!subGroup) {
145
+ commandKey = `${group}-${subGroup}-${command}`;
146
+ }
147
+ else {
148
+ commandKey = `${group}-null-${command}`;
149
+ }
150
+ }
151
+ else {
152
+ commandKey = `${command}-null-null`;
153
+ }
154
+ return commandKey;
155
+ }
156
+ };
157
+ __decorate([
158
+ (0, decorators_1.On)('ready'),
159
+ __metadata("design:type", Function),
160
+ __metadata("design:paramtypes", []),
161
+ __metadata("design:returntype", Promise)
162
+ ], CommandsService.prototype, "onReadyRegistration", null);
163
+ CommandsService = CommandsService_1 = __decorate([
164
+ (0, common_1.Injectable)(),
165
+ __param(3, (0, common_1.Inject)(necord_constants_1.NECORD_MODULE_OPTIONS)),
166
+ __metadata("design:paramtypes", [explorer_service_1.ExplorerService,
167
+ metadata_accessor_service_1.MetadataAccessorService,
168
+ discord_js_1.Client, Object])
169
+ ], CommandsService);
170
+ exports.CommandsService = CommandsService;
@@ -1,13 +1,13 @@
1
- import { ExplorerService } from './explorer.service';
2
- import { OnModuleInit } from '@nestjs/common';
3
- import { MetadataAccessorService } from './metadata-accessor.service';
4
- import { ComponentMetadata } from '../interfaces';
5
- import { Client } from 'discord.js';
6
- export declare class ComponentsService implements OnModuleInit {
7
- private readonly explorerService;
8
- private readonly metadataAccessor;
9
- private readonly client;
10
- private readonly components;
11
- constructor(explorerService: ExplorerService<ComponentMetadata>, metadataAccessor: MetadataAccessorService, client: Client);
12
- onModuleInit(): Promise<void>;
13
- }
1
+ import { ExplorerService } from './explorer.service';
2
+ import { OnModuleInit } from '@nestjs/common';
3
+ import { MetadataAccessorService } from './metadata-accessor.service';
4
+ import { ComponentMetadata } from '../interfaces';
5
+ import { Client } from 'discord.js';
6
+ export declare class ComponentsService implements OnModuleInit {
7
+ private readonly explorerService;
8
+ private readonly metadataAccessor;
9
+ private readonly client;
10
+ private readonly components;
11
+ constructor(explorerService: ExplorerService<ComponentMetadata>, metadataAccessor: MetadataAccessorService, client: Client);
12
+ onModuleInit(): Promise<void>;
13
+ }