-
-
Notifications
You must be signed in to change notification settings - Fork 744
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
Adds support for user's avatar decorations #2668
base: master
Are you sure you want to change the base?
Changes from all commits
0f90dec
434f9fb
573ba58
d4ac641
4ff7ae6
6a78c63
52a21f4
cde84c6
ba87a94
5eef4c8
23e7b32
ba3c9f1
3440015
1285d43
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import net.dv8tion.jda.internal.entities.UserSnowflakeImpl; | ||
import net.dv8tion.jda.internal.utils.Checks; | ||
import net.dv8tion.jda.internal.utils.EntityString; | ||
import net.dv8tion.jda.internal.utils.Helpers; | ||
|
||
import javax.annotation.CheckReturnValue; | ||
import javax.annotation.Nonnull; | ||
|
@@ -89,6 +90,8 @@ public interface User extends UserSnowflake | |
String DEFAULT_AVATAR_URL = "https://cdn.discordapp.com/embed/avatars/%s.png"; | ||
/** Template for {@link Profile#getBannerUrl()} */ | ||
String BANNER_URL = "https://cdn.discordapp.com/banners/%s/%s.%s"; | ||
/** Template for {@link AvatarDecoration#getDecorationAvatarUrl()} */ | ||
String DECORATION_AVATAR_URL = "https://cdn.discordapp.com/avatar-decoration-presets/%s.png"; | ||
|
||
/** Used to keep consistency between color values used in the API */ | ||
int DEFAULT_ACCENT_COLOR_RAW = 0x1FFFFFFF; // java.awt.Color fills the MSB with FF, we just use 1F to provide better consistency | ||
|
@@ -361,6 +364,14 @@ default ImageProxy getEffectiveAvatar() | |
*/ | ||
int getFlagsRaw(); | ||
|
||
/** | ||
* Returns the possibly-null {@link AvatarDecoration} of this user. If the user has not set a decoration avatar, this will return null. | ||
* | ||
* @return The possibly-null avatar decoration of this user | ||
*/ | ||
@Nullable | ||
AvatarDecoration getAvatarDecoration(); | ||
|
||
/** | ||
* Represents the information contained in a {@link User User}'s profile. | ||
* | ||
|
@@ -455,6 +466,79 @@ public String toString() | |
} | ||
} | ||
|
||
/** | ||
* Represents the avatar decoration of a {@link User User}. | ||
*/ | ||
class AvatarDecoration | ||
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. Missing equals() and hashCode(), since you rely on that for update checks. |
||
{ | ||
|
||
private final String decorationAvatarId; | ||
private final String skuId; | ||
|
||
public AvatarDecoration(String decorationAvatarId, String skuId) | ||
{ | ||
this.decorationAvatarId = decorationAvatarId; | ||
this.skuId = skuId; | ||
} | ||
|
||
/** | ||
* The never-null SKU id of the {@link User User} decoration avatar. | ||
* | ||
* @return The never-null SKU id of the {@link User User} decoration avatar. | ||
*/ | ||
@Nonnull | ||
public String getSkuId() | ||
MinnDevelopment marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return skuId; | ||
} | ||
|
||
/** | ||
* The never-null avatar ID for this user's decoration avatar image. | ||
* | ||
* @return The never-null avatar ID for this user's decoration avatar image. | ||
*/ | ||
@Nonnull | ||
public String getDecorationAvatarId() | ||
{ | ||
return decorationAvatarId; | ||
} | ||
|
||
/** | ||
* The URL for the user's decoration avatar image. | ||
* | ||
* @return The never-null String containing the {@link User User} decoration avatar url. | ||
* | ||
* @see User#DECORATION_AVATAR_URL | ||
*/ | ||
@Nonnull | ||
public String getDecorationAvatarUrl() | ||
{ | ||
return Helpers.format(DECORATION_AVATAR_URL, decorationAvatarId); | ||
} | ||
|
||
/** | ||
* Returns an {@link ImageProxy} for this user's decoration avatar. | ||
* | ||
* @return Never-null {@link ImageProxy} of this user's decoration avatar | ||
* | ||
* @see #getDecorationAvatarUrl() | ||
*/ | ||
@Nonnull | ||
public ImageProxy getDecorationAvatar() | ||
{ | ||
return new ImageProxy(getDecorationAvatarUrl()); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return new EntityString(this) | ||
.addMetadata("decorationAvatarId", decorationAvatarId) | ||
.addMetadata("skuId", skuId) | ||
.toString(); | ||
} | ||
} | ||
|
||
/** | ||
* Represents the bit offsets used by Discord for public flags | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,58 @@ | ||||||||
package net.dv8tion.jda.api.events.guild.member.update; | ||||||||
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. Missing copyright headers |
||||||||
|
||||||||
import net.dv8tion.jda.api.JDA; | ||||||||
import net.dv8tion.jda.api.entities.Member; | ||||||||
import net.dv8tion.jda.api.entities.User; | ||||||||
import org.jetbrains.annotations.NotNull; | ||||||||
import org.jetbrains.annotations.Nullable; | ||||||||
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. We use |
||||||||
|
||||||||
/** | ||||||||
* Indicates that a {@link net.dv8tion.jda.api.entities.Member Member} updated their {@link net.dv8tion.jda.api.entities.Guild Guild} {@link User.AvatarDecoration avatar decoration}. | ||||||||
* | ||||||||
* <p>Can be used to retrieve members who change their per guild avatar decoration, the triggering guild, the old avatar decoration and the new avatar decoration. | ||||||||
* | ||||||||
* <p>Identifier: {@code avatar_decoration} | ||||||||
* | ||||||||
* <p><b>Requirements</b><br> | ||||||||
* | ||||||||
* <p>This event requires the {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent to be enabled. | ||||||||
* <br>{@link net.dv8tion.jda.api.JDABuilder#createDefault(String) createDefault(String)} and | ||||||||
* {@link net.dv8tion.jda.api.JDABuilder#createLight(String) createLight(String)} disable this by default! | ||||||||
* | ||||||||
* <p>Additionally, this event requires the {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} | ||||||||
* to cache the updated members. Discord does not specifically tell us about the updates, but merely tells us the | ||||||||
* member was updated and gives us the updated member object. In order to fire a specific event like this we | ||||||||
* need to have the old member cached to compare against. | ||||||||
*/ | ||||||||
public class GuildMemberUpdateAvatarDecorationEvent extends GenericGuildMemberUpdateEvent<User.AvatarDecoration> { | ||||||||
|
||||||||
Comment on lines
+27
to
+28
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
|
||||||||
public static final String IDENTIFIER = "avatar_decoration"; | ||||||||
|
||||||||
public GuildMemberUpdateAvatarDecorationEvent(@NotNull JDA api, long responseNumber, @NotNull Member member, @Nullable User.AvatarDecoration next) | ||||||||
{ | ||||||||
super(api, responseNumber, member, member.getAvatarDecoration(), next, IDENTIFIER); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* The old avatar decoration | ||||||||
* | ||||||||
* @return The old avatar decoration | ||||||||
*/ | ||||||||
@Nullable | ||||||||
public User.AvatarDecoration getOldAvatarDecoration() | ||||||||
{ | ||||||||
return getOldValue(); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* The new avatar decoration | ||||||||
* | ||||||||
* @return The new avatar decoration | ||||||||
*/ | ||||||||
@Nullable | ||||||||
public User.AvatarDecoration getNewAvatarDecoration() | ||||||||
{ | ||||||||
return getNewValue(); | ||||||||
} | ||||||||
|
||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.dv8tion.jda.api.events.user.update; | ||
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. Missing copyright |
||
|
||
import net.dv8tion.jda.api.JDA; | ||
import net.dv8tion.jda.api.entities.User; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Indicates that the {@link net.dv8tion.jda.api.entities.User.AvatarDecoration AvatarDecoration} of a {@link net.dv8tion.jda.api.entities.User User} changed. | ||
* | ||
* <p>Can be used to retrieve the User who changed their avatar and their previous Avatar Decoration object. | ||
* | ||
* <p>Identifier: {@code avatar_decoration} | ||
* | ||
* <p><b>Requirements</b><br> | ||
* | ||
* <p>This event requires the {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent to be enabled. | ||
* <br>{@link net.dv8tion.jda.api.JDABuilder#createDefault(String) createDefault(String)} and | ||
* {@link net.dv8tion.jda.api.JDABuilder#createLight(String) createLight(String)} disable this by default! | ||
* | ||
* <p>Additionally, this event requires the {@link net.dv8tion.jda.api.utils.MemberCachePolicy MemberCachePolicy} | ||
* to cache the updated members. Discord does not specifically tell us about the updates, but merely tells us the | ||
* member was updated and gives us the updated member object. In order to fire a specific event like this we | ||
* need to have the old member cached to compare against. | ||
*/ | ||
public class UserUpdateAvatarDecorationEvent extends GenericUserUpdateEvent<User.AvatarDecoration> | ||
{ | ||
public static final String IDENTIFIER = "avatar_decoration"; | ||
|
||
public UserUpdateAvatarDecorationEvent(@NotNull JDA api, long responseNumber, @NotNull User user, @Nullable User.AvatarDecoration oldAvatarDecoration) | ||
{ | ||
super(api, responseNumber, user, oldAvatarDecoration, user.getAvatarDecoration(), IDENTIFIER); | ||
} | ||
|
||
/** | ||
* The old avatar decoration | ||
* @return The old avatar decoration | ||
*/ | ||
@Nullable | ||
public User.AvatarDecoration getOldAvatarDecoration() | ||
{ | ||
return getOldValue(); | ||
} | ||
|
||
/** | ||
* The new avatar decoration | ||
* @return The new avatar decoration | ||
*/ | ||
@Nullable | ||
public User.AvatarDecoration getNewAvatarDecoration() | ||
{ | ||
return getNewValue(); | ||
} | ||
|
||
} |
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.
This is missing docs