@@ -18,6 +18,7 @@ import {
1818import { FastifyInstance } from "fastify" ;
1919
2020import { discordAPIBaseURL , embedPink } from "../../../constants" ;
21+ import { DiscordPermissions } from "../../../consts" ;
2122import {
2223 ExpectedFailure ,
2324 ExpectedPermissionFailure ,
@@ -26,6 +27,7 @@ import {
2627} from "../../../errors" ;
2728import { checkIfRoleIsBelowUsersHighestRole } from "../../../lib/permissions/checks" ;
2829import { InternalPermissions } from "../../../lib/permissions/consts" ;
30+ import { checkDiscordPermissionValue } from "../../../lib/permissions/utils" ;
2931import { GuildSession } from "../../../lib/session" ;
3032import { addTipToEmbed } from "../../../lib/tips" ;
3133import { InternalInteractionType } from "../../interaction" ;
@@ -226,13 +228,13 @@ async function handlePermissionsManageSubcommand({
226228
227229 const resolvedData = interaction . data . resolved ;
228230 let targetType : "role" | "user" ;
231+ let targetPermissions : Snowflake | undefined ;
229232
230233 if ( resolvedData ?. roles && resolvedData . roles [ targetId ] !== undefined ) {
231234 targetType = "role" ;
235+ targetPermissions = resolvedData . roles [ targetId ] . permissions ;
232236 } else if (
233- resolvedData ?. members &&
234- resolvedData . members [ targetId ] !== undefined &&
235- resolvedData . users &&
237+ resolvedData ?. users &&
236238 resolvedData . users [ targetId ] !== undefined
237239 ) {
238240 targetType = "user" ;
@@ -243,6 +245,13 @@ async function handlePermissionsManageSubcommand({
243245 "The target cannot be a bot"
244246 ) ;
245247 }
248+ // If the user is in the guild, then it will be in the members resolved data
249+ // Otherwise not
250+ // If the user is in the guild, set the permissions value to it's permissions
251+ if ( resolvedData ?. members && resolvedData . members [ targetId ] !== undefined ) {
252+ targetPermissions =
253+ resolvedData . members [ targetId ] . permissions ?? undefined ;
254+ }
246255 } else {
247256 throw new UnexpectedFailure (
248257 InteractionOrRequestFinalStatus . APPLICATION_COMMAND_RESOLVED_MISSING_EXPECTED_VALUE ,
@@ -279,13 +288,21 @@ async function handlePermissionsManageSubcommand({
279288
280289 // Not deferred as no logic is 'heavy'
281290
291+ const hasAdminPermission =
292+ targetPermissions !== undefined &&
293+ checkDiscordPermissionValue (
294+ BigInt ( targetPermissions ) ,
295+ DiscordPermissions . ADMINISTRATOR
296+ ) ;
297+
282298 const permissionReturnData = await createPermissionsEmbed ( {
283299 targetType,
284300 targetId,
285301 channelId : channel ?. id ?? null ,
286302 guildId : session . guildId ,
287303 instance,
288304 first : true ,
305+ hasAdminPermission,
289306 } ) ;
290307
291308 // Void function that waits a bit then fetches the original interaction message
@@ -348,14 +365,14 @@ async function handlePermissionsQuickstartSubcommand({
348365 ) ;
349366 }
350367 let targetType : "role" | "user" ;
368+ let targetPermissions : Snowflake | undefined ;
351369 const resolvedData = interaction . data . resolved ;
352370
353371 if ( resolvedData ?. roles && resolvedData . roles [ targetId ] !== undefined ) {
354372 targetType = "role" ;
373+ targetPermissions = resolvedData . roles [ targetId ] . permissions ;
355374 } else if (
356- resolvedData ?. members &&
357- resolvedData . members [ targetId ] !== undefined &&
358- resolvedData . users &&
375+ resolvedData ?. users &&
359376 resolvedData . users [ targetId ] !== undefined
360377 ) {
361378 targetType = "user" ;
@@ -366,6 +383,13 @@ async function handlePermissionsQuickstartSubcommand({
366383 "The target cannot be a bot"
367384 ) ;
368385 }
386+ // If the user is in the guild, then it will be in the members resolved data
387+ // Otherwise not
388+ // If the user is in the guild, set the permissions value to it's permissions
389+ if ( resolvedData ?. members && resolvedData . members [ targetId ] !== undefined ) {
390+ targetPermissions =
391+ resolvedData . members [ targetId ] . permissions ?? undefined ;
392+ }
369393 } else {
370394 throw new UnexpectedFailure (
371395 InteractionOrRequestFinalStatus . APPLICATION_COMMAND_RESOLVED_MISSING_EXPECTED_VALUE ,
@@ -430,6 +454,7 @@ async function handlePermissionsQuickstartSubcommand({
430454 channelId : channel ?. id ,
431455 } ) ;
432456 }
457+
433458 return {
434459 type : InteractionResponseType . ChannelMessageWithSource ,
435460 data : {
@@ -451,7 +476,15 @@ async function handlePermissionsQuickstartSubcommand({
451476 targetType === "user" ? `<@${ targetId } >` : `<@&${ targetId } >`
452477 } ${
453478 channel !== undefined ? ` on the channel <#${ channel . id } >` : ""
454- } .`,
479+ } .` + // Add note if the target has admin perms about how they bypass permissions
480+ ( targetPermissions !== undefined
481+ ? checkDiscordPermissionValue (
482+ BigInt ( targetPermissions ) ,
483+ DiscordPermissions . ADMINISTRATOR
484+ )
485+ ? "\n\nNote: The target has the discord `ADMINISTRATOR` permission. Any user with this permission will bypass bot permission checks (all will be allowed)"
486+ : ""
487+ : "" ) ,
455488 color : embedPink ,
456489 timestamp : new Date ( ) . toISOString ( ) ,
457490 } ) ,
0 commit comments