From e0df2fe94dd580a497bdee6b4d5e935f48d3b768 Mon Sep 17 00:00:00 2001 From: IoyoCode Date: Fri, 29 Sep 2023 16:38:30 +0100 Subject: [PATCH 1/8] feat(guilds): implemented support for incident actions --- .../seailz/discordjar/model/guild/Guild.java | 40 ++++++++++- .../model/guild/incident/IncidentsData.java | 71 +++++++++++++++++++ .../com/seailz/discordjar/utils/URLS.java | 1 + 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java 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 4739337d..bdcdcd32 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/Guild.java +++ b/src/main/java/com/seailz/discordjar/model/guild/Guild.java @@ -19,6 +19,7 @@ import com.seailz.discordjar.model.emoji.Emoji; import com.seailz.discordjar.model.emoji.sticker.Sticker; import com.seailz.discordjar.model.guild.filter.ExplicitContentFilterLevel; +import com.seailz.discordjar.model.guild.incident.IncidentsData; import com.seailz.discordjar.model.guild.mfa.MFALevel; import com.seailz.discordjar.model.guild.notification.DefaultMessageNotificationLevel; import com.seailz.discordjar.model.guild.premium.PremiumTier; @@ -98,6 +99,8 @@ public class Guild implements Compilerable, Snowflake, CDNAble { private final boolean premiumProgressBarEnabled; private final String safetyAlertChannelId; private Channel safetyAlertChannel = null; + private final IncidentsData incidentsData; + private final DiscordJar discordJar; private final JsonCache roleCache; @@ -143,7 +146,7 @@ public Guild( List stickers, boolean premiumProgressBarEnabled, String safetyAlertChannelId, - DiscordJar discordJar, + IncidentsData incidentsData, DiscordJar discordJar, JsonCache roleCache ) { this.id = id; @@ -187,6 +190,7 @@ public Guild( this.stickers = stickers; this.premiumProgressBarEnabled = premiumProgressBarEnabled; this.safetyAlertChannelId = safetyAlertChannelId; + this.incidentsData = incidentsData; this.discordJar = discordJar; this.roleCache = roleCache; } @@ -330,6 +334,9 @@ public List stickers() { public boolean premiumProgressBarEnabled() { return premiumProgressBarEnabled; } + public IncidentsData incidentsData() { + return incidentsData; + } public DiscordJar discordJar() { return discordJar; @@ -381,7 +388,8 @@ public JSONObject compile() { .put("welcome_screen", welcomeScreen) .put("stickers", stickers) .put("premium_progress_bar_enabled", premiumProgressBarEnabled) - .put("safety_alerts_channel_id", safetyAlertChannelId); + .put("safety_alerts_channel_id", safetyAlertChannelId) + .put("incidents_data", incidentsData.compile()); } @NotNull @@ -671,6 +679,8 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar) { safetyAlertsChannelId = obj.getString("safety_alerts_channel_id"); } + IncidentsData incidentsData = obj.has("incidents_data") && !obj.isNull("incidents_data") ? IncidentsData.decompile(obj.getJSONObject("incidents_data")) : null; + Guild g = new Guild( id, name, @@ -713,7 +723,7 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar) { stickers, premiumProgressBarEnabled, safetyAlertsChannelId, - discordJar, + incidentsData, discordJar, JsonCache.newc(new DiscordRequest( new JSONObject(), new HashMap<>(), @@ -1730,6 +1740,30 @@ public Response deleteScheduledEvent(String id) { return res; } + public Response modifyGuildIncidentActions(@NotNull IncidentsData incidentsData) { + Response res = new Response<>(); + new java.lang.Thread(() -> { + try { + new DiscordRequest( + incidentsData.compile(), + new HashMap<>(), + URLS.PATCH.GUILD.MODIFY_GUILD_INCIDENT_ACTIONS.replace("{guild.id}", this.id), + discordJar, + URLS.PATCH.GUILD.MODIFY_GUILD_INCIDENT_ACTIONS, + RequestMethod.PATCH + ).invoke(); + res.complete(null); + } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { + res.completeError(new Response.Error( + e.getCode(), + e.getMessage(), + e.getBody() + )); + } + }).start(); + return res; + } + public @NotNull ModifyScheduledEventAction modifyScheduledEvent(String id) { return new ModifyScheduledEventAction(discordJar, this.id, id); } diff --git a/src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java b/src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java new file mode 100644 index 00000000..48fdaac8 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java @@ -0,0 +1,71 @@ +package com.seailz.discordjar.model.guild.incident; + +import com.seailz.discordjar.core.Compilerable; +import org.jetbrains.annotations.NotNull; +import org.joda.time.DateTime; +import org.json.JSONObject; + +/** + * Represents an IncidentsData object. + *
Each value is nullable & has a limit of 24 hours into the future. + */ +public record IncidentsData( + DateTime invitesDisabledUntil, + DateTime dmsDisabledUntil +) implements Compilerable { + + public boolean areInvitesDisabled() { + if (invitesDisabledUntil == null) return false; + return invitesDisabledUntil.isAfterNow(); + } + + public boolean areDmsDisabled() { + if (dmsDisabledUntil == null) return false; + return dmsDisabledUntil.isAfterNow(); + } + + @Override + public JSONObject compile() { + return new JSONObject() + .put("invites_disabled_until", invitesDisabledUntil.toString()) + .put("dms_disabled_until", dmsDisabledUntil.toString()); + } + + public static IncidentsData decompile(@NotNull JSONObject obj) { + DateTime invitesDisabledUntil = obj.has("invites_disabled_until") && !obj.isNull("invites_disabled_until") ? DateTime.parse(obj.getString("invites_disabled_until")) : null; + DateTime dmsDisabledUntil = obj.has("dms_disabled_until") && !obj.isNull("dms_disabled_until") ? DateTime.parse(obj.getString("dms_disabled_until")) : null; + + return new IncidentsData( + invitesDisabledUntil, + dmsDisabledUntil + ); + } + + public static IncidentsData none() { + return new IncidentsData( + null, + null + ); + } + + public static IncidentsData invitesDisabled23Hours() { + return new IncidentsData( + DateTime.now().plusHours(23), + null + ); + } + + public static IncidentsData dmsDisabled23Hours() { + return new IncidentsData( + null, + DateTime.now().plusHours(23) + ); + } + + public static IncidentsData allDisabled23Hours() { + return new IncidentsData( + DateTime.now().plusHours(23), + DateTime.now().plusHours(23) + ); + } +} diff --git a/src/main/java/com/seailz/discordjar/utils/URLS.java b/src/main/java/com/seailz/discordjar/utils/URLS.java index 4e80c0d1..dac71d82 100644 --- a/src/main/java/com/seailz/discordjar/utils/URLS.java +++ b/src/main/java/com/seailz/discordjar/utils/URLS.java @@ -445,6 +445,7 @@ public static class COMMANDS { public static class PATCH { public static class GUILD { + public static String MODIFY_GUILD_INCIDENT_ACTIONS = "/guilds/{guild.id}/incident-actions"; public static class SCHEDULED_EVENTS { public static String MODIFY_GUILD_SCHEDULED_EVENT = "/guilds/{guild.id}/scheduled-events/{event.id}"; } From cf68f133273c2dad9b9afdd624cfb40a6b8f11d7 Mon Sep 17 00:00:00 2001 From: IoyoCode Date: Thu, 26 Oct 2023 12:26:52 +0100 Subject: [PATCH 2/8] fix(incident-actions): fixed an issue with IncidentsData#compile where if either of the values were null it would fail to compile and throw a null pointer exception --- .../seailz/discordjar/model/guild/incident/IncidentsData.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java b/src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java index 48fdaac8..3422b8a0 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java +++ b/src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java @@ -27,8 +27,8 @@ public boolean areDmsDisabled() { @Override public JSONObject compile() { return new JSONObject() - .put("invites_disabled_until", invitesDisabledUntil.toString()) - .put("dms_disabled_until", dmsDisabledUntil.toString()); + .put("invites_disabled_until", invitesDisabledUntil == null ? JSONObject.NULL : invitesDisabledUntil.toString()) + .put("dms_disabled_until", dmsDisabledUntil == null ? JSONObject.NULL : dmsDisabledUntil.toString()); } public static IncidentsData decompile(@NotNull JSONObject obj) { From 68beb7849d81420fb007a091f4bd05d0b1d1aa0f Mon Sep 17 00:00:00 2001 From: IoyoCode Date: Thu, 26 Oct 2023 12:32:44 +0100 Subject: [PATCH 3/8] fix(incident-actions): Guild#modifyGuildIncidentActions was using the wrong HTTP verb --- 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 bdcdcd32..7e94ea3d 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/Guild.java +++ b/src/main/java/com/seailz/discordjar/model/guild/Guild.java @@ -1750,7 +1750,7 @@ public Response modifyGuildIncidentActions(@NotNull IncidentsData incident URLS.PATCH.GUILD.MODIFY_GUILD_INCIDENT_ACTIONS.replace("{guild.id}", this.id), discordJar, URLS.PATCH.GUILD.MODIFY_GUILD_INCIDENT_ACTIONS, - RequestMethod.PATCH + RequestMethod.PUT ).invoke(); res.complete(null); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { From 4d6f2b228946b522c708ff8727203fe28ea39536 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Feb 2024 04:08:07 +0000 Subject: [PATCH 4/8] build(deps): bump commons-codec:commons-codec from 1.16.0 to 1.16.1 Bumps [commons-codec:commons-codec](https://github.com/apache/commons-codec) from 1.16.0 to 1.16.1. - [Changelog](https://github.com/apache/commons-codec/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/apache/commons-codec/compare/rel/commons-codec-1.16.0...rel/commons-codec-1.16.1) --- updated-dependencies: - dependency-name: commons-codec:commons-codec 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 24469090..0d996e1c 100644 --- a/pom.xml +++ b/pom.xml @@ -82,7 +82,7 @@ commons-codec commons-codec - 1.16.0 + 1.16.1 From 8cc15477f64215293f0d727666d01d9622d0385f Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:40:13 -0800 Subject: [PATCH 5/8] feat(MessageCreateAction): add `enforceNonce` parameter --- .../action/message/MessageCreateAction.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java b/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java index f2e21d86..e8c925f2 100644 --- a/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java +++ b/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java @@ -34,6 +34,7 @@ public class MessageCreateAction { private String text; private String nonce; + private boolean enforceNonce; private boolean tts; private List embeds; private MessageReference messageReference; @@ -78,9 +79,10 @@ public MessageCreateAction(LinkedList attachments, @NotNull String c this.stickerIds = new ArrayList<>(); } - public MessageCreateAction(@Nullable String text, @Nullable String nonce, boolean tts, @Nullable MessageReference messageReference, @Nullable List components, @Nullable List stickerIds, @Nullable List attachments, boolean supressEmbeds, @NotNull String channelId, @NotNull DiscordJar discordJar) { + public MessageCreateAction(@Nullable String text, @Nullable String nonce, boolean enforceNonce, boolean tts, @Nullable MessageReference messageReference, @Nullable List components, @Nullable List stickerIds, @Nullable List attachments, boolean supressEmbeds, @NotNull String channelId, @NotNull DiscordJar discordJar) { this.text = text; this.nonce = nonce; + this.enforceNonce = enforceNonce; this.tts = tts; this.messageReference = messageReference; this.components = components; @@ -99,6 +101,10 @@ public String nonce() { return nonce; } + public boolean enforceNonce() { + return enforceNonce; + } + public boolean tts() { return tts; } @@ -158,6 +164,11 @@ public MessageCreateAction setNonce(@Nullable String nonce) { return this; } + public MessageCreateAction setEnforceNonce(boolean enforceNonce) { + this.enforceNonce = enforceNonce; + return this; + } + public MessageCreateAction setTts(boolean tts) { this.tts = tts; return this; @@ -270,6 +281,7 @@ public Response run() { JSONObject payload = new JSONObject(); if (this.text != null) payload.put("content", this.text); if (this.nonce != null) payload.put("nonce", this.nonce); + if (this.enforceNonce) payload.put("enforce_nonce", true); if (this.tts) payload.put("tts", true); if (this.messageReference != null) payload.put("message_reference", this.messageReference.compile()); if (this.waveform != null) { From da908b363dcb1702cd0530feb9fdad6b2799ccf6 Mon Sep 17 00:00:00 2001 From: Fury_Phoenix <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:45:50 -0800 Subject: [PATCH 6/8] Fix indentation --- .../action/message/MessageCreateAction.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java b/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java index e8c925f2..df1b0d8c 100644 --- a/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java +++ b/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java @@ -101,9 +101,9 @@ public String nonce() { return nonce; } - public boolean enforceNonce() { - return enforceNonce; - } + public boolean enforceNonce() { + return enforceNonce; + } public boolean tts() { return tts; @@ -164,10 +164,10 @@ public MessageCreateAction setNonce(@Nullable String nonce) { return this; } - public MessageCreateAction setEnforceNonce(boolean enforceNonce) { - this.enforceNonce = enforceNonce; - return this; - } + public MessageCreateAction setEnforceNonce(boolean enforceNonce) { + this.enforceNonce = enforceNonce; + return this; + } public MessageCreateAction setTts(boolean tts) { this.tts = tts; From b14259effb114c137ba05812a77d98c54bb076c0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 04:41:58 +0000 Subject: [PATCH 7/8] 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 24469090..a6efe28b 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 d04ca4fafb0bd5b873966492cc93e60b7a11d375 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 04:25:44 +0000 Subject: [PATCH 8/8] 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.1 to 3.2.3. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](https://github.com/spring-projects/spring-boot/compare/v3.2.1...v3.2.3) --- 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 24469090..beddda92 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ org.springframework.boot spring-boot-starter-websocket - 3.2.1 + 3.2.3