Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Permissions for JDA5 #1797

Merged
merged 10 commits into from
Sep 19, 2021
8 changes: 4 additions & 4 deletions src/main/java/net/dv8tion/jda/api/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ default List<StoreChannel> getStoreChannelsByName(@Nonnull String name, boolean
* not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord
* client, it is possible that you will see fewer channels than this returns. This is because the discord
* client hides any {@link net.dv8tion.jda.api.entities.TextChannel TextChannel} that you don't have the
* {@link net.dv8tion.jda.api.Permission#MESSAGE_READ Permission.MESSAGE_READ} permission in.
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} permission in.
*
* <p>This copies the backing store into a list. This means every call
* creates a new list with O(n) complexity. It is recommended to store this into
Expand All @@ -1704,7 +1704,7 @@ default List<TextChannel> getTextChannels()
* not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord
* client, it is you will not see the channel that this returns. This is because the discord client
* hides any {@link net.dv8tion.jda.api.entities.TextChannel TextChannel} that you don't have the
* {@link net.dv8tion.jda.api.Permission#MESSAGE_READ Permission.MESSAGE_READ} permission in.
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} permission in.
*
* @param id
* The id of the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
Expand All @@ -1728,7 +1728,7 @@ default TextChannel getTextChannelById(@Nonnull String id)
* not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord
* client, it is you will not see the channel that this returns. This is because the discord client
* hides any {@link net.dv8tion.jda.api.entities.TextChannel TextChannel} that you don't have the
* {@link net.dv8tion.jda.api.Permission#MESSAGE_READ Permission.MESSAGE_READ} permission in.
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} permission in.
*
* @param id
* The id of the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
Expand All @@ -1749,7 +1749,7 @@ default TextChannel getTextChannelById(long id)
* not mean that you will be able to send messages to it. Furthermore, if you log into this account on the discord
* client, it is possible that you will see fewer channels than this returns. This is because the discord client
* hides any {@link net.dv8tion.jda.api.entities.TextChannel TextChannel} that you don't have the
* {@link net.dv8tion.jda.api.Permission#MESSAGE_READ Permission.MESSAGE_READ} permission in.
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} permission in.
*
* @param name
* The name of the requested {@link net.dv8tion.jda.api.entities.TextChannel TextChannels}.
Expand Down
62 changes: 33 additions & 29 deletions src/main/java/net/dv8tion/jda/api/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,45 @@
*/
public enum Permission
{
CREATE_INSTANT_INVITE(0, true, true, "Create Instant Invite"),
// General Server / Channel Permissions
MANAGE_CHANNEL( 4, true, true, "Manage Channels"),
MANAGE_SERVER( 5, true, false, "Manage Server"),
VIEW_AUDIT_LOGS( 7, true, false, "View Audit Logs"),
VIEW_CHANNEL( 10, true, true, "View Channel(s)"),
VIEW_GUILD_INSIGHTS( 19, true, false, "View Server Insights"),
MANAGE_ROLES( 28, true, false, "Manage Roles"),
MANAGE_PERMISSIONS( 28, false, true, "Manage Permissions"),
MANAGE_WEBHOOKS( 29, true, true, "Manage Webhooks"),
MANAGE_EMOTES_AND_STICKERS(30, true, false, "Manage Emojis and Stickers"),

// Membership Permissions
CREATE_INSTANT_INVITE(0, true, true, "Create Instant Invite"),
KICK_MEMBERS( 1, true, false, "Kick Members"),
BAN_MEMBERS( 2, true, false, "Ban Members"),
ADMINISTRATOR( 3, true, false, "Administrator"),
MANAGE_CHANNEL( 4, true, true, "Manage Channels"),
MANAGE_SERVER( 5, true, false, "Manage Server"),
MESSAGE_ADD_REACTION( 6, true, true, "Add Reactions"),
VIEW_AUDIT_LOGS( 7, true, false, "View Audit Logs"),
PRIORITY_SPEAKER( 8, true, true, "Priority Speaker"),
VIEW_GUILD_INSIGHTS(19, true, false, "View Server Insights"),

// Applicable to all channel types
VIEW_CHANNEL( 10, true, true, "Read Text Channels & See Voice Channels"),
NICKNAME_CHANGE( 26, true, false, "Change Nickname"),
NICKNAME_MANAGE( 27, true, false, "Manage Nicknames"),

// Text Permissions
MESSAGE_READ( 10, true, true, "Read Messages"),
MESSAGE_WRITE( 11, true, true, "Send Messages"),
MESSAGE_ADD_REACTION( 6, true, true, "Add Reactions"),
MESSAGE_SEND( 11, true, true, "Send Messages"),
MESSAGE_TTS( 12, true, true, "Send TTS Messages"),
MESSAGE_MANAGE( 13, true, true, "Manage Messages"),
MESSAGE_EMBED_LINKS( 14, true, true, "Embed Links"),
MESSAGE_ATTACH_FILES( 15, true, true, "Attach Files"),
MESSAGE_HISTORY( 16, true, true, "Read History"),
MESSAGE_MENTION_EVERYONE(17, true, true, "Mention Everyone"),
MESSAGE_EXT_EMOJI( 18, true, true, "Use External Emojis"),
USE_APPLICATION_COMMANDS(31, true, true, "Use Application Commands"),
MESSAGE_EXT_STICKER( 37, true, true, "Use External Stickers"),
USE_SLASH_COMMANDS( 31, true, true, "Use Slash Commands"),

MANAGE_THREADS( 34, true, true, "Manage Threads"),
USE_PUBLIC_THREADS( 35, true, true, "Use Public Threads"),
USE_PRIVATE_THREADS(36, true, true, "Use Private Threads"),
// Thread Permissions
MANAGE_THREADS( 34, true, true, "Manage Threads"),
CREATE_PUBLIC_THREADS( 35, true, true, "Create Public Threads"),
CREATE_PRIVATE_THREADS( 36, true, true, "Create Private Threads"),
MESSAGE_SEND_IN_THREADS( 38, true, true, "Send Messages in Threads"),

// Voice Permissions
PRIORITY_SPEAKER( 8, true, true, "Priority Speaker"),
VOICE_STREAM( 9, true, true, "Video"),
VOICE_CONNECT( 20, true, true, "Connect"),
VOICE_SPEAK( 21, true, true, "Speak"),
Expand All @@ -69,15 +76,12 @@ public enum Permission
VOICE_USE_VAD( 25, true, true, "Use Voice Activity"),
VOICE_START_ACTIVITIES(39, true, true, "Launch Activities in Voice Channels"),

NICKNAME_CHANGE(26, true, false, "Change Nickname"),
NICKNAME_MANAGE(27, true, false, "Manage Nicknames"),
// Stage Channel Permissions
REQUEST_TO_SPEAK( 32, true, true, "Request to Speak"),

MANAGE_ROLES( 28, true, false, "Manage Roles"),
MANAGE_PERMISSIONS(28, false, true, "Manage Permissions"),
MANAGE_WEBHOOKS( 29, true, true, "Manage Webhooks"),
MANAGE_EMOTES( 30, true, false, "Manage Emojis"),
// Advanced Permissions
ADMINISTRATOR(3, true, false, "Administrator"),

REQUEST_TO_SPEAK( 32, true, true, "Request to Speak"),

UNKNOWN(-1, false, false, "Unknown");

Expand Down Expand Up @@ -108,10 +112,10 @@ public enum Permission
* All text channel specific permissions which are only available in text channel permission overrides
*/
public static final long ALL_TEXT_PERMISSIONS
= Permission.getRaw(MESSAGE_ADD_REACTION, MESSAGE_WRITE, MESSAGE_TTS, MESSAGE_MANAGE,
MESSAGE_EMBED_LINKS, MESSAGE_ATTACH_FILES, MESSAGE_EXT_STICKER,
MESSAGE_EXT_EMOJI, MESSAGE_HISTORY, MESSAGE_MENTION_EVERYONE,
USE_SLASH_COMMANDS, MANAGE_THREADS, USE_PUBLIC_THREADS, USE_PRIVATE_THREADS);
= Permission.getRaw(MESSAGE_ADD_REACTION, MESSAGE_SEND, MESSAGE_TTS, MESSAGE_MANAGE,
MESSAGE_EMBED_LINKS, MESSAGE_ATTACH_FILES, MESSAGE_EXT_EMOJI, MESSAGE_EXT_STICKER,
MESSAGE_HISTORY, MESSAGE_MENTION_EVERYONE, USE_APPLICATION_COMMANDS,
MANAGE_THREADS, CREATE_PUBLIC_THREADS, CREATE_PRIVATE_THREADS, MESSAGE_SEND_IN_THREADS);

/**
* All voice channel specific permissions which are only available in voice channel permission overrides
Expand Down Expand Up @@ -283,7 +287,7 @@ public static long getRaw(@Nonnull Permission... permissions)
/**
* This is effectively the opposite of {@link #getPermissions(long)}, this takes a Collection of {@link net.dv8tion.jda.api.Permission Permissions}
* and returns the raw offset {@code long} representation of the permissions.
* <br>Example: {@code getRaw(EnumSet.of(Permission.MESSAGE_READ, Permission.MESSAGE_WRITE))}
* <br>Example: {@code getRaw(EnumSet.of(Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND))}
*
* @param permissions
* The Collection of permissions of which to form into the raw long representation.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/dv8tion/jda/api/entities/Emote.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ default boolean hasRoles()
* @throws java.lang.UnsupportedOperationException
* If this emote is managed by discord ({@link #isManaged()})
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* if the Permission {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES MANAGE_EMOTES} is not given
* if the Permission {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS MANAGE_EMOTES_AND_STICKERS} is not given
*
* @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
* The RestAction to delete this Emote.
Expand All @@ -189,7 +189,7 @@ default boolean hasRoles()
* @throws IllegalStateException
* if this emote is created from a message or the bot does not have access to the emote
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES Permission.MANAGE_EMOTES}
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS Permission.MANAGE_EMOTES_AND_STICKERS}
*
* @return The EmoteManager for this Emote
*/
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ default List<Emote> getEmotesByName(@Nonnull String name, boolean ignoreCase)
* Retrieves an immutable list of emotes together with their respective creators.
*
* <p>Note that {@link ListedEmote#getUser()} is only available if the currently
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES Permission.MANAGE_EMOTES}.
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS Permission.MANAGE_EMOTES_AND_STICKERS}.
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: List of {@link net.dv8tion.jda.api.entities.ListedEmote ListedEmote}
*
Expand All @@ -2360,7 +2360,7 @@ default List<Emote> getEmotesByName(@Nonnull String name, boolean ignoreCase)
* <br><b>This does not include unicode emoji.</b>
*
* <p>Note that {@link ListedEmote#getUser()} is only available if the currently
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES Permission.MANAGE_EMOTES}.
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS Permission.MANAGE_EMOTES_AND_STICKERS}.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} include the following:
Expand All @@ -2387,7 +2387,7 @@ default List<Emote> getEmotesByName(@Nonnull String name, boolean ignoreCase)
* Retrieves a listed emote together with its respective creator.
*
* <p>Note that {@link ListedEmote#getUser()} is only available if the currently
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES Permission.MANAGE_EMOTES}.
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS Permission.MANAGE_EMOTES_AND_STICKERS}.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} include the following:
Expand All @@ -2414,7 +2414,7 @@ default RestAction<ListedEmote> retrieveEmoteById(long id)
* Retrieves a listed emote together with its respective creator.
*
* <p>Note that {@link ListedEmote#getUser()} is only available if the currently
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES Permission.MANAGE_EMOTES}.
* logged in account has {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS Permission.MANAGE_EMOTES_AND_STICKERS}.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} include the following:
Expand Down Expand Up @@ -2444,7 +2444,7 @@ default RestAction<ListedEmote> retrieveEmote(@Nonnull Emote emote)
if (emote instanceof ListedEmote)
{
ListedEmote listedEmote = (ListedEmote) emote;
if (listedEmote.hasUser() || !getSelfMember().hasPermission(Permission.MANAGE_EMOTES))
if (listedEmote.hasUser() || !getSelfMember().hasPermission(Permission.MANAGE_EMOTES_AND_STICKERS))
return listedEmote;
}
return null;
Expand Down Expand Up @@ -2609,7 +2609,7 @@ default RestAction<Ban> retrieveBan(@Nonnull User bannedUser)
* that is not directed at a specific {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
*
* <p>Note: This channel is the first channel in the guild (ordered by position) that the {@link #getPublicRole()}
* has the {@link net.dv8tion.jda.api.Permission#MESSAGE_READ Permission.MESSAGE_READ} in.
* has the {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL} in.
*
* @return The {@link net.dv8tion.jda.api.entities.TextChannel TextChannel} representing the default channel for this guild
*/
Expand Down Expand Up @@ -5391,7 +5391,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
/**
* Creates a new {@link net.dv8tion.jda.api.entities.Emote Emote} in this Guild.
* <br>If one or more Roles are specified the new Emote will only be available to Members with any of the specified Roles (see {@link Member#canInteract(Emote)})
* <br>For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES MANAGE_EMOTES} Permission.
* <br>For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS MANAGE_EMOTES_AND_STICKERS} Permission.
*
* <p><b><u>Unicode emojis are not included as {@link net.dv8tion.jda.api.entities.Emote Emote}!</u></b>
*
Expand All @@ -5416,7 +5416,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
* <br>If no roles are provided the Emote will be available to all Members of this Guild
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES MANAGE_EMOTES} Permission
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_EMOTES_AND_STICKERS MANAGE_EMOTES_AND_STICKERS} Permission
*
* @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction} - Type: {@link net.dv8tion.jda.api.entities.Emote Emote}
*/
Expand Down
Loading