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

Add support for Role Tags #1342

Closed
wants to merge 7 commits into from
Closed

Conversation

Chew
Copy link
Contributor

@Chew Chew commented Jul 10, 2020

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Description

Discord recently added "tags" object to Roles.
Tags appear for any of the following reasons:

  1. To indicate a Server Booster role, example
"tags": {
    "premium_subscriber": null
}

"premium_subscriber" will always be null, we only care about the key.

  1. To indicate a Bot integration, example
"tags": {
    "bot": "489034866206310410"
 }
  1. To indicate a Twitch/YouTube member role, example
"tags": {
    "integration": "717460314068746300"
}

If not any of the above 3, tags will not appear.

I've only implemented the first one (partially) by adding Role#isBoosterRole(). I plan to move forward and possibly add Role#isBotRole() or Role#isIntegrationRole() or similar. It would also be nice to have a Guild#getBoosterRole() as well.

This has not been tested so as of now it's a draft, it's really just here to get feedback as I work on it and to make sure everything is good along the way :)

@MinnDevelopment MinnDevelopment added the status: freezer this is currently put on hold label Jul 10, 2020
@Andre601
Copy link
Contributor

Iirc is there a Role#isManaged() function that is afaik for Bot and Twitch/YouTube roles.
Maybe we can implement those tags for those?

@Chew
Copy link
Contributor Author

Chew commented Jul 11, 2020

Iirc is there a Role#isManaged() function that is afaik for Bot and Twitch/YouTube roles.
Maybe we can implement those tags for those?

"Is Managed" applies to all 3 of these roles.
Managed =
image

@RedcodesDev
Copy link
Contributor

Maybe we could add Role#getManagedType() that returns a Enum with the Type

@Chew
Copy link
Contributor Author

Chew commented Jul 11, 2020

Yeah, perhaps

RoleType
NORMAL - A normal everyday role
BOT - A role for bot integrations
BOOSTER - The booster role
INTEGRATION - Role from integration e.g. twitch or youtube

@Andre601
Copy link
Contributor

Woldn't it be better and simpler to have the RoleType as an enum inside the Role?
I don't see it as a separate entity.

@Chew
Copy link
Contributor Author

Chew commented Jul 11, 2020

Good call, considering how tiny it is. Forgot about classes in classes

@averen
Copy link
Contributor

averen commented Jul 11, 2020

It also might be better to rename NORMAL as NONE instead. Since there is no field present, it feels more grammatically correct and follows the patterns set by other enums.

Copy link
Collaborator

@kantenkugel kantenkugel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be an official change yet, since its not yet in the discord docs.

Additionally, if the role tags can include other tags other than type of management, it would make sense to store them as some kind of List/Map similar to the Guild Tags.

But in case of this becoming an official change + the tags only really showing the type of management, i provided some changes

src/main/java/net/dv8tion/jda/api/entities/Role.java Outdated Show resolved Hide resolved
src/main/java/net/dv8tion/jda/api/entities/Role.java Outdated Show resolved Hide resolved
src/main/java/net/dv8tion/jda/api/entities/Role.java Outdated Show resolved Hide resolved
@Chew Chew marked this pull request as ready for review July 12, 2020 01:34
Copy link
Member

@MinnDevelopment MinnDevelopment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are ignoring the tag values completely which makes this a bad implementation. You must handle what the tag value is, in order to properly associate roles with their purpose. For example, to retrieve the role of the current bot you must know the bot_id value, which is identical to the bot's id.

In the current state I cannot possibly accept this pull request.

@@ -77,7 +78,10 @@

/**
* 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This is any role where the "This role is managed by an integration..." appears in the role list.
* <br>This is any role where the "This role is managed by an integration..." appears in the role list.

Comment on lines +84 to 85
* @see Role#getRoleType()
* @return True, if this {@link net.dv8tion.jda.api.entities.Role Role} is managed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @see Role#getRoleType()
* @return True, if this {@link net.dv8tion.jda.api.entities.Role Role} is managed.
* @return True, if this {@link net.dv8tion.jda.api.entities.Role Role} is managed.
*
* @see Role#getRoleType()

*
* @return this role's type
*/
RoleType getRoleType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RoleType getRoleType();
@Nonnull
RoleType getRoleType();

@@ -97,6 +101,14 @@
*/
boolean isMentionable();

/**
* Return the type of role this is
* Typically used for finding what kind of managed/integration role this is.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Typically used for finding what kind of managed/integration role this is.
* typically used to determine what kind of managed role this is.

@@ -271,4 +283,51 @@ default RoleAction createCopy()
*/
@Nonnull
JDA getJDA();


Copy link
Member

Choose a reason for hiding this comment

The 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..\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* A role created from a YouTube Member or Twitch Subscriber integration..\
* A role created for an integration. For example, twitch subscribers

*/
INTEGRATION,
/**
* The Server Booster role.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The Server Booster role.
* The Guild Booster role.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In API terminology were always use the term "guild".

Comment on lines +314 to +330
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;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}
}
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 +1062 to +1069
if(roleJson.hasKey("tags"))
{
role.setType(Role.RoleType.fromTags(roleJson.getObject("tags")));
}
else
{
role.setType(Role.RoleType.NORMAL);
}
Copy link
Member

Choose a reason for hiding this comment

The 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(roleJson.hasKey("tags"))
{
role.setType(Role.RoleType.fromTags(roleJson.getObject("tags")));
}
else
{
role.setType(Role.RoleType.NORMAL);
}
if (roleJson.hasKey("tags"))
role.setType(Role.RoleType.fromTags(roleJson.getObject("tags")));
else
role.setType(Role.RoleType.NORMAL);

@@ -56,6 +56,7 @@
private boolean managed;
private boolean hoisted;
private boolean mentionable;
private RoleType roleType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad way to handle tags.

@Chew Chew marked this pull request as draft July 12, 2020 17:42
@MinnDevelopment
Copy link
Member

I'm gonna implement this myself in #1343. I appreciate your efforts, but I have already planned how I would like to implement this a while ago.

@Chew Chew deleted the feature/role-tags branch April 10, 2021 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: freezer this is currently put on hold
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants