diff --git a/API/src/main/java/me/braydon/tether/model/user/ConnectedAccount.java b/API/src/main/java/me/braydon/tether/model/user/ConnectedAccount.java index 38f4f4b..4e8b1b6 100644 --- a/API/src/main/java/me/braydon/tether/model/user/ConnectedAccount.java +++ b/API/src/main/java/me/braydon/tether/model/user/ConnectedAccount.java @@ -4,7 +4,10 @@ import kong.unirest.core.json.JSONArray; import kong.unirest.core.json.JSONObject; import lombok.*; -import java.util.*; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; /** * A linked connection to a {@link DiscordUser}. diff --git a/API/src/main/java/me/braydon/tether/model/user/DiscordUser.java b/API/src/main/java/me/braydon/tether/model/user/DiscordUser.java index 9168fef..d18b827 100644 --- a/API/src/main/java/me/braydon/tether/model/user/DiscordUser.java +++ b/API/src/main/java/me/braydon/tether/model/user/DiscordUser.java @@ -79,6 +79,16 @@ public final class DiscordUser { */ private final String bannerColor; + /** + * The profile theme of this user, if any. + */ + private final ProfileTheme profileTheme; + + /** + * The profile effect this user has, if any. + */ + private final ProfileEffect profileEffect; + /** * The custom status of this user, if any. */ @@ -199,11 +209,12 @@ public final class DiscordUser { // Finally return the constructed user return new DiscordUser( snowflake, detailsJson.getString("username"), legacyUsername, detailsJson.optString("global_name", null), - discriminator, UserFlags.fromJson(detailsJson), Avatar.fromJson(snowflake, discriminator, legacyUsername != null, detailsJson), avatarDecoration, - Banner.fromJson(snowflake, detailsJson), detailsJson.optString("banner_color", null), CustomStatus.fromActivities(activities), - bio, pronouns, accentColor, onlineStatus, member == null ? EnumSet.noneOf(ClientType.class) : member.getActiveClients(), activities, - SpotifyActivity.fromActivities(activities), UserBadge.fromJson(userJson), ConnectedAccount.fromJson(userJson), clan, nitroSubscription, - detailsJson.optBoolean("bot", false), DiscordUtils.getTimeCreated(snowflake) + discriminator, UserFlags.fromJson(detailsJson), Avatar.fromJson(snowflake, discriminator, legacyUsername != null, detailsJson), + avatarDecoration, Banner.fromJson(snowflake, detailsJson), detailsJson.optString("banner_color", null), + ProfileTheme.fromJson(profileJson), ProfileEffect.fromJson(profileJson), CustomStatus.fromActivities(activities), bio, pronouns, accentColor, + onlineStatus, member == null ? EnumSet.noneOf(ClientType.class) : member.getActiveClients(), activities, SpotifyActivity.fromActivities(activities), + UserBadge.fromJson(userJson), ConnectedAccount.fromJson(userJson), clan, nitroSubscription, detailsJson.optBoolean("bot", false), + DiscordUtils.getTimeCreated(snowflake) ); } } \ No newline at end of file diff --git a/API/src/main/java/me/braydon/tether/model/user/ProfileEffect.java b/API/src/main/java/me/braydon/tether/model/user/ProfileEffect.java new file mode 100644 index 0000000..caca3d2 --- /dev/null +++ b/API/src/main/java/me/braydon/tether/model/user/ProfileEffect.java @@ -0,0 +1,39 @@ +package me.braydon.tether.model.user; + +import kong.unirest.core.json.JSONObject; +import lombok.*; + +/** + * A profile effect for a {@link DiscordUser}. + * + * @author Braydon + */ +@AllArgsConstructor(access = AccessLevel.PRIVATE) @Getter @EqualsAndHashCode +public class ProfileEffect { + /** + * The id of the user's profile effect. + */ + @NonNull private final String id; + + /** + * The unix time of when this profile effect expires, null if permanent. + */ + private final Long expires; + + /** + * Construct a profile effect for a user. + * + * @param userProfileJson the user profile json + * @return the constructed profile effect, null if none + */ + protected static ProfileEffect fromJson(JSONObject userProfileJson) { + JSONObject effectJson; + if (userProfileJson == null || ((effectJson = userProfileJson.isNull("profile_effect") ? null + : userProfileJson.getJSONObject("profile_effect")) == null)) { + return null; + } + String id = effectJson.getString("id"); + long expires = effectJson.optLong("expires_at", -1L); + return new ProfileEffect(id, expires == -1L ? null : expires); + } +} \ No newline at end of file diff --git a/API/src/main/java/me/braydon/tether/model/user/ProfileTheme.java b/API/src/main/java/me/braydon/tether/model/user/ProfileTheme.java new file mode 100644 index 0000000..d8d6406 --- /dev/null +++ b/API/src/main/java/me/braydon/tether/model/user/ProfileTheme.java @@ -0,0 +1,40 @@ +package me.braydon.tether.model.user; + +import kong.unirest.core.json.JSONArray; +import kong.unirest.core.json.JSONObject; +import lombok.*; + +/** + * The theme of a {@link DiscordUser}'s profile. + * + * @author Braydon + */ +@AllArgsConstructor(access = AccessLevel.PRIVATE) @Getter @EqualsAndHashCode +public class ProfileTheme { + /** + * The primary (hex) color of this theme. + */ + @NonNull private final String primary; + + /** + * The accent (hex) color of this theme. + */ + @NonNull private final String accent; + + /** + * Construct a profile theme for a user. + * + * @param userProfileJson the user profile json + * @return the constructed profile theme, null if none + */ + protected static ProfileTheme fromJson(JSONObject userProfileJson) { + JSONArray themeJson; + if (userProfileJson == null || ((themeJson = userProfileJson.isNull("theme_colors") ? null + : userProfileJson.getJSONArray("theme_colors")) == null)) { + return null; + } + String primaryHex = String.format("#%06X", (0xFFFFFF & themeJson.getInt(0))); + String accentHex = String.format("#%06X", (0xFFFFFF & themeJson.getInt(1))); + return new ProfileTheme(primaryHex, accentHex); + } +} \ No newline at end of file