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 BOT_HTTP_INTERACTIONS user flag #1865

Merged
merged 3 commits into from
Nov 7, 2021
Merged
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
71 changes: 36 additions & 35 deletions src/main/java/net/dv8tion/jda/api/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ default String getEffectiveAvatarUrl()
*
* @throws UnsupportedOperationException
* If this User was created with {@link #fromId(long)}
*
*
* @return EnumSet containing the flags of the user.
*/
@Nonnull
Expand All @@ -339,7 +339,7 @@ default String getEffectiveAvatarUrl()
*
* @throws UnsupportedOperationException
* If this User was created with {@link #fromId(long)}
*
*
* @return bitmask representation of the user's flags.
*/
int getFlagsRaw();
Expand All @@ -349,35 +349,36 @@ default String getEffectiveAvatarUrl()
*/
enum UserFlag
{
STAFF( 0, "Discord Employee"),
PARTNER( 1, "Partnered Server Owner"),
HYPESQUAD( 2, "HypeSquad Events"),
BUG_HUNTER_LEVEL_1( 3, "Bug Hunter Level 1"),
STAFF( 0, "Discord Employee"),
PARTNER( 1, "Partnered Server Owner"),
HYPESQUAD( 2, "HypeSquad Events"),
BUG_HUNTER_LEVEL_1( 3, "Bug Hunter Level 1"),

// HypeSquad
HYPESQUAD_BRAVERY( 6, "HypeSquad Bravery"),
HYPESQUAD_BRILLIANCE(7, "HypeSquad Brilliance"),
HYPESQUAD_BALANCE( 8, "HypeSquad Balance"),
HYPESQUAD_BRAVERY( 6, "HypeSquad Bravery"),
HYPESQUAD_BRILLIANCE( 7, "HypeSquad Brilliance"),
HYPESQUAD_BALANCE( 8, "HypeSquad Balance"),

EARLY_SUPPORTER( 9, "Early Supporter"),
TEAM_USER( 10, "Team User"),
EARLY_SUPPORTER( 9, "Early Supporter"),
TEAM_USER( 10, "Team User"),
sebm253 marked this conversation as resolved.
Show resolved Hide resolved
@Deprecated
@ForRemoval(deadline = "4.4.0")
@ReplaceWith("User.isSystem()")
@DeprecatedSince("4.3.0")
SYSTEM( 12, "System User"),
BUG_HUNTER_LEVEL_2( 14, "Bug Hunter Level 2"),
VERIFIED_BOT( 16, "Verified Bot"),
VERIFIED_DEVELOPER( 17, "Early Verified Bot Developer"),
CERTIFIED_MODERATOR(18, "Discord Certified Moderator"),

SYSTEM( 12, "System User"),
BUG_HUNTER_LEVEL_2( 14, "Bug Hunter Level 2"),
VERIFIED_BOT( 16, "Verified Bot"),
VERIFIED_DEVELOPER( 17, "Early Verified Bot Developer"),
CERTIFIED_MODERATOR( 18, "Discord Certified Moderator"),
BOT_HTTP_INTERACTIONS(19, "HTTP Interactions Bot"),
sebm253 marked this conversation as resolved.
Show resolved Hide resolved

UNKNOWN(-1, "Unknown");

/**
* Empty array of UserFlag enum, useful for optimized use in {@link java.util.Collection#toArray(Object[])}.
*/
public static final UserFlag[] EMPTY_FLAGS = new UserFlag[0];

private final int offset;
private final int raw;
private final String name;
Expand All @@ -391,7 +392,7 @@ enum UserFlag

/**
* The readable name as used in the Discord Client.
*
*
* @return The readable name of this UserFlag.
*/
@Nonnull
Expand All @@ -402,7 +403,7 @@ public String getName()

/**
* The binary offset of the flag.
*
*
* @return The offset that represents this UserFlag.
*/
public int getOffset()
Expand All @@ -413,7 +414,7 @@ public int getOffset()
/**
* The value of this flag when viewed as raw value.
* <br>This is equivalent to: <code>1 {@literal <<} {@link #getOffset()}</code>
*
*
* @return The raw value of this specific flag.
*/
public int getRawValue()
Expand All @@ -425,10 +426,10 @@ public int getRawValue()
* Gets the first UserFlag relating to the provided offset.
* <br>If there is no UserFlag that matches the provided offset,
* {@link #UNKNOWN} is returned.
*
*
* @param offset
* The offset to match a UserFlag to.
*
*
* @return UserFlag relating to the provided offset.
*/
@Nonnull
Expand All @@ -441,55 +442,55 @@ public static UserFlag getFromOffset(int offset)
}
return UNKNOWN;
}

/**
* A set of all UserFlags that are specified by this raw int representation of
* flags.
*
*
* @param flags
* The raw {@code int} representation if flags.
*
*
* @return Possibly-empty EnumSet of UserFlags.
*/
@Nonnull
public static EnumSet<UserFlag> getFlags(int flags)
{
final EnumSet<UserFlag> foundFlags = EnumSet.noneOf(UserFlag.class);

if (flags == 0)
return foundFlags; //empty

for (UserFlag flag : values())
{
if (flag != UNKNOWN && (flags & flag.raw) == flag.raw)
foundFlags.add(flag);
}

return foundFlags;
}

/**
* This is effectively the opposite of {@link #getFlags(int)}, this takes 1 or more UserFlags
* and returns the bitmask representation of the flags.
*
*
* @param flags
* The array of flags of which to form into the raw int representation.
*
* @throws java.lang.IllegalArgumentException
* When the provided UserFlags are null.
*
*
* @return bitmask representing the provided flags.
*/
public static int getRaw(@Nonnull UserFlag... flags){
Checks.noneNull(flags, "UserFlags");

int raw = 0;
for (UserFlag flag : flags)
{
if (flag != null && flag != UNKNOWN)
raw |= flag.raw;
}

return raw;
}

Expand All @@ -505,13 +506,13 @@ public static int getRaw(@Nonnull UserFlag... flags){
* When the provided UserFLags are null.
*
* @return bitmask representing the provided flags.
*
*
* @see java.util.EnumSet EnumSet
*/
public static int getRaw(@Nonnull Collection<UserFlag> flags)
{
Checks.notNull(flags, "Flag Collection");

return getRaw(flags.toArray(EMPTY_FLAGS));
}
}
Expand Down