-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from discord-jar/feature/incidentactions
feat(guilds): implemented support for incident actions
- Loading branch information
Showing
3 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/com/seailz/discordjar/model/guild/incident/IncidentsData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters