-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Add support for Role Tags #1342
Changes from all commits
6b4b91e
bdc9001
71ec987
c378f9f
267b884
101b65e
bb56a76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import net.dv8tion.jda.api.managers.RoleManager; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import net.dv8tion.jda.api.requests.restaction.RoleAction; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import net.dv8tion.jda.api.utils.data.DataObject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import javax.annotation.CheckReturnValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import javax.annotation.Nonnull; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -77,7 +78,10 @@ public interface Role extends IMentionable, IPermissionHolder, Comparable<Role> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Whether this {@link net.dv8tion.jda.api.entities.Role Role} is managed by an integration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* This is any role where the "This role is managed by an integration..." appears in the role list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Integration can be: Bot role, Booster role, or a connected partner account role. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @see Role#getRoleType() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @return True, if this {@link net.dv8tion.jda.api.entities.Role Role} is managed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+84
to
85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean isManaged(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -97,6 +101,14 @@ public interface Role extends IMentionable, IPermissionHolder, Comparable<Role> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
boolean isMentionable(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Return the type of role this is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Typically used for finding what kind of managed/integration role this is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @return this role's type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RoleType getRoleType(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* The {@code long} representation of the literal permissions that this {@link net.dv8tion.jda.api.entities.Role Role} has. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* <br><b>NOTE:</b> these do not necessarily represent the permissions this role will have in a {@link GuildChannel GuildChannel}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -271,4 +283,51 @@ default RoleAction createCopy() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Nonnull | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
JDA getJDA(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Enum used to differentiate between the different types of Guild Roles. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
enum RoleType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* A basic, user-created role. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NORMAL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* A role created from a bot on join. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BOT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* A role created from a YouTube Member or Twitch Subscriber integration..\ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
INTEGRATION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* The Server Booster role. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The role is explicitly called "Server Booster" when it's created. So this should be "The Guild's Server Booster" role There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In API terminology were always use the term "guild". |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BOOSTER, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Unknown RoleType. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
UNKNOWN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public static RoleType fromTags(DataObject tags) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(tags.hasKey("premium_subscriber")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return RoleType.BOOSTER; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if(tags.hasKey("bot_id")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return RoleType.BOT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else if(tags.hasKey("integration_id")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return RoleType.INTEGRATION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return RoleType.UNKNOWN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+314
to
+330
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1059,6 +1059,14 @@ public Role createRole(GuildImpl guild, DataObject roleJson, long guildId) | |||||||||||||||||||||||||
.setHoisted(roleJson.getBoolean("hoist")) | ||||||||||||||||||||||||||
.setColor(color == 0 ? Role.DEFAULT_COLOR_RAW : color) | ||||||||||||||||||||||||||
.setMentionable(roleJson.getBoolean("mentionable")); | ||||||||||||||||||||||||||
if(roleJson.hasKey("tags")) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
role.setType(Role.RoleType.fromTags(roleJson.getObject("tags"))); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
role.setType(Role.RoleType.NORMAL); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+1062
to
+1069
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good way to handle tags. You should be storing the tags in a map so that you can also retrieve the associated values. For example, which bot a role belongs to.
Suggested change
|
||||||||||||||||||||||||||
if (playbackCache) | ||||||||||||||||||||||||||
getJDA().getEventCache().playbackCache(EventCache.Type.ROLE, id); | ||||||||||||||||||||||||||
return role; | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ public class RoleImpl implements Role | |
private boolean managed; | ||
private boolean hoisted; | ||
private boolean mentionable; | ||
private RoleType roleType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bad way to handle tags. |
||
private long rawPermissions; | ||
private int color; | ||
private int rawPosition; | ||
|
@@ -116,6 +117,12 @@ public boolean isMentionable() | |
return mentionable; | ||
} | ||
|
||
@Override | ||
public RoleType getRoleType() | ||
{ | ||
return roleType; | ||
} | ||
|
||
@Override | ||
public long getPermissionsRaw() | ||
{ | ||
|
@@ -368,6 +375,12 @@ public RoleImpl setMentionable(boolean mentionable) | |
return this; | ||
} | ||
|
||
public RoleImpl setType(RoleType roleType) | ||
{ | ||
this.roleType = roleType; | ||
return this; | ||
} | ||
|
||
public RoleImpl setRawPermissions(long rawPermissions) | ||
{ | ||
this.rawPermissions = rawPermissions; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.