Skip to content

Commit

Permalink
Revert "feat(json): implemented 2 new classes, SJSONArray & SJSONObje…
Browse files Browse the repository at this point in the history
…ct. They are simplified versions of JSONArray & JSONObject that better fit discord.jar's needs."

This reverts commit da31efd.
  • Loading branch information
seailz committed Jul 24, 2023
1 parent 293d454 commit 027216c
Show file tree
Hide file tree
Showing 167 changed files with 1,127 additions and 1,324 deletions.
78 changes: 39 additions & 39 deletions src/main/java/com/seailz/discordjar/DiscordJar.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/java/com/seailz/discordjar/DiscordJarBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.seailz.discordjar.model.application.Intent;
import com.seailz.discordjar.utils.HTTPOnlyInfo;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONObject;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.DiscordResponse;
import com.seailz.discordjar.model.api.version.APIVersion;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.EnumSet;
Expand Down Expand Up @@ -156,7 +156,7 @@ public DiscordJarBuilder setNumShards(int numShards) {

public int getRecommendedShardCount() {
DiscordRequest req = new DiscordRequest(
new SJSONObject(),
new JSONObject(),
new HashMap<>(),
URLS.GET.GATEWAY.GET_GATEWAY_BOT,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import com.seailz.discordjar.model.role.Role;
import com.seailz.discordjar.utils.Checker;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONArray;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.json.SJSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
Expand Down Expand Up @@ -147,26 +147,26 @@ public AutomodRuleCreateAction addExemptRole(Role role) {
public CompletableFuture<AutomodRule> run() {
CompletableFuture<AutomodRule> future = new CompletableFuture<>();
future.completeAsync(() -> {
SJSONObject payload = new SJSONObject();
JSONObject payload = new JSONObject();
payload.put("name", name);
payload.put("event_type", eventType.getCode());
payload.put("trigger_type", triggerType.getCode());
if (triggerMetadata != null) payload.put("trigger_metadata", triggerMetadata.compile());

SJSONArray actionsArray = new SJSONArray();
JSONArray actionsArray = new JSONArray();
actions.stream().map(AutomodRule.Action::compile).forEach(actionsArray::put);

payload.put("actions", actionsArray);
payload.put("enabled", enabled);

if (exemptChannels != null) {
SJSONArray exemptChannelsArray = new SJSONArray();
JSONArray exemptChannelsArray = new JSONArray();
exemptChannels.stream().map(Channel::id).forEach(exemptChannelsArray::put);
payload.put("exempt_channels", exemptChannelsArray);
}

if (exemptRoles != null) {
SJSONArray exemptRolesArray = new SJSONArray();
JSONArray exemptRolesArray = new JSONArray();
exemptRoles.stream().map(Role::id).forEach(exemptRolesArray::put);
payload.put("exempt_roles", exemptRolesArray);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import com.seailz.discordjar.model.role.Role;
import com.seailz.discordjar.utils.Checker;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONArray;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.json.SJSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
Expand Down Expand Up @@ -153,26 +153,26 @@ public AutomodRuleModifyAction addExemptRole(Role role) {
public CompletableFuture<AutomodRule> run() {
CompletableFuture<AutomodRule> future = new CompletableFuture<>();
future.completeAsync(() -> {
SJSONObject payload = new SJSONObject();
JSONObject payload = new JSONObject();
payload.put("name", name);
payload.put("event_type", eventType.getCode());
payload.put("trigger_type", triggerType.getCode());
if (triggerMetadata != null) payload.put("trigger_metadata", triggerMetadata.compile());

SJSONArray actionsArray = new SJSONArray();
JSONArray actionsArray = new JSONArray();
actions.stream().map(AutomodRule.Action::compile).forEach(actionsArray::put);

payload.put("actions", actionsArray);
payload.put("enabled", enabled);

if (exemptChannels != null) {
SJSONArray exemptChannelsArray = new SJSONArray();
JSONArray exemptChannelsArray = new JSONArray();
exemptChannels.stream().map(Channel::id).forEach(exemptChannelsArray::put);
payload.put("exempt_channels", exemptChannelsArray);
}

if (exemptRoles != null) {
SJSONArray exemptRolesArray = new SJSONArray();
JSONArray exemptRolesArray = new JSONArray();
exemptRoles.stream().map(Role::id).forEach(exemptRolesArray::put);
payload.put("exempt_roles", exemptRolesArray);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import com.seailz.discordjar.model.channel.utils.ChannelType;
import com.seailz.discordjar.model.permission.PermissionOverwrite;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONArray;
import com.seailz.discordjar.utils.json.SJSONObject;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.DiscordResponse;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
Expand Down Expand Up @@ -257,7 +257,7 @@ public void setDefaultForumLayout(ForumChannel.DefaultForumLayout defaultForumLa
public CompletableFuture<Channel> run() {
CompletableFuture<Channel> future = new CompletableFuture<>();
future.completeAsync(() -> {
SJSONObject body = new SJSONObject();
JSONObject body = new JSONObject();
if (name != null) body.put("name", name);
if (type != null) body.put("type", type.getCode());
if (topic != null) body.put("topic", topic);
Expand All @@ -267,7 +267,7 @@ public CompletableFuture<Channel> run() {
if (rateLimitPerUser != -1) body.put("rate_limit_per_user", rateLimitPerUser);
if (userLimit != -1) body.put("user_limit", userLimit);
if (permissionOverwrites != null) {
SJSONArray array = new SJSONArray();
JSONArray array = new JSONArray();
for (PermissionOverwrite overwrite : permissionOverwrites) {
array.put(overwrite.compile());
}
Expand All @@ -279,7 +279,7 @@ public CompletableFuture<Channel> run() {
if (defaultAutoArchiveDuration != null) body.put("default_auto_archive_duration", defaultAutoArchiveDuration);
if (flags != -1) body.put("flags", flags);
if (availableTags != null) {
SJSONArray array = new SJSONArray();
JSONArray array = new JSONArray();
for (ForumTag tag : availableTags) {
array.put(tag.compile());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.DiscordResponse;
import com.seailz.discordjar.utils.json.SJSONObject;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
Expand Down Expand Up @@ -112,7 +112,7 @@ public CompletableFuture<Invite> run() {
throw new IllegalStateException("Target application must be set if target type is set to EMBEDDED_APPLICATION");


SJSONObject body = new SJSONObject();
JSONObject body = new JSONObject();
if (maxAge != -1) body.put("max_age", maxAge);
if (maxUses != -1) body.put("max_uses", maxUses);
if (temporary) body.put("temporary", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.seailz.discordjar.model.guild.Guild;
import com.seailz.discordjar.utils.Checker;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONObject;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.DiscordResponse;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
Expand Down Expand Up @@ -93,7 +93,7 @@ public List<Guild> run() {
DiscordResponse response = null;
try {
response = new DiscordRequest(
new SJSONObject(),
new JSONObject(),
new HashMap<>(),
url,
discordJar,
Expand All @@ -105,7 +105,7 @@ public List<Guild> run() {
}

List<Guild> returnGuilds = new ArrayList<>();
response.arr().forEach(guild -> returnGuilds.add(Guild.decompile((SJSONObject) guild, discordJar)));
response.arr().forEach(guild -> returnGuilds.add(Guild.decompile((JSONObject) guild, discordJar)));

returnGuilds.forEach(g -> discordJar.getGuildCache().cache(g));
return returnGuilds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.seailz.discordjar.model.guild.Guild;
import com.seailz.discordjar.model.permission.PermissionOverwrite;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONObject;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.DiscordResponse;
import com.seailz.discordjar.utils.rest.Response;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class CreateGuildChannelAction {

Expand Down Expand Up @@ -100,13 +102,13 @@ public Response<GuildChannel> run() {
try {
GuildChannel chan = GuildChannel.decompile(
new DiscordRequest(
new SJSONObject()
new JSONObject()
.put("name", name)
.put("type", type.getCode())
.put("topic", topic != null ? topic : SJSONObject.NULL)
.put("topic", topic != null ? topic : JSONObject.NULL)
.put("position", position)
.put("permission_overwrites", permissionOverwrites)
.put("parent_id", categoryId != null ? categoryId : SJSONObject.NULL),
.put("parent_id", categoryId != null ? categoryId : JSONObject.NULL),
new HashMap<>(),
URLS.POST.GUILDS.CHANNELS.CREATE.replace("{guild.id}", guild.id()),
discordJar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import com.seailz.discordjar.model.message.Attachment;
import com.seailz.discordjar.model.message.Message;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONObject;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.Response;
import org.jetbrains.annotations.Nullable;
import com.seailz.discordjar.utils.json.SJSONArray;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class EditInteractionMessageAction {

Expand Down Expand Up @@ -127,10 +128,10 @@ public EditInteractionMessageAction addComponent(DisplayComponent component) {
public Response<Message> run() {
Response<Message> future = new Response<>();
new Thread(() -> {
SJSONObject obj = new SJSONObject();
JSONObject obj = new JSONObject();
if (content != null) obj.put("content", content);
if (embeds != null) {
SJSONArray embeds = new SJSONArray();
JSONArray embeds = new JSONArray();
for (Embeder embed : this.embeds) {
embeds.put(embed.compile());
}
Expand All @@ -139,7 +140,7 @@ public Response<Message> run() {
}

if (components != null) {
SJSONArray components = new SJSONArray();
JSONArray components = new JSONArray();
for (DisplayComponent component : this.components) {
components.put(component.compile());
}
Expand All @@ -148,7 +149,7 @@ public Response<Message> run() {
}

if (attachments != null) {
SJSONArray attachments = new SJSONArray();
JSONArray attachments = new JSONArray();
for (Attachment attachment : this.attachments) {
attachments.put(attachment.compile());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.Response;
import com.seailz.discordjar.utils.json.SJSONObject;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.File;
Expand Down Expand Up @@ -47,7 +47,7 @@ public InteractionReply getReply() {
}

public Response<InteractionHandler> run() {
SJSONObject json = new SJSONObject();
JSONObject json = new JSONObject();
json.put("type", this.type.getCode());
json.put("data", this.reply.compile());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
import com.seailz.discordjar.model.message.MessageFlag;
import com.seailz.discordjar.model.message.MessageReference;
import com.seailz.discordjar.utils.URLS;
import com.seailz.discordjar.utils.json.SJSONArray;
import com.seailz.discordjar.utils.json.SJSONObject;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import com.seailz.discordjar.utils.rest.DiscordResponse;
import com.seailz.discordjar.utils.rest.Response;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.File;
import java.util.*;
import java.util.concurrent.CompletableFuture;

/**
* Used to create a message and define extra properties
Expand Down Expand Up @@ -266,7 +267,7 @@ public Response<Message> run() {
new Thread(() -> {
String url = URLS.POST.MESSAGES.SEND.replace("{channel.id}", channelId);

SJSONObject payload = new SJSONObject();
JSONObject payload = new JSONObject();
if (this.text != null) payload.put("content", this.text);
if (this.nonce != null) payload.put("nonce", this.nonce);
if (this.tts) payload.put("tts", true);
Expand All @@ -281,7 +282,7 @@ public Response<Message> run() {
payload.put("duration", this.duration);
}

SJSONArray components = new SJSONArray();
JSONArray components = new JSONArray();
if (this.components != null && !this.components.isEmpty()) {
for (DisplayComponent component : this.components) {
components.put(component.compile());
Expand All @@ -291,7 +292,7 @@ public Response<Message> run() {
if (this.components != null && !this.components.isEmpty())
payload.put("components", components);

SJSONArray embeds = new SJSONArray();
JSONArray embeds = new JSONArray();
if (this.embeds != null) {
for (Embeder embed : this.embeds) {
embeds.put(embed.compile());
Expand All @@ -301,7 +302,7 @@ public Response<Message> run() {
if (this.embeds != null)
payload.put("embeds", embeds);

SJSONArray stickerIds = new SJSONArray();
JSONArray stickerIds = new JSONArray();
if (this.stickerIds != null) {
for (String stickerId : this.stickerIds) {
stickerIds.put(stickerId);
Expand All @@ -312,7 +313,7 @@ public Response<Message> run() {
payload.put("sticker_ids", stickerIds);

if (this.attachments != null) {
SJSONArray files = new SJSONArray();
JSONArray files = new JSONArray();
for (Attachment attachment : this.attachments) {
files.put(attachment.compile());
}
Expand Down
Loading

0 comments on commit 027216c

Please sign in to comment.