nuxt-discord 0.0.15 → 0.0.17
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/README.md +2 -2
- package/dist/module.d.mts +21 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +81 -15
- package/dist/runtime/client/pages/slash-commands.css +1 -1
- package/dist/runtime/client/pages/slash-commands.vue +13 -8
- package/dist/runtime/server/api/discord/slash-command/remote-diff.post.d.ts +233 -14
- package/dist/runtime/server/plugins/discord.js +1 -1
- package/dist/runtime/server/utils/client.d.ts +236 -11
- package/dist/runtime/server/utils/client.js +151 -74
- package/dist/runtime/server/utils/reply.d.ts +1 -0
- package/dist/runtime/server/utils/reply.js +63 -29
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +9 -0
- package/package.json +15 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { NuxtDiscordOptions, SlashCommandRuntime } from '../../../types.js';
|
|
3
|
-
import { Client as InternalClient } from 'discord.js';
|
|
1
|
+
import type { APIApplicationCommandOption, ChatInputCommandInteraction, CommandInteraction, RESTGetAPIApplicationCommandsResult, RESTPutAPIApplicationCommandsResult } from 'discord.js';
|
|
2
|
+
import type { NuxtDiscordOptions, SlashCommandRuntime, SlashCommandSubcommandGroupRuntime, SlashCommandSubcommandRuntime } from '../../../types.js';
|
|
3
|
+
import { ApplicationCommandOptionType, Client as InternalClient } from 'discord.js';
|
|
4
4
|
export interface DiscordClientErrorBase {
|
|
5
5
|
type: string;
|
|
6
6
|
client: DiscordClient;
|
|
@@ -45,18 +45,243 @@ export declare class DiscordClient {
|
|
|
45
45
|
getSlashCommand(name: string): SlashCommandRuntime | undefined;
|
|
46
46
|
getRemoteSlashCommands(): Promise<RESTGetAPIApplicationCommandsResult>;
|
|
47
47
|
diffRemoteSlashCommands(localCommands?: SlashCommandRuntime[], forceRefresh?: boolean): Promise<{
|
|
48
|
-
added: SlashCommandRuntime[];
|
|
49
|
-
removed:
|
|
48
|
+
added: (SlashCommandRuntime | SlashCommandSubcommandRuntime | SlashCommandSubcommandGroupRuntime)[];
|
|
49
|
+
removed: ({
|
|
50
|
+
name: string;
|
|
51
|
+
subcommands: never[];
|
|
52
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
53
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
54
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
55
|
+
description: string;
|
|
56
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
57
|
+
required?: boolean;
|
|
58
|
+
} | {
|
|
59
|
+
name: string;
|
|
60
|
+
subcommands: {
|
|
61
|
+
name: string;
|
|
62
|
+
subcommands: never[];
|
|
63
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
64
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
65
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
66
|
+
description: string;
|
|
67
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
68
|
+
required?: boolean;
|
|
69
|
+
}[];
|
|
70
|
+
options?: import("discord.js").APIApplicationCommandSubcommandOption[];
|
|
71
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
72
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
73
|
+
description: string;
|
|
74
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
75
|
+
required?: boolean;
|
|
76
|
+
} | {
|
|
77
|
+
subcommands: ({
|
|
78
|
+
name: string;
|
|
79
|
+
subcommands: never[];
|
|
80
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
81
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
82
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
83
|
+
description: string;
|
|
84
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
85
|
+
required?: boolean;
|
|
86
|
+
} | {
|
|
87
|
+
name: string;
|
|
88
|
+
subcommands: {
|
|
89
|
+
name: string;
|
|
90
|
+
subcommands: never[];
|
|
91
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
92
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
93
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
94
|
+
description: string;
|
|
95
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
96
|
+
required?: boolean;
|
|
97
|
+
}[];
|
|
98
|
+
options?: import("discord.js").APIApplicationCommandSubcommandOption[];
|
|
99
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
100
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
101
|
+
description: string;
|
|
102
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
103
|
+
required?: boolean;
|
|
104
|
+
})[];
|
|
105
|
+
id: import("discord.js").Snowflake;
|
|
106
|
+
type: import("discord.js").ApplicationCommandType;
|
|
107
|
+
application_id: import("discord.js").Snowflake;
|
|
108
|
+
guild_id?: import("discord.js").Snowflake;
|
|
109
|
+
name: string;
|
|
110
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
111
|
+
name_localized?: string;
|
|
112
|
+
description: string;
|
|
113
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
114
|
+
description_localized?: string;
|
|
115
|
+
options?: APIApplicationCommandOption[];
|
|
116
|
+
default_member_permissions: import("discord.js").Permissions | null;
|
|
117
|
+
dm_permission?: boolean;
|
|
118
|
+
default_permission?: boolean;
|
|
119
|
+
nsfw?: boolean;
|
|
120
|
+
integration_types?: import("discord.js").ApplicationIntegrationType[];
|
|
121
|
+
contexts?: import("discord.js").InteractionContextType[] | null;
|
|
122
|
+
version: import("discord.js").Snowflake;
|
|
123
|
+
handler?: import("discord.js").EntryPointCommandHandlerType;
|
|
124
|
+
})[];
|
|
50
125
|
changed: {
|
|
51
|
-
local: SlashCommandRuntime;
|
|
52
|
-
remote:
|
|
126
|
+
local: SlashCommandRuntime | SlashCommandSubcommandRuntime | SlashCommandSubcommandGroupRuntime;
|
|
127
|
+
remote: {
|
|
128
|
+
name: string;
|
|
129
|
+
subcommands: never[];
|
|
130
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
131
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
132
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
133
|
+
description: string;
|
|
134
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
135
|
+
required?: boolean;
|
|
136
|
+
} | {
|
|
137
|
+
name: string;
|
|
138
|
+
subcommands: {
|
|
139
|
+
name: string;
|
|
140
|
+
subcommands: never[];
|
|
141
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
142
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
143
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
144
|
+
description: string;
|
|
145
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
146
|
+
required?: boolean;
|
|
147
|
+
}[];
|
|
148
|
+
options?: import("discord.js").APIApplicationCommandSubcommandOption[];
|
|
149
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
150
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
151
|
+
description: string;
|
|
152
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
153
|
+
required?: boolean;
|
|
154
|
+
} | {
|
|
155
|
+
subcommands: ({
|
|
156
|
+
name: string;
|
|
157
|
+
subcommands: never[];
|
|
158
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
159
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
160
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
161
|
+
description: string;
|
|
162
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
163
|
+
required?: boolean;
|
|
164
|
+
} | {
|
|
165
|
+
name: string;
|
|
166
|
+
subcommands: {
|
|
167
|
+
name: string;
|
|
168
|
+
subcommands: never[];
|
|
169
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
170
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
171
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
172
|
+
description: string;
|
|
173
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
174
|
+
required?: boolean;
|
|
175
|
+
}[];
|
|
176
|
+
options?: import("discord.js").APIApplicationCommandSubcommandOption[];
|
|
177
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
178
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
179
|
+
description: string;
|
|
180
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
181
|
+
required?: boolean;
|
|
182
|
+
})[];
|
|
183
|
+
id: import("discord.js").Snowflake;
|
|
184
|
+
type: import("discord.js").ApplicationCommandType;
|
|
185
|
+
application_id: import("discord.js").Snowflake;
|
|
186
|
+
guild_id?: import("discord.js").Snowflake;
|
|
187
|
+
name: string;
|
|
188
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
189
|
+
name_localized?: string;
|
|
190
|
+
description: string;
|
|
191
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
192
|
+
description_localized?: string;
|
|
193
|
+
options?: APIApplicationCommandOption[];
|
|
194
|
+
default_member_permissions: import("discord.js").Permissions | null;
|
|
195
|
+
dm_permission?: boolean;
|
|
196
|
+
default_permission?: boolean;
|
|
197
|
+
nsfw?: boolean;
|
|
198
|
+
integration_types?: import("discord.js").ApplicationIntegrationType[];
|
|
199
|
+
contexts?: import("discord.js").InteractionContextType[] | null;
|
|
200
|
+
version: import("discord.js").Snowflake;
|
|
201
|
+
handler?: import("discord.js").EntryPointCommandHandlerType;
|
|
202
|
+
};
|
|
53
203
|
}[];
|
|
54
204
|
synced: {
|
|
55
|
-
local: SlashCommandRuntime;
|
|
56
|
-
remote:
|
|
205
|
+
local: SlashCommandRuntime | SlashCommandSubcommandRuntime | SlashCommandSubcommandGroupRuntime;
|
|
206
|
+
remote: {
|
|
207
|
+
name: string;
|
|
208
|
+
subcommands: never[];
|
|
209
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
210
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
211
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
212
|
+
description: string;
|
|
213
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
214
|
+
required?: boolean;
|
|
215
|
+
} | {
|
|
216
|
+
name: string;
|
|
217
|
+
subcommands: {
|
|
218
|
+
name: string;
|
|
219
|
+
subcommands: never[];
|
|
220
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
221
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
222
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
223
|
+
description: string;
|
|
224
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
225
|
+
required?: boolean;
|
|
226
|
+
}[];
|
|
227
|
+
options?: import("discord.js").APIApplicationCommandSubcommandOption[];
|
|
228
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
229
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
230
|
+
description: string;
|
|
231
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
232
|
+
required?: boolean;
|
|
233
|
+
} | {
|
|
234
|
+
subcommands: ({
|
|
235
|
+
name: string;
|
|
236
|
+
subcommands: never[];
|
|
237
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
238
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
239
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
240
|
+
description: string;
|
|
241
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
242
|
+
required?: boolean;
|
|
243
|
+
} | {
|
|
244
|
+
name: string;
|
|
245
|
+
subcommands: {
|
|
246
|
+
name: string;
|
|
247
|
+
subcommands: never[];
|
|
248
|
+
options?: import("discord.js").APIApplicationCommandBasicOption[];
|
|
249
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
250
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
251
|
+
description: string;
|
|
252
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
253
|
+
required?: boolean;
|
|
254
|
+
}[];
|
|
255
|
+
options?: import("discord.js").APIApplicationCommandSubcommandOption[];
|
|
256
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
257
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
258
|
+
description: string;
|
|
259
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
260
|
+
required?: boolean;
|
|
261
|
+
})[];
|
|
262
|
+
id: import("discord.js").Snowflake;
|
|
263
|
+
type: import("discord.js").ApplicationCommandType;
|
|
264
|
+
application_id: import("discord.js").Snowflake;
|
|
265
|
+
guild_id?: import("discord.js").Snowflake;
|
|
266
|
+
name: string;
|
|
267
|
+
name_localizations?: import("discord.js").LocalizationMap | null;
|
|
268
|
+
name_localized?: string;
|
|
269
|
+
description: string;
|
|
270
|
+
description_localizations?: import("discord.js").LocalizationMap | null;
|
|
271
|
+
description_localized?: string;
|
|
272
|
+
options?: APIApplicationCommandOption[];
|
|
273
|
+
default_member_permissions: import("discord.js").Permissions | null;
|
|
274
|
+
dm_permission?: boolean;
|
|
275
|
+
default_permission?: boolean;
|
|
276
|
+
nsfw?: boolean;
|
|
277
|
+
integration_types?: import("discord.js").ApplicationIntegrationType[];
|
|
278
|
+
contexts?: import("discord.js").InteractionContextType[] | null;
|
|
279
|
+
version: import("discord.js").Snowflake;
|
|
280
|
+
handler?: import("discord.js").EntryPointCommandHandlerType;
|
|
281
|
+
};
|
|
57
282
|
}[];
|
|
58
|
-
conflict: SlashCommandRuntime[];
|
|
283
|
+
conflict: (SlashCommandRuntime | SlashCommandSubcommandRuntime | SlashCommandSubcommandGroupRuntime)[];
|
|
59
284
|
}>;
|
|
60
|
-
registerSlashCommands(): Promise<RESTPutAPIApplicationCommandsResult | PromiseSettledResult<APIApplicationCommand>[]>;
|
|
285
|
+
registerSlashCommands(): Promise<RESTPutAPIApplicationCommandsResult | PromiseSettledResult<import("discord.js").APIApplicationCommand>[]>;
|
|
61
286
|
}
|
|
62
287
|
export declare function isPromise(value: any): value is Promise<unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import { ApplicationCommandOptionType, Events, Client as InternalClient, REST, Routes, SlashCommandBuilder } from "discord.js";
|
|
2
|
+
import { ApplicationCommandOptionType, Events, Client as InternalClient, REST, Routes, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from "discord.js";
|
|
3
3
|
import { useNitroApp } from "nitropack/runtime";
|
|
4
4
|
import { effectScope, isRef } from "vue";
|
|
5
5
|
import { logger } from "../../logger.js";
|
|
@@ -53,7 +53,27 @@ export class DiscordClient {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
const commandName = interaction.commandName;
|
|
56
|
-
|
|
56
|
+
let command = this.#slashCommands.find((cmd) => cmd.name === commandName);
|
|
57
|
+
if (!command) {
|
|
58
|
+
logger.warn(`Unknown slash command: ${commandName}`);
|
|
59
|
+
this.#nitro.hooks.callHook("discord:client:error", {
|
|
60
|
+
type: "UnknownSlashCommandError",
|
|
61
|
+
client: this,
|
|
62
|
+
interaction
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (command.subcommands != null && (command.subcommands?.length ?? 0) > 0) {
|
|
67
|
+
const group = interaction.options.getSubcommandGroup(false);
|
|
68
|
+
const subcommand = interaction.options.getSubcommand(false);
|
|
69
|
+
if (group && subcommand) {
|
|
70
|
+
command = command.subcommands.find((subcmd) => subcmd.name === group)?.subcommands?.find((subcmd) => subcmd.name === subcommand);
|
|
71
|
+
} else if (subcommand) {
|
|
72
|
+
command = command.subcommands.find((subcmd) => subcmd.name === subcommand);
|
|
73
|
+
} else {
|
|
74
|
+
logger.warn(`Unknown slash command subcommand: ${commandName} ${group ?? ""} ${subcommand}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
57
77
|
if (!command) {
|
|
58
78
|
logger.warn(`Unknown slash command: ${commandName}`);
|
|
59
79
|
this.#nitro.hooks.callHook("discord:client:error", {
|
|
@@ -266,67 +286,84 @@ export class DiscordClient {
|
|
|
266
286
|
const choices = await autocompleteFunction(focusedOption.value, interaction);
|
|
267
287
|
await interaction.respond(choices);
|
|
268
288
|
}
|
|
269
|
-
#getSlashCommandBuilder(command) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
289
|
+
#getSlashCommandBuilder(command, builder) {
|
|
290
|
+
builder ??= new SlashCommandBuilder();
|
|
291
|
+
builder.setName(command.name).setDescription(command.description);
|
|
292
|
+
if (command.subcommands != null && command.subcommands.length > 0) {
|
|
293
|
+
for (const subcommand of command.subcommands) {
|
|
294
|
+
if (builder instanceof SlashCommandBuilder) {
|
|
295
|
+
if ("subcommands" in subcommand && (subcommand.subcommands?.length ?? 0) > 0) {
|
|
296
|
+
builder.addSubcommandGroup((subcommandGroupBuilder) => this.#getSlashCommandBuilder(subcommand, subcommandGroupBuilder));
|
|
297
|
+
} else {
|
|
298
|
+
builder.addSubcommand((subcommandBuilder) => this.#getSlashCommandBuilder(subcommand, subcommandBuilder));
|
|
299
|
+
}
|
|
300
|
+
} else if (builder instanceof SlashCommandSubcommandGroupBuilder) {
|
|
301
|
+
builder.addSubcommand((subcommandBuilder) => this.#getSlashCommandBuilder(subcommand, subcommandBuilder));
|
|
302
|
+
} else {
|
|
303
|
+
throw new TypeError(`Unexpected builder type: ${builder.constructor.name}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
} else if (builder instanceof SlashCommandBuilder || builder instanceof SlashCommandSubcommandBuilder) {
|
|
307
|
+
for (const option of command.options) {
|
|
308
|
+
switch (option.type) {
|
|
309
|
+
case ApplicationCommandOptionType.String:
|
|
310
|
+
builder.addStringOption((opt) => {
|
|
311
|
+
opt.setName(option.name).setRequired(option.required);
|
|
312
|
+
if (option.description.length > 0)
|
|
313
|
+
opt = opt.setDescription(option.description);
|
|
314
|
+
if (option.minLength)
|
|
315
|
+
opt = opt.setMinLength(option.minLength);
|
|
316
|
+
if (option.maxLength)
|
|
317
|
+
opt = opt.setMaxLength(option.maxLength);
|
|
318
|
+
if (option.choices)
|
|
319
|
+
opt = opt.addChoices(...option.choices);
|
|
320
|
+
if (option.hasAutocomplete) {
|
|
321
|
+
opt = opt.setAutocomplete(true);
|
|
322
|
+
}
|
|
323
|
+
return opt;
|
|
324
|
+
});
|
|
325
|
+
break;
|
|
326
|
+
case ApplicationCommandOptionType.Integer:
|
|
327
|
+
builder.addIntegerOption((opt) => {
|
|
328
|
+
opt.setName(option.name).setRequired(option.required);
|
|
329
|
+
if (option.description.length > 0)
|
|
330
|
+
opt = opt.setDescription(option.description);
|
|
331
|
+
if (option.min)
|
|
332
|
+
opt = opt.setMinValue(option.min);
|
|
333
|
+
if (option.max)
|
|
334
|
+
opt = opt.setMaxValue(option.max);
|
|
335
|
+
if (option.choices)
|
|
336
|
+
opt = opt.addChoices(...option.choices);
|
|
337
|
+
if (option.hasAutocomplete)
|
|
338
|
+
opt = opt.setAutocomplete(true);
|
|
339
|
+
return opt;
|
|
340
|
+
});
|
|
341
|
+
break;
|
|
342
|
+
case ApplicationCommandOptionType.Number:
|
|
343
|
+
builder.addNumberOption((opt) => {
|
|
344
|
+
opt.setName(option.name).setRequired(option.required);
|
|
345
|
+
if (option.description.length > 0)
|
|
346
|
+
opt = opt.setDescription(option.description);
|
|
347
|
+
if (option.min)
|
|
348
|
+
opt = opt.setMinValue(option.min);
|
|
349
|
+
if (option.max)
|
|
350
|
+
opt = opt.setMaxValue(option.max);
|
|
351
|
+
if (option.choices)
|
|
352
|
+
opt = opt.addChoices(...option.choices);
|
|
353
|
+
if (option.hasAutocomplete)
|
|
354
|
+
opt = opt.setAutocomplete(true);
|
|
355
|
+
return opt;
|
|
356
|
+
});
|
|
357
|
+
break;
|
|
358
|
+
case ApplicationCommandOptionType.Boolean:
|
|
359
|
+
builder.addBooleanOption((opt) => {
|
|
360
|
+
opt.setName(option.name).setRequired(option.required);
|
|
361
|
+
if (option.description.length > 0)
|
|
362
|
+
opt = opt.setDescription(option.description);
|
|
363
|
+
return opt;
|
|
364
|
+
});
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
330
367
|
}
|
|
331
368
|
}
|
|
332
369
|
return builder;
|
|
@@ -341,23 +378,61 @@ export class DiscordClient {
|
|
|
341
378
|
await this.getRemoteSlashCommands();
|
|
342
379
|
}
|
|
343
380
|
const remoteCommands = this.#cachedRemoteSlashCommands;
|
|
344
|
-
const
|
|
381
|
+
const flattenedRemoteCommands = remoteCommands.flatMap((cmd) => {
|
|
382
|
+
const subcommands = cmd.options?.flatMap((option) => {
|
|
383
|
+
const name = `${cmd.name} ${option.name}`;
|
|
384
|
+
if (option.type === ApplicationCommandOptionType.Subcommand) {
|
|
385
|
+
return [{ ...option, name, subcommands: [] }];
|
|
386
|
+
} else if (option.type === ApplicationCommandOptionType.SubcommandGroup) {
|
|
387
|
+
const subcommands2 = option.options?.flatMap((suboption) => {
|
|
388
|
+
return suboption.type === ApplicationCommandOptionType.Subcommand ? [{ ...suboption, name: `${name} ${suboption.name}`, subcommands: [] }] : [];
|
|
389
|
+
}) ?? [];
|
|
390
|
+
return [
|
|
391
|
+
{ ...option, name, subcommands: subcommands2 },
|
|
392
|
+
...subcommands2
|
|
393
|
+
];
|
|
394
|
+
}
|
|
395
|
+
return [];
|
|
396
|
+
}) ?? [];
|
|
397
|
+
return [
|
|
398
|
+
{ ...cmd, subcommands },
|
|
399
|
+
...subcommands
|
|
400
|
+
];
|
|
401
|
+
});
|
|
402
|
+
const flattenedLocalCommands = localCommands.flatMap(
|
|
403
|
+
(cmd) => [
|
|
404
|
+
cmd,
|
|
405
|
+
...cmd.subcommands?.flatMap((subcmd) => {
|
|
406
|
+
const name = `${cmd.name} ${subcmd.name}`;
|
|
407
|
+
return [
|
|
408
|
+
{ ...subcmd, name },
|
|
409
|
+
...subcmd.subcommands?.map((subsubcmd) => ({ ...subsubcmd, name: `${name} ${subsubcmd.name}` })) ?? []
|
|
410
|
+
];
|
|
411
|
+
}) ?? []
|
|
412
|
+
]
|
|
413
|
+
);
|
|
414
|
+
const nameToCommands = flattenedLocalCommands.reduce((acc, command) => {
|
|
345
415
|
(acc[command.name] ??= []).push(command);
|
|
346
416
|
return acc;
|
|
347
417
|
}, {});
|
|
348
|
-
return
|
|
349
|
-
const remoteCommand = remoteCommands.find((cmd) => cmd.name === command.name);
|
|
418
|
+
return flattenedLocalCommands.reduce((acc, command) => {
|
|
350
419
|
if (nameToCommands[command.name].length > 1) {
|
|
351
420
|
acc.conflict.push(command);
|
|
352
|
-
|
|
421
|
+
return acc;
|
|
422
|
+
}
|
|
423
|
+
const remoteCommand = flattenedRemoteCommands.find((cmd) => cmd.name === command.name);
|
|
424
|
+
if (!remoteCommand) {
|
|
353
425
|
acc.added.push(command);
|
|
354
|
-
} else if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
426
|
+
} else if (
|
|
427
|
+
// if some properties are different
|
|
428
|
+
!propsEqual(command, remoteCommand, [
|
|
429
|
+
"description"
|
|
430
|
+
/* TODO: more */
|
|
431
|
+
]) || !((command.subcommands?.length ?? 0) > 0 && remoteCommand.subcommands.length > 0) && ((command.options?.length ?? 0) !== (remoteCommand.options?.length ?? 0) || (remoteCommand.options ?? []).some((opt, i) => !optionEqual(command.options[i], opt)))
|
|
432
|
+
) {
|
|
358
433
|
acc.changed.push({ local: command, remote: remoteCommand });
|
|
359
434
|
} else {
|
|
360
|
-
if (
|
|
435
|
+
if ("id" in remoteCommand && !command.id) {
|
|
361
436
|
command.id = remoteCommand.id;
|
|
362
437
|
}
|
|
363
438
|
acc.synced.push({ local: command, remote: remoteCommand });
|
|
@@ -365,7 +440,7 @@ export class DiscordClient {
|
|
|
365
440
|
return acc;
|
|
366
441
|
}, {
|
|
367
442
|
added: [],
|
|
368
|
-
removed:
|
|
443
|
+
removed: flattenedRemoteCommands.filter(({ name }) => !(name in nameToCommands)),
|
|
369
444
|
changed: [],
|
|
370
445
|
synced: [],
|
|
371
446
|
conflict: []
|
|
@@ -378,7 +453,7 @@ export class DiscordClient {
|
|
|
378
453
|
return [];
|
|
379
454
|
}
|
|
380
455
|
this.#cachedRemoteSlashCommands = null;
|
|
381
|
-
if (
|
|
456
|
+
if (true) {
|
|
382
457
|
try {
|
|
383
458
|
const result = await this.#rest.put(
|
|
384
459
|
Routes.applicationCommands(this.#clientId),
|
|
@@ -402,6 +477,8 @@ export class DiscordClient {
|
|
|
402
477
|
} else {
|
|
403
478
|
const results = await Promise.allSettled(
|
|
404
479
|
diff.changed.map((command) => {
|
|
480
|
+
if (!("id" in command.remote))
|
|
481
|
+
return Promise.reject(new Error(`Remote command ${command.local.name} does not have an ID`));
|
|
405
482
|
logger.log(`Updating slash command: ${command.local.name}`);
|
|
406
483
|
const builder = this.#getSlashCommandBuilder(command.local);
|
|
407
484
|
return this.#rest.patch(
|