|
1 | 1 | import axios from "axios"; |
2 | 2 | import { Snowflake } from "discord-api-types/globals"; |
3 | 3 | import { |
4 | | - APIApplicationCommandInteractionDataBooleanOption, |
5 | 4 | APIApplicationCommandInteractionDataChannelOption, |
6 | 5 | APIApplicationCommandInteractionDataMentionableOption, |
| 6 | + APIApplicationCommandInteractionDataStringOption, |
7 | 7 | APIApplicationCommandInteractionDataSubcommandGroupOption, |
8 | 8 | APIApplicationCommandInteractionDataSubcommandOption, |
9 | 9 | APIChatInputApplicationCommandGuildInteraction, |
@@ -372,46 +372,31 @@ async function handlePermissionsQuickstartSubcommand({ |
372 | 372 | "Target not found in resolved data" |
373 | 373 | ); |
374 | 374 | } |
375 | | - const messagePreset = |
376 | | - ( |
377 | | - subcommand.options?.find( |
378 | | - (option) => |
379 | | - option.name === "message-access" && |
380 | | - option.type === ApplicationCommandOptionType.Boolean |
381 | | - ) as APIApplicationCommandInteractionDataBooleanOption | undefined |
382 | | - )?.value ?? false; |
383 | | - const managementPreset = |
384 | | - ( |
385 | | - subcommand.options?.find( |
386 | | - (option) => |
387 | | - option.name === "management-access" && |
388 | | - option.type === ApplicationCommandOptionType.Boolean |
389 | | - ) as APIApplicationCommandInteractionDataBooleanOption | undefined |
390 | | - )?.value ?? false; |
391 | | - if (!messagePreset && !managementPreset) { |
392 | | - throw new ExpectedFailure( |
393 | | - InteractionOrRequestFinalStatus.NO_PERMISSIONS_PRESET_SELECTED, |
394 | | - "You need to select at least one permission preset" |
395 | | - ); |
396 | | - } |
| 375 | + const preset: "message-access" | "management-access" | undefined = ( |
| 376 | + subcommand.options?.find( |
| 377 | + (option) => |
| 378 | + option.name === "preset" && |
| 379 | + option.type === ApplicationCommandOptionType.String |
| 380 | + ) as APIApplicationCommandInteractionDataStringOption | undefined |
| 381 | + )?.value as "message-access" | "management-access" | undefined; |
397 | 382 |
|
398 | | - if (managementPreset && channel === undefined) { |
| 383 | + if (preset === "management-access" && channel !== undefined) { |
399 | 384 | throw new ExpectedFailure( |
400 | 385 | InteractionOrRequestFinalStatus.MANAGEMENT_PERMISSIONS_CANNOT_BE_SET_ON_CHANNEL_LEVEL, |
401 | 386 | "The management preset can only be set on guild level - leave as false to set message access" |
402 | 387 | ); |
403 | 388 | } |
404 | 389 |
|
405 | 390 | let permissions: number[] = []; |
406 | | - if (messagePreset) { |
| 391 | + if (preset === "message-access") { |
407 | 392 | permissions = [ |
408 | 393 | InternalPermissions.VIEW_MESSAGES, |
409 | 394 | InternalPermissions.EDIT_MESSAGES, |
410 | 395 | InternalPermissions.SEND_MESSAGES, |
411 | 396 | InternalPermissions.DELETE_MESSAGES, |
412 | 397 | ]; |
413 | 398 | } |
414 | | - if (managementPreset) { |
| 399 | + if (preset === "management-access") { |
415 | 400 | permissions = [ |
416 | 401 | ...permissions, |
417 | 402 | InternalPermissions.MANAGE_PERMISSIONS, |
@@ -453,13 +438,12 @@ async function handlePermissionsQuickstartSubcommand({ |
453 | 438 | title: "Permissions Quickstart", |
454 | 439 | description: |
455 | 440 | `The permissions preset ${ |
456 | | - messagePreset |
| 441 | + preset === "message-access" |
457 | 442 | ? "message access with the permissions `VIEW_MESSAGES`, `EDIT_MESSAGES`, `SEND_MESSAGES`, `DELETE_MESSAGES` " |
458 | 443 | : "" |
459 | 444 | }` + |
460 | | - `${messagePreset && managementPreset ? "and " : ""}` + |
461 | 445 | `${ |
462 | | - managementPreset |
| 446 | + preset === "management-access" |
463 | 447 | ? "the permissions preset management access with the permissions `MANAGE_PERMISSIONS`, `MANAGE_CONFIG` " |
464 | 448 | : "" |
465 | 449 | }` + |
|
0 commit comments