@pikokr/command.ts 3.0.6-dev.92a9148 → 3.0.6-dev.be7b9e0

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.
@@ -1,9 +1,10 @@
1
1
  import { BuiltInModule } from './BuiltInModule';
2
- import { Client, CommandInteraction } from 'discord.js';
2
+ import { Client, CommandInteraction, CommandInteractionOptionResolver } from 'discord.js';
3
3
  import { CommandClient } from '../structures';
4
4
  export declare class BuiltinSlashCommandConverters extends BuiltInModule {
5
5
  private cts;
6
6
  client: Client;
7
7
  constructor(cts: CommandClient);
8
8
  message(interaction: CommandInteraction): CommandInteraction;
9
+ optionResolver(interaction: CommandInteraction): CommandInteractionOptionResolver;
9
10
  }
@@ -22,6 +22,9 @@ class BuiltinSlashCommandConverters extends BuiltInModule_1.BuiltInModule {
22
22
  message(interaction) {
23
23
  return interaction;
24
24
  }
25
+ optionResolver(interaction) {
26
+ return interaction.options;
27
+ }
25
28
  }
26
29
  __decorate([
27
30
  command_1.slashArgumentConverter(discord_js_1.CommandInteraction),
@@ -29,4 +32,10 @@ __decorate([
29
32
  __metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
30
33
  __metadata("design:returntype", void 0)
31
34
  ], BuiltinSlashCommandConverters.prototype, "message", null);
35
+ __decorate([
36
+ command_1.slashArgumentConverter(discord_js_1.CommandInteractionOptionResolver),
37
+ __metadata("design:type", Function),
38
+ __metadata("design:paramtypes", [discord_js_1.CommandInteraction]),
39
+ __metadata("design:returntype", discord_js_1.CommandInteractionOptionResolver)
40
+ ], BuiltinSlashCommandConverters.prototype, "optionResolver", null);
32
41
  exports.BuiltinSlashCommandConverters = BuiltinSlashCommandConverters;
@@ -120,12 +120,19 @@ class Registry {
120
120
  }
121
121
  syncCommands() {
122
122
  return __awaiter(this, void 0, void 0, function* () {
123
+ console.log(`[Command.TS] Syncing commands...`);
123
124
  const commands = this.slashCommands.filter((x) => !x.guild);
124
125
  const guild = this.client.options.slashCommands.guild;
125
126
  if (guild) {
126
127
  const syncForGuild = (g) => __awaiter(this, void 0, void 0, function* () {
128
+ console.log(`Syncing for guild ${g.name}(${g.id})`);
129
+ const commandsToRegister = [
130
+ ...commands.map((x) => x.commandBuilder),
131
+ ...this.slashCommands.filter((y) => { var _a; return y.guild === g.id || ((_a = y.guild) === null || _a === void 0 ? void 0 : _a.includes(g.id)) || false; }).map((x) => x.commandBuilder),
132
+ ];
133
+ console.log(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`);
127
134
  yield this.client.rest.put(v9_1.Routes.applicationGuildCommands(this.client.client.application.id, g.id), {
128
- body: commands.map((x) => x.commandBuilder.toJSON()),
135
+ body: commandsToRegister.map((x) => x.toJSON()),
129
136
  });
130
137
  });
131
138
  if (typeof guild === 'string') {
@@ -138,10 +145,12 @@ class Registry {
138
145
  }
139
146
  }
140
147
  else {
148
+ console.log('Syncing global...');
141
149
  yield this.client.rest.put(v9_1.Routes.applicationCommands(this.client.client.application.id), {
142
150
  body: commands.map((x) => x.commandBuilder.toJSON()),
143
151
  });
144
152
  }
153
+ console.log('Syncing ended.');
145
154
  });
146
155
  }
147
156
  unregisterModule(module) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pikokr/command.ts",
3
3
  "description": "Discord.js command framework for typescript.",
4
- "version": "3.0.6-dev.92a9148",
4
+ "version": "3.0.6-dev.be7b9e0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  import { BuiltInModule } from './BuiltInModule'
2
2
  import { slashArgumentConverter } from '../command'
3
- import { Client, CommandInteraction } from 'discord.js'
3
+ import { Client, CommandInteraction, CommandInteractionOptionResolver } from 'discord.js'
4
4
  import { CommandClient } from '../structures'
5
5
 
6
6
  export class BuiltinSlashCommandConverters extends BuiltInModule {
@@ -15,4 +15,9 @@ export class BuiltinSlashCommandConverters extends BuiltInModule {
15
15
  message(interaction: CommandInteraction) {
16
16
  return interaction
17
17
  }
18
+
19
+ @slashArgumentConverter(CommandInteractionOptionResolver)
20
+ optionResolver(interaction: CommandInteraction): CommandInteractionOptionResolver {
21
+ return interaction.options
22
+ }
18
23
  }
@@ -118,12 +118,19 @@ export class Registry {
118
118
  }
119
119
 
120
120
  async syncCommands() {
121
+ console.log(`[Command.TS] Syncing commands...`)
121
122
  const commands = this.slashCommands.filter((x) => !x.guild)
122
123
  const guild = this.client.options.slashCommands.guild
123
124
  if (guild) {
124
125
  const syncForGuild = async (g: Guild) => {
126
+ console.log(`Syncing for guild ${g.name}(${g.id})`)
127
+ const commandsToRegister = [
128
+ ...commands.map((x) => x.commandBuilder),
129
+ ...this.slashCommands.filter((y) => y.guild === g.id || y.guild?.includes(g.id) || false).map((x) => x.commandBuilder),
130
+ ]
131
+ console.log(`Command List: ${commandsToRegister.map((x) => x.name).join(', ')}`)
125
132
  await this.client.rest.put(Routes.applicationGuildCommands(this.client.client.application!.id, g.id) as any, {
126
- body: commands.map((x) => x.commandBuilder.toJSON()),
133
+ body: commandsToRegister.map((x) => x.toJSON()),
127
134
  })
128
135
  }
129
136
 
@@ -135,10 +142,12 @@ export class Registry {
135
142
  }
136
143
  }
137
144
  } else {
145
+ console.log('Syncing global...')
138
146
  await this.client.rest.put(Routes.applicationCommands(this.client.client.application!.id) as any, {
139
147
  body: commands.map((x) => x.commandBuilder.toJSON()),
140
148
  })
141
149
  }
150
+ console.log('Syncing ended.')
142
151
  }
143
152
 
144
153
  async unregisterModule(module: Module) {