necord 5.6.1 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ # [5.6.1](https://github.com/necordjs/necord/compare/v5.6.0...v5.6.1) - (2023-04-13)
5
+
6
+ ## Refactor
7
+
8
+ - Rename guild audit logs event names ([af91ac7](https://github.com/necordjs/necord/commit/af91ac7b8f39d7fc890baef3c9c95fa974fc6dab))
9
+
4
10
  # [5.6.0](https://github.com/necordjs/necord/compare/v5.5.4...v5.6.0) - (2023-04-13)
5
11
 
6
12
  ## Refactor
@@ -1,15 +1,25 @@
1
- import { OnModuleInit } from '@nestjs/common';
1
+ import { OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
2
2
  import { Client } from 'discord.js';
3
3
  import { NecordModuleOptions } from '../necord-options.interface';
4
4
  import { ContextMenusService } from './context-menus';
5
+ import { CommandDiscovery } from './command.discovery';
5
6
  import { SlashCommandsService } from './slash-commands';
6
- export declare class CommandsService implements OnModuleInit {
7
+ export declare class CommandsService implements OnModuleInit, OnApplicationBootstrap {
7
8
  private readonly client;
8
9
  private readonly options;
9
10
  private readonly contextMenusService;
10
11
  private readonly slashCommandsService;
11
12
  private readonly logger;
13
+ private readonly applicationCommands;
12
14
  constructor(client: Client, options: NecordModuleOptions, contextMenusService: ContextMenusService, slashCommandsService: SlashCommandsService);
13
15
  onModuleInit(): Client<boolean>;
14
- register(client: Client): Promise<void>;
16
+ onApplicationBootstrap(): void;
17
+ register(): Promise<void>;
18
+ registerInGuild(guildId: string): Promise<import("@discordjs/collection").Collection<string, import("discord.js").ApplicationCommand<{
19
+ guild: import("discord.js").GuildResolvable;
20
+ }>>>;
21
+ getCommands(): CommandDiscovery[];
22
+ getCommandsByGuildId(guildId: string): CommandDiscovery[];
23
+ getCommandByName(name: string): CommandDiscovery;
24
+ getCommandByGuildIdAndName(guildId: string, name: string): CommandDiscovery;
15
25
  }
@@ -35,41 +35,61 @@ let CommandsService = CommandsService_1 = class CommandsService {
35
35
  this.contextMenusService = contextMenusService;
36
36
  this.slashCommandsService = slashCommandsService;
37
37
  this.logger = new common_1.Logger(CommandsService_1.name);
38
+ this.applicationCommands = new Map([[undefined, []]]);
38
39
  }
39
40
  onModuleInit() {
40
41
  if (this.options.skipRegistration) {
41
42
  return;
42
43
  }
43
- return this.client.once('ready', (client) => __awaiter(this, void 0, void 0, function* () { return this.register(client); }));
44
+ return this.client.once('ready', (client) => __awaiter(this, void 0, void 0, function* () { return this.register(); }));
44
45
  }
45
- register(client) {
46
+ onApplicationBootstrap() {
46
47
  var _a, _b;
47
- return __awaiter(this, void 0, void 0, function* () {
48
- if (client.application.partial) {
49
- yield client.application.fetch();
48
+ const commands = [
49
+ ...this.contextMenusService.getCommands(),
50
+ ...this.slashCommandsService.getCommands()
51
+ ];
52
+ for (const command of commands) {
53
+ const guilds = Array.isArray(this.options.development)
54
+ ? this.options.development
55
+ : (_a = command.getGuilds()) !== null && _a !== void 0 ? _a : [undefined];
56
+ for (const guildId of guilds) {
57
+ const visitedCommands = (_b = this.applicationCommands.get(guildId)) !== null && _b !== void 0 ? _b : [];
58
+ this.applicationCommands.set(guildId, visitedCommands.concat(command));
50
59
  }
51
- const clientCommands = client.application.commands;
52
- const commands = [
53
- ...this.contextMenusService.getCommands(),
54
- ...this.slashCommandsService.getCommands()
55
- ];
56
- const commandsByGuildMap = new Map([[undefined, []]]);
57
- for (const command of commands) {
58
- const guilds = Array.isArray(this.options.development)
59
- ? this.options.development
60
- : (_a = command.getGuilds()) !== null && _a !== void 0 ? _a : [undefined];
61
- for (const guildId of guilds) {
62
- const visitedCommands = (_b = commandsByGuildMap.get(guildId)) !== null && _b !== void 0 ? _b : [];
63
- commandsByGuildMap.set(guildId, visitedCommands.concat(command));
64
- }
60
+ }
61
+ }
62
+ register() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ if (this.client.application.partial) {
65
+ yield this.client.application.fetch();
65
66
  }
66
67
  this.logger.log(`Started refreshing application commands.`);
67
- for (const [guild, commands] of commandsByGuildMap) {
68
- yield clientCommands.set(commands.flatMap(command => command.toJSON()), guild);
68
+ for (const guild of this.applicationCommands.keys()) {
69
+ yield this.registerInGuild(guild);
69
70
  }
70
71
  this.logger.log(`Successfully reloaded application commands.`);
71
72
  });
72
73
  }
74
+ registerInGuild(guildId) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ return this.client.application.commands.set(this.getCommandsByGuildId(guildId).flatMap(command => command.toJSON()));
77
+ });
78
+ }
79
+ getCommands() {
80
+ var _a;
81
+ return (_a = this.applicationCommands.get(undefined)) !== null && _a !== void 0 ? _a : [];
82
+ }
83
+ getCommandsByGuildId(guildId) {
84
+ var _a;
85
+ return (_a = this.applicationCommands.get(guildId)) !== null && _a !== void 0 ? _a : [];
86
+ }
87
+ getCommandByName(name) {
88
+ return this.getCommands().find(command => command.getName() === name);
89
+ }
90
+ getCommandByGuildIdAndName(guildId, name) {
91
+ return this.getCommandsByGuildId(guildId).find(command => command.getName() === name);
92
+ }
73
93
  };
74
94
  CommandsService = CommandsService_1 = __decorate([
75
95
  (0, common_1.Injectable)(),
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": "5.6.1",
4
+ "version": "5.7.0",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc -p tsconfig.build.json",
7
7
  "prepublish:npm": "npm run build",