From 6a703c4e21fd101f80607756fc21b7b75ed236bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 05:00:48 +0000 Subject: [PATCH 01/12] build(deps): bump org.apache.maven.plugins:maven-shade-plugin Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.1 to 3.5.2. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.1...maven-shade-plugin-3.5.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c79475e..b38564ff 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.1 + 3.5.2 package From 3bf94cad3156da9b7ba8cd20563f14fa2d44d7bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 04:56:54 +0000 Subject: [PATCH 02/12] build(deps): bump org.json:json from 20240205 to 20240303 Bumps [org.json:json](https://github.com/douglascrockford/JSON-java) from 20240205 to 20240303. - [Release notes](https://github.com/douglascrockford/JSON-java/releases) - [Changelog](https://github.com/stleary/JSON-java/blob/master/docs/RELEASES.md) - [Commits](https://github.com/douglascrockford/JSON-java/commits) --- updated-dependencies: - dependency-name: org.json:json dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c79475e..82a9340f 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,7 @@ org.json json - 20240205 + 20240303 com.google.code.gson From d6d092316b490c68549eb049308ebe152365c1fd Mon Sep 17 00:00:00 2001 From: George <81972974+seailz@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:04:14 +0000 Subject: [PATCH 03/12] Update README.md --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84ef0c5b..f27faba5 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,14 @@ https://discord.gg/tmvS8A57J4 Before we start - please note that discord.jar is still a work in progress and there are some risks of deploying it in a production enviroment. +## Example Usages +- [Tune](https://github.com/seailz/Tune) An example Discord Music bot built using discord.jar & LavaPlayer in just 1 hour, that's how simple it is! + +## Tools built for Discord.jar +
    +
  • Discript - a scripting language to simplify bot development.
  • +
+ ### Prerequisites You'll need to add discord.jar to your project's dependencies. We are currently using @@ -189,9 +197,6 @@ To contribute to the `/examples` module, please see [here](https://github.com/di ## License License info can be found [here](https://github.com/discord-jar/discord.jar/blob/main/LICENSE). This project is licensed under GNU General Public License V3 -## Example Usages -- [Tune](https://github.com/seailz/Tune) An example Discord Music bot built using discord.jar & LavaPlayer in just 1 hour, that's how simple it is! - ## Contact Our official Discord server: From 2232b28ffdb066a7b2625f412a44792626fa8a8e Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:48:50 -0700 Subject: [PATCH 04/12] fix(commands): Null check possibly null types in decompile --- src/main/java/com/seailz/discordjar/command/Command.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/seailz/discordjar/command/Command.java b/src/main/java/com/seailz/discordjar/command/Command.java index ecee0993..f8ecbfb4 100644 --- a/src/main/java/com/seailz/discordjar/command/Command.java +++ b/src/main/java/com/seailz/discordjar/command/Command.java @@ -89,21 +89,21 @@ public static Command decompile(JSONObject obj) { boolean canUseInDms = true; boolean nsfw = false; - if (obj.has("name_localizations")) { + if (obj.has("name_localizations") && !obj.isNull("name_localizations")) { JSONObject nameLocalesJson = obj.getJSONObject("name_localizations"); for (String locale : nameLocalesJson.keySet()) { nameLocales.put(locale, nameLocalesJson.getString(locale)); } } - if (obj.has("description_localizations")) { + if (obj.has("description_localizations") && !obj.isNull("description_localizations")) { JSONObject descriptionLocalesJson = obj.getJSONObject("description_localizations"); for (String locale : descriptionLocalesJson.keySet()) { descriptionLocales.put(locale, descriptionLocalesJson.getString(locale)); } } - if (obj.has("default_member_permissions")) { + if (obj.has("default_member_permissions") && !obj.isNull("default_member_permissions")) { int permissions = obj.getInt("default_member_permissions"); BitwiseUtil util = new BitwiseUtil<>(); EnumSet permissionsList = util.get(permissions, Permission.class); From 2dff812d4e619cca0759d5347d18a8a5dfa7daef Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Sat, 16 Mar 2024 21:42:33 -0700 Subject: [PATCH 05/12] refactor(events): Validate listeners --- .../com/seailz/discordjar/events/EventDispatcher.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/seailz/discordjar/events/EventDispatcher.java b/src/main/java/com/seailz/discordjar/events/EventDispatcher.java index b1e9d890..0c52201b 100644 --- a/src/main/java/com/seailz/discordjar/events/EventDispatcher.java +++ b/src/main/java/com/seailz/discordjar/events/EventDispatcher.java @@ -55,7 +55,15 @@ public void addListener(DiscordListener... listeners) { for (DiscordListener listener : listeners) { for (Method method : listener.getClass().getMethods()) { if (method.isAnnotationPresent(EventMethod.class)) { - Class eventType = (Class) method.getParameterTypes()[0]; + Class maybeEventType = method.getParameterTypes()[0]; + + if (!Event.class.isAssignableFrom(maybeEventType)) + throw new IllegalArgumentException(String.format("%s first arg is not of Event", method)); + else if (method.getParameterTypes().length > 1) + throw new IllegalArgumentException(String.format("%s#%s is an invalid listener", method.getDeclaringClass(), method.getName())); + + @SuppressWarnings("unchecked") + Class eventType = (Class) maybeEventType; EventMethod eventMethod = method.getAnnotation(EventMethod.class); String customId = null; From a96e3b0ed8b2393229ba0224799bc2f5dee4c3c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 04:30:25 +0000 Subject: [PATCH 06/12] build(deps): bump org.apache.maven.plugins:maven-compiler-plugin Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.1 to 3.13.0. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.1...maven-compiler-plugin-3.13.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c79475e..4b1f522a 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.13.0 ${java.version} ${java.version} From 47b5a99bf79cfdd6e9b5214262f38021e1e50683 Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:03:36 -0700 Subject: [PATCH 07/12] refactor(events): Fix parameter validation Co-authored-by: George <81972974+seailz@users.noreply.github.com> --- src/main/java/com/seailz/discordjar/events/EventDispatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/seailz/discordjar/events/EventDispatcher.java b/src/main/java/com/seailz/discordjar/events/EventDispatcher.java index 0c52201b..b1509501 100644 --- a/src/main/java/com/seailz/discordjar/events/EventDispatcher.java +++ b/src/main/java/com/seailz/discordjar/events/EventDispatcher.java @@ -59,7 +59,7 @@ public void addListener(DiscordListener... listeners) { if (!Event.class.isAssignableFrom(maybeEventType)) throw new IllegalArgumentException(String.format("%s first arg is not of Event", method)); - else if (method.getParameterTypes().length > 1) + else if (method.getParameterTypes().length != 1) throw new IllegalArgumentException(String.format("%s#%s is an invalid listener", method.getDeclaringClass(), method.getName())); @SuppressWarnings("unchecked") From 37a5ac430ad7f3cfceca0fb3671586e481f90161 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 04:14:28 +0000 Subject: [PATCH 08/12] build(deps): bump org.springframework.boot:spring-boot-starter-websocket Bumps [org.springframework.boot:spring-boot-starter-websocket](https://github.com/spring-projects/spring-boot) from 3.2.3 to 3.2.4. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.2.3...v3.2.4) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-websocket dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c79475e..932341fb 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ org.springframework.boot spring-boot-starter-websocket - 3.2.3 + 3.2.4 From 9f869e79e6b63ccfce4e926b901afadc71e91469 Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Sat, 23 Mar 2024 18:21:35 -0700 Subject: [PATCH 09/12] refactor(Guild): Drop IllegalAccessException --- src/main/java/com/seailz/discordjar/model/guild/Guild.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/seailz/discordjar/model/guild/Guild.java b/src/main/java/com/seailz/discordjar/model/guild/Guild.java index a33e75be..c01a8732 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/Guild.java +++ b/src/main/java/com/seailz/discordjar/model/guild/Guild.java @@ -1232,7 +1232,7 @@ public StringFormatter formatter() { *

* This action is irreversible! */ - public void delete() throws IllegalAccessException { + public void delete() { DiscordResponse response; try { response = new DiscordRequest( From 367824308ca3ff02a05115025cc17591b4842e12 Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:35:43 -0700 Subject: [PATCH 10/12] refactor(model): Fix NPE in Guild#roles --- src/main/java/com/seailz/discordjar/model/guild/Guild.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/seailz/discordjar/model/guild/Guild.java b/src/main/java/com/seailz/discordjar/model/guild/Guild.java index a33e75be..b7308763 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/Guild.java +++ b/src/main/java/com/seailz/discordjar/model/guild/Guild.java @@ -1138,6 +1138,7 @@ public List roles() { } if (res == null) { System.out.println(response.code() + " " + (response.body() == null ? "null" : response.body().toString())); + return List.of(); } res.forEach(o -> roles.add(Role.decompile((JSONObject) o))); From 9755541f68152c02b54f4cfed49507f830ab4116 Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:51:54 -0700 Subject: [PATCH 11/12] refactor(rest): Remove unneeded null guard --- .../java/com/seailz/discordjar/utils/rest/DiscordRequest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java b/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java index c7aadb17..3c40b38d 100644 --- a/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java +++ b/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java @@ -240,9 +240,6 @@ private DiscordResponse invoke(String contentType, boolean auth) throws Unhandle if (auth) { requestBuilder.addHeader("Authorization", "Bot " + djv.getToken()); } - if (contentType == null) { - requestBuilder.addHeader("Content-Type", "application/json"); - } if (contentType != null) { requestBuilder.addHeader("Content-Type", contentType); } From c0562f7c55c5473d582f1d33dd38caaa0789774f Mon Sep 17 00:00:00 2001 From: seailz Date: Fri, 29 Mar 2024 16:18:09 +0000 Subject: [PATCH 12/12] 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); + } + } }