diff --git a/pom.xml b/pom.xml index 24469090..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 @@ -82,7 +82,7 @@ commons-codec commons-codec - 1.16.0 + 1.16.1 @@ -105,7 +105,7 @@ org.springframework.boot spring-boot-starter-websocket - 3.2.1 + 3.2.3 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..df1b0d8c 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) { 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 1d5a0da9..a33e75be 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 @@ -676,6 +684,8 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar, boolean byp 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, @@ -718,7 +728,7 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar, boolean byp stickers, premiumProgressBarEnabled, safetyAlertsChannelId, - discordJar, + incidentsData, discordJar, JsonCache.newc(new DiscordRequest( new JSONObject(), new HashMap<>(), @@ -1735,6 +1745,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.PUT + ).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..3422b8a0 --- /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 == null ? JSONObject.NULL : invitesDisabledUntil.toString()) + .put("dms_disabled_until", dmsDisabledUntil == null ? JSONObject.NULL : 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 8e3396d3..93ca1080 100644 --- a/src/main/java/com/seailz/discordjar/utils/URLS.java +++ b/src/main/java/com/seailz/discordjar/utils/URLS.java @@ -447,6 +447,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}"; }