Skip to content

Commit e01b1a6

Browse files
fix: remove confusion boolean options and replace with options, quickstart
1 parent b038bee commit e01b1a6

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

src/discord_commands/global.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,21 @@
7272
"required": true,
7373
"description": "The user or role to setup permissions for"
7474
},
75-
76-
{
77-
"type": 5,
78-
"name": "message-access",
79-
"required": true,
80-
"description": "Grants permissions required to manage messages. Note: setting this to false won't deny permissions"
81-
},
8275
{
83-
"type": 5,
84-
"name": "management-access",
76+
"type": 3,
77+
"name": "preset",
8578
"required": true,
86-
"description": "Grants permissions required to manage bot setup. Note: setting this to false won't deny permissions"
79+
"description": "The preset to grant to the target",
80+
"choices": [
81+
{
82+
"name": "message-access",
83+
"value": "message-access"
84+
},
85+
{
86+
"name": "management-access",
87+
"value": "management-access"
88+
}
89+
]
8790
},
8891
{
8992
"type": 7,

src/interactions/commands/chatInput/config.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import axios from "axios";
22
import { Snowflake } from "discord-api-types/globals";
33
import {
4-
APIApplicationCommandInteractionDataBooleanOption,
54
APIApplicationCommandInteractionDataChannelOption,
65
APIApplicationCommandInteractionDataMentionableOption,
6+
APIApplicationCommandInteractionDataStringOption,
77
APIApplicationCommandInteractionDataSubcommandGroupOption,
88
APIApplicationCommandInteractionDataSubcommandOption,
99
APIChatInputApplicationCommandGuildInteraction,
@@ -372,46 +372,31 @@ async function handlePermissionsQuickstartSubcommand({
372372
"Target not found in resolved data"
373373
);
374374
}
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;
397382

398-
if (managementPreset && channel === undefined) {
383+
if (preset === "management-access" && channel !== undefined) {
399384
throw new ExpectedFailure(
400385
InteractionOrRequestFinalStatus.MANAGEMENT_PERMISSIONS_CANNOT_BE_SET_ON_CHANNEL_LEVEL,
401386
"The management preset can only be set on guild level - leave as false to set message access"
402387
);
403388
}
404389

405390
let permissions: number[] = [];
406-
if (messagePreset) {
391+
if (preset === "message-access") {
407392
permissions = [
408393
InternalPermissions.VIEW_MESSAGES,
409394
InternalPermissions.EDIT_MESSAGES,
410395
InternalPermissions.SEND_MESSAGES,
411396
InternalPermissions.DELETE_MESSAGES,
412397
];
413398
}
414-
if (managementPreset) {
399+
if (preset === "management-access") {
415400
permissions = [
416401
...permissions,
417402
InternalPermissions.MANAGE_PERMISSIONS,
@@ -453,13 +438,12 @@ async function handlePermissionsQuickstartSubcommand({
453438
title: "Permissions Quickstart",
454439
description:
455440
`The permissions preset ${
456-
messagePreset
441+
preset === "message-access"
457442
? "message access with the permissions `VIEW_MESSAGES`, `EDIT_MESSAGES`, `SEND_MESSAGES`, `DELETE_MESSAGES` "
458443
: ""
459444
}` +
460-
`${messagePreset && managementPreset ? "and " : ""}` +
461445
`${
462-
managementPreset
446+
preset === "management-access"
463447
? "the permissions preset management access with the permissions `MANAGE_PERMISSIONS`, `MANAGE_CONFIG` "
464448
: ""
465449
}` +

0 commit comments

Comments
 (0)