diff options
Diffstat (limited to 'src/lib/common/util')
-rw-r--r-- | src/lib/common/util/Moderation.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/common/util/Moderation.ts b/src/lib/common/util/Moderation.ts index cb6b4db..fc01602 100644 --- a/src/lib/common/util/Moderation.ts +++ b/src/lib/common/util/Moderation.ts @@ -1,13 +1,16 @@ import { ActivePunishment, ActivePunishmentType, + baseMuteResponse, colors, emojis, format, Guild as GuildDB, humanizeDuration, ModLog, - type ModLogType + permissionsResponse, + type ModLogType, + type ValueOf } from '#lib'; import assert from 'assert'; import { @@ -119,6 +122,25 @@ export async function permissionCheck( } /** + * Performs permission checks that are required in order to (un)mute a member. + * @param guild The guild to check the mute permissions in. + * @returns A {@link MuteResponse} or true if nothing failed. + */ +export async function checkMutePermissions( + guild: Guild +): Promise<ValueOf<typeof baseMuteResponse> | ValueOf<typeof permissionsResponse> | true> { + if (!guild.members.me!.permissions.has('ManageRoles')) return permissionsResponse.MISSING_PERMISSIONS; + const muteRoleID = await guild.getSetting('muteRole'); + if (!muteRoleID) return baseMuteResponse.NO_MUTE_ROLE; + const muteRole = guild.roles.cache.get(muteRoleID); + if (!muteRole) return baseMuteResponse.MUTE_ROLE_INVALID; + if (muteRole.position >= guild.members.me!.roles.highest.position || muteRole.managed) + return baseMuteResponse.MUTE_ROLE_NOT_MANAGEABLE; + + return true; +} + +/** * Creates a modlog entry for a punishment. * @param options Options for creating a modlog entry. * @param getCaseNumber Whether or not to get the case number of the entry. |