From c0562f7c55c5473d582f1d33dd38caaa0789774f Mon Sep 17 00:00:00 2001 From: seailz Date: Fri, 29 Mar 2024 16:18:09 +0000 Subject: [PATCH] feat(applications): added new integration_types_config field --- .../model/application/Application.java | 65 ++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/seailz/discordjar/model/application/Application.java b/src/main/java/com/seailz/discordjar/model/application/Application.java index dd516cc3..7e95cb2e 100644 --- a/src/main/java/com/seailz/discordjar/model/application/Application.java +++ b/src/main/java/com/seailz/discordjar/model/application/Application.java @@ -78,11 +78,16 @@ public record Application( InstallParams installParams, String roleConnectionsVerificationUrl, int approximateGuildCount, + HashMap integrationTypes, DiscordJar discordJar ) implements Compilerable, Snowflake { @Override public JSONObject compile() { + JSONObject integrationTypes = new JSONObject(); + this.integrationTypes.forEach((key, val) -> { + integrationTypes.put(String.valueOf(key.code), val.compile()); + }); return new JSONObject() .put("id", id) .put("name", name) @@ -106,11 +111,12 @@ public JSONObject compile() { .put("custom_install_url", customInstallUrl) .put("role_connections_verification_url", roleConnectionsVerificationUrl) .put("approximate_guild_count", approximateGuildCount) + .put("integration_types_config", integrationTypes) .put("guild", guild.compile()); } public static Application decompile(JSONObject obj, DiscordJar discordJar) { - if (obj == null) return new Application(null, null, null, null, null, false, false, null, null, null, null, null, null, null, null, null, null, null, null, 0, null, null, null, null, 0, discordJar); + if (obj == null) return new Application(null, null, null, null, null, false, false, null, null, null, null, null, null, null, null, null, null, null, null, 0, null, null, null, null, 0, null, discordJar); String id; String name; String iconUrl; @@ -136,6 +142,7 @@ public static Application decompile(JSONObject obj, DiscordJar discordJar) { InstallParams installParams; String roleConnectionsVerificationUrl; int approximateGuildCount; + HashMap integrationTypesConfiguration = null; try { id = obj.getString("id"); @@ -282,6 +289,14 @@ public static Application decompile(JSONObject obj, DiscordJar discordJar) { guild = null; } + if (obj.has("integration_types_config")) { + integrationTypesConfiguration = new HashMap<>(); + JSONObject integrationTypesConfig = obj.getJSONObject("integration_types_config"); + for (String code : integrationTypesConfig.keySet()) { + integrationTypesConfiguration.put(IntegrationTypes.getByCode(Integer.parseInt(code)), IntegrationTypeConfiguration.decompile(integrationTypesConfig.getJSONObject(code))); + } + } + return new Application( id, name, @@ -308,6 +323,7 @@ public static Application decompile(JSONObject obj, DiscordJar discordJar) { installParams, roleConnectionsVerificationUrl, approximateGuildCount, + integrationTypesConfiguration, discordJar ); } @@ -348,7 +364,7 @@ public List getRoleConnections() { * * @param roleConnections The list of role connection metadata objects to update. * - * @throws com.seailz.discordjar.utils.Checker.NullArgumentException if the list is null. + * @throws Checker.NullArgumentException if the list is null. * @throws IllegalArgumentException if the list has more than 5 elements. */ public void setRoleConnections(@NotNull List roleConnections) { @@ -425,4 +441,49 @@ public int id() { return id; } } + + + public enum IntegrationTypes { + + GUILD_INSTALL(0), + USER_INSTALL(1), + UNKNOWN(-1) + ; + + private final int code; + + IntegrationTypes(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + + public static IntegrationTypes getByCode(int code) { + for (IntegrationTypes value : values()) { + if (value.getCode() == code) return value; + } + return UNKNOWN; + } + } + + public record IntegrationTypeConfiguration( + InstallParams installParams + ) implements Compilerable { + + @Override + public JSONObject compile() { + return new JSONObject() + .put("oauth2_install_params", installParams == null ? JSONObject.NULL : installParams.compile()); + } + + public static IntegrationTypeConfiguration decompile(JSONObject obj) { + InstallParams oauth2InstallParams = null; + if (obj.has("oauth2_install_params")) { + oauth2InstallParams = InstallParams.decompile(obj.getJSONObject("oauth2_install_params")); + } + return new IntegrationTypeConfiguration(oauth2InstallParams); + } + } }