necord 3.0.1 → 3.0.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.
@@ -0,0 +1,5 @@
1
+ import { CommandInteraction } from 'discord.js';
2
+ export declare class AppCommands {
3
+ onPing(interaction: CommandInteraction): Promise<void>;
4
+ sayHello(interaction: CommandInteraction): Promise<void>;
5
+ }
@@ -0,0 +1,44 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AppCommands = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const _1 = require(".");
18
+ const discord_js_1 = require("discord.js");
19
+ let AppCommands = class AppCommands {
20
+ onPing(interaction) {
21
+ return interaction.reply({ content: 'Pong!' });
22
+ }
23
+ sayHello(interaction) {
24
+ return interaction.reply({ content: 'hello' });
25
+ }
26
+ };
27
+ __decorate([
28
+ (0, _1.SlashCommand)({ name: 'ping', description: 'Ping-pong' }),
29
+ __param(0, (0, _1.Context)()),
30
+ __metadata("design:type", Function),
31
+ __metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
32
+ __metadata("design:returntype", void 0)
33
+ ], AppCommands.prototype, "onPing", null);
34
+ __decorate([
35
+ (0, _1.SlashCommand)({ name: 'greeting', description: 'Say hello' }),
36
+ __param(0, (0, _1.Context)()),
37
+ __metadata("design:type", Function),
38
+ __metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
39
+ __metadata("design:returntype", void 0)
40
+ ], AppCommands.prototype, "sayHello", null);
41
+ AppCommands = __decorate([
42
+ (0, common_1.Injectable)()
43
+ ], AppCommands);
44
+ exports.AppCommands = AppCommands;
File without changes
@@ -7,19 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AppModule = void 0;
10
- const __1 = require("..");
11
10
  const common_1 = require("@nestjs/common");
12
- const discord_js_1 = require("discord.js");
13
11
  const app_commands_1 = require("./app.commands");
12
+ const _1 = require(".");
13
+ const discord_js_1 = require("discord.js");
14
14
  let AppModule = class AppModule {
15
15
  };
