Skip to content

Commit

Permalink
[Change] Updates for Pomelo API Changes
Browse files Browse the repository at this point in the history
Ref: https://discord.com/developers/docs/change-log#unique-usernames-on-discord

- Added null-safety for the discriminator field (Now defaults to `0` if no longer present in the Json)
- Fixed `getDefaultAvatarId` calculation to support non-discriminator lookups

- `global_name` is not being supported at this time, due to its infancy in the API. It will be added in a future commit once it becomes present in the API.
  • Loading branch information
CDAGaming committed Jun 16, 2023
1 parent 663d4fc commit 9ba0ce3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/discordipc/IPCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ private void readPipe(final IPCClient instance) {
final JsonObject u = data.getAsJsonObject("user");
final User user = new User(
u.getAsJsonPrimitive("username").getAsString(),
u.getAsJsonPrimitive("discriminator").getAsString(),
u.has("discriminator") ? u.getAsJsonPrimitive("discriminator").getAsString() : "0",
Long.parseLong(u.getAsJsonPrimitive("id").getAsString()),
u.has("avatar") && u.get("avatar").isJsonPrimitive() ? u.getAsJsonPrimitive("avatar").getAsString() : null
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jagrosh/discordipc/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public String getAvatarUrl() {
* @return The Users {@link DefaultAvatar} avatar ID.
*/
public String getDefaultAvatarId() {
return DefaultAvatar.values()[Integer.parseInt(getDiscriminator()) % DefaultAvatar.values().length].toString();
return DefaultAvatar.values()[(getDiscriminator().equals("0") ? (int) getIdLong() >> 22 : Integer.parseInt(getDiscriminator())) % DefaultAvatar.values().length].toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static Pipe openPipe(IPCClient ipcClient, long clientId, HashMap<String,

pipe.currentUser = new User(
userData.getAsJsonPrimitive("username").getAsString(),
userData.getAsJsonPrimitive("discriminator").getAsString(),
userData.has("discriminator") ? userData.getAsJsonPrimitive("discriminator").getAsString() : "0",
Long.parseLong(userData.getAsJsonPrimitive("id").getAsString()),
userData.has("avatar") && userData.get("avatar").isJsonPrimitive() ? userData.getAsJsonPrimitive("avatar").getAsString() : null
);
Expand Down

0 comments on commit 9ba0ce3

Please sign in to comment.