Class PermissionUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canInteract
(Member issuer, RichCustomEmoji emoji) static boolean
canInteract
(Member issuer, Member target) Checks if one given Member can interact with a 2nd given Member - in a permission sense (kick/ban/modify perms).static boolean
canInteract
(Member issuer, Role target) Checks if a given Member can interact with a given Role - in a permission sense (kick/ban/modify perms).static boolean
canInteract
(Role issuer, Role target) Checks if one given Role can interact with a 2nd given Role - in a permission sense (kick/ban/modify perms).static boolean
canInteract
(User issuer, RichCustomEmoji emoji, MessageChannel channel) Checks whether the specifiedRichCustomEmoji
can be used by the providedUser
in theMessageChannel
.static boolean
canInteract
(User issuer, RichCustomEmoji emoji, MessageChannel channel, boolean botOverride) static boolean
checkPermission
(IPermissionContainer channel, Member member, Permission... permissions) static boolean
checkPermission
(Member member, Permission... permissions) static long
getEffectivePermission
(GuildChannel channel, Member member) Gets thelong
representation of the effective permissions allowed for thisMember
in thisGuildChannel
.static long
getEffectivePermission
(GuildChannel channel, Role role) Gets thelong
representation of the effective permissions allowed for thisRole
in thisGuildChannel
.static long
getEffectivePermission
(Member member) static long
getExplicitPermission
(GuildChannel channel, Member member) Retrieves the explicit permissions of the specifiedMember
in its hostingGuild
and specificGuildChannel
.static long
getExplicitPermission
(GuildChannel channel, Member member, boolean includeRoles) Retrieves the explicit permissions of the specifiedMember
in its hostingGuild
and specificGuildChannel
.static long
getExplicitPermission
(GuildChannel channel, Role role) Retrieves the explicit permissions of the specifiedRole
in its hostingGuild
and specificGuildChannel
.static long
getExplicitPermission
(GuildChannel channel, Role role, boolean includeRoles) Retrieves the explicit permissions of the specifiedRole
in its hostingGuild
and specificGuildChannel
.static long
getExplicitPermission
(Member member)
-
Constructor Details
-
PermissionUtil
public PermissionUtil()
-
-
Method Details
-
canInteract
Checks if one given Member can interact with a 2nd given Member - in a permission sense (kick/ban/modify perms). This only checks the Role-Position and does not check the actual permission (kick/ban/manage_role/...)- Parameters:
issuer
- The member that tries to interact with 2nd membertarget
- The member that is the target of the interaction- Returns:
- True, if issuer can interact with target in guild
- Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
canInteract
Checks if a given Member can interact with a given Role - in a permission sense (kick/ban/modify perms). This only checks the Role-Position and does not check the actual permission (kick/ban/manage_role/...)- Parameters:
issuer
- The member that tries to interact with the roletarget
- The role that is the target of the interaction- Returns:
- True, if issuer can interact with target
- Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
canInteract
Checks if one given Role can interact with a 2nd given Role - in a permission sense (kick/ban/modify perms). This only checks the Role-Position and does not check the actual permission (kick/ban/manage_role/...)- Parameters:
issuer
- The role that tries to interact with 2nd roletarget
- The role that is the target of the interaction- Returns:
- True, if issuer can interact with target
- Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
canInteract
Check whether the providedMember
can use the specifiedEmoji
.If the specified Member is not in the emoji's guild or the emoji provided is from a message this will return false. Otherwise, it will check if the emoji is restricted to any roles and if that is the case if the Member has one of these.
Note: This is not checking if the issuer owns the Guild or not.- Parameters:
issuer
- The member that tries to interact with the Emojiemoji
- The emoji that is the target interaction- Returns:
- True, if the issuer can interact with the emoji
- Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
canInteract
public static boolean canInteract(User issuer, RichCustomEmoji emoji, MessageChannel channel, boolean botOverride) - Parameters:
issuer
- The user that tries to interact with the emojiemoji
- The emoji that is the target interactionchannel
- The MessageChannel this emoji should be interacted withinbotOverride
- Whether bots can use non-managed emojis in other guilds- Returns:
- True, if the issuer can interact with the emoji within the specified MessageChannel
- Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
canInteract
Checks whether the specifiedRichCustomEmoji
can be used by the providedUser
in theMessageChannel
.- Parameters:
issuer
- The user that tries to interact with the emojiemoji
- The emoji that is the target interactionchannel
- The MessageChannel this emoji should be interacted within- Returns:
- True, if the issuer can interact with the emoji within the specified MessageChannel
- Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
checkPermission
Checks to see if theMember
has the specifiedPermissions
in the specifiedGuild
. This method properly deals with Owner status.Note: this is based on effective permissions, not literal permissions. If a member has permissions that would enable them to do something without the literal permission to do it, this will still return true.
Example: If a member has thePermission.ADMINISTRATOR
permission, they will be able toPermission.MANAGE_SERVER
as well, even without the literal permissions.- Parameters:
member
- TheMember
whose permissions are being checked.permissions
- ThePermissions
being checked for.- Returns:
- True -
if the
Member
effectively has the specifiedPermissions
. - Throws:
IllegalArgumentException
- if any of the provided parameters is null
-
checkPermission
public static boolean checkPermission(IPermissionContainer channel, Member member, Permission... permissions) Checks to see if theMember
has the specifiedPermissions
in the specifiedGuildChannel
. This method properly deals withPermissionOverrides
and Owner status.Note: this is based on effective permissions, not literal permissions. If a member has permissions that would enable them to do something without the literal permission to do it, this will still return true.
Example: If a member has thePermission.ADMINISTRATOR
permission, they will be able toPermission.MESSAGE_SEND
in every channel.- Parameters:
channel
- TheGuildChannel
being checked.member
- TheMember
whose permissions are being checked.permissions
- ThePermissions
being checked for.- Returns:
- True -
if the
Member
effectively has the specifiedPermissions
. - Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
getEffectivePermission
Gets thelong
representation of the effective permissions allowed for thisMember
in thisGuild
. This can be used in conjunction withPermission.getPermissions(int)
to easily get a list of allPermissions
that this member has in thisGuild
.This only returns the Guild-level permissions!
- Parameters:
member
- TheMember
whose permissions are being checked.- Returns:
- The
long
representation of the literal permissions that thisMember
has in thisGuild
. - Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guildDetachedEntityException
- If the provided member is in a guild the bot is not a member of
-
getEffectivePermission
Gets thelong
representation of the effective permissions allowed for thisMember
in thisGuildChannel
. This can be used in conjunction withPermission.getPermissions(long)
to easily get a list of allPermissions
that this member can use in thisGuildChannel
.
This functions very similarly to howRole.getPermissionsRaw()
.- Parameters:
channel
- TheGuildChannel
being checked.member
- TheMember
whose permissions are being checked.- Returns:
- The
long
representation of the effective permissions that thisMember
has in thisGuildChannel
. - Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guildDetachedEntityException
- If the provided member is in a guild the bot is not a member of
-
getEffectivePermission
Gets thelong
representation of the effective permissions allowed for thisRole
in thisGuildChannel
. This can be used in conjunction withPermission.getPermissions(long)
to easily get a list of allPermissions
that this role can use in thisGuildChannel
.- Parameters:
channel
- TheGuildChannel
in which permissions are being checked.role
- TheRole
whose permissions are being checked.- Returns:
- The
long
representation of the effective permissions that thisRole
has in thisGuildChannel
- Throws:
IllegalArgumentException
- if any of the provided parameters isnull
or the provided entities are not from the same guild
-
getExplicitPermission
Retrieves the explicit permissions of the specifiedMember
in its hostingGuild
.
This method does not calculate the owner in.All permissions returned are explicitly granted to this Member via its
Roles
.
Permissions likePermission.ADMINISTRATOR
do not grant other permissions in this value.- Parameters:
member
- The non-nullMember
for which to get implicit permissions- Returns:
- Primitive (unsigned) long value with the implicit permissions of the specified member
- Throws:
IllegalArgumentException
- If the specified member isnull
DetachedEntityException
- If the provided member is in a guild the bot is not a member of- Since:
- 3.1
-
getExplicitPermission
Retrieves the explicit permissions of the specifiedMember
in its hostingGuild
and specificGuildChannel
.
This method does not calculate the owner in. Allowed permissions override denied permissions ofPermissionOverrides
!All permissions returned are explicitly granted to this Member via its
Roles
.
Permissions likePermission.ADMINISTRATOR
do not grant other permissions in this value.This factor in all
PermissionOverrides
that affect this member and only grants the ones that are explicitly given.- Parameters:
channel
- The target channel of which to checkPermissionOverrides
member
- The non-nullMember
for which to get implicit permissions- Returns:
- Primitive (unsigned) long value with the implicit permissions of the specified member in the specified channel
- Throws:
IllegalArgumentException
- If any of the arguments isnull
or the specified entities are not from the sameGuild
- Since:
- 3.1
-
getExplicitPermission
Retrieves the explicit permissions of the specifiedMember
in its hostingGuild
and specificGuildChannel
.
This method does not calculate the owner in. Allowed permissions override denied permissions ofPermissionOverrides
!All permissions returned are explicitly granted to this Member via its
Roles
.
Permissions likePermission.ADMINISTRATOR
do not grant other permissions in this value.This factor in all
PermissionOverrides
that affect this member and only grants the ones that are explicitly given.- Parameters:
channel
- The target channel of which to checkPermissionOverrides
member
- The non-nullMember
for which to get implicit permissionsincludeRoles
- Whether the base role permissions should be included- Returns:
- Primitive (unsigned) long value with the implicit permissions of the specified member in the specified channel
- Throws:
IllegalArgumentException
- If any of the arguments isnull
or the specified entities are not from the sameGuild
DetachedEntityException
- If the provided member is in a guild the bot is not a member of- Since:
- 3.1
-
getExplicitPermission
Retrieves the explicit permissions of the specifiedRole
in its hostingGuild
and specificGuildChannel
.
Allowed permissions override denied permissions ofPermissionOverrides
!All permissions returned are explicitly granted to this Role.
Permissions likePermission.ADMINISTRATOR
do not grant other permissions in this value.This factor in existing
PermissionOverrides
if possible.- Parameters:
channel
- The target channel of which to checkPermissionOverrides
role
- The non-nullRole
for which to get implicit permissions- Returns:
- Primitive (unsigned) long value with the implicit permissions of the specified role in the specified channel
- Throws:
IllegalArgumentException
- If any of the arguments isnull
or the specified entities are not from the sameGuild
- Since:
- 3.1
-
getExplicitPermission
Retrieves the explicit permissions of the specifiedRole
in its hostingGuild
and specificGuildChannel
.
Allowed permissions override denied permissions ofPermissionOverrides
!All permissions returned are explicitly granted to this Role.
Permissions likePermission.ADMINISTRATOR
do not grant other permissions in this value.This factor in existing
PermissionOverrides
if possible.- Parameters:
channel
- The target channel of which to checkPermissionOverrides
role
- The non-nullRole
for which to get implicit permissionsincludeRoles
- Whether the base role permissions should be included- Returns:
- Primitive (unsigned) long value with the implicit permissions of the specified role in the specified channel
- Throws:
IllegalArgumentException
- If any of the arguments isnull
or the specified entities are not from the sameGuild
DetachedEntityException
- If the provided role is in a guild the bot is not a member of- Since:
- 3.1
-