16
16
  AppModule = __decorate([
17
17
  (0, common_1.Module)({
18
18
  imports: [
19
- __1.NecordModule.forRoot({
20
- token: 'NzQ3MDM4NjQwNTcxNDE2NjY2.X0JD8w.uT6X8c-E0ej6aHk5xgK28CaXtTM',
21
- registerApplicationCommands: true,
22
- intents: [discord_js_1.Intents.FLAGS.GUILDS, discord_js_1.Intents.FLAGS.GUILD_MESSAGES, discord_js_1.Intents.FLAGS.DIRECT_MESSAGES]
19
+ _1.NecordModule.forRoot({
20
+ token: 'OTExMjg5NTI0MjQyNDkzNDkw.YZfOgQ.nfkQAgSBS6ntgNghLr_oT2RVPLI',
21
+ intents: [discord_js_1.Intents.FLAGS.GUILDS],
22
+ registerApplicationCommands: '917922073064640552'
23
23
  })
24
24
  ],
25
25
  providers: [app_commands_1.AppCommands]
@@ -2,36 +2,36 @@ import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums';
2
2
  export declare const BooleanOption: (data: Omit<import("discord.js").ApplicationCommandNonOptionsData & {
3
3
  readonly type?: ApplicationCommandOptionTypes.BOOLEAN;
4
4
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
5
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
5
+ }, "type" | "methodName">) => PropertyDecorator;
6
6
  export declare const IntegerOption: (data: Omit<import("discord.js").ApplicationCommandChoicesData & {
7
7
  readonly type?: ApplicationCommandOptionTypes.INTEGER;
8
8
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
9
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
9
+ }, "type" | "methodName">) => PropertyDecorator;
10
10
  export declare const NumberOption: (data: Omit<import("discord.js").ApplicationCommandChoicesData & {
11
11
  readonly type?: ApplicationCommandOptionTypes.NUMBER;
12
12
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
13
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
13
+ }, "type" | "methodName">) => PropertyDecorator;
14
14
  export declare const StringOption: (data: Omit<import("discord.js").ApplicationCommandChoicesData & {
15
15
  readonly type?: ApplicationCommandOptionTypes.STRING;
16
16
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
17
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
17
+ }, "type" | "methodName">) => PropertyDecorator;
18
18
  export declare const UserOption: (data: Omit<import("discord.js").ApplicationCommandNonOptionsData & {
19
19
  readonly type?: ApplicationCommandOptionTypes.USER;
20
20
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
21
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
21
+ }, "type" | "methodName">) => PropertyDecorator;
22
22
  export declare const MemberOption: (data: Omit<import("discord.js").ApplicationCommandNonOptionsData & {
23
23
  readonly type?: ApplicationCommandOptionTypes.USER;
24
24
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
25
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
25
+ }, "type" | "methodName">) => PropertyDecorator;
26
26
  export declare const ChannelOption: (data: Omit<import("discord.js").ApplicationCommandNonOptionsData & {
27
27
  readonly type?: ApplicationCommandOptionTypes.USER;
28
28
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
29
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
29
+ }, "type" | "methodName">) => PropertyDecorator;
30
30
  export declare const RoleOption: (data: Omit<import("discord.js").ApplicationCommandNonOptionsData & {
31
31
  readonly type?: ApplicationCommandOptionTypes.ROLE;
32
32
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
33
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
33
+ }, "type" | "methodName">) => PropertyDecorator;
34
34
  export declare const MentionableOption: (data: Omit<import("discord.js").ApplicationCommandNonOptionsData & {
35
35
  readonly type?: ApplicationCommandOptionTypes.MENTIONABLE;
36
36
  methodName?: keyof import("discord.js").CommandInteractionOptionResolver<import("discord.js").CacheType>;
37
- }, "type" | "transform" | "propertyKey">) => PropertyDecorator;
37
+ }, "type" | "methodName">) => PropertyDecorator;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './necord.module';
2
- export * from './necord-client';
3
2
  export * from './context';
4
3
  export * from './decorators';
5
4
  export * from './services';
package/dist/index.js CHANGED
@@ -11,7 +11,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./necord.module"), exports);
14
- __exportStar(require("./necord-client"), exports);
15
14
  __exportStar(require("./context"), exports);
16
15
  __exportStar(require("./decorators"), exports);
17
16
  __exportStar(require("./services"), exports);
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- export declare const MODULE_OPTIONS = "necord:module_options";
1
+ export declare const NECORD_MODULE_OPTIONS = "necord:module_options";
2
2
  export declare const PARAM_ARGS_METADATA = "__routeArguments__";
3
3
  export declare const APPLICATION_COMMAND_METADATA = "necord:application_command_meta";
4
4
  export declare const MESSAGE_COMPONENT_METADATA = "necord:message_component_meta";
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OPTIONS_METADATA = exports.SUBGROUP_METADATA = exports.GROUP_METADATA = exports.LISTENERS_METADATA = exports.MESSAGE_COMPONENT_METADATA = exports.APPLICATION_COMMAND_METADATA = exports.PARAM_ARGS_METADATA = exports.MODULE_OPTIONS = void 0;
3
+ exports.OPTIONS_METADATA = exports.SUBGROUP_METADATA = exports.GROUP_METADATA = exports.LISTENERS_METADATA = exports.MESSAGE_COMPONENT_METADATA = exports.APPLICATION_COMMAND_METADATA = exports.PARAM_ARGS_METADATA = exports.NECORD_MODULE_OPTIONS = void 0;
4
4
  const constants_1 = require("@nestjs/common/constants");
5
- exports.MODULE_OPTIONS = 'necord:module_options';
5
+ exports.NECORD_MODULE_OPTIONS = 'necord:module_options';
6
6
  exports.PARAM_ARGS_METADATA = constants_1.ROUTE_ARGS_METADATA;
7
7
  exports.APPLICATION_COMMAND_METADATA = 'necord:application_command_meta';
8
8
  exports.MESSAGE_COMPONENT_METADATA = 'necord:message_component_meta';
@@ -1,6 +1,12 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { Client } from 'discord.js';
2
+ import { DynamicModule, OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
2
3
  import { NecordModuleAsyncOptions, NecordModuleOptions } from './interfaces';
3
- export declare class NecordModule {
4
+ export declare class NecordModule implements OnApplicationBootstrap, OnApplicationShutdown {
5
+ private readonly options;
6
+ private readonly client;
7
+ constructor(options: NecordModuleOptions, client: Client);
8
+ onApplicationBootstrap(): Promise<string>;
9
+ onApplicationShutdown(signal?: string): void;
4
10
  static forRoot(options: NecordModuleOptions): DynamicModule;
5
11
  static forRootAsync(options: NecordModuleAsyncOptions): DynamicModule;
6
12
  private static createAsyncProviders;
@@ -5,6 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
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
+ };
8
14
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
15
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
16
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -17,28 +23,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17
23
  var NecordModule_1;
18
24
  Object.defineProperty(exports, "__esModule", { value: true });
19
25
  exports.NecordModule = void 0;
26
+ const discord_js_1 = require("discord.js");
20
27
  const common_1 = require("@nestjs/common");
21
28
  const core_1 = require("@nestjs/core");
22
- const necord_client_1 = require("./necord-client");
23
29
  const necord_constants_1 = require("./necord.constants");
24
30
  const services_1 = require("./services");
25
31
  let NecordModule = NecordModule_1 = class NecordModule {
32
+ constructor(options, client) {
33
+ this.options = options;
34
+ this.client = client;
35
+ }
36
+ onApplicationBootstrap() {
37
+ return this.client.login(this.options.token);
38
+ }
39
+ onApplicationShutdown(signal) {
40
+ return this.client.destroy();
41
+ }
26
42
  static forRoot(options) {
43
+ const ClientProvider = {
44
+ provide: discord_js_1.Client,
45
+ useValue: new discord_js_1.Client(options)
46
+ };
27
47
  return {
28
48
  module: NecordModule_1,
29
49
  providers: [
30
50
  {
31
- provide: necord_constants_1.MODULE_OPTIONS,
51
+ provide: necord_constants_1.NECORD_MODULE_OPTIONS,
32
52
  useValue: options
33
- }
34
- ]
53
+ },
54
+ ClientProvider
55
+ ],
56
+ exports: [ClientProvider]
35
57
  };
36
58
  }
37
59
  static forRootAsync(options) {
60
+ const ClientFactoryProvider = {
61
+ provide: discord_js_1.Client,
62
+ useFactory: (options) => new discord_js_1.Client(options),
63
+ inject: [necord_constants_1.NECORD_MODULE_OPTIONS]
64
+ };
38
65
  return {
39
66
  module: NecordModule_1,
40
67
  imports: options.imports,
41
- providers: this.createAsyncProviders(options)
68
+ providers: this.createAsyncProviders(options).concat(ClientFactoryProvider),
69
+ exports: [ClientFactoryProvider]
42
70
  };
43
71
  }
44
72
  static createAsyncProviders(options) {
@@ -56,30 +84,25 @@ let NecordModule = NecordModule_1 = class NecordModule {
56
84
  static createAsyncOptionsProvider(options) {
57
85
  if (options.useFactory) {
58
86
  return {
59
- provide: necord_constants_1.MODULE_OPTIONS,
87
+ provide: necord_constants_1.NECORD_MODULE_OPTIONS,
60
88
  useFactory: (...args) => __awaiter(this, void 0, void 0, function* () { return yield options.useFactory(...args); }),
61
89
  inject: options.inject || []
62
90
  };
63
91
  }
64
92
  return {
65
- provide: necord_constants_1.MODULE_OPTIONS,
93
+ provide: necord_constants_1.NECORD_MODULE_OPTIONS,
66
94
  useFactory: (optionsFactory) => __awaiter(this, void 0, void 0, function* () { return yield optionsFactory.createNecordOptions(); }),
67
95
  inject: [options.useExisting || options.useClass]
68
96
  };
69
97
  }
70
98
  };
71
99
  NecordModule = NecordModule_1 = __decorate([
100
+ (0, common_1.Global)(),
72
101
  (0, common_1.Module)({
73
102
  imports: [core_1.DiscoveryModule],
74
- providers: [
75
- services_1.CommandsService,
76
- services_1.ComponentsService,
77
- services_1.ListenersService,
78
- services_1.ExplorerService,
79
- services_1.MetadataAccessorService,
80
- necord_client_1.NecordClient
81
- ],
82
- exports: [necord_client_1.NecordClient]
83
- })
103
+ providers: [services_1.CommandsService, services_1.ComponentsService, services_1.ListenersService, services_1.ExplorerService, services_1.MetadataAccessorService]
104
+ }),
105
+ __param(0, (0, common_1.Inject)(necord_constants_1.NECORD_MODULE_OPTIONS)),
106
+ __metadata("design:paramtypes", [Object, discord_js_1.Client])
84
107
  ], NecordModule);
85
108
  exports.NecordModule = NecordModule;
@@ -1,15 +1,18 @@
1
1
  import { OnModuleInit } from '@nestjs/common';
2
2
  import { ExplorerService } from './explorer.service';
3
- import { ApplicationCommandMetadata } from '../interfaces';
3
+ import { ApplicationCommandMetadata, NecordModuleOptions } from '../interfaces';
4
4
  import { MetadataAccessorService } from './metadata-accessor.service';
5
- import { NecordClient } from '../necord-client';
5
+ import { Client } from 'discord.js';
6
6
  export declare class CommandsService implements OnModuleInit {
7
7
  private readonly explorerService;
8
8
  private readonly metadataAccessor;
9
9
  private readonly client;
10
+ private readonly options;
11
+ private readonly logger;
10
12
  private readonly commands;
11
- constructor(explorerService: ExplorerService<ApplicationCommandMetadata>, metadataAccessor: MetadataAccessorService, client: NecordClient);
12
- onModuleInit(): void;
13
+ constructor(explorerService: ExplorerService<ApplicationCommandMetadata>, metadataAccessor: MetadataAccessorService, client: Client, options: NecordModuleOptions);
14
+ onModuleInit(): Promise<void>;
15
+ private onReadyRegistration;
13
16
  private registerContextMenuHandler;
14
17
  private registerSlashCommandHandler;
15
18
  private static getCommandKey;
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
11
14
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
15
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
16
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,56 +37,78 @@ exports.CommandsService = void 0;
34
37
  const common_1 = require("@nestjs/common");
35
38
  const explorer_service_1 = require("./explorer.service");
36
39
  const metadata_accessor_service_1 = require("./metadata-accessor.service");
37
- const necord_client_1 = require("../necord-client");
40
+ const discord_js_1 = require("discord.js");
41
+ const decorators_1 = require("../decorators");
42
+ const necord_constants_1 = require("../necord.constants");
38
43
  let CommandsService = CommandsService_1 = class CommandsService {
39
- constructor(explorerService, metadataAccessor, client) {
44
+ constructor(explorerService, metadataAccessor, client, options) {
40
45
  this.explorerService = explorerService;
41
46
  this.metadataAccessor = metadataAccessor;
42
47
  this.client = client;
48
+ this.options = options;
49
+ this.logger = new common_1.Logger(CommandsService_1.name);
43
50
  this.commands = [];
44
51
  }
45
52
  onModuleInit() {
46
- const commands = this.explorerService.explore((instance, prototype, method) => {
47
- const command = this.metadataAccessor.getApplicationCommandMetadata(instance, method);
48
- if (!command)
49
- return;
50
- return Object.assign(Object.assign({}, command), { instance,
51
- prototype,
52
- method });
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
+ });
53
95
  });
54
- for (let _a of commands) {
55
- const { instance, prototype, method } = _a, command = __rest(_a, ["instance", "prototype", "method"]);
56
- const options = this.metadataAccessor.getOptionsMetadata(instance, method);
57
- let group = this.metadataAccessor.getCommandGroupMetadata(instance, method);
58
- let subGroup = this.metadataAccessor.getCommandSubGroupMetadata(instance, method);
59
- if (command.type !== 1 /* CHAT_INPUT */) {
60
- this.commands.push(command);
61
- this.registerContextMenuHandler(command, command.execute);
62
- return;
63
- }
64
- else if (!group && subGroup) {
65
- subGroup = undefined;
66
- }
67
- command.options = Object.values(options);
68
- this.registerSlashCommandHandler(group === null || group === void 0 ? void 0 : group.name, subGroup === null || subGroup === void 0 ? void 0 : subGroup.name, command, options, command.execute);
69
- if (!group && !subGroup) {
70
- this.commands.push(command);
71
- return;
72
- }
73
- const cachedGroup = this.commands.find(c => c.type === 1 /* CHAT_INPUT */ && c.name === group.name);
74
- group = cachedGroup !== null && cachedGroup !== void 0 ? cachedGroup : group;
75
- if (!subGroup) {
76
- group.options.push(command);
96
+ }
97
+ onReadyRegistration() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ if (!this.options.registerApplicationCommands) {
77
100
  return;
78
101
  }
79
- else {
80
- const cachedSubGroup = group.options.find(s => s.type === 2 /* SUB_COMMAND_GROUP */ && s.name === (subGroup === null || subGroup === void 0 ? void 0 : subGroup.name));
81
- subGroup = cachedSubGroup !== null && cachedSubGroup !== void 0 ? cachedSubGroup : subGroup;
82
- subGroup.options.push(command);
83
- !cachedSubGroup && group.options.push(subGroup);
102
+ if (this.client.application.partial) {
103
+ yield this.client.application.fetch();
84
104
  }
85
- !cachedGroup && this.commands.push(group);
86
- }
105
+ console.log(this.commands);
106
+ this.logger.log(`Started refreshing application commands.`);
107
+ yield this.client.application.commands.set(this.commands, typeof this.options.registerApplicationCommands === 'string'
108
+ ? this.options.registerApplicationCommands
109
+ : undefined);
110
+ this.logger.log(`Successfully reloaded application commands.`);
111
+ });
87
112
  }
88
113
  registerContextMenuHandler(command, execute) {
89
114
  this.client.on('interactionCreate', interaction => interaction.isContextMenu() &&
@@ -130,10 +155,17 @@ let CommandsService = CommandsService_1 = class CommandsService {
130
155
  return commandKey;
131
156
  }
132
157
  };
158
+ __decorate([
159
+ (0, decorators_1.On)('ready'),
160
+ __metadata("design:type", Function),
161
+ __metadata("design:paramtypes", []),
162
+ __metadata("design:returntype", Promise)
163
+ ], CommandsService.prototype, "onReadyRegistration", null);
133
164
  CommandsService = CommandsService_1 = __decorate([
134
165
  (0, common_1.Injectable)(),
166
+ __param(3, (0, common_1.Inject)(necord_constants_1.NECORD_MODULE_OPTIONS)),
135
167
  __metadata("design:paramtypes", [explorer_service_1.ExplorerService,
136
168
  metadata_accessor_service_1.MetadataAccessorService,
137
- necord_client_1.NecordClient])
169
+ discord_js_1.Client, Object])
138
170
  ], CommandsService);
139
171
  exports.CommandsService = CommandsService;
@@ -1,13 +1,13 @@
1
1
  import { ExplorerService } from './explorer.service';
2
2
  import { OnModuleInit } from '@nestjs/common';
3
3
  import { MetadataAccessorService } from './metadata-accessor.service';
4
- import { NecordClient } from '../necord-client';
5
4
  import { ComponentMetadata } from '../interfaces';
5
+ import { Client } from 'discord.js';
6
6
  export declare class ComponentsService implements OnModuleInit {
7
7
  private readonly explorerService;
8
8
  private readonly metadataAccessor;
9
9
  private readonly client;
10
10
  private readonly components;
11
- constructor(explorerService: ExplorerService<ComponentMetadata>, metadataAccessor: MetadataAccessorService, client: NecordClient);
11
+ constructor(explorerService: ExplorerService<ComponentMetadata>, metadataAccessor: MetadataAccessorService, client: Client);
12
12
  onModuleInit(): void;
13
13
  }
@@ -13,7 +13,6 @@ exports.ComponentsService = void 0;
13
13
  const explorer_service_1 = require("./explorer.service");
14
14
  const common_1 = require("@nestjs/common");
15
15
  const metadata_accessor_service_1 = require("./metadata-accessor.service");
16
- const necord_client_1 = require("../necord-client");
17
16
  const discord_js_1 = require("discord.js");
18
17
  let ComponentsService = class ComponentsService {
19
18
  constructor(explorerService, metadataAccessor, client) {
@@ -36,6 +35,6 @@ ComponentsService = __decorate([
36
35
  (0, common_1.Injectable)(),
37
36
  __metadata("design:paramtypes", [explorer_service_1.ExplorerService,
38
37
  metadata_accessor_service_1.MetadataAccessorService,
39
- necord_client_1.NecordClient])
38
+ discord_js_1.Client])
40
39
  ], ComponentsService);
41
40
  exports.ComponentsService = ComponentsService;
@@ -1,12 +1,12 @@
1
1
  import { OnModuleInit } from '@nestjs/common';
2
2
  import { ListenerMetadata } from '../interfaces';
3
3
  import { MetadataAccessorService } from './metadata-accessor.service';
4
- import { NecordClient } from '../necord-client';
5
4
  import { ExplorerService } from './explorer.service';
5
+ import { Client } from 'discord.js';
6
6
  export declare class ListenersService implements OnModuleInit {
7
7
  private readonly explorerService;
8
8
  private readonly metadataAccessor;
9
9
  private readonly client;
10
- constructor(explorerService: ExplorerService<ListenerMetadata>, metadataAccessor: MetadataAccessorService, client: NecordClient);
10
+ constructor(explorerService: ExplorerService<ListenerMetadata>, metadataAccessor: MetadataAccessorService, client: Client);
11
11
  onModuleInit(): Promise<void>;
12
12
  }
@@ -21,8 +21,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.ListenersService = void 0;
22
22
  const common_1 = require("@nestjs/common");
23
23
  const metadata_accessor_service_1 = require("./metadata-accessor.service");
24
- const necord_client_1 = require("../necord-client");
25
24
  const explorer_service_1 = require("./explorer.service");
25
+ const discord_js_1 = require("discord.js");
26
26
  let ListenersService = class ListenersService {
27
27
  constructor(explorerService, metadataAccessor, client) {
28
28
  this.explorerService = explorerService;
@@ -42,6 +42,6 @@ ListenersService = __decorate([
42
42
  (0, common_1.Injectable)(),
43
43
  __metadata("design:paramtypes", [explorer_service_1.ExplorerService,
44
44
  metadata_accessor_service_1.MetadataAccessorService,
45
- necord_client_1.NecordClient])
45
+ discord_js_1.Client])
46
46
  ], ListenersService);
47
47
  exports.ListenersService = ListenersService;
@@ -1,2 +1,2 @@
1
1
  import { OptionData, OptionMetadata, OptionTransform } from '../interfaces';
2
- export declare function createNecordOptionDecorator<T extends OptionData['type'], C extends OptionMetadata<T> = OptionMetadata<T>>(type: T, methodName: OptionTransform): (data: Omit<C, 'transform' | 'propertyKey' | 'type'>) => PropertyDecorator;
2
+ export declare function createNecordOptionDecorator<T extends OptionData['type'], C extends OptionMetadata<T> = OptionMetadata<T>>(type: T, methodName: OptionTransform): (data: Omit<C, 'type' | 'methodName'>) => PropertyDecorator;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "necord",
3
3
  "description": "A module for creating Discord bots using NestJS, based on Discord.js.",
4
- "version": "3.0.1",
4
+ "version": "3.0.2",
5
5
  "scripts": {
6
6
  "build": "rimraf -rf dist && tsc -p tsconfig.json",
7
7
  "prepublish:npm": "npm run build",
@@ -1,11 +0,0 @@
1
- import { OnApplicationBootstrap, OnApplicationShutdown } from '@nestjs/common';
2
- import { NecordModuleOptions } from './interfaces';
3
- import { Client } from 'discord.js';
4
- export declare class NecordClient extends Client implements OnApplicationBootstrap, OnApplicationShutdown {
5
- readonly options: NecordModuleOptions;
6
- private readonly logger;
7
- constructor(options: NecordModuleOptions);
8
- onApplicationBootstrap: any;
9
- onApplicationShutdown: any;
10
- private onReadyRegistration;
11
- }
@@ -1,68 +0,0 @@
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 NecordClient_1;
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.NecordClient = void 0;
26
- const common_1 = require("@nestjs/common");
27
- const discord_js_1 = require("discord.js");
28
- const decorators_1 = require("./decorators");
29
- const necord_constants_1 = require("./necord.constants");
30
- let NecordClient = NecordClient_1 = class NecordClient extends discord_js_1.Client {
31
- constructor(options) {
32
- super(options);
33
- this.options = options;
34
- this.logger = new common_1.Logger(NecordClient_1.name);
35
- this.onApplicationBootstrap = this.login.bind(this, this.options.token);
36
- this.onApplicationShutdown = this.destroy.bind(this);
37
- }
38
- onReadyRegistration() {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- if (!this.options.registerApplicationCommands) {
41
- return;
42
- }
43
- if (this.application.partial) {
44
- yield this.application.fetch();
45
- }
46
- // this.logger.log(`Started refreshing application commands.`);
47
- // await this.application.commands.set(
48
- // this.applicationCommands,
49
- // typeof this.options.registerApplicationCommands === 'string'
50
- // ? this.options.registerApplicationCommands
51
- // : undefined
52
- // );
53
- // this.logger.log(`Successfully reloaded application commands.`);
54
- });
55
- }
56
- };
57
- __decorate([
58
- (0, decorators_1.On)('ready'),
59
- __metadata("design:type", Function),
60
- __metadata("design:paramtypes", []),
61
- __metadata("design:returntype", Promise)
62
- ], NecordClient.prototype, "onReadyRegistration", null);
63
- NecordClient = NecordClient_1 = __decorate([
64
- (0, common_1.Injectable)(),
65
- __param(0, (0, common_1.Inject)(necord_constants_1.MODULE_OPTIONS)),
66
- __metadata("design:paramtypes", [Object])
67
- ], NecordClient);
68
- exports.NecordClient = NecordClient;
@@ -1,7 +0,0 @@
1
- import { CommandInteraction } from 'discord.js';
2
- import { LengthDto } from './dtos/length.dto';
3
- export declare class AppCommands {
4
- private onReady;
5
- onPing(interaction: CommandInteraction): Promise<void>;
6
- onLength(interaction: CommandInteraction, { text }: LengthDto): Promise<void>;
7
- }
@@ -1,70 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.AppCommands = void 0;
25
- const common_1 = require("@nestjs/common");
26
- const __1 = require("../");
27
- const discord_js_1 = require("discord.js");
28
- const length_dto_1 = require("./dtos/length.dto");
29
- let AppCommands = class AppCommands {
30
- onReady() {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- console.log(123);
33
- });
34
- }
35
- onPing(interaction) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- return interaction.reply({ content: 'Pong!' });
38
- });
39
- }
40
- onLength(interaction, { text }) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- return interaction.reply({ content: `Length of your text ${text.length}` });
43
- });
44
- }
45
- };
46
- __decorate([
47
- (0, __1.On)('ready'),
48
- __metadata("design:type", Function),
49
- __metadata("design:paramtypes", []),
50
- __metadata("design:returntype", Promise)
51
- ], AppCommands.prototype, "onReady", null);
52
- __decorate([
53
- (0, __1.SlashCommand)({ name: 'ping', description: 'Ping-Pong Command' }),
54
- __param(0, (0, __1.Context)()),
55
- __metadata("design:type", Function),
56
- __metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
57
- __metadata("design:returntype", Promise)
58
- ], AppCommands.prototype, "onPing", null);
59
- __decorate([
60
- (0, __1.SlashCommand)({ name: 'length', description: 'Get length of text' }),
61
- __param(0, (0, __1.Context)()),
62
- __param(1, (0, __1.Options)()),
63
- __metadata("design:type", Function),
64
- __metadata("design:paramtypes", [discord_js_1.CommandInteraction, length_dto_1.LengthDto]),
65
- __metadata("design:returntype", Promise)
66
- ], AppCommands.prototype, "onLength", null);
67
- AppCommands = __decorate([
68
- (0, common_1.Injectable)()
69
- ], AppCommands);
70
- exports.AppCommands = AppCommands;
@@ -1,3 +0,0 @@
1
- export declare class LengthDto {
2
- text: string;
3
- }
@@ -1,24 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LengthDto = void 0;
13
- const __1 = require("../..");
14
- class LengthDto {
15
- }
16
- __decorate([
17
- (0, __1.StringOption)({
18
- name: 'text',
19
- description: 'Your text',
20
- required: true
21
- }),
22
- __metadata("design:type", String)
23
- ], LengthDto.prototype, "text", void 0);
24
- exports.LengthDto = LengthDto;