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 TeamMember.RoleType #2703

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/TeamMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.Nonnull;

/**
Expand Down Expand Up @@ -45,6 +47,14 @@ public interface TeamMember
@Nonnull
MembershipState getMembershipState();

/**
* The role of this member.
*
* @return The {@link RoleType}, or {@link RoleType#UNKNOWN UNKNOWN}
*/
@Nonnull
RoleType getRoleType();

/**
* The id for the team this member belongs to.
*
Expand Down Expand Up @@ -111,4 +121,81 @@ public static MembershipState fromKey(int key)
return UNKNOWN;
}
}

/**
* The role in the team.
*/
enum RoleType
{
/**
* Owners are the most permissible role, and can take destructive,
* irreversible actions like deleting team-owned apps or the team itself.
*
* <p>Teams are limited to one owner.
*/
OWNER(""),
/**
* Admins have similar access as owners,
* except they cannot take destructive actions on the team or team-owned apps.
*/
ADMIN("admin"),
/**
* Members which can access information about team-owned apps, like the client secret or public key.
* <br>They can also take limited actions on team-owned apps, like configuring interaction endpoints or resetting the bot token.
* <br>Members with the Developer role cannot manage the team or its members, or take destructive actions on team-owned apps.
*/
DEVELOPER("developer"),
/**
* Members which can access information about a team and any team-owned apps.
* <br>Some examples include getting the IDs of applications and exporting payout records.
* <br>Members can also invite bots associated with team-owned apps that are marked private.
*/
READ_ONLY("read_only"),
/**
* Placeholder for future types
*/
UNKNOWN("");

private final String key;

RoleType(String key)
{
this.key = key;
}

/**
* The key for this role that is used in the API.
*
* @return The key for this role
*/
@Nonnull
public String getKey()
{
return key;
}

/**
* Resolves the provided key to the correct RoleType.
*
* <p><b>Note:</b> {@link #OWNER} will never be returned, check the team owner ID instead.
*
* @param key
* The key to resolve
*
* @return The RoleType, or {@link #UNKNOWN}
*/
@Nonnull
public static RoleType fromKey(@Nonnull String key)
{
Checks.notNull(key, "Key");
if (key.isEmpty()) return UNKNOWN;

for (RoleType state : values())
{
if (state.key.equals(key))
return state;
}
return UNKNOWN;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,10 @@ public ApplicationTeam createApplicationTeam(DataObject object)
DataObject userJson = o.getObject("user");
TeamMember.MembershipState state = TeamMember.MembershipState.fromKey(o.getInt("membership_state"));
User user = createUser(userJson);
return new TeamMemberImpl(user, state, id);
TeamMember.RoleType roleType = user.getIdLong() == ownerId
? TeamMember.RoleType.OWNER
: TeamMember.RoleType.fromKey(o.getString("role"));
freya022 marked this conversation as resolved.
Show resolved Hide resolved
return new TeamMemberImpl(user, state, roleType, id);
});
return new ApplicationTeamImpl(iconId, members, id, ownerId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public class TeamMemberImpl implements TeamMember
{
private final User user;
private final MembershipState state;
private final RoleType roleType;
private final long teamId;

public TeamMemberImpl(User user, MembershipState state, long teamId)
public TeamMemberImpl(User user, MembershipState state, RoleType roleType, long teamId)
{
this.user = user;
this.state = state;
this.roleType = roleType;
this.teamId = teamId;
}

Expand All @@ -50,6 +52,13 @@ public MembershipState getMembershipState()
return state;
}

@Nonnull
@Override
public RoleType getRoleType()
{
return roleType;
}

@Override
public long getTeamIdLong()
{
Expand Down
Loading