Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
seailz committed Feb 25, 2024
2 parents cf3cbb4 + b6b38b2 commit 014db28
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.0</version>
<version>1.16.1</version>
</dependency>
<!-- Used for interaction-only bot security -->
<dependency>
Expand All @@ -105,7 +105,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>3.2.1</version>
<version>3.2.3</version>
</dependency>
<!-- Used for marking methods and params -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MessageCreateAction {

private String text;
private String nonce;
private boolean enforceNonce;
private boolean tts;
private List<Embeder> embeds;
private MessageReference messageReference;
Expand Down Expand Up @@ -78,9 +79,10 @@ public MessageCreateAction(LinkedList<Attachment> attachments, @NotNull String c
this.stickerIds = new ArrayList<>();
}

public MessageCreateAction(@Nullable String text, @Nullable String nonce, boolean tts, @Nullable MessageReference messageReference, @Nullable List<DisplayComponent> components, @Nullable List<String> stickerIds, @Nullable List<Attachment> 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<DisplayComponent> components, @Nullable List<String> stickerIds, @Nullable List<Attachment> 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;
Expand All @@ -99,6 +101,10 @@ public String nonce() {
return nonce;
}

public boolean enforceNonce() {
return enforceNonce;
}

public boolean tts() {
return tts;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -270,6 +281,7 @@ public Response<Message> 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) {
Expand Down
40 changes: 37 additions & 3 deletions src/main/java/com/seailz/discordjar/model/guild/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -143,7 +146,7 @@ public Guild(
List<Sticker> stickers,
boolean premiumProgressBarEnabled,
String safetyAlertChannelId,
DiscordJar discordJar,
IncidentsData incidentsData, DiscordJar discordJar,
JsonCache roleCache
) {
this.id = id;
Expand Down Expand Up @@ -187,6 +190,7 @@ public Guild(
this.stickers = stickers;
this.premiumProgressBarEnabled = premiumProgressBarEnabled;
this.safetyAlertChannelId = safetyAlertChannelId;
this.incidentsData = incidentsData;
this.discordJar = discordJar;
this.roleCache = roleCache;
}
Expand Down Expand Up @@ -330,6 +334,9 @@ public List<Sticker> stickers() {
public boolean premiumProgressBarEnabled() {
return premiumProgressBarEnabled;
}
public IncidentsData incidentsData() {
return incidentsData;
}

public DiscordJar discordJar() {
return discordJar;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<>(),
Expand Down Expand Up @@ -1735,6 +1745,30 @@ public Response<Void> deleteScheduledEvent(String id) {
return res;
}

public Response<Void> modifyGuildIncidentActions(@NotNull IncidentsData incidentsData) {
Response<Void> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
* <br> 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)
);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/seailz/discordjar/utils/URLS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
Expand Down

0 comments on commit 014db28

Please sign in to comment.