From da31efd23d4206ec909501c7d0433402c3ead38c Mon Sep 17 00:00:00 2001 From: IoyoCode Date: Sun, 23 Jul 2023 22:03:50 +0100 Subject: [PATCH] feat(json): implemented 2 new classes, SJSONArray & SJSONObject. They are simplified versions of JSONArray & JSONObject that better fit discord.jar's needs. --- .../com/seailz/discordjar/DiscordJar.java | 78 ++++---- .../seailz/discordjar/DiscordJarBuilder.java | 4 +- .../automod/AutomodRuleCreateAction.java | 12 +- .../automod/AutomodRuleModifyAction.java | 12 +- .../channel/ModifyBaseChannelAction.java | 10 +- .../invites/CreateChannelInviteAction.java | 4 +- .../guild/GetCurrentUserGuildsAction.java | 6 +- .../channel/CreateGuildChannelAction.java | 10 +- .../EditInteractionMessageAction.java | 13 +- .../InteractionCallbackAction.java | 4 +- .../action/message/MessageCreateAction.java | 15 +- .../action/message/MessageEditAction.java | 13 +- .../StartThreadForumChannelAction.java | 20 +- .../action/sticker/ModifyStickerAction.java | 10 +- .../com/seailz/discordjar/cache/Cache.java | 10 +- .../seailz/discordjar/cache/JsonCache.java | 8 +- .../discordjar/cache/impl/JsonCacheImpl.java | 10 +- .../seailz/discordjar/command/Command.java | 22 +-- .../discordjar/command/CommandChoice.java | 8 +- .../discordjar/command/CommandOption.java | 24 +-- .../listeners/slash/SlashSubCommand.java | 14 +- .../listeners/slash/SubCommandGroup.java | 10 +- .../ApplicationCommandPermissions.java | 14 +- .../ApplicationCommandPermissionsData.java | 8 +- .../seailz/discordjar/core/Compilerable.java | 4 +- .../seailz/discordjar/events/model/Event.java | 8 +- .../model/automod/AutoModExecutionEvent.java | 6 +- .../automod/rule/AutoModRuleCreateEvent.java | 4 +- .../automod/rule/AutoModRuleDeleteEvent.java | 4 +- .../model/automod/rule/AutoModRuleEvent.java | 5 +- .../automod/rule/AutoModRuleUpdateEvent.java | 4 +- .../events/model/channel/ChannelEvent.java | 4 +- .../model/channel/ChannelPinsUpdateEvent.java | 6 +- .../channel/edit/ChannelCreateEvent.java | 5 +- .../channel/edit/ChannelDeleteEvent.java | 4 +- .../channel/edit/ChannelUpdateEvent.java | 4 +- .../command/CommandPermissionUpdateEvent.java | 4 +- .../model/gateway/GatewayResumedEvent.java | 4 +- .../events/model/general/ReadyEvent.java | 6 +- .../events/model/guild/GuildCreateEvent.java | 4 +- .../events/model/guild/GuildDeleteEvent.java | 4 +- .../events/model/guild/GuildEvent.java | 5 +- .../events/model/guild/GuildUpdateEvent.java | 4 +- .../guild/member/GuildMemberAddEvent.java | 6 +- .../guild/member/GuildMemberRemoveEvent.java | 4 +- .../guild/member/GuildMemberUpdateEvent.java | 5 +- .../model/interaction/InteractionEvent.java | 4 +- .../button/ButtonInteractionEvent.java | 4 +- .../command/CommandInteractionEvent.java | 4 +- ...MessageContextCommandInteractionEvent.java | 6 +- .../command/SlashCommandInteractionEvent.java | 14 +- .../UserContextCommandInteractionEvent.java | 6 +- .../modal/ModalInteractionEvent.java | 4 +- .../StringSelectMenuInteractionEvent.java | 5 +- .../ChannelSelectMenuInteractionEvent.java | 5 +- .../RoleSelectMenuInteractionEvent.java | 4 +- .../UserSelectMenuInteractionEvent.java | 5 +- .../model/message/MessageCreateEvent.java | 4 +- .../events/model/message/MessageEvent.java | 4 +- .../model/message/TypingStartEvent.java | 6 +- .../discordjar/gateway/GatewayFactory.java | 32 ++-- .../gateway/events/DispatchedEvents.java | 24 +-- .../discordjar/gateway/heartbeat/Heart.java | 4 +- .../discordjar/http/HttpOnlyManager.java | 30 +-- .../model/application/Application.java | 18 +- .../ApplicationRoleConnectionMetadata.java | 16 +- .../discordjar/model/automod/AutomodRule.java | 73 ++++---- .../model/channel/AudioChannel.java | 9 +- .../discordjar/model/channel/Category.java | 9 +- .../model/channel/CategoryMember.java | 4 +- .../discordjar/model/channel/Channel.java | 8 +- .../discordjar/model/channel/DMChannel.java | 18 +- .../model/channel/ForumChannel.java | 20 +- .../discordjar/model/channel/GroupDM.java | 10 +- .../model/channel/GuildChannel.java | 22 +-- .../model/channel/MessagingChannel.java | 48 +---- .../discordjar/model/channel/UserDM.java | 10 +- .../model/channel/VoiceChannel.java | 14 +- .../model/channel/audio/VoiceRegion.java | 4 +- .../model/channel/forum/DefaultReaction.java | 8 +- .../model/channel/forum/ForumTag.java | 8 +- .../interfaces/MessageRetrievable.java | 40 ++-- .../model/channel/interfaces/Typeable.java | 4 +- .../channel/internal/AudioChannelImpl.java | 4 +- .../model/channel/internal/CategoryImpl.java | 4 +- .../model/channel/internal/ChannelImpl.java | 14 +- .../model/channel/internal/DMChannelImpl.java | 4 +- .../channel/internal/ForumChannelImpl.java | 4 +- .../model/channel/internal/GroupDMImpl.java | 4 +- .../channel/internal/GuildChannelImpl.java | 4 +- .../internal/MessagingChannelImpl.java | 7 +- .../channel/internal/TextChannelImpl.java | 5 +- .../model/channel/internal/ThreadImpl.java | 5 +- .../channel/internal/VoiceChannelImpl.java | 4 +- .../model/channel/thread/Thread.java | 23 ++- .../model/channel/thread/ThreadMember.java | 8 +- .../model/channel/thread/ThreadMetadata.java | 8 +- .../model/channel/utils/ChannelMention.java | 8 +- .../discordjar/model/component/ActionRow.java | 16 +- .../discordjar/model/component/Component.java | 20 +- .../model/component/RawComponent.java | 9 +- .../component/button/internal/ButtonImpl.java | 14 +- .../component/impl/UnknownRawComponent.java | 14 +- .../modal/ResolvedModalComponent.java | 8 +- .../model/component/select/SelectOption.java | 8 +- .../select/entity/ChannelSelectMenu.java | 27 ++- .../select/entity/MentionableSelectMenu.java | 16 +- .../select/entity/RoleSelectMenu.java | 16 +- .../select/entity/UserSelectMenu.java | 16 +- .../select/string/StringSelectMenu.java | 24 ++- .../model/component/text/TextInput.java | 18 +- .../seailz/discordjar/model/embed/Embed.java | 14 +- .../discordjar/model/embed/EmbedAuthor.java | 8 +- .../discordjar/model/embed/EmbedField.java | 8 +- .../discordjar/model/embed/EmbedFooter.java | 8 +- .../discordjar/model/embed/EmbedImage.java | 8 +- .../discordjar/model/embed/EmbedProvider.java | 8 +- .../discordjar/model/embed/Embeder.java | 4 +- .../discordjar/model/embed/EmbederImpl.java | 20 +- .../seailz/discordjar/model/emoji/Emoji.java | 10 +- .../discordjar/model/emoji/Reaction.java | 8 +- .../model/emoji/sticker/Sticker.java | 20 +- .../model/emoji/sticker/StickerPack.java | 20 +- .../seailz/discordjar/model/guild/Guild.java | 137 +++++++------- .../discordjar/model/guild/GuildBan.java | 8 +- .../seailz/discordjar/model/guild/Member.java | 36 ++-- .../model/guild/UnavailableGuild.java | 22 +-- .../model/guild/welcome/WelcomeScreen.java | 14 +- .../guild/welcome/WelcomeScreenChannel.java | 8 +- .../model/interaction/Interaction.java | 14 +- .../model/interaction/InteractionData.java | 4 +- .../internal/InteractionHandlerImpl.java | 15 +- .../model/interaction/data/ResolvedData.java | 22 +-- .../ApplicationCommandInteractionData.java | 14 +- .../data/command/ResolvedCommandOption.java | 14 +- .../MessageComponentInteractionData.java | 14 +- .../modal/ModalSubmitInteractionData.java | 14 +- .../reply/InteractionMessageResponse.java | 12 +- .../reply/InteractionModalResponse.java | 10 +- .../model/invite/internal/InviteImpl.java | 20 +- .../invite/internal/InviteMetadataImpl.java | 22 +-- .../model/mentions/AllowedMentions.java | 14 +- .../discordjar/model/message/Attachment.java | 8 +- .../discordjar/model/message/Message.java | 73 ++++---- .../model/message/MessageReference.java | 8 +- .../message/activity/MessageActivity.java | 8 +- .../model/permission/PermissionOverwrite.java | 8 +- .../seailz/discordjar/model/role/Role.java | 8 +- .../seailz/discordjar/model/role/RoleTag.java | 8 +- .../model/scopes/InstallParams.java | 13 +- .../discordjar/model/status/Status.java | 14 +- .../model/status/activity/Activity.java | 12 +- .../model/status/activity/ActivityAssets.java | 8 +- .../model/status/activity/ActivityButton.java | 8 +- .../model/status/activity/ActivityParty.java | 8 +- .../status/activity/ActivitySecrets.java | 8 +- .../status/activity/ActivityTimestamp.java | 8 +- .../seailz/discordjar/model/team/Team.java | 14 +- .../model/team/member/TeamMember.java | 8 +- .../seailz/discordjar/model/user/User.java | 12 +- .../seailz/discordjar/oauth2/LinkedRoles.java | 10 +- .../oauth2/LinkedRolesRestController.java | 12 +- .../discordjar/utils/json/SJSONArray.java | 99 ++++++++++ .../discordjar/utils/json/SJSONObject.java | 175 ++++++++++++++++++ .../discordjar/utils/rest/DiscordRequest.java | 68 ++++--- .../utils/rest/DiscordResponse.java | 8 +- .../discordjar/utils/rest/Response.java | 32 ++-- 167 files changed, 1324 insertions(+), 1127 deletions(-) create mode 100644 src/main/java/com/seailz/discordjar/utils/json/SJSONArray.java create mode 100644 src/main/java/com/seailz/discordjar/utils/json/SJSONObject.java diff --git a/src/main/java/com/seailz/discordjar/DiscordJar.java b/src/main/java/com/seailz/discordjar/DiscordJar.java index db747920..427f8bd4 100644 --- a/src/main/java/com/seailz/discordjar/DiscordJar.java +++ b/src/main/java/com/seailz/discordjar/DiscordJar.java @@ -37,6 +37,8 @@ import com.seailz.discordjar.utils.URLS; import com.seailz.discordjar.cache.Cache; import com.seailz.discordjar.cache.JsonCache; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.memory.MemoryWatcher; import com.seailz.discordjar.utils.rest.DiscordRequest; import com.seailz.discordjar.utils.rest.DiscordResponse; @@ -46,8 +48,6 @@ import com.seailz.discordjar.model.api.version.APIVersion; 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.IOException; @@ -221,7 +221,7 @@ public DiscordJar(String token, EnumSet intents, APIVersion version, boo this.debug = debug; this.guildCache = new Cache<>(this, Guild.class, new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.GET_GUILD.replace("{guild.id}", "%s"), this, @@ -232,7 +232,7 @@ public DiscordJar(String token, EnumSet intents, APIVersion version, boo this.guildMemberCaches = new HashMap<>(); this.userCache = new Cache<>(this, User.class, new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.USER.GET_USER.replace("{user.id}", "%s"), this, @@ -241,7 +241,7 @@ public DiscordJar(String token, EnumSet intents, APIVersion version, boo ), CacheType.USERS); this.channelCache = new Cache<>(this, Channel.class, new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.GET_CHANNEL.replace("{channel.id}", "%s"), this, @@ -418,7 +418,7 @@ public Bucket getBucketForUrl(String url) { public void setStatus(@NotNull Status status) { if (gatewayFactory == null) throw new IllegalStateException("Cannot set status on an HTTP-only bot. See the constructor for more information."); - JSONObject json = new JSONObject(); + SJSONObject json = new SJSONObject(); json.put("d", status.compile()); json.put("op", 3); gatewayFactory.queueMessage(json); @@ -460,7 +460,7 @@ public User getSelfUser() { return User.decompile(getSelfUserCache.get(), this); DiscordRequest req = new DiscordRequest( - new JSONObject(), new HashMap<>(), + new SJSONObject(), new HashMap<>(), URLS.GET.USER.GET_USER.replace("{user.id}", "@me"), this, URLS.GET.USER.GET_USER, RequestMethod.GET ); @@ -521,7 +521,7 @@ public Channel getChannelById(String id) { @Nullable public MessagingChannel getTextChannelById(String id) { Checker.isSnowflake(id, "Given id is not a snowflake"); - JSONObject raw = null; + SJSONObject raw = null; try { raw = getChannelCache().getById(id).raw(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -540,7 +540,7 @@ public MessagingChannel getTextChannelById(String id) { @Nullable public com.seailz.discordjar.model.channel.thread.Thread getThreadById(String id) { Checker.isSnowflake(id, "Given id is not a snowflake"); - JSONObject raw = null; + SJSONObject raw = null; try { raw = getChannelCache().getById(id).raw(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -559,7 +559,7 @@ public com.seailz.discordjar.model.channel.thread.Thread getThreadById(String id @Nullable public DMChannel getDmChannelById(String id) { Checker.isSnowflake(id, "Given id is not a snowflake"); - JSONObject raw = null; + SJSONObject raw = null; try { raw = getChannelCache().getById(id).raw(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -578,7 +578,7 @@ public DMChannel getDmChannelById(String id) { @Nullable public ForumChannel getForumChannelById(String id) { Checker.isSnowflake(id, "Given id is not a snowflake"); - JSONObject raw = null; + SJSONObject raw = null; try { raw = getChannelCache().getById(id).raw(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -597,7 +597,7 @@ public ForumChannel getForumChannelById(String id) { @Nullable public Category getCategoryById(String id) { Checker.isSnowflake(id, "Given id is not a snowflake"); - JSONObject raw = null; + SJSONObject raw = null; try { raw = getChannelCache().getById(id).raw(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -647,7 +647,7 @@ public Sticker getStickerById(String id) { Checker.isSnowflake(id, "Given id is not a snowflake"); try { return Sticker.decompile(new DiscordRequest( - new JSONObject(), new HashMap<>(), + new SJSONObject(), new HashMap<>(), URLS.GET.STICKER.GET_STICKER.replace("{sticker.id}", id), this, URLS.GET.STICKER.GET_STICKER, RequestMethod.GET ).invoke().body(), this); @@ -665,7 +665,7 @@ public Sticker getStickerById(String id) { public List getNitroStickerPacks() { try { return StickerPack.decompileList(new DiscordRequest( - new JSONObject(), new HashMap<>(), + new SJSONObject(), new HashMap<>(), URLS.GET.STICKER.GET_NITRO_STICKER_PACKS, this, URLS.GET.STICKER.GET_NITRO_STICKER_PACKS, RequestMethod.GET ).invoke().body(), this); @@ -717,7 +717,7 @@ public Application getSelfInfo() { return Application.decompile(selfUserCache.get(), this); DiscordRequest request = new DiscordRequest( - new JSONObject(), new HashMap<>(), + new SJSONObject(), new HashMap<>(), URLS.GET.APPLICATION.APPLICATION_INFORMATION, this, URLS.GET.APPLICATION.APPLICATION_INFORMATION, RequestMethod.GET ); @@ -808,7 +808,7 @@ public void insertMemberCache(@NotNull String guildId, @NotNull Member member) { this, Member.class, new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.MEMBERS.GET_GUILD_MEMBER.replace("{guild.id}", guildId).replace("{user.id}", "%s"), this, @@ -871,7 +871,7 @@ private Member getMemberManuallyOrNull(@NotNull String guildId, @NotNull String DiscordResponse req = null; try { req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.MEMBERS.GET_GUILD_MEMBER.replace( "{guild.id}", @@ -1021,7 +1021,7 @@ protected void registerCommand(Command command) { */ public void clearCommands() { DiscordRequest cmdDelReq = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.POST.COMMANDS.GLOBAL_COMMANDS.replace("{application.id}", getSelfInfo().id()), this, @@ -1029,7 +1029,7 @@ public void clearCommands() { RequestMethod.PUT ); try { - cmdDelReq.invoke(new JSONArray()); + cmdDelReq.invoke(new SJSONArray()); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -1043,21 +1043,21 @@ public void clearCommands() { @Nullable public List getGlobalCommands(boolean withLocalizations) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMANDS.replace("{application.id}", getSelfInfo().id()) + (withLocalizations ? "?with_localizations=true" : ""), this, URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMANDS, RequestMethod.GET ); - JSONArray res = null; + SJSONArray res = null; try { res = req.invoke().arr(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } List commands = new ArrayList<>(); - res.forEach(o -> commands.add(Command.decompile((JSONObject) o))); + res.forEach(o -> commands.add(Command.decompile((SJSONObject) o))); return commands; } @@ -1074,14 +1074,14 @@ public List getGlobalCommands() { @Nullable public Command getGlobalCommand(String commandId) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{command.id}", commandId), this, URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMAND, RequestMethod.GET ); - JSONObject res = null; + SJSONObject res = null; try { res = req.invoke().body(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -1106,7 +1106,7 @@ public Command editGlobalCommand(@NotNull Command newCommand, String commandId) URLS.PATCH.APPLICATIONS.COMMANDS.EDIT_GLOBAL_COMMAND, RequestMethod.PATCH ); - JSONObject res = null; + SJSONObject res = null; try { res = req.invoke().body(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -1121,7 +1121,7 @@ public Command editGlobalCommand(@NotNull Command newCommand, String commandId) */ public void deleteGlobalCommand(String commandId) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.APPLICATION.COMMANDS.DELETE_GLOBAL_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{command.id}", commandId), this, @@ -1140,7 +1140,7 @@ public void deleteGlobalCommand(String commandId) { * @param commands The new commands to overwrite with. */ public void bulkOverwriteCommands(@NotNull List commands) { - JSONArray arr = new JSONArray(); + SJSONArray arr = new SJSONArray(); commands.forEach(c -> arr.put(c.compile())); DiscordRequest req = new DiscordRequest( arr, @@ -1166,21 +1166,21 @@ public void bulkOverwriteCommands(@NotNull List commands) { @Nullable public List getGuildCommands(String guildId, boolean withLocalizations) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMANDS.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId) + (withLocalizations ? "?with_localizations=true" : ""), this, URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMANDS, RequestMethod.GET ); - JSONArray res = null; + SJSONArray res = null; try { res = req.invoke().arr(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } List commands = new ArrayList<>(); - res.forEach(o -> commands.add(Command.decompile((JSONObject) o))); + res.forEach(o -> commands.add(Command.decompile((SJSONObject) o))); return commands; } @@ -1198,14 +1198,14 @@ public List getGuildCommands(String guildId) { @Nullable public Command getGuildCommand(String guildId, String commandId) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId).replace("{command.id}", commandId), this, URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMAND, RequestMethod.GET ); - JSONObject res = null; + SJSONObject res = null; try { res = req.invoke().body(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -1231,7 +1231,7 @@ public Command editGuildCommand(@NotNull Command newCommand, String guildId, Str URLS.PATCH.APPLICATIONS.COMMANDS.EDIT_GUILD_COMMAND, RequestMethod.PATCH ); - JSONObject res = null; + SJSONObject res = null; try { res = req.invoke().body(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -1247,7 +1247,7 @@ public Command editGuildCommand(@NotNull Command newCommand, String guildId, Str */ public void deleteGuildCommand(String guildId, String commandId) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.APPLICATION.COMMANDS.DELETE_GUILD_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId).replace("{command.id}", commandId), this, @@ -1267,7 +1267,7 @@ public void deleteGuildCommand(String guildId, String commandId) { * @param guildId The id of the guild. */ public void bulkOverwriteGuildCommands(@NotNull List commands, String guildId) { - JSONArray arr = new JSONArray(); + SJSONArray arr = new SJSONArray(); commands.forEach(c -> arr.put(c.compile())); DiscordRequest req = new DiscordRequest( arr, @@ -1311,14 +1311,14 @@ public GetCurrentUserGuildsAction getGuilds() { */ public List getVoiceRegions() { DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.VOICE.REGIONS.GET_VOICE_REGIONS, this, URLS.GET.VOICE.REGIONS.GET_VOICE_REGIONS, RequestMethod.GET ); - JSONArray response = null; + SJSONArray response = null; try { response = request.invoke().arr(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -1337,7 +1337,7 @@ public List getVoiceRegions() { @Nullable public Invite getInvite(String code) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.INVITES.GET_INVITE.replace("{invite.code}", code), this, @@ -1359,7 +1359,7 @@ public Invite getInvite(String code) { */ public void deleteInvite(String code) { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.INVITE.DELETE_INVITE.replace("{invite.code}", code), this, diff --git a/src/main/java/com/seailz/discordjar/DiscordJarBuilder.java b/src/main/java/com/seailz/discordjar/DiscordJarBuilder.java index 9ccd1cfd..0d7fca2d 100644 --- a/src/main/java/com/seailz/discordjar/DiscordJarBuilder.java +++ b/src/main/java/com/seailz/discordjar/DiscordJarBuilder.java @@ -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; @@ -151,7 +151,7 @@ public DiscordJarBuilder setNumShards(int numShards) { public int getRecommendedShardCount() { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GATEWAY.GET_GATEWAY_BOT, null, diff --git a/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleCreateAction.java b/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleCreateAction.java index bb19f54f..b57a9b0d 100644 --- a/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleCreateAction.java +++ b/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleCreateAction.java @@ -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 org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -147,26 +147,26 @@ public AutomodRuleCreateAction addExemptRole(Role role) { public CompletableFuture run() { CompletableFuture future = new CompletableFuture<>(); future.completeAsync(() -> { - JSONObject payload = new JSONObject(); + SJSONObject payload = new SJSONObject(); 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()); - JSONArray actionsArray = new JSONArray(); + SJSONArray actionsArray = new SJSONArray(); actions.stream().map(AutomodRule.Action::compile).forEach(actionsArray::put); payload.put("actions", actionsArray); payload.put("enabled", enabled); if (exemptChannels != null) { - JSONArray exemptChannelsArray = new JSONArray(); + SJSONArray exemptChannelsArray = new SJSONArray(); exemptChannels.stream().map(Channel::id).forEach(exemptChannelsArray::put); payload.put("exempt_channels", exemptChannelsArray); } if (exemptRoles != null) { - JSONArray exemptRolesArray = new JSONArray(); + SJSONArray exemptRolesArray = new SJSONArray(); exemptRoles.stream().map(Role::id).forEach(exemptRolesArray::put); payload.put("exempt_roles", exemptRolesArray); } diff --git a/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleModifyAction.java b/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleModifyAction.java index 91115555..3518da6a 100644 --- a/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleModifyAction.java +++ b/src/main/java/com/seailz/discordjar/action/automod/AutomodRuleModifyAction.java @@ -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 org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -153,26 +153,26 @@ public AutomodRuleModifyAction addExemptRole(Role role) { public CompletableFuture run() { CompletableFuture future = new CompletableFuture<>(); future.completeAsync(() -> { - JSONObject payload = new JSONObject(); + SJSONObject payload = new SJSONObject(); 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()); - JSONArray actionsArray = new JSONArray(); + SJSONArray actionsArray = new SJSONArray(); actions.stream().map(AutomodRule.Action::compile).forEach(actionsArray::put); payload.put("actions", actionsArray); payload.put("enabled", enabled); if (exemptChannels != null) { - JSONArray exemptChannelsArray = new JSONArray(); + SJSONArray exemptChannelsArray = new SJSONArray(); exemptChannels.stream().map(Channel::id).forEach(exemptChannelsArray::put); payload.put("exempt_channels", exemptChannelsArray); } if (exemptRoles != null) { - JSONArray exemptRolesArray = new JSONArray(); + SJSONArray exemptRolesArray = new SJSONArray(); exemptRoles.stream().map(Role::id).forEach(exemptRolesArray::put); payload.put("exempt_roles", exemptRolesArray); } diff --git a/src/main/java/com/seailz/discordjar/action/channel/ModifyBaseChannelAction.java b/src/main/java/com/seailz/discordjar/action/channel/ModifyBaseChannelAction.java index eca0c7a0..469d2d09 100644 --- a/src/main/java/com/seailz/discordjar/action/channel/ModifyBaseChannelAction.java +++ b/src/main/java/com/seailz/discordjar/action/channel/ModifyBaseChannelAction.java @@ -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; @@ -257,7 +257,7 @@ public void setDefaultForumLayout(ForumChannel.DefaultForumLayout defaultForumLa public CompletableFuture run() { CompletableFuture future = new CompletableFuture<>(); future.completeAsync(() -> { - JSONObject body = new JSONObject(); + SJSONObject body = new SJSONObject(); if (name != null) body.put("name", name); if (type != null) body.put("type", type.getCode()); if (topic != null) body.put("topic", topic); @@ -267,7 +267,7 @@ public CompletableFuture run() { if (rateLimitPerUser != -1) body.put("rate_limit_per_user", rateLimitPerUser); if (userLimit != -1) body.put("user_limit", userLimit); if (permissionOverwrites != null) { - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (PermissionOverwrite overwrite : permissionOverwrites) { array.put(overwrite.compile()); } @@ -279,7 +279,7 @@ public CompletableFuture run() { if (defaultAutoArchiveDuration != null) body.put("default_auto_archive_duration", defaultAutoArchiveDuration); if (flags != -1) body.put("flags", flags); if (availableTags != null) { - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (ForumTag tag : availableTags) { array.put(tag.compile()); } diff --git a/src/main/java/com/seailz/discordjar/action/channel/invites/CreateChannelInviteAction.java b/src/main/java/com/seailz/discordjar/action/channel/invites/CreateChannelInviteAction.java index cef30a21..7c8f00c5 100644 --- a/src/main/java/com/seailz/discordjar/action/channel/invites/CreateChannelInviteAction.java +++ b/src/main/java/com/seailz/discordjar/action/channel/invites/CreateChannelInviteAction.java @@ -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 org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -112,7 +112,7 @@ public CompletableFuture run() { throw new IllegalStateException("Target application must be set if target type is set to EMBEDDED_APPLICATION"); - JSONObject body = new JSONObject(); + SJSONObject body = new SJSONObject(); if (maxAge != -1) body.put("max_age", maxAge); if (maxUses != -1) body.put("max_uses", maxUses); if (temporary) body.put("temporary", true); diff --git a/src/main/java/com/seailz/discordjar/action/guild/GetCurrentUserGuildsAction.java b/src/main/java/com/seailz/discordjar/action/guild/GetCurrentUserGuildsAction.java index f6688399..8b4a4712 100644 --- a/src/main/java/com/seailz/discordjar/action/guild/GetCurrentUserGuildsAction.java +++ b/src/main/java/com/seailz/discordjar/action/guild/GetCurrentUserGuildsAction.java @@ -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; @@ -93,7 +93,7 @@ public List run() { DiscordResponse response = null; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), url, discordJar, @@ -105,7 +105,7 @@ public List run() { } List returnGuilds = new ArrayList<>(); - response.arr().forEach(guild -> returnGuilds.add(Guild.decompile((JSONObject) guild, discordJar))); + response.arr().forEach(guild -> returnGuilds.add(Guild.decompile((SJSONObject) guild, discordJar))); returnGuilds.forEach(g -> discordJar.getGuildCache().cache(g)); return returnGuilds; diff --git a/src/main/java/com/seailz/discordjar/action/guild/channel/CreateGuildChannelAction.java b/src/main/java/com/seailz/discordjar/action/guild/channel/CreateGuildChannelAction.java index ed455522..685c0522 100644 --- a/src/main/java/com/seailz/discordjar/action/guild/channel/CreateGuildChannelAction.java +++ b/src/main/java/com/seailz/discordjar/action/guild/channel/CreateGuildChannelAction.java @@ -7,15 +7,13 @@ 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 { @@ -102,13 +100,13 @@ public Response run() { try { GuildChannel chan = GuildChannel.decompile( new DiscordRequest( - new JSONObject() + new SJSONObject() .put("name", name) .put("type", type.getCode()) - .put("topic", topic != null ? topic : JSONObject.NULL) + .put("topic", topic != null ? topic : SJSONObject.NULL) .put("position", position) .put("permission_overwrites", permissionOverwrites) - .put("parent_id", categoryId != null ? categoryId : JSONObject.NULL), + .put("parent_id", categoryId != null ? categoryId : SJSONObject.NULL), new HashMap<>(), URLS.POST.GUILDS.CHANNELS.CREATE.replace("{guild.id}", guild.id()), discordJar, diff --git a/src/main/java/com/seailz/discordjar/action/interaction/EditInteractionMessageAction.java b/src/main/java/com/seailz/discordjar/action/interaction/EditInteractionMessageAction.java index fb5e927d..c60f47e8 100644 --- a/src/main/java/com/seailz/discordjar/action/interaction/EditInteractionMessageAction.java +++ b/src/main/java/com/seailz/discordjar/action/interaction/EditInteractionMessageAction.java @@ -6,18 +6,17 @@ 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 org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; 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 { @@ -128,10 +127,10 @@ public EditInteractionMessageAction addComponent(DisplayComponent component) { public Response run() { Response future = new Response<>(); new Thread(() -> { - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); if (content != null) obj.put("content", content); if (embeds != null) { - JSONArray embeds = new JSONArray(); + SJSONArray embeds = new SJSONArray(); for (Embeder embed : this.embeds) { embeds.put(embed.compile()); } @@ -140,7 +139,7 @@ public Response run() { } if (components != null) { - JSONArray components = new JSONArray(); + SJSONArray components = new SJSONArray(); for (DisplayComponent component : this.components) { components.put(component.compile()); } @@ -149,7 +148,7 @@ public Response run() { } if (attachments != null) { - JSONArray attachments = new JSONArray(); + SJSONArray attachments = new SJSONArray(); for (Attachment attachment : this.attachments) { attachments.put(attachment.compile()); } diff --git a/src/main/java/com/seailz/discordjar/action/interaction/InteractionCallbackAction.java b/src/main/java/com/seailz/discordjar/action/interaction/InteractionCallbackAction.java index be08708a..5f58c9e9 100644 --- a/src/main/java/com/seailz/discordjar/action/interaction/InteractionCallbackAction.java +++ b/src/main/java/com/seailz/discordjar/action/interaction/InteractionCallbackAction.java @@ -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 org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.io.File; @@ -47,7 +47,7 @@ public InteractionReply getReply() { } public Response run() { - JSONObject json = new JSONObject(); + SJSONObject json = new SJSONObject(); json.put("type", this.type.getCode()); json.put("data", this.reply.compile()); 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 eec0d1a6..6d8e01cb 100644 --- a/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java +++ b/src/main/java/com/seailz/discordjar/action/message/MessageCreateAction.java @@ -9,18 +9,17 @@ 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 @@ -267,7 +266,7 @@ public Response run() { new Thread(() -> { String url = URLS.POST.MESSAGES.SEND.replace("{channel.id}", channelId); - JSONObject payload = new JSONObject(); + SJSONObject payload = new SJSONObject(); 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); @@ -282,7 +281,7 @@ public Response run() { payload.put("duration", this.duration); } - JSONArray components = new JSONArray(); + SJSONArray components = new SJSONArray(); if (this.components != null && !this.components.isEmpty()) { for (DisplayComponent component : this.components) { components.put(component.compile()); @@ -292,7 +291,7 @@ public Response run() { if (this.components != null && !this.components.isEmpty()) payload.put("components", components); - JSONArray embeds = new JSONArray(); + SJSONArray embeds = new SJSONArray(); if (this.embeds != null) { for (Embeder embed : this.embeds) { embeds.put(embed.compile()); @@ -302,7 +301,7 @@ public Response run() { if (this.embeds != null) payload.put("embeds", embeds); - JSONArray stickerIds = new JSONArray(); + SJSONArray stickerIds = new SJSONArray(); if (this.stickerIds != null) { for (String stickerId : this.stickerIds) { stickerIds.put(stickerId); @@ -313,7 +312,7 @@ public Response run() { payload.put("sticker_ids", stickerIds); if (this.attachments != null) { - JSONArray files = new JSONArray(); + SJSONArray files = new SJSONArray(); for (Attachment attachment : this.attachments) { files.put(attachment.compile()); } diff --git a/src/main/java/com/seailz/discordjar/action/message/MessageEditAction.java b/src/main/java/com/seailz/discordjar/action/message/MessageEditAction.java index f2029443..99f9fd85 100644 --- a/src/main/java/com/seailz/discordjar/action/message/MessageEditAction.java +++ b/src/main/java/com/seailz/discordjar/action/message/MessageEditAction.java @@ -6,14 +6,13 @@ import com.seailz.discordjar.model.message.Attachment; import com.seailz.discordjar.model.message.Message; 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 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; @@ -185,10 +184,10 @@ public CompletableFuture run() { future.completeAsync(() -> { String url = URLS.PATCH.CHANNEL.MESSAGE.EDIT.replace("{channel.id}", channelId).replace("{message.id}", messageId); - JSONObject payload = new JSONObject(); + SJSONObject payload = new SJSONObject(); if (this.text != null) payload.put("content", this.text); - JSONArray components = new JSONArray(); + SJSONArray components = new SJSONArray(); if (this.components != null && !this.components.isEmpty()) { for (DisplayComponent component : this.components) { components.put(component.compile()); @@ -198,7 +197,7 @@ public CompletableFuture run() { if (this.components != null && !this.components.isEmpty()) payload.put("components", components); - JSONArray embeds = new JSONArray(); + SJSONArray embeds = new SJSONArray(); if (this.embeds != null) { for (Embeder embed : this.embeds) { embeds.put(embed.compile()); @@ -209,7 +208,7 @@ public CompletableFuture run() { payload.put("embeds", embeds); if (this.attachments != null) { - JSONArray files = new JSONArray(); + SJSONArray files = new SJSONArray(); for (Attachment attachment : this.attachments) { files.put(attachment.compile()); } diff --git a/src/main/java/com/seailz/discordjar/action/message/StartThreadForumChannelAction.java b/src/main/java/com/seailz/discordjar/action/message/StartThreadForumChannelAction.java index 68f47955..c52a74b6 100644 --- a/src/main/java/com/seailz/discordjar/action/message/StartThreadForumChannelAction.java +++ b/src/main/java/com/seailz/discordjar/action/message/StartThreadForumChannelAction.java @@ -7,10 +7,10 @@ import com.seailz.discordjar.model.message.Attachment; import com.seailz.discordjar.model.message.MessageFlag; 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 org.jetbrains.annotations.Nullable; -import org.json.JSONArray; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.io.File; @@ -111,7 +111,7 @@ public StartThreadForumChannelAction setTagIds(String... tagIds) { public CompletableFuture run() { CompletableFuture future = new CompletableFuture<>(); future.completeAsync(() -> { - JSONObject payload = new JSONObject(); + SJSONObject payload = new SJSONObject(); payload.put("name", name); if (autoArchiveDuration != null) { payload.put("auto_archive_duration", autoArchiveDuration.getMinutes()); @@ -122,7 +122,7 @@ public CompletableFuture run() { } if (!tagIds.isEmpty()) { - JSONArray tagIdsArray = new JSONArray(); + SJSONArray tagIdsArray = new SJSONArray(); tagIds.forEach(tagIdsArray::put); payload.put("applied_tags", tagIdsArray); } @@ -323,11 +323,11 @@ public boolean isSilent() { return silent; } - protected JSONObject compile() { - JSONObject payload = new JSONObject(); + protected SJSONObject compile() { + SJSONObject payload = new SJSONObject(); if (this.text != null) payload.put("content", this.text); - JSONArray components = new JSONArray(); + SJSONArray components = new SJSONArray(); if (this.components != null && !this.components.isEmpty()) { for (DisplayComponent component : this.components) { components.put(component.compile()); @@ -337,7 +337,7 @@ protected JSONObject compile() { if (this.components != null && !this.components.isEmpty()) payload.put("components", components); - JSONArray embeds = new JSONArray(); + SJSONArray embeds = new SJSONArray(); if (this.embeds != null) { for (Embeder embed : this.embeds) { embeds.put(embed.compile()); @@ -347,7 +347,7 @@ protected JSONObject compile() { if (this.embeds != null) payload.put("embeds", embeds); - JSONArray stickerIds = new JSONArray(); + SJSONArray stickerIds = new SJSONArray(); if (this.stickerIds != null) { for (String stickerId : this.stickerIds) { stickerIds.put(stickerId); @@ -358,7 +358,7 @@ protected JSONObject compile() { payload.put("sticker_ids", stickerIds); if (this.attachments != null) { - JSONArray files = new JSONArray(); + SJSONArray files = new SJSONArray(); for (Attachment attachment : this.attachments) { files.put(attachment.compile()); } diff --git a/src/main/java/com/seailz/discordjar/action/sticker/ModifyStickerAction.java b/src/main/java/com/seailz/discordjar/action/sticker/ModifyStickerAction.java index c067f7a8..b3a1d1e1 100644 --- a/src/main/java/com/seailz/discordjar/action/sticker/ModifyStickerAction.java +++ b/src/main/java/com/seailz/discordjar/action/sticker/ModifyStickerAction.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.emoji.sticker.Sticker; import com.seailz.discordjar.utils.URLS; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -56,10 +56,10 @@ public CompletableFuture run() { try { return Sticker.decompile( new DiscordRequest( - new JSONObject() - .put("name", name != null ? name : JSONObject.NULL) - .put("description", description != null ? description : JSONObject.NULL) - .put("tags", tags != null ? tags : JSONObject.NULL), + new SJSONObject() + .put("name", name != null ? name : SJSONObject.NULL) + .put("description", description != null ? description : SJSONObject.NULL) + .put("tags", tags != null ? tags : SJSONObject.NULL), new HashMap<>(), URLS.PATCH.GUILD.STICKER.MODIFY_GUILD_STICKER.replace( "{sticker_id}", diff --git a/src/main/java/com/seailz/discordjar/cache/Cache.java b/src/main/java/com/seailz/discordjar/cache/Cache.java index da3d2fe5..d445aa81 100644 --- a/src/main/java/com/seailz/discordjar/cache/Cache.java +++ b/src/main/java/com/seailz/discordjar/cache/Cache.java @@ -3,10 +3,10 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.guild.Member; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.DiscordRequest; import com.seailz.discordjar.utils.rest.DiscordResponse; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.lang.reflect.InvocationTargetException; @@ -175,13 +175,13 @@ public T getById(String id) throws DiscordRequest.UnhandledDiscordAPIErrorExcept ).invoke(); Method decompile; try { - decompile = clazz.getMethod("decompile", JSONObject.class, DiscordJar.class); + decompile = clazz.getMethod("decompile", SJSONObject.class, DiscordJar.class); } catch (NoSuchMethodException e) { try { - decompile = clazz.getMethod("decompile", JSONObject.class); + decompile = clazz.getMethod("decompile", SJSONObject.class); } catch (NoSuchMethodException ex) { try { - decompile = clazz.getMethod("decompile", JSONObject.class, DiscordJar.class, String.class, Guild.class); + decompile = clazz.getMethod("decompile", SJSONObject.class, DiscordJar.class, String.class, Guild.class); } catch (NoSuchMethodException exx) { Logger.getLogger("DiscordJar").severe("Was unable to return object from cache, please report this to discord.jar's github!"); throw new RuntimeException(exx); @@ -243,7 +243,7 @@ private T getFromCacheByIdOrNull(String id) { return returnObject.get() == null ? null : (T) returnObject.get(); } - public JSONObject getFresh(String id) { + public SJSONObject getFresh(String id) { DiscordResponse response = null; try { response = new DiscordRequest( diff --git a/src/main/java/com/seailz/discordjar/cache/JsonCache.java b/src/main/java/com/seailz/discordjar/cache/JsonCache.java index b53d9346..b50915ad 100644 --- a/src/main/java/com/seailz/discordjar/cache/JsonCache.java +++ b/src/main/java/com/seailz/discordjar/cache/JsonCache.java @@ -2,9 +2,9 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.cache.impl.JsonCacheImpl; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.DiscordRequest; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; import java.util.Random; @@ -26,14 +26,14 @@ public interface JsonCache { *
or null if the cache is empty. */ @Nullable - JSONObject get(); + SJSONObject get(); /** * Updates the cache. * * @param object The object to update the cache with */ - void update(JSONObject object); + void update(SJSONObject object); /** * Returns the DiscordRequest object that @@ -124,7 +124,7 @@ static JsonCache newc(DiscordRequest howToUpdateFresh) { * * @param object The object to store in the cache when initialized. */ - static JsonCache newc(JSONObject object, DiscordRequest howToUpdateFresh) { + static JsonCache newc(SJSONObject object, DiscordRequest howToUpdateFresh) { return new JsonCacheImpl(object, howToUpdateFresh); } diff --git a/src/main/java/com/seailz/discordjar/cache/impl/JsonCacheImpl.java b/src/main/java/com/seailz/discordjar/cache/impl/JsonCacheImpl.java index 5ca43da8..c418bd68 100644 --- a/src/main/java/com/seailz/discordjar/cache/impl/JsonCacheImpl.java +++ b/src/main/java/com/seailz/discordjar/cache/impl/JsonCacheImpl.java @@ -2,7 +2,7 @@ import com.seailz.discordjar.cache.JsonCache; import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Implementation of the {@link JsonCache} interface. @@ -11,7 +11,7 @@ */ public class JsonCacheImpl implements JsonCache { - private JSONObject object; + private SJSONObject object; private final DiscordRequest request; /** @@ -19,7 +19,7 @@ public class JsonCacheImpl implements JsonCache { * * @param object The object to store in the cache */ - public JsonCacheImpl(JSONObject object, DiscordRequest request) { + public JsonCacheImpl(SJSONObject object, DiscordRequest request) { this.object = object; this.request = request; } @@ -33,12 +33,12 @@ public JsonCacheImpl(DiscordRequest request) { } @Override - public JSONObject get() { + public SJSONObject get() { return object; } @Override - public void update(JSONObject object) { + public void update(SJSONObject object) { this.object = object; } diff --git a/src/main/java/com/seailz/discordjar/command/Command.java b/src/main/java/com/seailz/discordjar/command/Command.java index ecee0993..7f3bdab6 100644 --- a/src/main/java/com/seailz/discordjar/command/Command.java +++ b/src/main/java/com/seailz/discordjar/command/Command.java @@ -3,9 +3,9 @@ import com.seailz.discordjar.command.annotation.Locale; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.flag.BitwiseUtil; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.permission.Permission; -import org.json.JSONArray; -import org.json.JSONObject; import java.lang.annotation.Annotation; import java.util.ArrayList; @@ -34,11 +34,11 @@ public record Command( boolean nsfw ) implements Compilerable { @Override - public JSONObject compile() { - JSONArray optionsJson = new JSONArray(); + public SJSONObject compile() { + SJSONArray optionsJson = new SJSONArray(); options.forEach((option) -> optionsJson.put(option.compile())); - JSONObject nameLocales = new JSONObject(); + SJSONObject nameLocales = new SJSONObject(); HashMap nameLocalesMap = new HashMap<>(); for (Locale locale : nameLocalizations) { nameLocalesMap.put(locale.locale(), locale.value()); @@ -47,7 +47,7 @@ public JSONObject compile() { nameLocales.put(locale, nameLocalesMap.get(locale)); } - JSONObject descriptionLocales = new JSONObject(); + SJSONObject descriptionLocales = new SJSONObject(); HashMap descriptionLocalesMap = new HashMap<>(); for (Locale locale : descriptionLocalizations) { descriptionLocalesMap.put(locale.locale(), locale.value()); @@ -62,7 +62,7 @@ public JSONObject compile() { permissions |= (1 << permission.code()); } - JSONObject obj = new JSONObject() + SJSONObject obj = new SJSONObject() .put("name", name) .put("type", type.getCode()) .put("description", description) @@ -78,7 +78,7 @@ public JSONObject compile() { return obj; } - public static Command decompile(JSONObject obj) { + public static Command decompile(SJSONObject obj) { String name = obj.has("name") ? obj.getString("name") : null; CommandType type = obj.has("type") ? CommandType.fromCode(obj.getInt("type")) : CommandType.UNKNOWN; String description = obj.has("description") ? obj.getString("description") : null; @@ -90,14 +90,14 @@ public static Command decompile(JSONObject obj) { boolean nsfw = false; if (obj.has("name_localizations")) { - JSONObject nameLocalesJson = obj.getJSONObject("name_localizations"); + SJSONObject nameLocalesJson = obj.getJSONObject("name_localizations"); for (String locale : nameLocalesJson.keySet()) { nameLocales.put(locale, nameLocalesJson.getString(locale)); } } if (obj.has("description_localizations")) { - JSONObject descriptionLocalesJson = obj.getJSONObject("description_localizations"); + SJSONObject descriptionLocalesJson = obj.getJSONObject("description_localizations"); for (String locale : descriptionLocalesJson.keySet()) { descriptionLocales.put(locale, descriptionLocalesJson.getString(locale)); } @@ -120,7 +120,7 @@ public static Command decompile(JSONObject obj) { if (obj.has("options")) { for (Object v : obj.getJSONArray("options")) { - options.add(CommandOption.decompile((JSONObject) v)); + options.add(CommandOption.decompile((SJSONObject) v)); } } diff --git a/src/main/java/com/seailz/discordjar/command/CommandChoice.java b/src/main/java/com/seailz/discordjar/command/CommandChoice.java index 980bce77..7c560e78 100644 --- a/src/main/java/com/seailz/discordjar/command/CommandChoice.java +++ b/src/main/java/com/seailz/discordjar/command/CommandChoice.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.command; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a choice of a {@link CommandOption}. @@ -14,13 +14,13 @@ public record CommandChoice( String value ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("name", name) .put("value", value); } - public static CommandChoice decompile(JSONObject obj) { + public static CommandChoice decompile(SJSONObject obj) { String name = obj.has("name") ? obj.getString("name") : null; String value = obj.has("value") ? obj.getString("value") : null; diff --git a/src/main/java/com/seailz/discordjar/command/CommandOption.java b/src/main/java/com/seailz/discordjar/command/CommandOption.java index da87c9d9..ade4ec62 100644 --- a/src/main/java/com/seailz/discordjar/command/CommandOption.java +++ b/src/main/java/com/seailz/discordjar/command/CommandOption.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.command.listeners.slash.SlashSubCommand; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.channel.utils.ChannelType; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -74,18 +74,18 @@ public CommandOption addSubCommand(SlashSubCommand subCommand) { } @Override - public JSONObject compile() { - JSONArray choicesJson = new JSONArray(); + public SJSONObject compile() { + SJSONArray choicesJson = new SJSONArray(); if (this.choices != null) { choices.forEach((commandChoice -> choicesJson.put(commandChoice.compile()))); } - JSONArray subCommandsJson = new JSONArray(); + SJSONArray subCommandsJson = new SJSONArray(); if (this.subCommands != null) { subCommands.forEach((subCommand -> subCommandsJson.put(subCommand.compile()))); } - JSONObject obj = new JSONObject() + SJSONObject obj = new SJSONObject() .put("name", name) .put("description", description) .put("type", type.getCode()); @@ -98,13 +98,13 @@ public JSONObject compile() { if (this.subCommands != null && !this.subCommands.isEmpty()) obj.put("options", subCommandsJson); if (this.options != null && !this.options.isEmpty()) { - JSONArray optionsJson = new JSONArray(); + SJSONArray optionsJson = new SJSONArray(); options.forEach((option) -> optionsJson.put(option.compile())); obj.put("options", optionsJson); } if (this.channelTypes != null && !this.channelTypes.isEmpty()) { - JSONArray channelTypesJson = new JSONArray(); + SJSONArray channelTypesJson = new SJSONArray(); channelTypes.forEach((channelType) -> channelTypesJson.put(channelType.getCode())); obj.put("channel_types", channelTypesJson); } @@ -126,7 +126,7 @@ public JSONObject compile() { return obj; } - public static CommandOption decompile(JSONObject obj) { + public static CommandOption decompile(SJSONObject obj) { String name = obj.has("name") ? obj.getString("name") : null; String description = obj.has("description") ? obj.getString("description") : null; CommandOptionType type = obj.has("type") ? CommandOptionType.fromCode(obj.getInt("type")) : CommandOptionType.STRING; @@ -142,20 +142,20 @@ public static CommandOption decompile(JSONObject obj) { if (obj.has("choices")) { for (Object v : obj.getJSONArray("choices")) { - choices.add(CommandChoice.decompile((JSONObject) v)); + choices.add(CommandChoice.decompile((SJSONObject) v)); } } List subCommands = new ArrayList<>(); if (obj.has("options") && type == CommandOptionType.SUB_COMMAND_GROUP) { for (Object v : obj.getJSONArray("options")) { - subCommands.add(SlashSubCommand.decompile((JSONObject) v)); + subCommands.add(SlashSubCommand.decompile((SJSONObject) v)); } } if (obj.has("options") && type == CommandOptionType.SUB_COMMAND) { for (Object v : obj.getJSONArray("options")) { - options.add(CommandOption.decompile((JSONObject) v)); + options.add(CommandOption.decompile((SJSONObject) v)); } } diff --git a/src/main/java/com/seailz/discordjar/command/listeners/slash/SlashSubCommand.java b/src/main/java/com/seailz/discordjar/command/listeners/slash/SlashSubCommand.java index 2812fb59..d10433d4 100644 --- a/src/main/java/com/seailz/discordjar/command/listeners/slash/SlashSubCommand.java +++ b/src/main/java/com/seailz/discordjar/command/listeners/slash/SlashSubCommand.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.command.CommandOption; import com.seailz.discordjar.command.CommandOptionType; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -35,24 +35,24 @@ public SlashSubCommand addOption(CommandOption option) { } @Override - public JSONObject compile() { - JSONObject json = new JSONObject(); + public SJSONObject compile() { + SJSONObject json = new SJSONObject(); json.put("type", CommandOptionType.SUB_COMMAND.getCode()); json.put("name", name); json.put("description", description); - JSONArray optionsJson = new JSONArray(); + SJSONArray optionsJson = new SJSONArray(); options.forEach((option -> optionsJson.put(option.compile()))); if (options.isEmpty()) json.put("options", optionsJson); return json; } - public static SlashSubCommand decompile(JSONObject obj) { + public static SlashSubCommand decompile(SJSONObject obj) { String name = obj.getString("name"); String description = obj.getString("description"); List options = new ArrayList<>(); - JSONArray optionsJson = obj.getJSONArray("options"); + SJSONArray optionsJson = obj.getJSONArray("options"); for (int i = 0; i < optionsJson.length(); i++) { options.add(CommandOption.decompile(optionsJson.getJSONObject(i))); } diff --git a/src/main/java/com/seailz/discordjar/command/listeners/slash/SubCommandGroup.java b/src/main/java/com/seailz/discordjar/command/listeners/slash/SubCommandGroup.java index 15b6c222..2a21100b 100644 --- a/src/main/java/com/seailz/discordjar/command/listeners/slash/SubCommandGroup.java +++ b/src/main/java/com/seailz/discordjar/command/listeners/slash/SubCommandGroup.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.Checker; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.HashMap; @@ -42,14 +42,14 @@ public SubCommandGroup addSubCommand(SlashSubCommand subCommand, SubCommandListe return this; } @Override - public JSONObject compile() { - JSONArray subCommandsJson = new JSONArray(); + public SJSONObject compile() { + SJSONArray subCommandsJson = new SJSONArray(); subCommands.keySet().forEach((subCommand -> subCommandsJson.put(subCommand.compile()))); Checker.notNull(name, "Name cannot be null"); Checker.notNull(description, "Description cannot be null"); - return new JSONObject() + return new SJSONObject() .put("type", 1) .put("description", description) .put("name", name) diff --git a/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissions.java b/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissions.java index 98d830e4..a4ba8a2f 100644 --- a/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissions.java +++ b/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissions.java @@ -3,9 +3,9 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.Snowflake; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; +import com.seailz.discordjar.utils.json.SJSONArray; import org.json.JSONException; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * This class is used to represent an application command permission. @@ -26,13 +26,13 @@ public record ApplicationCommandPermissions( ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - JSONArray permissionsArray = new JSONArray(); + public SJSONObject compile() { + SJSONArray permissionsArray = new SJSONArray(); for (ApplicationCommandPermissionsData permission : permissions) { permissionsArray.put(permission.compile()); } - return new JSONObject() + return new SJSONObject() .put("id", id) .put("application_id", applicationId) .put("guild_id", guildId) @@ -40,7 +40,7 @@ public JSONObject compile() { } @NotNull - public static ApplicationCommandPermissions decompile(@NotNull JSONObject obj) { + public static ApplicationCommandPermissions decompile(@NotNull SJSONObject obj) { String id; String applicationId; String guildId; @@ -65,7 +65,7 @@ public static ApplicationCommandPermissions decompile(@NotNull JSONObject obj) { } try { - JSONArray permissionsArray = obj.getJSONArray("permissions"); + SJSONArray permissionsArray = obj.getJSONArray("permissions"); permissions = new ApplicationCommandPermissionsData[permissionsArray.length()]; for (int i = 0; i < permissionsArray.length(); i++) { permissions[i] = ApplicationCommandPermissionsData.decompile(permissionsArray.getJSONObject(i)); diff --git a/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissionsData.java b/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissionsData.java index 991104c7..92c5ca97 100644 --- a/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissionsData.java +++ b/src/main/java/com/seailz/discordjar/command/permissions/ApplicationCommandPermissionsData.java @@ -2,9 +2,9 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.Snowflake; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; import org.json.JSONException; -import org.json.JSONObject; /** * This class is used to represent the data of an application command permission. @@ -23,15 +23,15 @@ public record ApplicationCommandPermissionsData( ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("type", type.getCode()) .put("permission", permission); } @NotNull - public static ApplicationCommandPermissionsData decompile(@NotNull JSONObject obj) { + public static ApplicationCommandPermissionsData decompile(@NotNull SJSONObject obj) { String id; ApplicationCommandPermissionType type; boolean permission; diff --git a/src/main/java/com/seailz/discordjar/core/Compilerable.java b/src/main/java/com/seailz/discordjar/core/Compilerable.java index d895563a..49c60ef3 100644 --- a/src/main/java/com/seailz/discordjar/core/Compilerable.java +++ b/src/main/java/com/seailz/discordjar/core/Compilerable.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.core; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public interface Compilerable { - JSONObject compile(); + SJSONObject compile(); } diff --git a/src/main/java/com/seailz/discordjar/events/model/Event.java b/src/main/java/com/seailz/discordjar/events/model/Event.java index 2b70c2c9..013f8494 100644 --- a/src/main/java/com/seailz/discordjar/events/model/Event.java +++ b/src/main/java/com/seailz/discordjar/events/model/Event.java @@ -2,7 +2,7 @@ import com.seailz.discordjar.DiscordJar; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents an event that is fired by the Discord API @@ -19,9 +19,9 @@ public class Event { private final DiscordJar bot; private final long sequence; - private final JSONObject json; + private final SJSONObject json; - public Event(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public Event(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { this.bot = bot; this.sequence = sequence; this.json = data; @@ -37,7 +37,7 @@ public long getSequence() { } @NotNull - public JSONObject getJson() { + public SJSONObject getJson() { return json; } diff --git a/src/main/java/com/seailz/discordjar/events/model/automod/AutoModExecutionEvent.java b/src/main/java/com/seailz/discordjar/events/model/automod/AutoModExecutionEvent.java index f81cb0a2..339d1707 100644 --- a/src/main/java/com/seailz/discordjar/events/model/automod/AutoModExecutionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/automod/AutoModExecutionEvent.java @@ -4,15 +4,13 @@ import com.seailz.discordjar.events.model.guild.GuildEvent; import com.seailz.discordjar.model.automod.AutomodRule; import com.seailz.discordjar.model.channel.GuildChannel; -import com.seailz.discordjar.model.message.Message; import com.seailz.discordjar.model.user.User; -import com.seailz.discordjar.utils.rest.DiscordRequest; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; public class AutoModExecutionEvent extends GuildEvent { - public AutoModExecutionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public AutoModExecutionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleCreateEvent.java b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleCreateEvent.java index febaa861..6d4d6f6c 100644 --- a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleCreateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleCreateEvent.java @@ -2,11 +2,11 @@ import com.seailz.discordjar.DiscordJar; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public class AutoModRuleCreateEvent extends AutoModRuleEvent { - public AutoModRuleCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public AutoModRuleCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleDeleteEvent.java b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleDeleteEvent.java index 68a4cc3a..5237d436 100644 --- a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleDeleteEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleDeleteEvent.java @@ -1,11 +1,11 @@ package com.seailz.discordjar.events.model.automod.rule; import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public class AutoModRuleDeleteEvent extends AutoModRuleEvent { - public AutoModRuleDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public AutoModRuleDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } } diff --git a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleEvent.java b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleEvent.java index 2257a163..a6c1c16b 100644 --- a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleEvent.java @@ -3,13 +3,12 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.guild.GuildEvent; import com.seailz.discordjar.model.automod.AutomodRule; -import com.seailz.discordjar.utils.rest.DiscordRequest; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public class AutoModRuleEvent extends GuildEvent { - public AutoModRuleEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public AutoModRuleEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleUpdateEvent.java index 478de7d9..3d7e798a 100644 --- a/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleUpdateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/automod/rule/AutoModRuleUpdateEvent.java @@ -1,11 +1,11 @@ package com.seailz.discordjar.events.model.automod.rule; import com.seailz.discordjar.DiscordJar; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public class AutoModRuleUpdateEvent extends AutoModRuleEvent { - public AutoModRuleUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public AutoModRuleUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } } diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java index a4118295..8b18cfd4 100644 --- a/src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelEvent.java @@ -3,11 +3,11 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.model.channel.Channel; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public class ChannelEvent extends Event { - public ChannelEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ChannelEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java index a362f67f..26201340 100644 --- a/src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/channel/ChannelPinsUpdateEvent.java @@ -3,13 +3,11 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.model.channel.Channel; -import com.seailz.discordjar.model.channel.MessagingChannel; import com.seailz.discordjar.model.guild.Guild; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; -import java.util.Date; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -30,7 +28,7 @@ public class ChannelPinsUpdateEvent extends Event { private LocalDateTime lastPinTimestamp; - public ChannelPinsUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ChannelPinsUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); guildId = data.has("guild_id") ? data.getString("guild_id") : null; diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java index 30693876..7865ef5a 100644 --- a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelCreateEvent.java @@ -1,13 +1,12 @@ package com.seailz.discordjar.events.model.channel.edit; import com.seailz.discordjar.DiscordJar; -import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.events.model.channel.ChannelEvent; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public class ChannelCreateEvent extends ChannelEvent { - public ChannelCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ChannelCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } } diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java index 9f1a0c64..351e2087 100644 --- a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelDeleteEvent.java @@ -3,10 +3,10 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.channel.ChannelEvent; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public class ChannelDeleteEvent extends ChannelEvent { - public ChannelDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ChannelDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } } diff --git a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java index c91fb70a..192ee58a 100644 --- a/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/channel/edit/ChannelUpdateEvent.java @@ -3,10 +3,10 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.channel.ChannelEvent; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public class ChannelUpdateEvent extends ChannelEvent { - public ChannelUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ChannelUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } } diff --git a/src/main/java/com/seailz/discordjar/events/model/command/CommandPermissionUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/command/CommandPermissionUpdateEvent.java index dfe6fdc4..695106ef 100644 --- a/src/main/java/com/seailz/discordjar/events/model/command/CommandPermissionUpdateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/command/CommandPermissionUpdateEvent.java @@ -4,7 +4,7 @@ import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.command.permissions.ApplicationCommandPermissions; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Sent when the permissions of an application command are updated. @@ -14,7 +14,7 @@ * @since 1.0 */ public class CommandPermissionUpdateEvent extends Event { - public CommandPermissionUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public CommandPermissionUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/gateway/GatewayResumedEvent.java b/src/main/java/com/seailz/discordjar/events/model/gateway/GatewayResumedEvent.java index ecf72ed0..85f6f518 100644 --- a/src/main/java/com/seailz/discordjar/events/model/gateway/GatewayResumedEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/gateway/GatewayResumedEvent.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.Event; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; /** * This event fires when the gateway connection resumes. @@ -14,7 +14,7 @@ * @since 1.0 */ public class GatewayResumedEvent extends Event { - public GatewayResumedEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GatewayResumedEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } } diff --git a/src/main/java/com/seailz/discordjar/events/model/general/ReadyEvent.java b/src/main/java/com/seailz/discordjar/events/model/general/ReadyEvent.java index f5ede72d..07827fbd 100644 --- a/src/main/java/com/seailz/discordjar/events/model/general/ReadyEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/general/ReadyEvent.java @@ -5,8 +5,8 @@ import com.seailz.discordjar.model.application.Application; import com.seailz.discordjar.model.guild.UnavailableGuild; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -19,7 +19,7 @@ * @since 1.0 */ public class ReadyEvent extends Event { - public ReadyEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ReadyEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } @@ -48,7 +48,7 @@ public String getShard() { public List getGuilds() { List guilds = new ArrayList<>(); for (Object guild : getJson().getJSONObject("d").getJSONArray("guilds")) { - guilds.add(UnavailableGuild.decompile((JSONObject) guild, getBot())); + guilds.add(UnavailableGuild.decompile((SJSONObject) guild, getBot())); } return guilds; } diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/GuildCreateEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/GuildCreateEvent.java index 9a2bfa6f..eece0fe4 100644 --- a/src/main/java/com/seailz/discordjar/events/model/guild/GuildCreateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/guild/GuildCreateEvent.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.model.guild.Guild; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; /** * This event fires when the bot joins a guild. @@ -15,7 +15,7 @@ * @since 1.0 */ public class GuildCreateEvent extends Event { - public GuildCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GuildCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java index ddf76557..6c7dea3b 100644 --- a/src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/guild/GuildDeleteEvent.java @@ -4,7 +4,7 @@ import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.model.guild.UnavailableGuild; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Sent when the guild becomes or was already unavailable due to an outage, or when the user leaves or is removed from a guild. @@ -13,7 +13,7 @@ public class GuildDeleteEvent extends Event { private UnavailableGuild guild; - public GuildDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GuildDeleteEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); guild = UnavailableGuild.decompile(getJson().getJSONObject("d"), getBot()); } diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/GuildEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/GuildEvent.java index 62b50a60..bb9e6cac 100644 --- a/src/main/java/com/seailz/discordjar/events/model/guild/GuildEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/guild/GuildEvent.java @@ -3,14 +3,13 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.model.guild.Guild; -import com.seailz.discordjar.utils.rest.DiscordRequest; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public class GuildEvent extends Event { - public GuildEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GuildEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java index b272667d..2ebe3b16 100644 --- a/src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/guild/GuildUpdateEvent.java @@ -3,11 +3,11 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.model.guild.Guild; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public class GuildUpdateEvent extends Event { - public GuildUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GuildUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberAddEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberAddEvent.java index 305e05c7..121d9e3e 100644 --- a/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberAddEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberAddEvent.java @@ -1,12 +1,10 @@ package com.seailz.discordjar.events.model.guild.member; import com.seailz.discordjar.DiscordJar; -import com.seailz.discordjar.events.model.Event; import com.seailz.discordjar.events.model.guild.GuildEvent; import com.seailz.discordjar.model.guild.Member; -import com.seailz.discordjar.utils.rest.DiscordRequest; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Sent when a user joins a guild. @@ -17,7 +15,7 @@ * @see Member */ public class GuildMemberAddEvent extends GuildEvent { - public GuildMemberAddEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GuildMemberAddEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberRemoveEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberRemoveEvent.java index 8507ea09..42ead972 100644 --- a/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberRemoveEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberRemoveEvent.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.guild.GuildEvent; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; /** * Sent when a user is removed from a guild. @@ -21,7 +21,7 @@ * @see com.seailz.discordjar.model.guild.Member Member */ public class GuildMemberRemoveEvent extends GuildEvent { - public GuildMemberRemoveEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GuildMemberRemoveEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberUpdateEvent.java b/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberUpdateEvent.java index 8170bb19..230bfa5a 100644 --- a/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberUpdateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/guild/member/GuildMemberUpdateEvent.java @@ -3,9 +3,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.guild.GuildEvent; import com.seailz.discordjar.model.guild.Member; -import com.seailz.discordjar.utils.rest.DiscordRequest; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Sent when a guild member is updated. @@ -13,7 +12,7 @@ *
Requires the {@code GUILD_MEMBERS} intent. */ public class GuildMemberUpdateEvent extends GuildEvent { - public GuildMemberUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public GuildMemberUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/InteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/InteractionEvent.java index c522517d..c7dba17e 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/InteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/InteractionEvent.java @@ -17,7 +17,7 @@ import com.seailz.discordjar.utils.rest.DiscordRequest; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.lang.reflect.InvocationTargetException; @@ -30,7 +30,7 @@ * @since 1.0 */ public class InteractionEvent extends Event { - public InteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public InteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/button/ButtonInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/button/ButtonInteractionEvent.java index 112486f6..7e3d551d 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/button/ButtonInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/button/ButtonInteractionEvent.java @@ -9,12 +9,12 @@ import com.seailz.discordjar.model.interaction.modal.Modal; import com.seailz.discordjar.model.interaction.reply.InteractionModalResponse; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.registry.components.ButtonRegistry; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public class ButtonInteractionEvent extends InteractionEvent implements CustomIdable { - public ButtonInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ButtonInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); // First checks the button registry for any actions that match the custom id. We'll do this in a separate thread in order to not block the gateway thread. new Thread(() -> { diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/command/CommandInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/command/CommandInteractionEvent.java index 3ead9168..ece81c0d 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/command/CommandInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/command/CommandInteractionEvent.java @@ -8,12 +8,12 @@ import com.seailz.discordjar.model.interaction.data.command.ApplicationCommandInteractionData; import com.seailz.discordjar.model.interaction.modal.Modal; import com.seailz.discordjar.model.interaction.reply.InteractionModalResponse; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; public class CommandInteractionEvent extends InteractionEvent { - public CommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public CommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/command/MessageContextCommandInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/command/MessageContextCommandInteractionEvent.java index 09b591fd..4b12c400 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/command/MessageContextCommandInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/command/MessageContextCommandInteractionEvent.java @@ -3,18 +3,18 @@ import com.seailz.discordjar.DiscordJar; 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.DiscordResponse; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; public class MessageContextCommandInteractionEvent extends CommandInteractionEvent { - public MessageContextCommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public MessageContextCommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } @@ -29,7 +29,7 @@ public Message getTarget() { null; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.GET_MESSAGE.replace("{channel.id}", getInteraction().channel().id()).replace("{message.id}", String.valueOf(getCommandData().targetId())), getBot(), diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/command/SlashCommandInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/command/SlashCommandInteractionEvent.java index 00701aa3..dad305b2 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/command/SlashCommandInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/command/SlashCommandInteractionEvent.java @@ -2,18 +2,18 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.interaction.data.command.ResolvedCommandOption; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; public class SlashCommandInteractionEvent extends CommandInteractionEvent { - public SlashCommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public SlashCommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } @@ -25,7 +25,7 @@ public SlashCommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @Not @Nullable public List getOptions() { if (!getJson().getJSONObject("d").getJSONObject("data").has("options")) return null; - JSONArray options = getJson().getJSONObject("d").getJSONObject("data").getJSONArray("options"); + SJSONArray options = getJson().getJSONObject("d").getJSONObject("data").getJSONArray("options"); try { options = options.getJSONObject(0).getJSONArray("options"); @@ -33,7 +33,7 @@ public List getOptions() { List decompiled = new ArrayList<>(); for (Object option : options) { - decompiled.add(ResolvedCommandOption.decompile((JSONObject) option, getCommandData().resolved())); + decompiled.add(ResolvedCommandOption.decompile((SJSONObject) option, getCommandData().resolved())); } return decompiled; } @@ -45,11 +45,11 @@ public List getOptions() { */ public List getOptionsInternal() { if (!getJson().getJSONObject("d").getJSONObject("data").has("options")) return null; - JSONArray options = getJson().getJSONObject("d").getJSONObject("data").getJSONArray("options"); + SJSONArray options = getJson().getJSONObject("d").getJSONObject("data").getJSONArray("options"); List decompiled = new ArrayList<>(); for (Object option : options) { - decompiled.add(ResolvedCommandOption.decompile((JSONObject) option, getCommandData().resolved())); + decompiled.add(ResolvedCommandOption.decompile((SJSONObject) option, getCommandData().resolved())); } return decompiled; } diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/command/UserContextCommandInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/command/UserContextCommandInteractionEvent.java index 5f63e1bd..ecb85742 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/command/UserContextCommandInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/command/UserContextCommandInteractionEvent.java @@ -3,17 +3,17 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.user.User; 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.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; public class UserContextCommandInteractionEvent extends CommandInteractionEvent { - public UserContextCommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public UserContextCommandInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } @@ -29,7 +29,7 @@ public User getTarget() { null; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.USER.GET_USER.replace("{user_id}", String.valueOf(getCommandData().targetId())), getBot(), diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/modal/ModalInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/modal/ModalInteractionEvent.java index 91529d9d..2402c126 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/modal/ModalInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/modal/ModalInteractionEvent.java @@ -9,7 +9,7 @@ import com.seailz.discordjar.model.interaction.modal.Modal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -26,7 +26,7 @@ * @since 1.0 */ public class ModalInteractionEvent extends InteractionEvent implements CustomIdable { - public ModalInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public ModalInteractionEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/select/StringSelectMenuInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/select/StringSelectMenuInteractionEvent.java index 3ebadc01..90f625a8 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/select/StringSelectMenuInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/select/StringSelectMenuInteractionEvent.java @@ -12,10 +12,9 @@ import com.seailz.discordjar.model.interaction.modal.Modal; import com.seailz.discordjar.model.interaction.reply.InteractionModalResponse; import com.seailz.discordjar.model.user.User; -import com.seailz.discordjar.utils.registry.components.ButtonRegistry; import com.seailz.discordjar.utils.registry.components.StringSelectRegistry; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -33,7 +32,7 @@ */ public class StringSelectMenuInteractionEvent extends InteractionEvent implements CustomIdable { - public StringSelectMenuInteractionEvent(DiscordJar bot, long sequence, JSONObject data) { + public StringSelectMenuInteractionEvent(DiscordJar bot, long sequence, SJSONObject data) { super(bot, sequence, data); StringSelectRegistry.getInstance().getRegistry().stream() diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/ChannelSelectMenuInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/ChannelSelectMenuInteractionEvent.java index 7b495dc4..0d29dc79 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/ChannelSelectMenuInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/ChannelSelectMenuInteractionEvent.java @@ -12,10 +12,9 @@ import com.seailz.discordjar.model.interaction.modal.Modal; import com.seailz.discordjar.model.interaction.reply.InteractionModalResponse; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.registry.components.ChannelSelectRegistry; -import com.seailz.discordjar.utils.registry.components.StringSelectRegistry; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -34,7 +33,7 @@ */ public class ChannelSelectMenuInteractionEvent extends InteractionEvent implements CustomIdable { - public ChannelSelectMenuInteractionEvent(DiscordJar bot, long sequence, JSONObject data) { + public ChannelSelectMenuInteractionEvent(DiscordJar bot, long sequence, SJSONObject data) { super(bot, sequence, data); ChannelSelectRegistry.getInstance().getRegistry().stream() diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/RoleSelectMenuInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/RoleSelectMenuInteractionEvent.java index 45d16717..7111196b 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/RoleSelectMenuInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/RoleSelectMenuInteractionEvent.java @@ -12,8 +12,8 @@ import com.seailz.discordjar.model.interaction.reply.InteractionModalResponse; import com.seailz.discordjar.model.role.Role; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import java.util.List; @@ -31,7 +31,7 @@ */ public class RoleSelectMenuInteractionEvent extends InteractionEvent implements CustomIdable { - public RoleSelectMenuInteractionEvent(DiscordJar bot, long sequence, JSONObject data) { + public RoleSelectMenuInteractionEvent(DiscordJar bot, long sequence, SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/UserSelectMenuInteractionEvent.java b/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/UserSelectMenuInteractionEvent.java index 4522204d..215e94ff 100644 --- a/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/UserSelectMenuInteractionEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/interaction/select/entity/UserSelectMenuInteractionEvent.java @@ -11,9 +11,8 @@ import com.seailz.discordjar.model.interaction.modal.Modal; import com.seailz.discordjar.model.interaction.reply.InteractionModalResponse; import com.seailz.discordjar.model.user.User; -import com.seailz.discordjar.utils.rest.DiscordRequest; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -32,7 +31,7 @@ */ public class UserSelectMenuInteractionEvent extends InteractionEvent implements CustomIdable { - public UserSelectMenuInteractionEvent(DiscordJar bot, long sequence, JSONObject data) { + public UserSelectMenuInteractionEvent(DiscordJar bot, long sequence, SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/message/MessageCreateEvent.java b/src/main/java/com/seailz/discordjar/events/model/message/MessageCreateEvent.java index ddc62f0f..027fa9c9 100644 --- a/src/main/java/com/seailz/discordjar/events/model/message/MessageCreateEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/message/MessageCreateEvent.java @@ -6,7 +6,7 @@ import com.seailz.discordjar.utils.rest.DiscordRequest; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * This event will fire when a message is sent/created. @@ -26,7 +26,7 @@ public class MessageCreateEvent extends MessageEvent { * @param sequence The sequence number of the event * @param data The data of the event */ - public MessageCreateEvent(DiscordJar bot, long sequence, JSONObject data) { + public MessageCreateEvent(DiscordJar bot, long sequence, SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/message/MessageEvent.java b/src/main/java/com/seailz/discordjar/events/model/message/MessageEvent.java index bcde74e9..8c4c7252 100644 --- a/src/main/java/com/seailz/discordjar/events/model/message/MessageEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/message/MessageEvent.java @@ -2,7 +2,7 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.events.model.Event; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a message event that is fired by the Discord API @@ -14,7 +14,7 @@ * @since 1.0 */ class MessageEvent extends Event { - public MessageEvent(DiscordJar bot, long sequence, JSONObject data) { + public MessageEvent(DiscordJar bot, long sequence, SJSONObject data) { super(bot, sequence, data); } diff --git a/src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java b/src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java index 5ebac707..66637bf2 100644 --- a/src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java +++ b/src/main/java/com/seailz/discordjar/events/model/message/TypingStartEvent.java @@ -8,7 +8,7 @@ import com.seailz.discordjar.model.user.User; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * This event will fire when a user starts typing. @@ -30,9 +30,9 @@ public class TypingStartEvent extends Event { private final long timestamp; private Member member; - public TypingStartEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObject data) { + public TypingStartEvent(@NotNull DiscordJar bot, long sequence, @NotNull SJSONObject data) { super(bot, sequence, data); - JSONObject inner = data.getJSONObject("d"); + SJSONObject inner = data.getJSONObject("d"); channelId = inner.getString("channel_id"); guildId = inner.has("guild_id") && !inner.isNull("guild_id") ? inner.getString("guild_id") : null; userId = inner.getString("user_id"); diff --git a/src/main/java/com/seailz/discordjar/gateway/GatewayFactory.java b/src/main/java/com/seailz/discordjar/gateway/GatewayFactory.java index e17cb220..561765b4 100644 --- a/src/main/java/com/seailz/discordjar/gateway/GatewayFactory.java +++ b/src/main/java/com/seailz/discordjar/gateway/GatewayFactory.java @@ -12,11 +12,11 @@ import com.seailz.discordjar.model.guild.Member; import com.seailz.discordjar.model.status.Status; 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.JSONArray; +import com.seailz.discordjar.utils.json.SJSONArray; import org.json.JSONException; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; @@ -77,7 +77,7 @@ public GatewayFactory(DiscordJar discordJar, boolean debug, int shardId, int num DiscordResponse response = null; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), "/gateway", discordJar, @@ -223,7 +223,7 @@ public Status getStatus() { return status; } - public void queueMessage(JSONObject payload) { + public void queueMessage(SJSONObject payload) { if (debug) { logger.info("[DISCORD.JAR - DEBUG] Queued message: " + payload.toString()); } @@ -239,7 +239,7 @@ public void queueMessage(JSONObject payload) { @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { super.handleTextMessage(session, message); - JSONObject payload = new JSONObject(message.getPayload()); + SJSONObject payload = new SJSONObject(message.getPayload()); if (discordJar.getGateway() != this) { // Drop connection if we're not the active gateway killConnection(); @@ -307,7 +307,7 @@ protected void handleTextMessage(WebSocketSession session, TextMessage message) } } - private void handleDispatched(JSONObject payload) { + private void handleDispatched(SJSONObject payload) { // Handle dispatched events // actually dispatch the event Class eventClass = DispatchedEvents.getEventByName(payload.getString("t")).getEvent().apply(payload, this, discordJar); @@ -323,7 +323,7 @@ private void handleDispatched(JSONObject payload) { new Thread(() -> { Event event; try { - event = eventClass.getConstructor(DiscordJar.class, long.class, JSONObject.class) + event = eventClass.getConstructor(DiscordJar.class, long.class, SJSONObject.class) .newInstance(discordJar, sequence, payload); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException e) { logger.warning("[DISCORD.JAR - EVENTS] Failed to dispatch " + eventClass.getName() + " event. This is usually a bug, please report it on discord.jar's GitHub with this log message."); @@ -352,7 +352,7 @@ private void handleDispatched(JSONObject payload) { readyForMessages = true; if (discordJar.getStatus() != null) { - JSONObject json = new JSONObject(); + SJSONObject json = new SJSONObject(); json.put("d", discordJar.getStatus().compile()); json.put("op", 3); queueMessage(json); @@ -417,7 +417,7 @@ public void reconnect() throws IOException { connect(resumeUrl); */ } - private void handleHello(JSONObject payload) { + private void handleHello(SJSONObject payload) { heartbeatManager = new Heart(payload.getJSONObject("d").getInt("heartbeat_interval"), this); } @@ -434,21 +434,21 @@ private void sendIdentify() { discordJar.getIntents().forEach(intent -> intents.getAndAdd(intent.getLeftShiftId())); } - JSONObject payload = new JSONObject(); + SJSONObject payload = new SJSONObject(); payload.put("op", 2); - JSONObject data = new JSONObject(); + SJSONObject data = new SJSONObject(); data.put("token", discordJar.getToken()); if (numShards != -1 && shardId != -1) { - data.put("shard", new JSONArray().put(shardId).put(numShards)); + data.put("shard", new SJSONArray().put(shardId).put(numShards)); } String os = System.getProperty("os.name").toLowerCase(); - data.put("properties", new JSONObject().put("os", os).put("browser", "discord.jar").put("device", "discord.jar")); + data.put("properties", new SJSONObject().put("os", os).put("browser", "discord.jar").put("device", "discord.jar")); data.put("intents", intents.get()); payload.put("d", data); sendPayload(payload); } - public void sendPayload(JSONObject payload) { + public void sendPayload(SJSONObject payload) { if (session == null) { // Session is null, restart gateway discordJar.restartGateway(); @@ -470,8 +470,8 @@ public void requestGuildMembers(RequestGuildMembersAction action, CompletableFut logger.info("[DISCORD.JAR - DEBUG] Requesting guild members..."); } - JSONObject payload = new JSONObject(); - JSONObject dPayload = new JSONObject(); + SJSONObject payload = new SJSONObject(); + SJSONObject dPayload = new SJSONObject(); dPayload.put("guild_id", action.getGuildId()); if (action.getQuery() != null) { dPayload.put("query", action.getQuery()); diff --git a/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java b/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java index 7cff9fb7..bf363415 100644 --- a/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java +++ b/src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java @@ -41,9 +41,9 @@ import com.seailz.discordjar.model.interaction.callback.InteractionCallbackType; import com.seailz.discordjar.utils.TriFunction; import com.seailz.discordjar.utils.URLS; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -75,9 +75,9 @@ public enum DispatchedEvents { Guild guild = Guild.decompile(p.getJSONObject("d"), g); g.getGuildCache().cache(guild); - JSONArray arr = p.getJSONObject("d").getJSONArray("channels"); + SJSONArray arr = p.getJSONObject("d").getJSONArray("channels"); arr.forEach(o -> g.getChannelCache().cache( - Channel.decompile((JSONObject) o, g) + Channel.decompile((SJSONObject) o, g) )); // Cache all members @@ -86,7 +86,7 @@ public enum DispatchedEvents { long start = System.currentTimeMillis(); g.insertMemberCache( guild.id(), Member.decompile( - (JSONObject) o, + (SJSONObject) o, g, guild.id(), guild @@ -134,7 +134,7 @@ public enum DispatchedEvents { try { new DiscordRequest( - new JSONObject() + new SJSONObject() .put("type", InteractionCallbackType.PONG.getCode()), new HashMap<>(), URLS.POST.INTERACTIONS.CALLBACK.replace("{interaction.id}", @@ -254,7 +254,7 @@ public enum DispatchedEvents { AUTO_MODERATION_ACTION_EXECUTION((p, g, d) -> AutoModExecutionEvent.class), GUILD_MEMBERS_CHUNK((p, g, d) -> { - JSONObject payload = p.getJSONObject("d"); + SJSONObject payload = p.getJSONObject("d"); String nonce = payload.getString("nonce"); if (nonce == null) { @@ -270,9 +270,9 @@ public enum DispatchedEvents { return null; } - JSONArray members = payload.getJSONArray("members"); + SJSONArray members = payload.getJSONArray("members"); members.forEach(member -> { - wrapper.addMember(Member.decompile((JSONObject) member, d, payload.getString("guild_id"), d.getGuildById(payload.getString("guild_id")))); + wrapper.addMember(Member.decompile((SJSONObject) member, d, payload.getString("guild_id"), d.getGuildById(payload.getString("guild_id")))); }); int chunkCount = payload.getInt("chunk_count") - 1; @@ -288,13 +288,13 @@ public enum DispatchedEvents { UNKNOWN((p, g, d) -> null), ; - private final TriFunction> event; + private final TriFunction> event; - DispatchedEvents(TriFunction> event) { + DispatchedEvents(TriFunction> event) { this.event = event; } - public TriFunction> getEvent() { + public TriFunction> getEvent() { return event; } diff --git a/src/main/java/com/seailz/discordjar/gateway/heartbeat/Heart.java b/src/main/java/com/seailz/discordjar/gateway/heartbeat/Heart.java index 64a128a2..b771dc63 100644 --- a/src/main/java/com/seailz/discordjar/gateway/heartbeat/Heart.java +++ b/src/main/java/com/seailz/discordjar/gateway/heartbeat/Heart.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.gateway.heartbeat; import com.seailz.discordjar.gateway.GatewayFactory; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.Date; import java.util.Random; @@ -68,7 +68,7 @@ public void forceHeartbeat() { private void send() { factory.sendPayload( - new JSONObject() + new SJSONObject() .put("op", 1) .put("d", GatewayFactory.sequence) ); diff --git a/src/main/java/com/seailz/discordjar/http/HttpOnlyManager.java b/src/main/java/com/seailz/discordjar/http/HttpOnlyManager.java index 9e913634..cb847550 100644 --- a/src/main/java/com/seailz/discordjar/http/HttpOnlyManager.java +++ b/src/main/java/com/seailz/discordjar/http/HttpOnlyManager.java @@ -15,10 +15,10 @@ import com.seailz.discordjar.gateway.GatewayFactory; import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.interaction.Interaction; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.DiscordRequest; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.codec.DecoderException; -import org.json.JSONObject; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -69,7 +69,7 @@ public ResponseEntity get(HttpServletRequest request) throws IOException // handle interaction request - Interaction interaction = Interaction.decompile(new JSONObject(body), discordJar); + Interaction interaction = Interaction.decompile(new SJSONObject(body), discordJar); switch (interaction.type()) { case PING -> { return ResponseEntity.ok("{\"type\": 1}"); @@ -77,38 +77,38 @@ public ResponseEntity get(HttpServletRequest request) throws IOException case APPLICATION_COMMAND -> { CommandInteractionEvent event = null; - switch (CommandType.fromCode(new JSONObject(interaction.raw()).getJSONObject("data").getInt("type"))) { + switch (CommandType.fromCode(new SJSONObject(interaction.raw()).getJSONObject("data").getInt("type"))) { case SLASH_COMMAND -> { - event = new SlashCommandInteractionEvent(discordJar, GatewayFactory.sequence, new JSONObject().put("d", new JSONObject(body))); + event = new SlashCommandInteractionEvent(discordJar, GatewayFactory.sequence, new SJSONObject().put("d", new SJSONObject(body))); } case USER -> - event = new UserContextCommandInteractionEvent(discordJar, GatewayFactory.sequence, new JSONObject().put("d", new JSONObject(body))); + event = new UserContextCommandInteractionEvent(discordJar, GatewayFactory.sequence, new SJSONObject().put("d", new SJSONObject(body))); case MESSAGE -> - event = new MessageContextCommandInteractionEvent(discordJar, GatewayFactory.sequence, new JSONObject().put("d", new JSONObject(body))); + event = new MessageContextCommandInteractionEvent(discordJar, GatewayFactory.sequence, new SJSONObject().put("d", new SJSONObject(body))); } - discordJar.getCommandDispatcher().dispatch(new JSONObject(interaction.raw()).getJSONObject("data").getString("name"), event); + discordJar.getCommandDispatcher().dispatch(new SJSONObject(interaction.raw()).getJSONObject("data").getString("name"), event); } case MESSAGE_COMPONENT -> { - switch (ComponentType.getType(new JSONObject().put("d", new JSONObject(body)).getJSONObject("d").getJSONObject("data").getInt("component_type"))) { + switch (ComponentType.getType(new SJSONObject().put("d", new SJSONObject(body)).getJSONObject("d").getJSONObject("data").getInt("component_type"))) { case BUTTON -> { - ButtonInteractionEvent event = new ButtonInteractionEvent(discordJar, 0L, new JSONObject().put("d", new JSONObject(body))); + ButtonInteractionEvent event = new ButtonInteractionEvent(discordJar, 0L, new SJSONObject().put("d", new SJSONObject(body))); discordJar.getEventDispatcher().dispatchEvent(event, ButtonInteractionEvent.class, discordJar); } case STRING_SELECT -> { - StringSelectMenuInteractionEvent event = new StringSelectMenuInteractionEvent(discordJar, 0L, new JSONObject().put("d", new JSONObject(body))); + StringSelectMenuInteractionEvent event = new StringSelectMenuInteractionEvent(discordJar, 0L, new SJSONObject().put("d", new SJSONObject(body))); discordJar.getEventDispatcher().dispatchEvent(event, StringSelectMenuInteractionEvent.class, discordJar); } case ROLE_SELECT -> { - RoleSelectMenuInteractionEvent event = new RoleSelectMenuInteractionEvent(discordJar, 0L, new JSONObject().put("d", new JSONObject(body))); + RoleSelectMenuInteractionEvent event = new RoleSelectMenuInteractionEvent(discordJar, 0L, new SJSONObject().put("d", new SJSONObject(body))); discordJar.getEventDispatcher().dispatchEvent(event, RoleSelectMenuInteractionEvent.class, discordJar); } case USER_SELECT -> { - UserSelectMenuInteractionEvent event = new UserSelectMenuInteractionEvent(discordJar, 0L, new JSONObject().put("d", new JSONObject(body))); + UserSelectMenuInteractionEvent event = new UserSelectMenuInteractionEvent(discordJar, 0L, new SJSONObject().put("d", new SJSONObject(body))); discordJar.getEventDispatcher().dispatchEvent(event, UserSelectMenuInteractionEvent.class, discordJar); } case CHANNEL_SELECT -> { - ChannelSelectMenuInteractionEvent event = new ChannelSelectMenuInteractionEvent(discordJar, 0L, new JSONObject().put("d", new JSONObject(body))); + ChannelSelectMenuInteractionEvent event = new ChannelSelectMenuInteractionEvent(discordJar, 0L, new SJSONObject().put("d", new SJSONObject(body))); discordJar.getEventDispatcher().dispatchEvent(event, ChannelSelectMenuInteractionEvent.class, discordJar); } @@ -118,12 +118,12 @@ public ResponseEntity get(HttpServletRequest request) throws IOException } case MODAL_SUBMIT -> { - ModalInteractionEvent event = new ModalInteractionEvent(discordJar, 0L, new JSONObject().put("d", new JSONObject(body))); + ModalInteractionEvent event = new ModalInteractionEvent(discordJar, 0L, new SJSONObject().put("d", new SJSONObject(body))); discordJar.getEventDispatcher().dispatchEvent(event, ModalInteractionEvent.class, discordJar); } case UNKNOWN -> { Logger.getLogger("DispatchedEvents").warning( - "[discord.jar] Unknown interaction type: " + new JSONObject().put("d", new JSONObject(body)).getJSONObject("d").getInt("type") + ". This is usually because of an outdated framework version. Please update discord.jar"); + "[discord.jar] Unknown interaction type: " + new SJSONObject().put("d", new SJSONObject(body)).getJSONObject("d").getInt("type") + ". This is usually because of an outdated framework version. Please update discord.jar"); return null; } } diff --git a/src/main/java/com/seailz/discordjar/model/application/Application.java b/src/main/java/com/seailz/discordjar/model/application/Application.java index 064a7035..0e7fa2de 100644 --- a/src/main/java/com/seailz/discordjar/model/application/Application.java +++ b/src/main/java/com/seailz/discordjar/model/application/Application.java @@ -8,15 +8,15 @@ import com.seailz.discordjar.utils.Checker; import com.seailz.discordjar.utils.URLS; import com.seailz.discordjar.utils.flag.Bitwiseable; +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.Snowflake; import com.seailz.discordjar.utils.flag.BitwiseUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.Arrays; @@ -79,8 +79,8 @@ public record Application( ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("name", name) .put("icon", iconUrl) @@ -104,7 +104,7 @@ public JSONObject compile() { .put("role_connections_verification_url", roleConnectionsVerificationUrl); } - public static Application decompile(JSONObject obj, DiscordJar discordJar) { + public static Application decompile(SJSONObject obj, DiscordJar discordJar) { if (obj == null) return new Application(null, null, null, null, null, false, false, null, null, null, null, null, null, null, null, null, null, null, 0, null, null, null, null, discordJar); String id; String name; @@ -300,7 +300,7 @@ public List getRoleConnections() { DiscordResponse response = null; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.APPLICATIONS.GET_APPLICATION_ROLE_CONNECTIONS .replace("{application.id}", id), @@ -313,8 +313,8 @@ public List getRoleConnections() { } if (response.code() == 200) { - return new JSONArray(response.body()).toList().stream() - .map(o -> ApplicationRoleConnectionMetadata.decompile((JSONObject) o)) + return new SJSONArray(response.body()).toList().stream() + .map(o -> ApplicationRoleConnectionMetadata.decompile((SJSONObject) o)) .toList(); } else { return null; @@ -333,7 +333,7 @@ public List getRoleConnections() { public void setRoleConnections(@NotNull List roleConnections) { Checker.notNull(roleConnections, "Role connections must not be null"); Checker.sizeLessThan(roleConnections, 5, "You can only have up to 5 role connections."); - JSONArray roleConnectionsArray = new JSONArray(); + SJSONArray roleConnectionsArray = new SJSONArray(); roleConnections.stream().map(ApplicationRoleConnectionMetadata::compile).forEach(roleConnectionsArray::put); try { diff --git a/src/main/java/com/seailz/discordjar/model/application/ApplicationRoleConnectionMetadata.java b/src/main/java/com/seailz/discordjar/model/application/ApplicationRoleConnectionMetadata.java index c62cf0bd..86581fb4 100644 --- a/src/main/java/com/seailz/discordjar/model/application/ApplicationRoleConnectionMetadata.java +++ b/src/main/java/com/seailz/discordjar/model/application/ApplicationRoleConnectionMetadata.java @@ -1,9 +1,9 @@ package com.seailz.discordjar.model.application; import com.seailz.discordjar.core.Compilerable; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import java.util.HashMap; @@ -33,27 +33,27 @@ public record ApplicationRoleConnectionMetadata( HashMap descriptionLocalizations ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject json = new JSONObject(); + public SJSONObject compile() { + SJSONObject json = new SJSONObject(); json.put("type", type.getCode()); json.put("key", key); json.put("name", name); - if (!nameLocalizations.isEmpty()) json.put("name_localizations", new JSONObject(nameLocalizations)); + if (!nameLocalizations.isEmpty()) json.put("name_localizations", new SJSONObject(nameLocalizations)); json.put("description", description); - if (!descriptionLocalizations.isEmpty()) json.put("description_localizations", new JSONObject(descriptionLocalizations)); + if (!descriptionLocalizations.isEmpty()) json.put("description_localizations", new SJSONObject(descriptionLocalizations)); return json; } @NotNull @Contract("_ -> new") - public static ApplicationRoleConnectionMetadata decompile(@NotNull JSONObject json) { + public static ApplicationRoleConnectionMetadata decompile(@NotNull SJSONObject json) { Type type = json.has("type") ? Type.fromCode(json.getInt("type")) : null; String key = json.has("key") ? json.getString("key") : null; String name = json.has("name") ? json.getString("name") : null; HashMap nameLocalizations; if (json.has("name_localizations")) { - JSONObject nameLocalizationsJson = json.getJSONObject("name_localizations"); + SJSONObject nameLocalizationsJson = json.getJSONObject("name_localizations"); nameLocalizations = new HashMap<>(); for (String key1 : nameLocalizationsJson.keySet()) { nameLocalizations.put(key1, nameLocalizationsJson.getString(key1)); @@ -66,7 +66,7 @@ public static ApplicationRoleConnectionMetadata decompile(@NotNull JSONObject js HashMap descriptionLocalizations; if (json.has("description_localizations")) { - JSONObject descriptionLocalizationsJson = json.getJSONObject("description_localizations"); + SJSONObject descriptionLocalizationsJson = json.getJSONObject("description_localizations"); descriptionLocalizations = new HashMap<>(); for (String key1 : descriptionLocalizationsJson.keySet()) { descriptionLocalizations.put(key1, descriptionLocalizationsJson.getString(key1)); diff --git a/src/main/java/com/seailz/discordjar/model/automod/AutomodRule.java b/src/main/java/com/seailz/discordjar/model/automod/AutomodRule.java index b2de93e8..ad32db11 100644 --- a/src/main/java/com/seailz/discordjar/model/automod/AutomodRule.java +++ b/src/main/java/com/seailz/discordjar/model/automod/AutomodRule.java @@ -8,13 +8,12 @@ import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.Checker; import com.seailz.discordjar.utils.Snowflake; -import com.seailz.discordjar.utils.rest.DiscordRequest; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; -import org.json.JSONArray; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -50,8 +49,8 @@ public record AutomodRule( @NotNull @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("guild_id", guild.id()); @@ -61,7 +60,7 @@ public JSONObject compile() { obj.put("trigger", trigger.code); obj.put("trigger_metadata", triggerMetadata.compile()); - JSONArray actionsArray = new JSONArray(); + SJSONArray actionsArray = new SJSONArray(); for (Action action : actions) { actionsArray.put(action.compile()); } @@ -69,7 +68,7 @@ public JSONObject compile() { obj.put("actions", actionsArray); obj.put("enabled", enabled); - JSONArray exemptRolesArray = new JSONArray(); + SJSONArray exemptRolesArray = new SJSONArray(); Checker.check(exemptChannels.size() > 20, "Exempt roles cannot be more than 20"); for (Role role : exemptRoles) { exemptRolesArray.put(role.id()); @@ -77,7 +76,7 @@ public JSONObject compile() { obj.put("exempt_roles", exemptRolesArray); - JSONArray exemptChannelsArray = new JSONArray(); + SJSONArray exemptChannelsArray = new SJSONArray(); Checker.check(exemptChannels.size() > 50, "Exempt channels cannot be more than 50"); for (Channel channel : exemptChannels) { exemptChannelsArray.put(channel.id()); @@ -89,7 +88,7 @@ public JSONObject compile() { @NotNull @Contract("_, _ -> new") - public static AutomodRule decompile(@NotNull JSONObject obj, @NotNull DiscordJar discordJar) { + public static AutomodRule decompile(@NotNull SJSONObject obj, @NotNull DiscordJar discordJar) { String id; Guild guild; String name; @@ -110,7 +109,7 @@ public static AutomodRule decompile(@NotNull JSONObject obj, @NotNull DiscordJar trigger = TriggerType.fromCode(obj.getInt("trigger_type")); triggerMetadata = TriggerMetadata.decompile(obj.getJSONObject("trigger_metadata")); - JSONArray actionsArray = obj.getJSONArray("actions"); + SJSONArray actionsArray = obj.getJSONArray("actions"); actions = new ArrayList<>(); for (int i = 0; i < actionsArray.length(); i++) { actions.add(Action.decompile(actionsArray.getJSONObject(i))); @@ -118,7 +117,7 @@ public static AutomodRule decompile(@NotNull JSONObject obj, @NotNull DiscordJar enabled = obj.getBoolean("enabled"); - JSONArray exemptRolesArray = obj.getJSONArray("exempt_roles"); + SJSONArray exemptRolesArray = obj.getJSONArray("exempt_roles"); exemptRoles = new ArrayList<>(); for (int i = 0; i < exemptRolesArray.length(); i++) { int finalI = i; @@ -129,7 +128,7 @@ public static AutomodRule decompile(@NotNull JSONObject obj, @NotNull DiscordJar }); } - JSONArray exemptChannelsArray = obj.getJSONArray("exempt_channels"); + SJSONArray exemptChannelsArray = obj.getJSONArray("exempt_channels"); exemptChannels = new ArrayList<>(); for (int i = 0; i < exemptChannelsArray.length(); i++) { exemptChannels.add(discordJar.getChannelById(exemptChannelsArray.getString(i))); @@ -139,7 +138,7 @@ public static AutomodRule decompile(@NotNull JSONObject obj, @NotNull DiscordJar } @NotNull - public static List decompileList(@NotNull JSONArray array, @NotNull DiscordJar discordJar) { + public static List decompileList(@NotNull SJSONArray array, @NotNull DiscordJar discordJar) { List rules = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { rules.add(decompile(array.getJSONObject(i), discordJar)); @@ -224,12 +223,12 @@ public record TriggerMetadata( ) implements Compilerable { @NotNull @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); if (keywords != null) { Checker.check(keywords.size() > 1000, "keywords list must be less than 1000"); - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (String keyword : keywords) { array.put(keyword); } @@ -238,7 +237,7 @@ public JSONObject compile() { if (regexes != null) { Checker.check(regexes.size() > 10, "regexes list must be less than 10"); - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (String regex : regexes) { array.put(regex); } @@ -246,7 +245,7 @@ public JSONObject compile() { } if (presets != null) { - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (KeywordPresetType preset : presets) { array.put(preset.getCode()); } @@ -254,7 +253,7 @@ public JSONObject compile() { } if (allowList != null) { - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (String allow : allowList) { array.put(allow); } @@ -274,7 +273,7 @@ public JSONObject compile() { @Contract("_ -> new") @NotNull - public static TriggerMetadata decompile(@NotNull JSONObject obj) { + public static TriggerMetadata decompile(@NotNull SJSONObject obj) { List keywords = new ArrayList<>(); List regexes = new ArrayList<>(); List presets = new ArrayList<>(); @@ -283,22 +282,22 @@ public static TriggerMetadata decompile(@NotNull JSONObject obj) { boolean mentionRaidProtectionEnabled = false; if (obj.has("keywords")) { - JSONArray array = obj.getJSONArray("keywords"); + SJSONArray array = obj.getJSONArray("keywords"); array.toList().forEach(o -> keywords.add((String) o)); } if (obj.has("regexes")) { - JSONArray array = obj.getJSONArray("regexes"); + SJSONArray array = obj.getJSONArray("regexes"); array.toList().forEach(o -> regexes.add((String) o)); } if (obj.has("presets")) { - JSONArray array = obj.getJSONArray("presets"); + SJSONArray array = obj.getJSONArray("presets"); array.toList().forEach(o -> presets.add(KeywordPresetType.fromCode((int) o))); } if (obj.has("allow_list")) { - JSONArray array = obj.getJSONArray("allow_list"); + SJSONArray array = obj.getJSONArray("allow_list"); array.toList().forEach(o -> allowList.add((String) o)); } @@ -353,15 +352,15 @@ public record Action( ) implements Compilerable { @NotNull @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("type", type.getCode()); obj.put("metadata", metadata.compile()); return obj; } @NotNull - public static Action decompile(@NotNull JSONObject obj) { + public static Action decompile(@NotNull SJSONObject obj) { ActionType type = ActionType.fromCode(obj.getInt("type")); ActionMetadata metadata = ActionMetadata.decompile(obj.getJSONObject("metadata")); return new Action(type, metadata); @@ -404,7 +403,7 @@ public interface ActionMetadata extends Compilerable { @Nullable @Unmodifiable @Contract(pure = true, value = "_ -> new") - static ActionMetadata decompile(@NotNull JSONObject obj) { + static ActionMetadata decompile(@NotNull SJSONObject obj) { if (obj.has("channel_id")) return SendAlertActionMetadata.decompile(obj); else if (obj.has("duration_seconds")) @@ -417,8 +416,8 @@ public record SendAlertActionMetadata( String channelId ) implements ActionMetadata { @Override - public @NotNull JSONObject compile() { - JSONObject obj = new JSONObject(); + public @NotNull SJSONObject compile() { + SJSONObject obj = new SJSONObject(); Checker.isSnowflake(channelId, "channelId must be a snowflake"); obj.put("channel_id", channelId); return obj; @@ -426,7 +425,7 @@ public record SendAlertActionMetadata( @NotNull @Contract("_ -> new") - public static SendAlertActionMetadata decompile(@NotNull JSONObject obj) { + public static SendAlertActionMetadata decompile(@NotNull SJSONObject obj) { String channelId = obj.getString("channel_id"); return new SendAlertActionMetadata(channelId); } @@ -436,8 +435,8 @@ public record TimeoutActionMetadata( int duration ) implements ActionMetadata { @Override - public @NotNull JSONObject compile() { - JSONObject obj = new JSONObject(); + public @NotNull SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("duration_seconds", duration); Checker.check(duration < 2419200, "duration must be less than 2419200 (4 weeks)"); return obj; @@ -445,7 +444,7 @@ public record TimeoutActionMetadata( @NotNull @Contract("_ -> new") - public static TimeoutActionMetadata decompile(@NotNull JSONObject obj) { + public static TimeoutActionMetadata decompile(@NotNull SJSONObject obj) { int duration = obj.getInt("duration_seconds"); return new TimeoutActionMetadata(duration); } @@ -455,15 +454,15 @@ public record BlockMessageActionMetadata( String customMessage ) implements ActionMetadata { @Override - public @NotNull JSONObject compile() { - JSONObject obj = new JSONObject(); + public @NotNull SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("custom_message", customMessage); return obj; } @NotNull @Contract("_ -> new") - public static BlockMessageActionMetadata decompile(@NotNull JSONObject obj) { + public static BlockMessageActionMetadata decompile(@NotNull SJSONObject obj) { String customMessage = obj.getString("custom_message"); return new BlockMessageActionMetadata(customMessage); } diff --git a/src/main/java/com/seailz/discordjar/model/channel/AudioChannel.java b/src/main/java/com/seailz/discordjar/model/channel/AudioChannel.java index d40842cb..2d10c300 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/AudioChannel.java +++ b/src/main/java/com/seailz/discordjar/model/channel/AudioChannel.java @@ -10,9 +10,8 @@ import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.message.Message; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -36,7 +35,7 @@ public interface AudioChannel extends GuildChannel, CategoryMember, Typeable, Me */ int bitrate(); - static AudioChannel decompile(JSONObject obj, DiscordJar discordJar) { + static AudioChannel decompile(SJSONObject obj, DiscordJar discordJar) { String id = obj.getString("id"); String name = obj.getString("name"); int position = obj.getInt("position"); @@ -46,7 +45,7 @@ static AudioChannel decompile(JSONObject obj, DiscordJar discordJar) { discordJar.getVoiceRegions().stream().filter(r -> r.id().equals(obj.getString("region"))).findFirst().ifPresent(region::set); int bitrate = obj.getInt("bitrate"); Category category = Category.fromId(obj.getString("parent_id"), discordJar); - JSONArray array = obj.getJSONArray("permission_overwrites"); + SJSONArray array = obj.getJSONArray("permission_overwrites"); List permissionOverwrites = new ArrayList<>(); if (array.length() > 0) { permissionOverwrites = new ArrayList<>(); diff --git a/src/main/java/com/seailz/discordjar/model/channel/Category.java b/src/main/java/com/seailz/discordjar/model/channel/Category.java index e181968c..7686066a 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/Category.java +++ b/src/main/java/com/seailz/discordjar/model/channel/Category.java @@ -5,9 +5,8 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -16,14 +15,14 @@ public interface Category extends GuildChannel { List members(); - static Category decompile(JSONObject obj, DiscordJar discordJar) { + static Category decompile(SJSONObject obj, DiscordJar discordJar) { String id = obj.getString("id"); ChannelType type = ChannelType.fromCode(obj.getInt("type")); String name = obj.getString("name"); Guild guild = obj.has("guild_id") ? discordJar.getGuildById(obj.getString("guild_id")) : null; int position = obj.getInt("position"); - JSONArray array = obj.getJSONArray("permission_overwrites"); + SJSONArray array = obj.getJSONArray("permission_overwrites"); List permissionOverwrites = new ArrayList<>(); if (array.length() > 0) { permissionOverwrites = new ArrayList<>(); diff --git a/src/main/java/com/seailz/discordjar/model/channel/CategoryMember.java b/src/main/java/com/seailz/discordjar/model/channel/CategoryMember.java index cabf6968..9e1b967d 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/CategoryMember.java +++ b/src/main/java/com/seailz/discordjar/model/channel/CategoryMember.java @@ -2,7 +2,7 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.channel.internal.CategoryMemberImpl; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a member of a {@link Category}. @@ -18,7 +18,7 @@ public interface CategoryMember { Category owner(); String parentId(); - static CategoryMember decompile(JSONObject obj, DiscordJar discordJar) { + static CategoryMember decompile(SJSONObject obj, DiscordJar discordJar) { Category owner = (Category) discordJar.getChannelById(obj.getString("parent_id")); return new CategoryMemberImpl(owner, obj.getString("parent_id")); } diff --git a/src/main/java/com/seailz/discordjar/model/channel/Channel.java b/src/main/java/com/seailz/discordjar/model/channel/Channel.java index 4541ce0e..1607dc73 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/Channel.java +++ b/src/main/java/com/seailz/discordjar/model/channel/Channel.java @@ -5,17 +5,15 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.channel.internal.ChannelImpl; import com.seailz.discordjar.model.channel.utils.ChannelType; -import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.resolve.Resolvable; import com.seailz.discordjar.utils.Checker; import com.seailz.discordjar.utils.Mentionable; import com.seailz.discordjar.utils.Snowflake; -import com.seailz.discordjar.utils.rest.DiscordRequest; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.Response; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; /** * Represents a Discord channel @@ -54,7 +52,7 @@ default String getMentionablePrefix() { @NotNull @Contract("_, _ -> new") - static Channel decompile(@NotNull JSONObject obj, DiscordJar discordJar) { + static Channel decompile(@NotNull SJSONObject obj, DiscordJar discordJar) { return new ChannelImpl( obj.getString("id"), ChannelType.fromCode(obj.getInt("type")), @@ -64,7 +62,7 @@ static Channel decompile(@NotNull JSONObject obj, DiscordJar discordJar) { } @NotNull - JSONObject raw(); + SJSONObject raw(); default ModifyBaseChannelAction modify() { return new ModifyBaseChannelAction(djv(), id()); diff --git a/src/main/java/com/seailz/discordjar/model/channel/DMChannel.java b/src/main/java/com/seailz/discordjar/model/channel/DMChannel.java index 8838c014..54549079 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/DMChannel.java +++ b/src/main/java/com/seailz/discordjar/model/channel/DMChannel.java @@ -9,10 +9,10 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.component.DisplayComponent; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -54,12 +54,12 @@ default MessageCreateAction sendComponents(DisplayComponent... components) { @NotNull @Contract("_, _ -> new") - static DMChannel decompile(@NotNull JSONObject obj, @NotNull DiscordJar djv) { - String lastMessageId = obj.has("last_message_id") && !obj.get("last_message_id").equals(JSONObject.NULL) ? obj.getString("last_message_id") : null; + static DMChannel decompile(@NotNull SJSONObject obj, @NotNull DiscordJar djv) { + String lastMessageId = obj.has("last_message_id") && !obj.get("last_message_id").equals(SJSONObject.NULL) ? obj.getString("last_message_id") : null; List recipients = new ArrayList<>(); - JSONArray recipientsArray = obj.getJSONArray("recipients"); - recipientsArray.forEach(o -> recipients.add(User.decompile((JSONObject) o, djv))); + SJSONArray recipientsArray = obj.getJSONArray("recipients"); + recipientsArray.forEach(o -> recipients.add(User.decompile((SJSONObject) o, djv))); String name = obj.has("name") ? obj.getString("name") : recipients.get(0).username(); return new DMChannelImpl(obj.getString("id"), ChannelType.DM, name, lastMessageId ,recipients, djv, obj); @@ -69,13 +69,13 @@ static DMChannel decompile(@NotNull JSONObject obj, @NotNull DiscordJar djv) { * Compiles this object */ @Override - default JSONObject compile() { - JSONObject obj = new JSONObject(); + default SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id()); obj.put("type", type().getCode()); if (lastMessageId() != null) obj.put("last_message_id", lastMessageId()); - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (User user : recipients()) array.put(user.compile()); diff --git a/src/main/java/com/seailz/discordjar/model/channel/ForumChannel.java b/src/main/java/com/seailz/discordjar/model/channel/ForumChannel.java index 1a4b5ef4..06357f5d 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/ForumChannel.java +++ b/src/main/java/com/seailz/discordjar/model/channel/ForumChannel.java @@ -4,14 +4,12 @@ import com.seailz.discordjar.action.message.StartThreadForumChannelAction; import com.seailz.discordjar.model.channel.forum.DefaultSortOrder; import com.seailz.discordjar.model.channel.forum.ForumTag; -import com.seailz.discordjar.model.channel.interfaces.Typeable; import com.seailz.discordjar.model.channel.internal.ForumChannelImpl; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; import java.util.ArrayList; import java.util.List; @@ -66,13 +64,13 @@ default StartThreadForumChannelAction startThread(String name, StartThreadForumC } @Override - default JSONObject compile() { - JSONArray permissionOverwrites = new JSONArray(); + default SJSONObject compile() { + SJSONArray permissionOverwrites = new SJSONArray(); permissionOverwrites.forEach(o -> permissionOverwrites.put(((PermissionOverwrite) o).compile())); - JSONArray tags = new JSONArray(); + SJSONArray tags = new SJSONArray(); tags.forEach(o -> tags.put(((ForumTag) o).compile())); - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("id", id()); obj.put("type", type().getCode()); obj.put("name", name()); @@ -87,14 +85,14 @@ default JSONObject compile() { return obj; } - static ForumChannel decompile(JSONObject obj, DiscordJar discordJar) { + static ForumChannel decompile(SJSONObject obj, DiscordJar discordJar) { String id = obj.getString("id"); String name = obj.getString("name"); int position = obj.getInt("position"); List permissionOverwrites = new ArrayList<>(); for (Object overwrite : obj.getJSONArray("permission_overwrites")) { - permissionOverwrites.add(PermissionOverwrite.decompile((JSONObject) overwrite)); + permissionOverwrites.add(PermissionOverwrite.decompile((SJSONObject) overwrite)); } boolean nsfw = obj.getBoolean("nsfw"); @@ -105,7 +103,7 @@ static ForumChannel decompile(JSONObject obj, DiscordJar discordJar) { List tags = new ArrayList<>(); if (obj.has("available_tags") && !obj.isNull("available_tags")) { for (Object tag : obj.getJSONArray("available_tags")) { - tags.add(ForumTag.decompile((JSONObject) tag)); + tags.add(ForumTag.decompile((SJSONObject) tag)); } } diff --git a/src/main/java/com/seailz/discordjar/model/channel/GroupDM.java b/src/main/java/com/seailz/discordjar/model/channel/GroupDM.java index 60c70441..13174f0a 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/GroupDM.java +++ b/src/main/java/com/seailz/discordjar/model/channel/GroupDM.java @@ -5,10 +5,10 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.image.ImageUtils; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; import java.util.ArrayList; import java.util.List; @@ -30,12 +30,12 @@ public interface GroupDM extends DMChannel { @NotNull @Contract("_, _ -> new") - static GroupDM decompile(@NotNull JSONObject obj, @NotNull DiscordJar discordJar) { + static GroupDM decompile(@NotNull SJSONObject obj, @NotNull DiscordJar discordJar) { String lastMessageId = obj.has("last_message_id") ? obj.getString("last_message_id") : null; List recipients = new ArrayList<>(); - JSONArray recipientsArray = obj.getJSONArray("recipients"); - recipientsArray.forEach(o -> recipients.add(User.decompile((JSONObject) o, discordJar))); + SJSONArray recipientsArray = obj.getJSONArray("recipients"); + recipientsArray.forEach(o -> recipients.add(User.decompile((SJSONObject) o, discordJar))); String name = obj.has("name") ? obj.getString("name") : recipients.get(0).username(); User owner = recipients.stream().filter(u -> u.id().equals(obj.getString("owner_id"))).findFirst().orElse(null); diff --git a/src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java b/src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java index 4dee137d..3ff58e68 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java +++ b/src/main/java/com/seailz/discordjar/model/channel/GuildChannel.java @@ -8,12 +8,12 @@ import com.seailz.discordjar.model.permission.PermissionOverwrite; import com.seailz.discordjar.utils.Checker; 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 org.jetbrains.annotations.Contract; 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.util.ArrayList; @@ -33,11 +33,11 @@ public interface GuildChannel extends Channel { boolean nsfw(); - @NotNull JSONObject raw(); + @NotNull SJSONObject raw(); @Override - default JSONObject compile() { - JSONObject obj = new JSONObject(); + default SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id()); obj.put("type", type().getCode()); obj.put("name", name()); @@ -46,7 +46,7 @@ default JSONObject compile() { obj.put("nsfw", nsfw()); if (permissionOverwrites() != null) { - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (PermissionOverwrite overwrite : permissionOverwrites()) array.put(overwrite.compile()); } @@ -56,16 +56,16 @@ default JSONObject compile() { } /** - * Decompile a {@link JSONObject} into a {@link GuildChannel} + * Decompile a {@link SJSONObject} into a {@link GuildChannel} * - * @param obj The {@link JSONObject} to decompile + * @param obj The {@link SJSONObject} to decompile * @param discordJar The {@link DiscordJar} instance * * @return The {@link GuildChannel} instance */ @NotNull @Contract("_, _ -> new") - static GuildChannel decompile(@NotNull JSONObject obj, @NotNull DiscordJar discordJar) { + static GuildChannel decompile(@NotNull SJSONObject obj, @NotNull DiscordJar discordJar) { String id = obj.getString("id"); ChannelType type = ChannelType.fromCode(obj.getInt("type")); String name = obj.getString("name"); @@ -75,9 +75,9 @@ static GuildChannel decompile(@NotNull JSONObject obj, @NotNull DiscordJar disco List permissionOverwrites = new ArrayList<>(); if (obj.has("permission_overwrites")) { - JSONArray array = obj.getJSONArray("permission_overwrites"); + SJSONArray array = obj.getJSONArray("permission_overwrites"); for (int i = 0; i < array.length(); i++) { - JSONObject overwrite = array.getJSONObject(i); + SJSONObject overwrite = array.getJSONObject(i); permissionOverwrites.add(PermissionOverwrite.decompile(overwrite)); } } diff --git a/src/main/java/com/seailz/discordjar/model/channel/MessagingChannel.java b/src/main/java/com/seailz/discordjar/model/channel/MessagingChannel.java index cc36b6e6..bcdd5178 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/MessagingChannel.java +++ b/src/main/java/com/seailz/discordjar/model/channel/MessagingChannel.java @@ -1,49 +1,21 @@ package com.seailz.discordjar.model.channel; import com.seailz.discordjar.DiscordJar; -import com.seailz.discordjar.action.message.MessageCreateAction; import com.seailz.discordjar.model.channel.interfaces.MessageRetrievable; import com.seailz.discordjar.model.channel.interfaces.Messageable; import com.seailz.discordjar.model.channel.interfaces.Transcriptable; import com.seailz.discordjar.model.channel.interfaces.Typeable; import com.seailz.discordjar.model.channel.internal.MessagingChannelImpl; -import com.seailz.discordjar.model.channel.transcript.TranscriptFormatter; import com.seailz.discordjar.model.channel.utils.ChannelType; -import com.seailz.discordjar.model.component.DisplayComponent; -import com.seailz.discordjar.model.embed.Embed; -import com.seailz.discordjar.model.embed.EmbedField; -import com.seailz.discordjar.model.embed.Embeder; import com.seailz.discordjar.model.guild.Guild; -import com.seailz.discordjar.model.message.Attachment; -import com.seailz.discordjar.model.guild.Member; -import com.seailz.discordjar.model.message.Message; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import com.seailz.discordjar.model.user.User; -import com.seailz.discordjar.utils.Checker; -import com.seailz.discordjar.utils.Snowflake; -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.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.Response; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.springframework.web.bind.annotation.RequestMethod; + import java.util.ArrayList; -import java.util.LinkedList; -import java.awt.*; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.time.OffsetDateTime; -import java.time.format.DateTimeFormatter; import java.util.List; -import java.util.*; -import java.util.stream.Collectors; /** * A channel that can be used to send messages. @@ -131,7 +103,7 @@ default Response bulkDeleteMessages(List messageIds, String reason @NotNull DiscordJar discordJv(); - static MessagingChannel decompile(JSONObject obj, DiscordJar discordJar) { + static MessagingChannel decompile(SJSONObject obj, DiscordJar discordJar) { String id = obj.getString("id"); ChannelType type = ChannelType.fromCode(obj.getInt("type")); String name = obj.getString("name"); @@ -140,21 +112,21 @@ static MessagingChannel decompile(JSONObject obj, DiscordJar discordJar) { int position = obj.getInt("position"); List permissionOverwrites = new ArrayList<>(); if (obj.has("permission_overwrites")) { - JSONArray array = obj.getJSONArray("permission_overwrites"); + SJSONArray array = obj.getJSONArray("permission_overwrites"); for (int i = 0; i < array.length(); i++) permissionOverwrites.add(PermissionOverwrite.decompile(array.getJSONObject(i))); } int slowMode = obj.has("rate_limit_per_user") ? obj.getInt("rate_limit_per_user") : 0; - String topic = !obj.has("topic") || obj.get("topic") == null || obj.get("topic").equals(JSONObject.NULL) ? null : obj.getString("topic"); - String lastMessageId = !obj.has("last_message_id") || obj.get("last_message_id") == null || obj.get("last_message_id").equals(JSONObject.NULL) ? null : obj.getString("last_message_id"); + String topic = !obj.has("topic") || obj.get("topic") == null || obj.get("topic").equals(SJSONObject.NULL) ? null : obj.getString("topic"); + String lastMessageId = !obj.has("last_message_id") || obj.get("last_message_id") == null || obj.get("last_message_id").equals(SJSONObject.NULL) ? null : obj.getString("last_message_id"); int defaultAutoArchiveDuration = obj.has("default_auto_archive_duration") ? obj.getInt("default_auto_archive_duration") : 0; return new MessagingChannelImpl(id, type, name, guild, position, permissionOverwrites, nsfw, obj.has("parent_id") && !obj.isNull("parent_id") ? obj.getString("parent_id") : null ,slowMode, topic, lastMessageId, defaultAutoArchiveDuration, discordJar, obj); } @Override - default JSONObject compile() { - JSONObject obj = new JSONObject(); + default SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id()); obj.put("type", type().getCode()); obj.put("name", name()); @@ -167,7 +139,7 @@ default JSONObject compile() { obj.put("default_auto_archive_duration", defaultAutoArchiveDuration()); if (permissionOverwrites() != null) { - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (PermissionOverwrite overwrite : permissionOverwrites()) array.put(overwrite.compile()); } diff --git a/src/main/java/com/seailz/discordjar/model/channel/UserDM.java b/src/main/java/com/seailz/discordjar/model/channel/UserDM.java index 98d498e9..6b208614 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/UserDM.java +++ b/src/main/java/com/seailz/discordjar/model/channel/UserDM.java @@ -6,8 +6,8 @@ import com.seailz.discordjar.model.user.User; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -35,12 +35,12 @@ public interface UserDM extends DMChannel { @NotNull @Contract("_, _ -> new") - static UserDM decompile(@NotNull JSONObject obj, @NotNull DiscordJar djv) { + static UserDM decompile(@NotNull SJSONObject obj, @NotNull DiscordJar djv) { String lastMessageId = obj.has("last_message_id") ? obj.getString("last_message_id") : null; List recipients = new ArrayList<>(); - JSONArray recipientsArray = obj.getJSONArray("recipients"); - recipientsArray.forEach(o -> recipients.add(User.decompile((JSONObject) o, djv))); + SJSONArray recipientsArray = obj.getJSONArray("recipients"); + recipientsArray.forEach(o -> recipients.add(User.decompile((SJSONObject) o, djv))); String name = obj.has("name") ? obj.getString("name") : recipients.get(0).username(); return new DMChannelImpl(obj.getString("id"), ChannelType.DM, name, lastMessageId ,recipients, djv, obj); diff --git a/src/main/java/com/seailz/discordjar/model/channel/VoiceChannel.java b/src/main/java/com/seailz/discordjar/model/channel/VoiceChannel.java index e991a448..3eb0a0f2 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/VoiceChannel.java +++ b/src/main/java/com/seailz/discordjar/model/channel/VoiceChannel.java @@ -3,14 +3,12 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.channel.audio.VideoQualityMode; import com.seailz.discordjar.model.channel.audio.VoiceRegion; -import com.seailz.discordjar.model.channel.interfaces.Messageable; import com.seailz.discordjar.model.channel.internal.VoiceChannelImpl; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -25,8 +23,8 @@ public interface VoiceChannel extends AudioChannel { VideoQualityMode videoQualityMode(); @Override - default JSONObject compile() { - JSONObject obj = new JSONObject(); + default SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id()); obj.put("type", type()); obj.put("name", name()); @@ -43,7 +41,7 @@ default JSONObject compile() { return obj; } - static VoiceChannel decompile(JSONObject obj, DiscordJar discordJar) { + static VoiceChannel decompile(SJSONObject obj, DiscordJar discordJar) { String id = obj.getString("id"); String name = obj.getString("name"); int position = obj.getInt("position"); @@ -53,7 +51,7 @@ static VoiceChannel decompile(JSONObject obj, DiscordJar discordJar) { discordJar.getVoiceRegions().stream().filter(r -> r.id().equals(obj.getString("region"))).findFirst().ifPresent(region::set); int bitrate = obj.getInt("bitrate"); Category category = Category.fromId(obj.getString("parent_id"), discordJar); - JSONArray array = obj.getJSONArray("permission_overwrites"); + SJSONArray array = obj.getJSONArray("permission_overwrites"); List permissionOverwrites = new ArrayList<>(); if (array.length() > 0) { permissionOverwrites = new ArrayList<>(); diff --git a/src/main/java/com/seailz/discordjar/model/channel/audio/VoiceRegion.java b/src/main/java/com/seailz/discordjar/model/channel/audio/VoiceRegion.java index 07f85557..efbb149d 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/audio/VoiceRegion.java +++ b/src/main/java/com/seailz/discordjar/model/channel/audio/VoiceRegion.java @@ -4,7 +4,7 @@ import com.seailz.discordjar.utils.Snowflake; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a region for a voice channel. @@ -44,7 +44,7 @@ public interface VoiceRegion extends Snowflake { @NotNull @Contract("_ -> new") - static VoiceRegion decompile(@NotNull JSONObject obj) { + static VoiceRegion decompile(@NotNull SJSONObject obj) { String id = obj.getString("id"); String name = obj.getString("name"); boolean optimal = obj.getBoolean("optimal"); diff --git a/src/main/java/com/seailz/discordjar/model/channel/forum/DefaultReaction.java b/src/main/java/com/seailz/discordjar/model/channel/forum/DefaultReaction.java index 4644ade3..bbb76dba 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/forum/DefaultReaction.java +++ b/src/main/java/com/seailz/discordjar/model/channel/forum/DefaultReaction.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.channel.forum; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record DefaultReaction( @@ -10,14 +10,14 @@ public record DefaultReaction( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("emoji_id", emojiId) .put("emoji_name", emojiName); } @NonNull - public static DefaultReaction decompile(JSONObject obj) { + public static DefaultReaction decompile(SJSONObject obj) { String emojiId; String emojiName; diff --git a/src/main/java/com/seailz/discordjar/model/channel/forum/ForumTag.java b/src/main/java/com/seailz/discordjar/model/channel/forum/ForumTag.java index d5c4f949..57335363 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/forum/ForumTag.java +++ b/src/main/java/com/seailz/discordjar/model/channel/forum/ForumTag.java @@ -2,7 +2,7 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.Snowflake; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; /** @@ -23,8 +23,8 @@ public record ForumTag( ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("name", name) .put("moderated", moderated) @@ -33,7 +33,7 @@ public JSONObject compile() { } @NonNull - public static ForumTag decompile(JSONObject obj) { + public static ForumTag decompile(SJSONObject obj) { String id; String name; boolean moderated; diff --git a/src/main/java/com/seailz/discordjar/model/channel/interfaces/MessageRetrievable.java b/src/main/java/com/seailz/discordjar/model/channel/interfaces/MessageRetrievable.java index 83ec415a..85352061 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/interfaces/MessageRetrievable.java +++ b/src/main/java/com/seailz/discordjar/model/channel/interfaces/MessageRetrievable.java @@ -6,8 +6,8 @@ import com.seailz.discordjar.utils.URLS; import com.seailz.discordjar.utils.rest.DiscordRequest; import com.seailz.discordjar.utils.rest.DiscordResponse; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.ArrayList; @@ -18,7 +18,7 @@ public interface MessageRetrievable extends Channel { default List messagesBefore(String before) { DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES.replace("{channel.id}", id()) + "?before=" + before, djv(), @@ -27,7 +27,7 @@ default List messagesBefore(String before) { ); List messages = new ArrayList<>(); try { - request.invoke().arr().forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + request.invoke().arr().forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -37,7 +37,7 @@ default List messagesBefore(String before) { default List messagesBefore(String before, int limit) { Checker.check(limit > 100 || limit < 1, "Limit must be between 1 and 100"); DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES.replace("{channel.id}", id()) + "?before=" + before + "&limit=" + limit, djv(), @@ -46,7 +46,7 @@ default List messagesBefore(String before, int limit) { ); List messages = new ArrayList<>(); try { - request.invoke().arr().forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + request.invoke().arr().forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -56,7 +56,7 @@ default List messagesBefore(String before, int limit) { default List messagesAfter(String after, int limit) { Checker.check(limit > 100 || limit < 1, "Limit must be between 1 and 100"); DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES.replace("{channel.id}", id()) + "?after=" + after + "&limit=" + limit, djv(), @@ -65,7 +65,7 @@ default List messagesAfter(String after, int limit) { ); List messages = new ArrayList<>(); try { - request.invoke().arr().forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + request.invoke().arr().forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -74,7 +74,7 @@ default List messagesAfter(String after, int limit) { default List messagesAfter(String after) { DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES.replace("{channel.id}", id()) + "?after=" + after, djv(), @@ -83,7 +83,7 @@ default List messagesAfter(String after) { ); List messages = new ArrayList<>(); try { - request.invoke().arr().forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + request.invoke().arr().forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -92,7 +92,7 @@ default List messagesAfter(String after) { default List messagesAround(String around) { DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES.replace("{channel.id}", id()) + "?around=" + around, djv(), @@ -101,7 +101,7 @@ default List messagesAround(String around) { ); List messages = new ArrayList<>(); try { - request.invoke().arr().forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + request.invoke().arr().forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -111,7 +111,7 @@ default List messagesAround(String around) { default List messagesAround(String around, int limit) { Checker.check(limit > 100 || limit < 1, "Limit must be between 1 and 100"); DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES.replace("{channel.id}", id()) + "?around=" + around + "&limit=" + limit, djv(), @@ -120,7 +120,7 @@ default List messagesAround(String around, int limit) { ); List messages = new ArrayList<>(); try { - request.invoke().arr().forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + request.invoke().arr().forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -130,7 +130,7 @@ default List messagesAround(String around, int limit) { default List messages(int limit) { Checker.check(limit > 100 || limit < 1, "Limit must be between 1 and 100"); DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES.replace("{channel.id}", id()) + "?limit=" + limit, djv(), @@ -138,7 +138,7 @@ default List messages(int limit) { RequestMethod.GET ); List messages = new ArrayList<>(); - JSONArray arr = null; + SJSONArray arr = null; try { arr = request.invoke().arr(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -146,13 +146,13 @@ default List messages(int limit) { } if (arr == null) return messages; - arr.forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + arr.forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); return messages; } default List messages() { DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGES, djv(), @@ -161,7 +161,7 @@ default List messages() { ); List messages = new ArrayList<>(); try { - request.invoke().arr().forEach(obj -> messages.add(Message.decompile((JSONObject) obj, djv()))); + request.invoke().arr().forEach(obj -> messages.add(Message.decompile((SJSONObject) obj, djv()))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -199,7 +199,7 @@ default Message getMessageById(String id) { DiscordResponse response = null; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.CHANNELS.MESSAGES.GET_MESSAGE.replace("{channel.id}", id()).replace("{message.id}", id), djv(), diff --git a/src/main/java/com/seailz/discordjar/model/channel/interfaces/Typeable.java b/src/main/java/com/seailz/discordjar/model/channel/interfaces/Typeable.java index 9c68c572..6fefcad1 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/interfaces/Typeable.java +++ b/src/main/java/com/seailz/discordjar/model/channel/interfaces/Typeable.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.model.channel.Channel; import com.seailz.discordjar.utils.URLS; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -18,7 +18,7 @@ public interface Typeable extends Channel { */ default void typing() { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.POST.CHANNELS.TRIGGER_TYPING_INDICATOR.replace("{channel.id}", id()), djv(), diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/AudioChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/AudioChannelImpl.java index b10acd61..4451917a 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/AudioChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/AudioChannelImpl.java @@ -7,7 +7,7 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -18,7 +18,7 @@ public class AudioChannelImpl extends GuildChannelImpl implements AudioChannel { private final int bitrate; private final Category category; - public AudioChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String lastMessageId, VoiceRegion region, Category category, int bitrate, JSONObject raw, DiscordJar discordJar) { + public AudioChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String lastMessageId, VoiceRegion region, Category category, int bitrate, SJSONObject raw, DiscordJar discordJar) { super(id, type, name, guild, position, permissionOverwrites, nsfw, raw, discordJar); this.lastMessageId = lastMessageId; this.region = region; diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/CategoryImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/CategoryImpl.java index 098c07c8..7d8d4bf7 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/CategoryImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/CategoryImpl.java @@ -6,7 +6,7 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -20,7 +20,7 @@ public class CategoryImpl extends GuildChannelImpl implements Category { private final List members; - public CategoryImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, List members, JSONObject raw, DiscordJar discordJar) { + public CategoryImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, List members, SJSONObject raw, DiscordJar discordJar) { super(id, type, name, guild, position, permissionOverwrites, false, raw, discordJar); this.members = members; } diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/ChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/ChannelImpl.java index 78581c2e..9035f714 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/ChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/ChannelImpl.java @@ -4,10 +4,10 @@ import com.seailz.discordjar.model.channel.Channel; import com.seailz.discordjar.model.channel.utils.ChannelType; 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.NotNull; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -20,10 +20,10 @@ public class ChannelImpl implements Channel { private final String id; private final ChannelType type; private final String name; - private final JSONObject raw; + private final SJSONObject raw; private final DiscordJar discordJar; - public ChannelImpl(String id, ChannelType type, String name, JSONObject raw, DiscordJar discordJar) { + public ChannelImpl(String id, ChannelType type, String name, SJSONObject raw, DiscordJar discordJar) { this.id = id; this.type = type; this.name = name; @@ -32,8 +32,8 @@ public ChannelImpl(String id, ChannelType type, String name, JSONObject raw, Dis } @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("type", type.getCode()) .put("name", name); @@ -59,7 +59,7 @@ public String name() { @NotNull @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @@ -68,7 +68,7 @@ public Response delete() { Response response = new Response<>(); new Thread(() -> { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.CHANNEL.DELETE_CHANNEL.replace("{channel.id}", id()), djv(), diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/DMChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/DMChannelImpl.java index 02969742..d8fa6876 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/DMChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/DMChannelImpl.java @@ -5,7 +5,7 @@ import com.seailz.discordjar.model.channel.UserDM; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.user.User; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -18,7 +18,7 @@ public class DMChannelImpl extends ChannelImpl implements DMChannel, UserDM { private final List recipients; private final DiscordJar discordJar; - public DMChannelImpl(String id, ChannelType type, String name, String lastMessageId, List recipients, DiscordJar discordJar, JSONObject raw) { + public DMChannelImpl(String id, ChannelType type, String name, String lastMessageId, List recipients, DiscordJar discordJar, SJSONObject raw) { super(id, type, name, raw, discordJar); this.lastMessageId = lastMessageId; this.recipients = recipients; diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/ForumChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/ForumChannelImpl.java index 0bd0fe4a..6aa4bc57 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/ForumChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/ForumChannelImpl.java @@ -7,7 +7,7 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -19,7 +19,7 @@ public class ForumChannelImpl extends GuildChannelImpl implements ForumChannel { private final String lastThreadId; private final DefaultForumLayout defaultForumLayout; - public ForumChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String postGuidelines, List tags, DefaultSortOrder defaultSortOrder, String lastThreadId, JSONObject raw, DiscordJar discordJar, DefaultForumLayout defaultForumLayout) { + public ForumChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String postGuidelines, List tags, DefaultSortOrder defaultSortOrder, String lastThreadId, SJSONObject raw, DiscordJar discordJar, DefaultForumLayout defaultForumLayout) { super(id, type, name, guild, position, permissionOverwrites, nsfw, raw, discordJar); this.postGuidelines = postGuidelines; this.tags = tags; diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/GroupDMImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/GroupDMImpl.java index c0dc0aff..9cac9ed6 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/GroupDMImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/GroupDMImpl.java @@ -4,7 +4,7 @@ import com.seailz.discordjar.model.channel.GroupDM; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.user.User; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -16,7 +16,7 @@ public class GroupDMImpl extends DMChannelImpl implements GroupDM { private final User owner; private final String iconUrl; - public GroupDMImpl(String id, ChannelType type, String name, String lastMessageId, List recipients, DiscordJar discordJar, User owner, String iconUrl, JSONObject raw) { + public GroupDMImpl(String id, ChannelType type, String name, String lastMessageId, List recipients, DiscordJar discordJar, User owner, String iconUrl, SJSONObject raw) { super(id, type, name, lastMessageId, recipients, discordJar, raw); this.owner = owner; this.iconUrl = iconUrl; diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java index bd874ac4..4fd3093b 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/GuildChannelImpl.java @@ -5,9 +5,9 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; import java.util.List; @@ -19,7 +19,7 @@ public class GuildChannelImpl extends ChannelImpl implements GuildChannel { private final boolean nsfw; private final DiscordJar discordJar; - public GuildChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, JSONObject raw, DiscordJar discordJar) { + public GuildChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, SJSONObject raw, DiscordJar discordJar) { super(id, type, name, raw, discordJar); this.guild = guild; this.position = position; diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/MessagingChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/MessagingChannelImpl.java index c23a9249..f879cb12 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/MessagingChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/MessagingChannelImpl.java @@ -7,11 +7,10 @@ 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.jetbrains.annotations.NotNull; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -28,7 +27,7 @@ public class MessagingChannelImpl extends GuildChannelImpl implements MessagingC private final DiscordJar discordJar; - public MessagingChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String ownerId, int slowMode, String topic, String lastMessageId, int defaultAutoArchiveDuration, DiscordJar discordJar, JSONObject raw) { + public MessagingChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String ownerId, int slowMode, String topic, String lastMessageId, int defaultAutoArchiveDuration, DiscordJar discordJar, SJSONObject raw) { super(id, type, name, guild, position, permissionOverwrites, nsfw, raw, discordJar); this.ownerId = ownerId; this.slowMode = slowMode; @@ -72,7 +71,7 @@ public Response bulkDeleteMessages(List messageIds, boolean filter if (reason != null) put("X-Audit-Log-Reason", reason); }}; DiscordRequest request = new DiscordRequest( - new JSONObject(), + new SJSONObject(), headers, URLS.POST.CHANNELS.MESSAGES.BULK_DELETE .replace("{channel.id}", id()), diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/TextChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/TextChannelImpl.java index 726c1d39..6eab17bf 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/TextChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/TextChannelImpl.java @@ -1,12 +1,11 @@ package com.seailz.discordjar.model.channel.internal; import com.seailz.discordjar.DiscordJar; -import com.seailz.discordjar.model.channel.Category; import com.seailz.discordjar.model.channel.TextChannel; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -14,7 +13,7 @@ * @see TextChannel */ public class TextChannelImpl extends MessagingChannelImpl implements TextChannel { - public TextChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String owner, int slowMode, String topic, String lastMessageId, int defaultAutoArchiveDuration, DiscordJar discordJar, JSONObject raw) { + public TextChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String owner, int slowMode, String topic, String lastMessageId, int defaultAutoArchiveDuration, DiscordJar discordJar, SJSONObject raw) { super(id, type, name, guild, position, permissionOverwrites, nsfw, owner, slowMode, topic, lastMessageId, defaultAutoArchiveDuration, discordJar, raw); } } diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/ThreadImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/ThreadImpl.java index 8da05d5a..1c70e06b 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/ThreadImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/ThreadImpl.java @@ -2,14 +2,13 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.channel.MessagingChannel; -import com.seailz.discordjar.model.channel.TextChannel; import com.seailz.discordjar.model.channel.thread.Thread; import com.seailz.discordjar.model.channel.thread.ThreadMember; import com.seailz.discordjar.model.channel.thread.ThreadMetadata; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -26,7 +25,7 @@ public class ThreadImpl extends GuildChannelImpl implements Thread { private final int defaultThreadRateLimitPerUser; private final String lastMessageId; - public ThreadImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, MessagingChannel owner, int rateLimitPerUser, String creatorId, String lastPinTimestamp, int messageCount, ThreadMetadata threadMetadata, ThreadMember threadMember, int totalMessageSent, int defaultThreadRateLimitPerUser, String lastMessageId, JSONObject raw, DiscordJar discordJar) { + public ThreadImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, MessagingChannel owner, int rateLimitPerUser, String creatorId, String lastPinTimestamp, int messageCount, ThreadMetadata threadMetadata, ThreadMember threadMember, int totalMessageSent, int defaultThreadRateLimitPerUser, String lastMessageId, SJSONObject raw, DiscordJar discordJar) { super(id, type, name, guild, position, permissionOverwrites, nsfw, raw, discordJar); this.owner = owner; this.rateLimitPerUser = rateLimitPerUser; diff --git a/src/main/java/com/seailz/discordjar/model/channel/internal/VoiceChannelImpl.java b/src/main/java/com/seailz/discordjar/model/channel/internal/VoiceChannelImpl.java index ac18bb01..560cdc64 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/internal/VoiceChannelImpl.java +++ b/src/main/java/com/seailz/discordjar/model/channel/internal/VoiceChannelImpl.java @@ -8,7 +8,7 @@ import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.permission.PermissionOverwrite; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; @@ -20,7 +20,7 @@ public class VoiceChannelImpl extends AudioChannelImpl implements VoiceChannel { private final int userLimit; private final VideoQualityMode videoQualityMode; - public VoiceChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String lastMessageId, VoiceRegion region, Category category, int bitrate, int userLimit, VideoQualityMode videoQualityMode, JSONObject raw, DiscordJar discordJar) { + public VoiceChannelImpl(String id, ChannelType type, String name, Guild guild, int position, List permissionOverwrites, boolean nsfw, String lastMessageId, VoiceRegion region, Category category, int bitrate, int userLimit, VideoQualityMode videoQualityMode, SJSONObject raw, DiscordJar discordJar) { super(id, type, name, guild, position, permissionOverwrites, nsfw, lastMessageId, region, category, bitrate, raw, discordJar); this.userLimit = userLimit; this.videoQualityMode = videoQualityMode; diff --git a/src/main/java/com/seailz/discordjar/model/channel/thread/Thread.java b/src/main/java/com/seailz/discordjar/model/channel/thread/Thread.java index c5410d0c..f9c235e3 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/thread/Thread.java +++ b/src/main/java/com/seailz/discordjar/model/channel/thread/Thread.java @@ -4,7 +4,6 @@ import com.seailz.discordjar.action.message.MessageCreateAction; import com.seailz.discordjar.model.channel.GuildChannel; import com.seailz.discordjar.model.channel.MessagingChannel; -import com.seailz.discordjar.model.channel.TextChannel; import com.seailz.discordjar.model.channel.interfaces.MessageRetrievable; import com.seailz.discordjar.model.channel.interfaces.Messageable; import com.seailz.discordjar.model.channel.interfaces.Transcriptable; @@ -19,11 +18,11 @@ import com.seailz.discordjar.model.permission.PermissionOverwrite; import com.seailz.discordjar.model.user.User; 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 org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.ArrayList; @@ -110,8 +109,8 @@ public interface Thread extends GuildChannel, Typeable, Messageable, MessageRetr String lastMessageId(); @Override - default JSONObject compile() { - JSONObject obj = new JSONObject(); + default SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id()); obj.put("type", type().getCode()); obj.put("name", name()); @@ -128,7 +127,7 @@ default JSONObject compile() { if (permissionOverwrites() != null) { - JSONArray array = new JSONArray(); + SJSONArray array = new SJSONArray(); for (PermissionOverwrite overwrite : permissionOverwrites()) array.put(overwrite.compile()); } @@ -138,16 +137,16 @@ default JSONObject compile() { } /** - * Decompile a {@link JSONObject} into a {@link GuildChannel} + * Decompile a {@link SJSONObject} into a {@link GuildChannel} * - * @param obj The {@link JSONObject} to decompile + * @param obj The {@link SJSONObject} to decompile * @param discordJar The {@link DiscordJar} instance * * @return The {@link GuildChannel} instance */ @NotNull @Contract("_, _ -> new") - static Thread decompile(@NotNull JSONObject obj, @NotNull DiscordJar discordJar) { + static Thread decompile(@NotNull SJSONObject obj, @NotNull DiscordJar discordJar) { String id = obj.getString("id"); ChannelType type = ChannelType.fromCode(obj.getInt("type")); String name = obj.getString("name"); @@ -167,9 +166,9 @@ static Thread decompile(@NotNull JSONObject obj, @NotNull DiscordJar discordJar) List permissionOverwrites = new ArrayList<>(); if (obj.has("permission_overwrites")) { - JSONArray array = obj.getJSONArray("permission_overwrites"); + SJSONArray array = obj.getJSONArray("permission_overwrites"); for (int i = 0; i < array.length(); i++) { - JSONObject overwrite = array.getJSONObject(i); + SJSONObject overwrite = array.getJSONObject(i); permissionOverwrites.add(PermissionOverwrite.decompile(overwrite)); } } @@ -197,7 +196,7 @@ default MessageCreateAction sendAttachments(Attachment... attachments) { default void removeMember(String userId) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.CHANNEL.THREAD_MEMBERS.REMOVE_THREAD_MEMBER .replace("{channel.id}", id()) diff --git a/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMember.java b/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMember.java index c8ddd2b8..4129494f 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMember.java +++ b/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMember.java @@ -1,8 +1,8 @@ package com.seailz.discordjar.model.channel.thread; import com.seailz.discordjar.core.Compilerable; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; /** * Represents a thread member object @@ -21,8 +21,8 @@ public record ThreadMember( @Override - public @NotNull JSONObject compile() { - JSONObject obj = new JSONObject(); + public @NotNull SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id()); obj.put("user_id", userId()); obj.put("join_timestamp", joinTimestamp()); @@ -30,7 +30,7 @@ public record ThreadMember( return obj; } - public static ThreadMember decompile(JSONObject obj) { + public static ThreadMember decompile(SJSONObject obj) { String id; String userId; String joinTimestamp; diff --git a/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMetadata.java b/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMetadata.java index 7fb7abc7..7f83cb27 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMetadata.java +++ b/src/main/java/com/seailz/discordjar/model/channel/thread/ThreadMetadata.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.channel.thread; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; /** @@ -24,8 +24,8 @@ public record ThreadMetadata( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("archived", archived) .put("auto_archive_duration", autoArchiveDuration) .put("archive_timestamp", archiveTimestamp) @@ -35,7 +35,7 @@ public JSONObject compile() { } @NonNull - public static ThreadMetadata decompile(JSONObject obj) { + public static ThreadMetadata decompile(SJSONObject obj) { boolean archived; int autoArchiveDuration; String archiveTimestamp; diff --git a/src/main/java/com/seailz/discordjar/model/channel/utils/ChannelMention.java b/src/main/java/com/seailz/discordjar/model/channel/utils/ChannelMention.java index 19005342..cb60fede 100644 --- a/src/main/java/com/seailz/discordjar/model/channel/utils/ChannelMention.java +++ b/src/main/java/com/seailz/discordjar/model/channel/utils/ChannelMention.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.channel.utils; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public record ChannelMention( String id, @@ -10,7 +10,7 @@ public record ChannelMention( String name ) implements Compilerable { - public static ChannelMention decompile(JSONObject obj) { + public static ChannelMention decompile(SJSONObject obj) { String id; String guildId; ChannelType type; @@ -43,8 +43,8 @@ public static ChannelMention decompile(JSONObject obj) { } @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("guild_id", guildId); obj.put("type", type); diff --git a/src/main/java/com/seailz/discordjar/model/component/ActionRow.java b/src/main/java/com/seailz/discordjar/model/component/ActionRow.java index d7e2b870..25df1f60 100644 --- a/src/main/java/com/seailz/discordjar/model/component/ActionRow.java +++ b/src/main/java/com/seailz/discordjar/model/component/ActionRow.java @@ -1,11 +1,9 @@ package com.seailz.discordjar.model.component; -import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.model.component.select.SelectMenu; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; @@ -19,11 +17,11 @@ public class ActionRow implements DisplayComponent { private List components; - private JSONObject raw; + private SJSONObject raw; @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("type", type().getCode()); List components = new ArrayList<>(components()); @@ -32,7 +30,7 @@ public JSONObject compile() { } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @@ -66,12 +64,12 @@ public static ActionRow of(RawComponent... components) { } @NotNull - public static ActionRow decompile(JSONObject obj) { + public static ActionRow decompile(SJSONObject obj) { ActionRow row = new ActionRow(); List comp = new ArrayList<>(); obj.getJSONArray("components").forEach(c -> { - JSONObject component = (JSONObject) c; + SJSONObject component = (SJSONObject) c; comp.add(RawComponent.unknown(component)); }); row.raw = obj; diff --git a/src/main/java/com/seailz/discordjar/model/component/Component.java b/src/main/java/com/seailz/discordjar/model/component/Component.java index 97629b41..8807b78e 100644 --- a/src/main/java/com/seailz/discordjar/model/component/Component.java +++ b/src/main/java/com/seailz/discordjar/model/component/Component.java @@ -4,8 +4,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.component.select.SelectMenu; import com.seailz.discordjar.model.interaction.modal.Modal; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -21,7 +21,7 @@ */ public interface Component extends Compilerable { - JSONObject raw(); + SJSONObject raw(); /** * The type of the component @@ -53,12 +53,12 @@ public interface Component extends Compilerable { boolean isSelect(); /** - * Decompiles a list of {@link Component}s from a {@link JSONArray} + * Decompiles a list of {@link Component}s from a {@link SJSONArray} * - * @param arr The {@link JSONArray} to decompile + * @param arr The {@link SJSONArray} to decompile * @return A list of {@link Component}s */ - static List decompileList(JSONArray arr, DiscordJar discordJar) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + static List decompileList(SJSONArray arr, DiscordJar discordJar) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { List components = new ArrayList<>(); for (int i = 0; i < arr.length(); i++) { ComponentType type = ComponentType.getType(arr.getJSONObject(i).getInt("type")); @@ -83,15 +83,15 @@ static List decompileList(JSONArray arr, DiscordJar discordJar) throw return components; } - static JSONArray compileList(List components) { - JSONArray arr = new JSONArray(); + static SJSONArray compileList(List components) { + SJSONArray arr = new SJSONArray(); for (Component component : components) arr.put(component.compile()); return arr; } - static JSONArray compileModalList(List components) { - JSONArray arr = new JSONArray(); + static SJSONArray compileModalList(List components) { + SJSONArray arr = new SJSONArray(); for (Component component : components) arr.put(component.compile()); return arr; diff --git a/src/main/java/com/seailz/discordjar/model/component/RawComponent.java b/src/main/java/com/seailz/discordjar/model/component/RawComponent.java index a5a60f1c..839a95a3 100644 --- a/src/main/java/com/seailz/discordjar/model/component/RawComponent.java +++ b/src/main/java/com/seailz/discordjar/model/component/RawComponent.java @@ -9,8 +9,7 @@ import com.seailz.discordjar.model.component.select.entity.RoleSelectMenu; import com.seailz.discordjar.model.component.select.string.StringSelectMenu; import com.seailz.discordjar.model.component.text.TextInput; -import org.json.JSONException; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Component which can be inserted into a {@link DisplayComponent} @@ -28,9 +27,9 @@ default int maxPerRow() { return type().getMaxPerRow(); } - JSONObject raw(); + SJSONObject raw(); - void setRaw(JSONObject raw); + void setRaw(SJSONObject raw); default Button asButton(DiscordJar discordJar) { if (!type().equals(ComponentType.BUTTON)) @@ -90,7 +89,7 @@ default boolean isModalCompatible() { return type().isModalCompatible(); } - static RawComponent unknown(JSONObject obj) { + static RawComponent unknown(SJSONObject obj) { return UnknownRawComponent.of(obj); } diff --git a/src/main/java/com/seailz/discordjar/model/component/button/internal/ButtonImpl.java b/src/main/java/com/seailz/discordjar/model/component/button/internal/ButtonImpl.java index b9e81df8..0c65dff5 100644 --- a/src/main/java/com/seailz/discordjar/model/component/button/internal/ButtonImpl.java +++ b/src/main/java/com/seailz/discordjar/model/component/button/internal/ButtonImpl.java @@ -6,8 +6,8 @@ import com.seailz.discordjar.model.component.button.Button; import com.seailz.discordjar.model.component.button.ButtonStyle; import com.seailz.discordjar.model.emoji.Emoji; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.registry.components.ButtonRegistry; -import org.json.JSONObject; import java.util.function.Consumer; @@ -20,11 +20,11 @@ public class ButtonImpl implements Button { private String url; private boolean isDisabled; - private JSONObject raw; + private SJSONObject raw; @Override - public JSONObject compile() { - JSONObject json = new JSONObject(); + public SJSONObject compile() { + SJSONObject json = new SJSONObject(); json.put("type", ComponentType.BUTTON.getCode()); json.put("label", label); json.put("style", style.code()); @@ -119,7 +119,7 @@ public String url() { return url; } - public static Button decompile(JSONObject obj, DiscordJar discordJar) { + public static Button decompile(SJSONObject obj, DiscordJar discordJar) { ButtonImpl button = new ButtonImpl(); button.setLabel(obj.getString("label")); button.setStyle(ButtonStyle.fromCode(obj.getInt("style"))); @@ -132,12 +132,12 @@ public static Button decompile(JSONObject obj, DiscordJar discordJar) { } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } } diff --git a/src/main/java/com/seailz/discordjar/model/component/impl/UnknownRawComponent.java b/src/main/java/com/seailz/discordjar/model/component/impl/UnknownRawComponent.java index 05391e1b..b7e3c222 100644 --- a/src/main/java/com/seailz/discordjar/model/component/impl/UnknownRawComponent.java +++ b/src/main/java/com/seailz/discordjar/model/component/impl/UnknownRawComponent.java @@ -3,7 +3,7 @@ import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.component.DisplayComponent; import com.seailz.discordjar.model.component.RawComponent; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * This is usually a component that will be returned by a method like {@link DisplayComponent#components()} but is not a known component type, @@ -17,15 +17,15 @@ public class UnknownRawComponent implements RawComponent { private ComponentType type; - private JSONObject raw; + private SJSONObject raw; - public UnknownRawComponent(ComponentType type, JSONObject raw) { + public UnknownRawComponent(ComponentType type, SJSONObject raw) { this.type = type; this.raw = raw; } @Override - public JSONObject compile() { + public SJSONObject compile() { return raw; } @@ -40,16 +40,16 @@ public boolean isSelect() { } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } - public static UnknownRawComponent of(JSONObject raw) { + public static UnknownRawComponent of(SJSONObject raw) { ComponentType type = ComponentType.getType(raw.getInt("type")); return new UnknownRawComponent(type, raw); } diff --git a/src/main/java/com/seailz/discordjar/model/component/modal/ResolvedModalComponent.java b/src/main/java/com/seailz/discordjar/model/component/modal/ResolvedModalComponent.java index 4b44a313..359cc016 100644 --- a/src/main/java/com/seailz/discordjar/model/component/modal/ResolvedModalComponent.java +++ b/src/main/java/com/seailz/discordjar/model/component/modal/ResolvedModalComponent.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.component.ComponentType; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; public record ResolvedModalComponent( String customId, @@ -11,15 +11,15 @@ public record ResolvedModalComponent( String value ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("custom_id", customId) .put("type", type.getCode()) .put("value", value); } @NotNull - public static ResolvedModalComponent decompile(JSONObject obj) { + public static ResolvedModalComponent decompile(SJSONObject obj) { return new ResolvedModalComponent( obj.getString("custom_id"), ComponentType.getType(obj.getInt("type")), diff --git a/src/main/java/com/seailz/discordjar/model/component/select/SelectOption.java b/src/main/java/com/seailz/discordjar/model/component/select/SelectOption.java index b6db2d4e..174a483a 100644 --- a/src/main/java/com/seailz/discordjar/model/component/select/SelectOption.java +++ b/src/main/java/com/seailz/discordjar/model/component/select/SelectOption.java @@ -3,7 +3,7 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.emoji.Emoji; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a select option @@ -78,8 +78,8 @@ public void setDefaultSelected(boolean defaultSelected) { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("label", label); obj.put("value", value); if (description != null) { @@ -94,7 +94,7 @@ public JSONObject compile() { return obj; } - public static SelectOption decompile(JSONObject obj, DiscordJar discordJar) { + public static SelectOption decompile(SJSONObject obj, DiscordJar discordJar) { SelectOption option = new SelectOption(obj.getString("label"), obj.getString("value")); if (obj.has("description")) { option.setDescription(obj.getString("description")); diff --git a/src/main/java/com/seailz/discordjar/model/component/select/entity/ChannelSelectMenu.java b/src/main/java/com/seailz/discordjar/model/component/select/entity/ChannelSelectMenu.java index 66354f1c..91d433f2 100644 --- a/src/main/java/com/seailz/discordjar/model/component/select/entity/ChannelSelectMenu.java +++ b/src/main/java/com/seailz/discordjar/model/component/select/entity/ChannelSelectMenu.java @@ -1,16 +1,13 @@ package com.seailz.discordjar.model.component.select.entity; -import com.seailz.discordjar.events.model.interaction.select.StringSelectMenuInteractionEvent; import com.seailz.discordjar.events.model.interaction.select.entity.ChannelSelectMenuInteractionEvent; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.component.ActionComponent; import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.component.select.SelectMenu; -import com.seailz.discordjar.model.component.select.string.StringSelectMenu; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.registry.components.ChannelSelectRegistry; -import com.seailz.discordjar.utils.registry.components.StringSelectRegistry; -import org.json.JSONArray; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -32,7 +29,7 @@ public class ChannelSelectMenu implements SelectMenu { private List channelTypes; private boolean disabled; - private JSONObject raw; + private SJSONObject raw; /** * Creates a new channel select menu @@ -52,7 +49,7 @@ public ChannelSelectMenu(String customId) { * @param maxValues The maximum amount of values that can be selected * @param channelTypes The channel types that can be selected */ - public ChannelSelectMenu(String customId, String placeholder, int minValues, int maxValues, List channelTypes, boolean disabled, JSONObject raw) { + public ChannelSelectMenu(String customId, String placeholder, int minValues, int maxValues, List channelTypes, boolean disabled, SJSONObject raw) { this.customId = customId; this.placeholder = placeholder; this.minValues = minValues; @@ -71,7 +68,7 @@ public ChannelSelectMenu(String customId, String placeholder, int minValues, int * @param maxValues The maximum amount of values that can be selected * @param channelTypes The channel types that can be selected */ - public ChannelSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean disabled, JSONObject raw, ChannelType... channelTypes) { + public ChannelSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean disabled, SJSONObject raw, ChannelType... channelTypes) { this(customId, placeholder, minValues, maxValues, List.of(channelTypes), disabled, raw); } @@ -152,13 +149,13 @@ public boolean isSelect() { } @Override - public JSONObject compile() { - JSONArray channelTypes = new JSONArray(); + public SJSONObject compile() { + SJSONArray channelTypes = new SJSONArray(); this.channelTypes.forEach(channelType -> channelTypes.put(channelType.getCode())); if (minValues > maxValues) throw new IllegalArgumentException("Min values cannot be greater than max values"); - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("type", type().getCode()); obj.put("custom_id", customId); if (placeholder != null) obj.put("placeholder", placeholder); @@ -169,12 +166,12 @@ public JSONObject compile() { return obj; } - public static ChannelSelectMenu decompile(JSONObject json) { + public static ChannelSelectMenu decompile(SJSONObject json) { String customId = json.has("custom_id") ? json.getString("custom_id") : null; String placeholder = json.has("placeholder") ? json.getString("placeholder") : null; int minValues = json.has("min_values") ? json.getInt("min_values") : 0; int maxValues = json.has("max_values") ? json.getInt("max_values") : 25; - JSONArray channelTypes = json.has("channel_types") ? json.getJSONArray("channel_types") : null; + SJSONArray channelTypes = json.has("channel_types") ? json.getJSONArray("channel_types") : null; boolean disabled = json.has("disabled") && json.getBoolean("disabled"); List channelTypesDecompiled = new ArrayList<>(); @@ -191,12 +188,12 @@ public static ChannelSelectMenu decompile(JSONObject json) { } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } diff --git a/src/main/java/com/seailz/discordjar/model/component/select/entity/MentionableSelectMenu.java b/src/main/java/com/seailz/discordjar/model/component/select/entity/MentionableSelectMenu.java index 18d7a562..401fe449 100644 --- a/src/main/java/com/seailz/discordjar/model/component/select/entity/MentionableSelectMenu.java +++ b/src/main/java/com/seailz/discordjar/model/component/select/entity/MentionableSelectMenu.java @@ -3,7 +3,7 @@ import com.seailz.discordjar.model.component.ActionComponent; import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.component.select.SelectMenu; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a {@link com.seailz.discordjar.utils.Mentionable} select menu ({@link com.seailz.discordjar.model.role.Role} & {@link com.seailz.discordjar.model.user.User}) @@ -20,7 +20,7 @@ public class MentionableSelectMenu implements SelectMenu { private int maxValues; private boolean disabled; - private JSONObject raw; + private SJSONObject raw; /** * Creates a new mentionable select menu @@ -39,7 +39,7 @@ public MentionableSelectMenu(String customId) { * @param minValues The minimum amount of values that can be selected * @param maxValues The maximum amount of values that can be selected */ - public MentionableSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean disabled, JSONObject raw) { + public MentionableSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean disabled, SJSONObject raw) { this.customId = customId; this.placeholder = placeholder; this.minValues = minValues; @@ -102,11 +102,11 @@ public boolean isSelect() { } @Override - public JSONObject compile() { + public SJSONObject compile() { if (minValues > maxValues) throw new IllegalArgumentException("Min values cannot be greater than max values"); - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("type", type().getCode()); obj.put("custom_id", customId); if (placeholder != null) obj.put("placeholder", placeholder); @@ -116,7 +116,7 @@ public JSONObject compile() { return obj; } - public static MentionableSelectMenu decompile(JSONObject json) { + public static MentionableSelectMenu decompile(SJSONObject json) { String customId = json.has("custom_id") ? json.getString("custom_id") : null; String placeholder = json.has("placeholder") ? json.getString("placeholder") : null; int minValues = json.has("min_values") ? json.getInt("min_values") : 0; @@ -127,12 +127,12 @@ public static MentionableSelectMenu decompile(JSONObject json) { } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } } diff --git a/src/main/java/com/seailz/discordjar/model/component/select/entity/RoleSelectMenu.java b/src/main/java/com/seailz/discordjar/model/component/select/entity/RoleSelectMenu.java index d36a6a17..26a212b8 100644 --- a/src/main/java/com/seailz/discordjar/model/component/select/entity/RoleSelectMenu.java +++ b/src/main/java/com/seailz/discordjar/model/component/select/entity/RoleSelectMenu.java @@ -3,7 +3,7 @@ import com.seailz.discordjar.model.component.ActionComponent; import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.component.select.SelectMenu; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a role select menu @@ -20,7 +20,7 @@ public class RoleSelectMenu implements SelectMenu { private int maxValues; private boolean isDisabled; - private JSONObject raw; + private SJSONObject raw; /** * Creates a new role select menu @@ -40,7 +40,7 @@ public RoleSelectMenu(String customId) { * @param maxValues The maximum amount of values that can be selected * @param disabled If the select menu is disabled */ - public RoleSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean disabled, JSONObject raw) { + public RoleSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean disabled, SJSONObject raw) { this.customId = customId; this.placeholder = placeholder; this.minValues = minValues; @@ -107,11 +107,11 @@ public boolean isSelect() { } @Override - public JSONObject compile() { + public SJSONObject compile() { if (minValues > maxValues) throw new IllegalArgumentException("Min values cannot be greater than max values"); - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("type", type().getCode()); obj.put("custom_id", customId); if (placeholder != null) obj.put("placeholder", placeholder); @@ -121,7 +121,7 @@ public JSONObject compile() { return obj; } - public static RoleSelectMenu decompile(JSONObject json) { + public static RoleSelectMenu decompile(SJSONObject json) { String customId = json.has("custom_id") ? json.getString("custom_id") : null; String placeholder = json.has("placeholder") ? json.getString("placeholder") : null; int minValues = json.has("min_values") ? json.getInt("min_values") : 0; @@ -133,12 +133,12 @@ public static RoleSelectMenu decompile(JSONObject json) { @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } } diff --git a/src/main/java/com/seailz/discordjar/model/component/select/entity/UserSelectMenu.java b/src/main/java/com/seailz/discordjar/model/component/select/entity/UserSelectMenu.java index 581ecd1e..8a7679f4 100644 --- a/src/main/java/com/seailz/discordjar/model/component/select/entity/UserSelectMenu.java +++ b/src/main/java/com/seailz/discordjar/model/component/select/entity/UserSelectMenu.java @@ -3,7 +3,7 @@ import com.seailz.discordjar.model.component.ActionComponent; import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.component.select.SelectMenu; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a user select menu @@ -20,7 +20,7 @@ public class UserSelectMenu implements SelectMenu { private int maxValues; private boolean isDisabled; - private JSONObject raw; + private SJSONObject raw; /** * Creates a new user select menu @@ -39,7 +39,7 @@ public UserSelectMenu(String customId) { * @param minValues The minimum amount of values that can be selected * @param maxValues The maximum amount of values that can be selected */ - public UserSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean isDisabled, JSONObject raw) { + public UserSelectMenu(String customId, String placeholder, int minValues, int maxValues, boolean isDisabled, SJSONObject raw) { this.customId = customId; this.placeholder = placeholder; this.minValues = minValues; @@ -106,11 +106,11 @@ public boolean isSelect() { } @Override - public JSONObject compile() { + public SJSONObject compile() { if (minValues > maxValues) throw new IllegalArgumentException("Min values cannot be greater than max values"); - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("type", type().getCode()); obj.put("custom_id", customId); if (placeholder != null) obj.put("placeholder", placeholder); @@ -120,7 +120,7 @@ public JSONObject compile() { return obj; } - public static UserSelectMenu decompile(JSONObject json) { + public static UserSelectMenu decompile(SJSONObject json) { String customId = json.has("custom_id") ? json.getString("custom_id") : null; String placeholder = json.has("placeholder") ? json.getString("placeholder") : null; int minValues = json.has("min_values") ? json.getInt("min_values") : 0; @@ -131,12 +131,12 @@ public static UserSelectMenu decompile(JSONObject json) { } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } } diff --git a/src/main/java/com/seailz/discordjar/model/component/select/string/StringSelectMenu.java b/src/main/java/com/seailz/discordjar/model/component/select/string/StringSelectMenu.java index a4a445e2..6bc56509 100644 --- a/src/main/java/com/seailz/discordjar/model/component/select/string/StringSelectMenu.java +++ b/src/main/java/com/seailz/discordjar/model/component/select/string/StringSelectMenu.java @@ -1,16 +1,14 @@ package com.seailz.discordjar.model.component.select.string; import com.seailz.discordjar.DiscordJar; -import com.seailz.discordjar.events.model.interaction.button.ButtonInteractionEvent; import com.seailz.discordjar.events.model.interaction.select.StringSelectMenuInteractionEvent; import com.seailz.discordjar.model.component.ActionComponent; import com.seailz.discordjar.model.component.ComponentType; -import com.seailz.discordjar.model.component.button.Button; import com.seailz.discordjar.model.component.select.SelectMenu; import com.seailz.discordjar.model.component.select.SelectOption; +import com.seailz.discordjar.utils.json.SJSONArray; import com.seailz.discordjar.utils.registry.components.StringSelectRegistry; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -32,7 +30,7 @@ public class StringSelectMenu implements SelectMenu { private SelectOption[] options; private boolean disabled; - private JSONObject raw; + private SJSONObject raw; /** * Creates a new string select menu @@ -54,7 +52,7 @@ public StringSelectMenu(String customId, List options) { * @param maxValues The maximum amount of values that can be selected * @param options The options of the select menu */ - public StringSelectMenu(String customId, String placeholder, int minValues, int maxValues, List options, boolean disabled, JSONObject raw) { + public StringSelectMenu(String customId, String placeholder, int minValues, int maxValues, List options, boolean disabled, SJSONObject raw) { this.customId = customId; this.placeholder = placeholder; this.minValues = minValues; @@ -160,8 +158,8 @@ public StringSelectMenu setAction(Consumer act } @Override - public JSONObject compile() { - JSONArray options = new JSONArray(); + public SJSONObject compile() { + SJSONArray options = new SJSONArray(); for (SelectOption option : this.options) options.put(option.compile()); @@ -177,7 +175,7 @@ public JSONObject compile() { if (options.length() > 25) throw new IllegalArgumentException("Select menu cannot have more than 25 options"); - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("type", type().getCode()); obj.put("custom_id", customId); if (placeholder != null) obj.put("placeholder", placeholder); @@ -188,7 +186,7 @@ public JSONObject compile() { return obj; } - public static StringSelectMenu decompile(JSONObject json, DiscordJar discordJar) { + public static StringSelectMenu decompile(SJSONObject json, DiscordJar discordJar) { String customId = json.has("custom_id") ? json.getString("custom_id") : null; String placeholder = json.has("placeholder") ? json.getString("placeholder") : null; int minValues = json.has("min_values") ? json.getInt("min_values") : 0; @@ -196,7 +194,7 @@ public static StringSelectMenu decompile(JSONObject json, DiscordJar discordJar) List options = new ArrayList<>(); if (json.has("options")) { - JSONArray optionsJson = json.getJSONArray("options"); + SJSONArray optionsJson = json.getJSONArray("options"); for (int i = 0; i < optionsJson.length(); i++) options.add(SelectOption.decompile(optionsJson.getJSONObject(i), discordJar)); } @@ -205,12 +203,12 @@ public static StringSelectMenu decompile(JSONObject json, DiscordJar discordJar) } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } diff --git a/src/main/java/com/seailz/discordjar/model/component/text/TextInput.java b/src/main/java/com/seailz/discordjar/model/component/text/TextInput.java index e93d8dc0..73a2205e 100644 --- a/src/main/java/com/seailz/discordjar/model/component/text/TextInput.java +++ b/src/main/java/com/seailz/discordjar/model/component/text/TextInput.java @@ -2,9 +2,9 @@ import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.component.ModalComponent; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; /** * Represents a text input component. @@ -25,7 +25,7 @@ public class TextInput implements ModalComponent { private int maxLength; private boolean required; - private JSONObject raw; + private SJSONObject raw; /** * Creates a new text input component @@ -38,7 +38,7 @@ public class TextInput implements ModalComponent { * @param minLength The minimum length of the input (min 0, max 4000), default 0 * @param maxLength The maximum length of the input (min 1, max 4000), default 4000 */ - public TextInput(@NotNull String customId, @NotNull TextInputStyle style, @NotNull String label, @Nullable String placeholder, @Nullable String value, int minLength, int maxLength, boolean required, JSONObject raw) { + public TextInput(@NotNull String customId, @NotNull TextInputStyle style, @NotNull String label, @Nullable String placeholder, @Nullable String value, int minLength, int maxLength, boolean required, SJSONObject raw) { this.customId = customId; this.style = style; this.label = label; @@ -55,13 +55,13 @@ public TextInput(@NotNull String customId, @NotNull TextInputStyle style, @NotNu } /** - * Compiles the component into a {@link JSONObject} + * Compiles the component into a {@link SJSONObject} * * @return The compiled component */ @NotNull @Override - public JSONObject compile() { + public SJSONObject compile() { if (maxLength < 1) throw new IllegalStateException("Max length must be greater than 1"); @@ -83,7 +83,7 @@ public JSONObject compile() { if (placeholder != null && placeholder.length() > 100) throw new IllegalStateException("Placeholder must be less than 100 characters"); - JSONObject object = new JSONObject(); + SJSONObject object = new SJSONObject(); object.put("type", type().getCode()); object.put("custom_id", customId); object.put("style", style.code()); @@ -100,7 +100,7 @@ public JSONObject compile() { * @param json The json to parse * @return The parsed {@link TextInput} */ - public static TextInput decompile(@NotNull JSONObject json) { + public static TextInput decompile(@NotNull SJSONObject json) { String customId = json.getString("custom_id"); TextInputStyle style = TextInputStyle.fromCode(json.getInt("style")); String label = json.getString("label"); @@ -215,12 +215,12 @@ public boolean required() { } @Override - public JSONObject raw() { + public SJSONObject raw() { return raw; } @Override - public void setRaw(JSONObject raw) { + public void setRaw(SJSONObject raw) { this.raw = raw; } } diff --git a/src/main/java/com/seailz/discordjar/model/embed/Embed.java b/src/main/java/com/seailz/discordjar/model/embed/Embed.java index 9be9e33d..218fcebc 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/Embed.java +++ b/src/main/java/com/seailz/discordjar/model/embed/Embed.java @@ -1,9 +1,9 @@ package com.seailz.discordjar.model.embed; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONArray; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.json.JSONException; -import org.json.JSONObject; import org.springframework.lang.NonNull; import java.awt.*; @@ -27,8 +27,8 @@ public record Embed( @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("title", title == null ? null : title) .put("type", type.toString()) .put("description", description == null ? null : description) @@ -41,11 +41,11 @@ public JSONObject compile() { .put("video", video == null ? null : video.compile()) .put("provider", provider == null ? null : provider.compile()) .put("author", author == null ? null : author.compile()) - .put("fields", fields == null ? null: new JSONArray(fields)); + .put("fields", fields == null ? null: new SJSONArray(fields)); } @NonNull - public static Embed decompile(JSONObject obj) { + public static Embed decompile(SJSONObject obj) { String title; EmbedType type; String description; @@ -133,7 +133,7 @@ public static Embed decompile(JSONObject obj) { } try { - JSONArray arr = obj.getJSONArray("fields"); + SJSONArray arr = obj.getJSONArray("fields"); ArrayList fields1 = new ArrayList<>(); for (int i = 0; i < arr.length(); i++) { fields1.add(EmbedField.decompile(arr.getJSONObject(i))); diff --git a/src/main/java/com/seailz/discordjar/model/embed/EmbedAuthor.java b/src/main/java/com/seailz/discordjar/model/embed/EmbedAuthor.java index 185448c3..cc1ee9de 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/EmbedAuthor.java +++ b/src/main/java/com/seailz/discordjar/model/embed/EmbedAuthor.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.embed; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record EmbedAuthor( @@ -12,8 +12,8 @@ public record EmbedAuthor( ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("name", name); obj.put("url", url); obj.put("icon_url", iconUrl); @@ -22,7 +22,7 @@ public JSONObject compile() { } @NonNull - public static EmbedAuthor decompile(JSONObject obj) { + public static EmbedAuthor decompile(SJSONObject obj) { String name; String url; String iconUrl; diff --git a/src/main/java/com/seailz/discordjar/model/embed/EmbedField.java b/src/main/java/com/seailz/discordjar/model/embed/EmbedField.java index f8b476c2..52eec733 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/EmbedField.java +++ b/src/main/java/com/seailz/discordjar/model/embed/EmbedField.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.embed; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record EmbedField( @@ -11,8 +11,8 @@ public record EmbedField( ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("name", name); obj.put("value", value); obj.put("inline", inline); @@ -20,7 +20,7 @@ public JSONObject compile() { } @NonNull - public static EmbedField decompile(JSONObject obj) { + public static EmbedField decompile(SJSONObject obj) { String name; String value; boolean inline; diff --git a/src/main/java/com/seailz/discordjar/model/embed/EmbedFooter.java b/src/main/java/com/seailz/discordjar/model/embed/EmbedFooter.java index 7ae66c5b..182f082f 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/EmbedFooter.java +++ b/src/main/java/com/seailz/discordjar/model/embed/EmbedFooter.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.embed; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record EmbedFooter( @@ -12,8 +12,8 @@ public record EmbedFooter( @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("text", text); obj.put("icon_url", iconUrl); obj.put("proxy_icon_url", proxyIconUrl); @@ -21,7 +21,7 @@ public JSONObject compile() { } @NonNull - public static EmbedFooter decompile(JSONObject obj) { + public static EmbedFooter decompile(SJSONObject obj) { String text; String iconUrl; String proxyIconUrl; diff --git a/src/main/java/com/seailz/discordjar/model/embed/EmbedImage.java b/src/main/java/com/seailz/discordjar/model/embed/EmbedImage.java index b0effe91..8327b9b0 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/EmbedImage.java +++ b/src/main/java/com/seailz/discordjar/model/embed/EmbedImage.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.embed; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record EmbedImage( @@ -12,8 +12,8 @@ public record EmbedImage( ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("url", url); obj.put("proxy_url", proxyUrl); if (height != 0) obj.put("height", height); @@ -22,7 +22,7 @@ public JSONObject compile() { } @NonNull - public static EmbedImage decompile(JSONObject obj) { + public static EmbedImage decompile(SJSONObject obj) { String url; String proxyUrl; int height; diff --git a/src/main/java/com/seailz/discordjar/model/embed/EmbedProvider.java b/src/main/java/com/seailz/discordjar/model/embed/EmbedProvider.java index 0c5b666c..1534f89b 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/EmbedProvider.java +++ b/src/main/java/com/seailz/discordjar/model/embed/EmbedProvider.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.embed; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record EmbedProvider( @@ -10,15 +10,15 @@ public record EmbedProvider( ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("name", name); obj.put("url", url); return obj; } @NonNull - public static EmbedProvider decompile(JSONObject obj) { + public static EmbedProvider decompile(SJSONObject obj) { String name; String url; diff --git a/src/main/java/com/seailz/discordjar/model/embed/Embeder.java b/src/main/java/com/seailz/discordjar/model/embed/Embeder.java index 19f897ca..57c3ccfc 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/Embeder.java +++ b/src/main/java/com/seailz/discordjar/model/embed/Embeder.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.awt.*; @@ -46,7 +46,7 @@ public interface Embeder { Embeder author(String name, String url, String iconUrl); - JSONObject compile(); + SJSONObject compile(); @Contract(value = " -> new", pure = true) static @NotNull Embeder e() { diff --git a/src/main/java/com/seailz/discordjar/model/embed/EmbederImpl.java b/src/main/java/com/seailz/discordjar/model/embed/EmbederImpl.java index fd5ad27e..0465fa9c 100644 --- a/src/main/java/com/seailz/discordjar/model/embed/EmbederImpl.java +++ b/src/main/java/com/seailz/discordjar/model/embed/EmbederImpl.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.embed; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.awt.*; import java.time.Instant; @@ -172,20 +172,20 @@ public Embeder removeField(String name) { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("title", title); obj.put("description", description); obj.put("url", url); obj.put("timestamp", timestamp); - obj.put("color", color != -1 ? color + 0xFFFFFF : JSONObject.NULL); - obj.put("footer", footer != null ? footer.compile() : JSONObject.NULL); - obj.put("image", image != null ? image.compile() : JSONObject.NULL); - obj.put("thumbnail", thumbnail != null ? thumbnail.compile() : JSONObject.NULL); - obj.put("author", author != null ? author.compile() : JSONObject.NULL); + obj.put("color", color != -1 ? color + 0xFFFFFF : SJSONObject.NULL); + obj.put("footer", footer != null ? footer.compile() : SJSONObject.NULL); + obj.put("image", image != null ? image.compile() : SJSONObject.NULL); + obj.put("thumbnail", thumbnail != null ? thumbnail.compile() : SJSONObject.NULL); + obj.put("author", author != null ? author.compile() : SJSONObject.NULL); // fields - JSONArray fields = new JSONArray(); + SJSONArray fields = new SJSONArray(); for (EmbedField field : this.fields) { fields.put(field.compile()); } diff --git a/src/main/java/com/seailz/discordjar/model/emoji/Emoji.java b/src/main/java/com/seailz/discordjar/model/emoji/Emoji.java index 9ade0936..8c4d2c79 100644 --- a/src/main/java/com/seailz/discordjar/model/emoji/Emoji.java +++ b/src/main/java/com/seailz/discordjar/model/emoji/Emoji.java @@ -5,7 +5,7 @@ import com.seailz.discordjar.model.role.Role; import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.Snowflake; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; import java.util.ArrayList; @@ -33,8 +33,8 @@ public record Emoji( boolean available ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("name", name); obj.put("roles", roles); @@ -47,7 +47,7 @@ public JSONObject compile() { } @NonNull - public static Emoji decompile(JSONObject obj, DiscordJar discordJar) { + public static Emoji decompile(SJSONObject obj, DiscordJar discordJar) { String id; String name; Role[] roles; @@ -72,7 +72,7 @@ public static Emoji decompile(JSONObject obj, DiscordJar discordJar) { try { ArrayList rolesList = new ArrayList<>(); for (Object o : obj.getJSONArray("roles")) { - rolesList.add(Role.decompile((JSONObject) o)); + rolesList.add(Role.decompile((SJSONObject) o)); } roles = rolesList.toArray(new Role[0]); } catch (Exception e) { diff --git a/src/main/java/com/seailz/discordjar/model/emoji/Reaction.java b/src/main/java/com/seailz/discordjar/model/emoji/Reaction.java index 18c00e98..dffae343 100644 --- a/src/main/java/com/seailz/discordjar/model/emoji/Reaction.java +++ b/src/main/java/com/seailz/discordjar/model/emoji/Reaction.java @@ -2,7 +2,7 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; /** @@ -19,8 +19,8 @@ public record Reaction( ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("count", count); obj.put("me", me); obj.put("emoji", emoji.compile()); @@ -28,7 +28,7 @@ public JSONObject compile() { } @NonNull - public static Reaction decompile(JSONObject obj, DiscordJar discordJar) { + public static Reaction decompile(SJSONObject obj, DiscordJar discordJar) { int count; boolean me; Emoji emoji; diff --git a/src/main/java/com/seailz/discordjar/model/emoji/sticker/Sticker.java b/src/main/java/com/seailz/discordjar/model/emoji/sticker/Sticker.java index bbf99a4d..ba06f209 100644 --- a/src/main/java/com/seailz/discordjar/model/emoji/sticker/Sticker.java +++ b/src/main/java/com/seailz/discordjar/model/emoji/sticker/Sticker.java @@ -4,10 +4,10 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.Snowflake; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -43,13 +43,13 @@ public record Sticker( /** - * Creates a {@link JSONObject} from a {@link Sticker} object + * Creates a {@link SJSONObject} from a {@link Sticker} object * - * @return The compiled {@link JSONObject} + * @return The compiled {@link SJSONObject} */ @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("pack_id", packId) .put("name", name) @@ -64,13 +64,13 @@ public JSONObject compile() { } /** - * Creates a {@link Sticker} object from a {@link JSONObject} + * Creates a {@link Sticker} object from a {@link SJSONObject} * - * @param obj The {@link JSONObject} to create the {@link Sticker} object from + * @param obj The {@link SJSONObject} to create the {@link Sticker} object from * @return The compiled {@link Sticker} object */ @NotNull - public static Sticker decompile(JSONObject obj, DiscordJar discordJar) { + public static Sticker decompile(SJSONObject obj, DiscordJar discordJar) { String id; String packId; String name; @@ -152,7 +152,7 @@ public static Sticker decompile(JSONObject obj, DiscordJar discordJar) { return new Sticker(id, packId, name, description, tags, type, format, available, guildId, user, sortValue); } - public static List decompileList(JSONArray array, DiscordJar discordJar) { + public static List decompileList(SJSONArray array, DiscordJar discordJar) { List stickers = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { stickers.add(decompile(array.getJSONObject(i), discordJar)); diff --git a/src/main/java/com/seailz/discordjar/model/emoji/sticker/StickerPack.java b/src/main/java/com/seailz/discordjar/model/emoji/sticker/StickerPack.java index 00345971..ac15f4ad 100644 --- a/src/main/java/com/seailz/discordjar/model/emoji/sticker/StickerPack.java +++ b/src/main/java/com/seailz/discordjar/model/emoji/sticker/StickerPack.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.Snowflake; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -21,11 +21,11 @@ public record StickerPack( @Override - public JSONObject compile() { - JSONArray stickers = new JSONArray(); + public SJSONObject compile() { + SJSONArray stickers = new SJSONArray(); this.stickers.forEach(sticker -> stickers.put(sticker.compile())); - return new JSONObject() + return new SJSONObject() .put("id", id) .put("stickers", stickers) .put("name", name) @@ -35,9 +35,9 @@ public JSONObject compile() { .put("banner_id", bannerId); } - public static StickerPack decompile(JSONObject json, DiscordJar discordJar) { + public static StickerPack decompile(SJSONObject json, DiscordJar discordJar) { List stickers = new ArrayList<>(); - json.getJSONArray("stickers").forEach(object -> stickers.add(Sticker.decompile((JSONObject) object, discordJar))); + json.getJSONArray("stickers").forEach(object -> stickers.add(Sticker.decompile((SJSONObject) object, discordJar))); return new StickerPack( json.getString("id"), @@ -50,10 +50,10 @@ public static StickerPack decompile(JSONObject json, DiscordJar discordJar) { ); } - public static List decompileList(JSONObject json, DiscordJar discordJar) { - JSONArray arr = json.getJSONArray("sticker_packs"); + public static List decompileList(SJSONObject json, DiscordJar discordJar) { + SJSONArray arr = json.getJSONArray("sticker_packs"); List packs = new ArrayList<>(); - arr.forEach(object -> packs.add(decompile((JSONObject) object, discordJar))); + arr.forEach(object -> packs.add(decompile((SJSONObject) object, discordJar))); return packs; } } 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 18b6445a..90287041 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/Guild.java +++ b/src/main/java/com/seailz/discordjar/model/guild/Guild.java @@ -7,12 +7,9 @@ import com.seailz.discordjar.action.guild.members.RequestGuildMembersAction; import com.seailz.discordjar.action.sticker.ModifyStickerAction; import com.seailz.discordjar.core.Compilerable; -import com.seailz.discordjar.model.application.Intent; import com.seailz.discordjar.model.automod.AutomodRule; import com.seailz.discordjar.model.channel.Channel; import com.seailz.discordjar.model.channel.GuildChannel; -import com.seailz.discordjar.model.channel.MessagingChannel; -import com.seailz.discordjar.model.channel.VoiceChannel; import com.seailz.discordjar.model.channel.thread.Thread; import com.seailz.discordjar.model.channel.utils.ChannelType; import com.seailz.discordjar.model.emoji.Emoji; @@ -25,20 +22,19 @@ import com.seailz.discordjar.model.guild.welcome.WelcomeScreen; import com.seailz.discordjar.model.invite.Invite; import com.seailz.discordjar.model.invite.InviteMetadata; -import com.seailz.discordjar.model.invite.internal.InviteImpl; import com.seailz.discordjar.model.invite.internal.InviteMetadataImpl; import com.seailz.discordjar.model.role.Role; import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.*; import com.seailz.discordjar.cache.JsonCache; +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.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.ArrayList; @@ -339,8 +335,8 @@ public JsonCache roleCache() { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("name", name) .put("icon", icon) @@ -383,7 +379,7 @@ public JSONObject compile() { } @NotNull - public static Guild decompile(JSONObject obj, DiscordJar discordJar) { + public static Guild decompile(SJSONObject obj, DiscordJar discordJar) { long nano = System.nanoTime(); String id; String name; @@ -522,7 +518,7 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar) { } try { - JSONArray rolesArray = obj.getJSONArray("roles"); + SJSONArray rolesArray = obj.getJSONArray("roles"); roles = new ArrayList<>(); for (int i = 0; i < rolesArray.length(); i++) { roles.add(Role.decompile(rolesArray.getJSONObject(i))); @@ -532,7 +528,7 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar) { } try { - JSONArray emojisArray = obj.getJSONArray("emojis"); + SJSONArray emojisArray = obj.getJSONArray("emojis"); emojis = new ArrayList<>(); for (int i = 0; i < emojisArray.length(); i++) { emojis.add(Emoji.decompile(emojisArray.getJSONObject(i), discordJar)); @@ -650,7 +646,7 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar) { } try { - JSONArray stickersArray = obj.getJSONArray("stickers"); + SJSONArray stickersArray = obj.getJSONArray("stickers"); stickers = new ArrayList<>(); for (int i = 0; i < stickersArray.length(); i++) { stickers.add(Sticker.decompile(stickersArray.getJSONObject(i), discordJar)); @@ -713,7 +709,7 @@ public static Guild decompile(JSONObject obj, DiscordJar discordJar) { safetyAlertsChannelId, discordJar, JsonCache.newc(new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.ROLES.GET_GUILD_ROLES.replace("{guild.id}", id), discordJar, @@ -759,7 +755,7 @@ public Channel safetyAlertsChannel() { public void leave() { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.GUILD.LEAVE_GUILD.replace( "{guild.id}", @@ -781,7 +777,7 @@ public List getStickers() { try { return Sticker.decompileList( new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.STICKERS.GET_GUILD_STICKERS.replace( "{guild.id}", @@ -807,7 +803,7 @@ public Sticker getStickerById(String stickerId) { try { return Sticker.decompile( new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.STICKERS.GET_GUILD_STICKER.replace( "{guild.id}", @@ -840,7 +836,7 @@ public ModifyStickerAction modifySticker(String stickerId) { public void deleteSticker(String stickerId) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.GUILD.STICKER.DELETE_GUILD_STICKER.replace( "{guild.id}", @@ -866,7 +862,7 @@ public List getAutomodRules() { try { return AutomodRule.decompileList( new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.AUTOMOD.LIST_AUTOMOD_RULES.replace( "{guild.id}", @@ -889,7 +885,7 @@ public AutomodRule getAutomodRuleById(String id) { try { return AutomodRule.decompile( new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.AUTOMOD.GET_AUTOMOD_RULE.replace( "{guild.id}", @@ -922,7 +918,7 @@ public AutomodRuleCreateAction createAutomodRule(String name, AutomodRule.EventT public void deleteAutoModRule(String id) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.GUILD.AUTOMOD.DELETE_AUTOMOD_RULE.replace( "{guild.id}", @@ -951,10 +947,10 @@ public Member getMemberById(String id) { public List getMembers(int limit, String after) { Checker.check(limit <= 0, "Limit must be greater than 0"); Checker.check(limit > 1000, "Limit must be less than or equal to 1000"); - JSONArray arr = null; + SJSONArray arr = null; try { arr = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.MEMBERS.LIST_GUILD_MEMBERS.replace( "{guild.id}", @@ -970,7 +966,7 @@ public List getMembers(int limit, String after) { List members = new ArrayList<>(); for (Object obj : arr) { - members.add(Member.decompile((JSONObject) obj, discordJar, id, this)); + members.add(Member.decompile((SJSONObject) obj, discordJar, id, this)); } return members; @@ -978,10 +974,10 @@ public List getMembers(int limit, String after) { public List getMembers() { - JSONArray arr = null; + SJSONArray arr = null; try { arr = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.MEMBERS.LIST_GUILD_MEMBERS.replace( "{guild.id}", @@ -997,7 +993,7 @@ public List getMembers() { List members = new ArrayList<>(); for (Object obj : arr) { - members.add(Member.decompile((JSONObject) obj, discordJar, id, this)); + members.add(Member.decompile((SJSONObject) obj, discordJar, id, this)); } return members; @@ -1012,13 +1008,13 @@ public List getEmojis() { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.EMOJIS.GUILD_EMOJIS.replace("{guild.id}", id), discordJar, URLS.GET.GUILDS.EMOJIS.GUILD_EMOJIS, RequestMethod.GET - ).invoke().arr().forEach((object) -> emojis.add(Emoji.decompile((JSONObject) object, discordJar))); + ).invoke().arr().forEach((object) -> emojis.add(Emoji.decompile((SJSONObject) object, discordJar))); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } @@ -1035,7 +1031,7 @@ public Emoji getEmojiById(@NotNull String emojiId) { try { return Emoji.decompile( new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.EMOJIS.GET_GUILD_EMOJI.replace("{guild.id}", this.id).replace("{emoji.id}", emojiId), discordJar, @@ -1068,7 +1064,7 @@ public List getChannels() { DiscordResponse req = null; try { req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.CHANNELS.GET_GUILD_CHANNELS.replace("{guild.id}", id), discordJar, @@ -1078,13 +1074,13 @@ public List getChannels() { } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { return new ArrayList<>(); } - JSONArray res = req.arr(); + SJSONArray res = req.arr(); if (res == null) { Logger.getLogger("DiscordJar").warning("Failed to get channels for guild " + req.code()); return new ArrayList<>(); } res.forEach(o -> { - channels.add(GuildChannel.decompile((JSONObject) o, discordJar)); + channels.add(GuildChannel.decompile((SJSONObject) o, discordJar)); }); return channels; } @@ -1099,21 +1095,21 @@ public List roles() { if (roleCache != null && !roleCache.isEmpty()) { List roles = new ArrayList<>(); roleCache.get().getJSONArray("data").forEach( - o -> roles.add(Role.decompile((JSONObject) o)) + o -> roles.add(Role.decompile((SJSONObject) o)) ); return roles; } List roles = new ArrayList<>(); DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.ROLES.GET_GUILD_ROLES.replace("{guild.id}", id), discordJar, URLS.GET.GUILDS.ROLES.GET_GUILD_ROLES, RequestMethod.GET ); - JSONArray res; + SJSONArray res; DiscordResponse response = null; try { response = req.invoke(); @@ -1125,10 +1121,10 @@ public List roles() { System.out.println(response.code() + " " + (response.body() == null ? "null" : response.body().toString())); } - res.forEach(o -> roles.add(Role.decompile((JSONObject) o))); + res.forEach(o -> roles.add(Role.decompile((SJSONObject) o))); if (roleCache != null) { - roleCache.update(new JSONObject().put("data", res)); + roleCache.update(new SJSONObject().put("data", res)); } return roles; } @@ -1188,20 +1184,20 @@ public CreateGuildChannelAction createChannel(String name, ChannelType type) { public List getInvites() { List invites = new ArrayList<>(); DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.GET_GUILD_INVITES.replace("{guild.id}", id), discordJar, URLS.GET.GUILDS.GET_GUILD_INVITES, RequestMethod.GET ); - JSONArray res; + SJSONArray res; try { res = req.invoke().arr(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); } - res.forEach(o -> invites.add(InviteMetadataImpl.decompile((JSONObject) o, discordJar))); + res.forEach(o -> invites.add(InviteMetadataImpl.decompile((SJSONObject) o, discordJar))); return invites; } @@ -1220,7 +1216,7 @@ public void delete() throws IllegalAccessException { DiscordResponse response; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.GUILD.DELETE_GUILD.replace("{guild.id}", id), discordJar, @@ -1241,7 +1237,7 @@ public void delete() throws IllegalAccessException { public void deleteRole(Role role) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.GUILD.ROLES.replace("{guild.id}", id).replace("{role.id}", role.id()), discordJar, @@ -1292,7 +1288,8 @@ public List getRolesByName(String name) { public void modifyMFALevel(MFALevel level) { try { new DiscordRequest( - new JSONObject("level", String.valueOf(level.getCode())), + new SJSONObject() + .put("code", String.valueOf(level.getCode())), new HashMap<>(), URLS.POST.GUILDS.UPDATE_MFA.replace("{guild.id}", id), discordJar, @@ -1312,7 +1309,7 @@ public List getBans() { DiscordResponse response; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.BANS.replace("{guild.id}", id), discordJar, @@ -1324,7 +1321,7 @@ public List getBans() { } List bans = new ArrayList<>(); - response.arr().forEach((object) -> bans.add(GuildBan.decompile((JSONObject) object, discordJar))); + response.arr().forEach((object) -> bans.add(GuildBan.decompile((SJSONObject) object, discordJar))); return bans; } @@ -1338,7 +1335,7 @@ public GuildBan getBan(String userId) { DiscordResponse response; try { response = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.USER_BAN.replace("{guild.id}", id).replace("{user.id}", userId), discordJar, @@ -1367,7 +1364,7 @@ public GuildBan getBan(long userId) { public void banUser(String userId) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.PUT.GUILD.BAN_USER.replace("{guild.id}", id).replace("{user.id}", userId), discordJar, @@ -1394,7 +1391,7 @@ public void banUser(long userId) { public void unbanUser(String userId) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.PUT.GUILD.BAN_USER.replace("{guild.id}", id).replace("{user.id}", userId), discordJar, @@ -1433,7 +1430,7 @@ public int getPruneCount(int days) { if (!Checker.inRange(1, 30, days, () -> Logger.getLogger("[DISCORD.JAR]").severe("Days cannot be outside of 1-30!"))) return 0; DiscordRequest req = new DiscordRequest( - new JSONObject() + new SJSONObject() .put("days", days), new HashMap<>(), URLS.GET.GUILDS.PRUNE.replace("{guild.id}", id), @@ -1458,7 +1455,7 @@ public int prune(int days) { try { DiscordResponse response = new DiscordRequest( - new JSONObject() + new SJSONObject() .put("days", days), new HashMap<>(), URLS.POST.GUILDS.PRUNE.replace("{guild.id}", id), @@ -1491,12 +1488,12 @@ public int getPruneCount(int days, List includedRoles) { } commaDelimitedSnowflakesString.append("]"); - JSONArray snowflakes = new JSONArray(); + SJSONArray snowflakes = new SJSONArray(); roles.forEach(r -> snowflakes.put(r.id())); try { DiscordResponse req = new DiscordRequest( - new JSONObject() + new SJSONObject() .put("days", days) .put("include_roles", commaDelimitedSnowflakesString), new HashMap<>(), @@ -1529,7 +1526,7 @@ public void prune(int days, List includedRoles) { try { new DiscordRequest( - new JSONObject() + new SJSONObject() .put("days", days) .put("include_roles", commaDelimitedSnowflakesString), new HashMap<>(), @@ -1563,13 +1560,13 @@ public List getMembersByName(String filter, int limit) { try { List namedMembers = new ArrayList<>(); new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.SEARCH_MEMBERS.replace("{guild.id}", id()).replace("{filter}", filter).replace("{limit}", String.valueOf(limit)), discordJar, URLS.GET.GUILDS.SEARCH_MEMBERS, RequestMethod.GET - ).invoke().arr().forEach((memberObject) -> namedMembers.add(Member.decompile((JSONObject) memberObject, discordJar, id(), this))); + ).invoke().arr().forEach((memberObject) -> namedMembers.add(Member.decompile((SJSONObject) memberObject, discordJar, id(), this))); return namedMembers; } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { throw new DiscordRequest.DiscordAPIErrorException(e); @@ -1583,7 +1580,7 @@ public List getMembersByName(String filter, int limit) { public void kickMember(Member member) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.GUILD.MEMBER.KICK_MEMBER.replace("{guild.id}", id()).replace("{user.id}", member.user().id()), discordJar, @@ -1603,14 +1600,14 @@ public List getActiveThreads() { try { List threads = new ArrayList<>(); new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.GET_ACTIVE_THREADS.replace("{guild.id}", id()), discordJar, URLS.GET.GUILDS.GET_ACTIVE_THREADS, RequestMethod.GET ).invoke().body().getJSONArray("threads").forEach((thread) -> { - Thread decompiledThread = Thread.decompile((JSONObject) thread, discordJar); + Thread decompiledThread = Thread.decompile((SJSONObject) thread, discordJar); threads.add(decompiledThread); }); return threads; @@ -1643,7 +1640,7 @@ public String getWidgetImageURL(String style) { */ public @NotNull Onboarding getOnboarding() { DiscordRequest req = new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.GUILDS.GET_GUILD_ONBOARDING.replace("{guild.id}", id), discordJar, @@ -1674,8 +1671,8 @@ public record Onboarding( @NotNull @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("enabled", enabled); obj.put("default_channel_ids", defaultChannelIds); obj.put("prompts", prompts.stream().map(Prompt::compile).collect(Collectors.toList())); @@ -1685,10 +1682,10 @@ public JSONObject compile() { @NotNull @Contract("_, _, _ -> new") - public static Onboarding decompile(@NotNull JSONObject obj, @NotNull Guild guild, @NotNull DiscordJar djar) { + public static Onboarding decompile(@NotNull SJSONObject obj, @NotNull Guild guild, @NotNull DiscordJar djar) { return new Onboarding( guild, - obj.getJSONArray("prompts").toList().stream().map(o -> Prompt.decompile((JSONObject) o, djar)).collect(Collectors.toList()), + obj.getJSONArray("prompts").toList().stream().map(o -> Prompt.decompile((SJSONObject) o, djar)).collect(Collectors.toList()), obj.getJSONArray("default_channel_ids").toList().stream().map(o -> (String) o).collect(Collectors.toList()), obj.getBoolean("enabled") ); @@ -1718,8 +1715,8 @@ public record Prompt( @NotNull @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("type", type.getCode()); obj.put("options", options.stream().map(Option::compile).collect(Collectors.toList())); @@ -1732,11 +1729,11 @@ public JSONObject compile() { @NotNull @Contract("_, _ -> new") - public static Prompt decompile(@NotNull JSONObject obj, @NotNull DiscordJar djar) { + public static Prompt decompile(@NotNull SJSONObject obj, @NotNull DiscordJar djar) { return new Prompt( obj.getString("id"), Type.fromCode(obj.getInt("type")), - obj.getJSONArray("options").toList().stream().map(o -> Option.decompile((JSONObject) o, djar)).collect(Collectors.toList()), + obj.getJSONArray("options").toList().stream().map(o -> Option.decompile((SJSONObject) o, djar)).collect(Collectors.toList()), obj.getString("title"), obj.getBoolean("single_select"), obj.getBoolean("required"), @@ -1789,8 +1786,8 @@ public record Option( ) implements Compilerable { @NotNull @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("channel_ids", channelIds); obj.put("role_ids", roleIds); @@ -1802,7 +1799,7 @@ public JSONObject compile() { @NotNull @Contract("_, _ -> new") - public static Option decompile(@NotNull JSONObject obj, DiscordJar discordJar) { + public static Option decompile(@NotNull SJSONObject obj, DiscordJar discordJar) { return new Option( obj.getString("id"), obj.getJSONArray("channel_ids").toList().stream().map(o -> (String) o).collect(Collectors.toList()), diff --git a/src/main/java/com/seailz/discordjar/model/guild/GuildBan.java b/src/main/java/com/seailz/discordjar/model/guild/GuildBan.java index 98805a99..5856dc77 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/GuildBan.java +++ b/src/main/java/com/seailz/discordjar/model/guild/GuildBan.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; /** * Represents a ban on a user in a {@link Guild}. @@ -16,13 +16,13 @@ public record GuildBan ( @NotNull User user ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("reason", reason) .put("user", user.compile()); } - public static GuildBan decompile(JSONObject json, DiscordJar discordJar) { + public static GuildBan decompile(SJSONObject json, DiscordJar discordJar) { return new GuildBan( json.has("reason") ? json.getString("reason") : null, User.decompile(json.getJSONObject("user"), discordJar) diff --git a/src/main/java/com/seailz/discordjar/model/guild/Member.java b/src/main/java/com/seailz/discordjar/model/guild/Member.java index 49d340fc..0aa7e44c 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/Member.java +++ b/src/main/java/com/seailz/discordjar/model/guild/Member.java @@ -7,13 +7,13 @@ import com.seailz.discordjar.model.user.User; 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.flag.BitwiseUtil; import com.seailz.discordjar.utils.permission.Permission; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.json.JSONException; -import org.json.JSONObject; import org.springframework.lang.NonNull; import org.springframework.web.bind.annotation.RequestMethod; @@ -55,12 +55,12 @@ public record Member( ) implements Compilerable, Resolvable { @Override - public JSONObject compile() { + public SJSONObject compile() { int permissions = 0; for (Permission permission : this.permissions) { permissions += permission.getLeftShiftId(); } - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("user", user.compile()); obj.put("nick", nick); obj.put("avatar", avatar); @@ -78,7 +78,7 @@ public JSONObject compile() { @NonNull @Contract("_, _, _, _ -> new") - public static Member decompile(@NotNull JSONObject obj, @NotNull DiscordJar discordJar, String guildId, Guild guild) { + public static Member decompile(@NotNull SJSONObject obj, @NotNull DiscordJar discordJar, String guildId, Guild guild) { User user = null; String nick = null; String avatar = null; @@ -93,9 +93,9 @@ public static Member decompile(@NotNull JSONObject obj, @NotNull DiscordJar disc List permissions = null; String communicationDisabledUntil = null; - if (obj.has("user") && obj.get("user") != JSONObject.NULL) user = User.decompile(obj.getJSONObject("user"), discordJar); - if (obj.has("nick") && obj.get("nick") != JSONObject.NULL) nick = obj.getString("nick"); - if (obj.has("avatar") && obj.get("avatar") != JSONObject.NULL) avatar = obj.getString("avatar"); + if (obj.has("user") && obj.get("user") != SJSONObject.NULL) user = User.decompile(obj.getJSONObject("user"), discordJar); + if (obj.has("nick") && obj.get("nick") != SJSONObject.NULL) nick = obj.getString("nick"); + if (obj.has("avatar") && obj.get("avatar") != SJSONObject.NULL) avatar = obj.getString("avatar"); if (obj.has("roles")) { if (guild != null) { List rolesList = new ArrayList<>(); @@ -109,11 +109,11 @@ public static Member decompile(@NotNull JSONObject obj, @NotNull DiscordJar disc roles = rolesList.toArray(new Role[0]); } } - if (obj.has("joined_at") && obj.get("joined_at") != JSONObject.NULL) joinedAt = obj.getString("joined_at"); - if (obj.has("premium_since") && obj.get("premium_since") != JSONObject.NULL) premiumSince = obj.getString("premium_since"); - if (obj.has("deaf") && obj.get("deaf") != JSONObject.NULL) deaf = obj.getBoolean("deaf"); - if (obj.has("mute") && obj.get("mute") != JSONObject.NULL) mute = obj.getBoolean("mute"); - if (obj.has("pending") && obj.get("pending") != JSONObject.NULL) pending = obj.getBoolean("pending"); + if (obj.has("joined_at") && obj.get("joined_at") != SJSONObject.NULL) joinedAt = obj.getString("joined_at"); + if (obj.has("premium_since") && obj.get("premium_since") != SJSONObject.NULL) premiumSince = obj.getString("premium_since"); + if (obj.has("deaf") && obj.get("deaf") != SJSONObject.NULL) deaf = obj.getBoolean("deaf"); + if (obj.has("mute") && obj.get("mute") != SJSONObject.NULL) mute = obj.getBoolean("mute"); + if (obj.has("pending") && obj.get("pending") != SJSONObject.NULL) pending = obj.getBoolean("pending"); try { BitwiseUtil bitwiseUtil = new BitwiseUtil<>(); @@ -130,7 +130,7 @@ public static Member decompile(@NotNull JSONObject obj, @NotNull DiscordJar disc flags = new ArrayList<>(bitwiseUtil.get(flagsRaw, MemberFlags.class)); } - if (obj.has("communication_disabled_until") && obj.get("communication_disabled_until") != JSONObject.NULL) + if (obj.has("communication_disabled_until") && obj.get("communication_disabled_until") != SJSONObject.NULL) communicationDisabledUntil = obj.getString("communication_disabled_until"); return new Member(user, nick, avatar, roles, joinedAt, premiumSince, deaf, mute, pending, permissions, communicationDisabledUntil, guildId, flags, flagsRaw, discordJar); } @@ -142,7 +142,7 @@ public static Member decompile(@NotNull JSONObject obj, @NotNull DiscordJar disc public void nickname(String nick) { try { new DiscordRequest( - new JSONObject().put("nick", nick), + new SJSONObject().put("nick", nick), new HashMap<>(), URLS.PATCH.GUILD.MEMBER.MODIFY_GUILD_MEMBER.replace("{guild.id}", guildId).replace("{user.id}", user.id()), discordJar, @@ -171,7 +171,7 @@ public void timeout(int seconds) { try { new DiscordRequest( - new JSONObject().put("communication_disabled_until", timeout), + new SJSONObject().put("communication_disabled_until", timeout), new HashMap<>(), URLS.PATCH.GUILD.MEMBER.MODIFY_GUILD_MEMBER.replace("{guild.id}", guildId).replace("{user.id}", user.id()), discordJar, @@ -187,7 +187,7 @@ public void timeout(int seconds) { public void removeTimeout() { try { new DiscordRequest( - new JSONObject().put("communication_disabled_until", JSONObject.NULL), + new SJSONObject().put("communication_disabled_until", SJSONObject.NULL), new HashMap<>(), URLS.PATCH.GUILD.MEMBER.MODIFY_GUILD_MEMBER.replace("{guild.id}", guildId).replace("{user.id}", user.id()), discordJar, @@ -207,7 +207,7 @@ public void removeTimeout() { public void addRole(Role role) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.PUT.GUILD.MEMBERS.ROLES.ADD_GUILD_MEMBER_ROLE.replace("{guild.id}", guildId).replace("{user.id}", user.id()).replace("{role.id}", role.id()), discordJar, @@ -227,7 +227,7 @@ public void addRole(Role role) { public void removeRole(Role role) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.GUILD.MEMBER.REMOVE_GUILD_MEMBER_ROLE.replace("{guild.id}", guildId).replace("{user.id}", user.id()).replace("{role.id}", role.id()), discordJar, diff --git a/src/main/java/com/seailz/discordjar/model/guild/UnavailableGuild.java b/src/main/java/com/seailz/discordjar/model/guild/UnavailableGuild.java index cc6b3426..2a13bc95 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/UnavailableGuild.java +++ b/src/main/java/com/seailz/discordjar/model/guild/UnavailableGuild.java @@ -5,10 +5,10 @@ import com.seailz.discordjar.model.emoji.Emoji; import com.seailz.discordjar.model.emoji.sticker.Sticker; import com.seailz.discordjar.utils.Snowflake; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -43,16 +43,16 @@ public record UnavailableGuild( ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - JSONArray emojis = new JSONArray(); + public SJSONObject compile() { + SJSONArray emojis = new SJSONArray(); this.emojis.forEach(emoji -> emojis.put(emoji.compile())); - JSONArray features = new JSONArray(); + SJSONArray features = new SJSONArray(); this.features.forEach(feature -> features.put(feature.toString())); - JSONArray stickers = new JSONArray(); + SJSONArray stickers = new SJSONArray(); this.stickers.forEach(sticker -> stickers.put(sticker.compile())); - return new JSONObject() + return new SJSONObject() .put("id", id) .put("name", name) .put("icon", icon) @@ -67,7 +67,7 @@ public JSONObject compile() { } @NotNull - public static UnavailableGuild decompile(JSONObject obj, DiscordJar discordjv) { + public static UnavailableGuild decompile(SJSONObject obj, DiscordJar discordjv) { String id; String name; String icon; @@ -112,7 +112,7 @@ public static UnavailableGuild decompile(JSONObject obj, DiscordJar discordjv) { try { List emojiList = new ArrayList<>(); - JSONArray emojiArray = obj.getJSONArray("emojis"); + SJSONArray emojiArray = obj.getJSONArray("emojis"); for (int i = 0; i < emojiArray.length(); i++) { emojiList.add(Emoji.decompile(emojiArray.getJSONObject(i), discordjv)); @@ -124,7 +124,7 @@ public static UnavailableGuild decompile(JSONObject obj, DiscordJar discordjv) { try { List featureList = new ArrayList<>(); - JSONArray featureArray = obj.getJSONArray("features"); + SJSONArray featureArray = obj.getJSONArray("features"); for (int i = 0; i < featureArray.length(); i++) { featureList.add(GuildFeature.valueOf(featureArray.getString(i))); @@ -154,7 +154,7 @@ public static UnavailableGuild decompile(JSONObject obj, DiscordJar discordjv) { try { List stickerList = new ArrayList<>(); - JSONArray stickerArray = obj.getJSONArray("stickers"); + SJSONArray stickerArray = obj.getJSONArray("stickers"); for (int i = 0; i < stickerArray.length(); i++) { stickerList.add(Sticker.decompile(stickerArray.getJSONObject(i), discordjv)); diff --git a/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreen.java b/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreen.java index 6629259b..bac46299 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreen.java +++ b/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreen.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -20,20 +20,20 @@ public record WelcomeScreen( ) implements Compilerable { @Override - public JSONObject compile() { - JSONArray welcomeChannels = new JSONArray(); + public SJSONObject compile() { + SJSONArray welcomeChannels = new SJSONArray(); for (WelcomeScreenChannel channel : welcomeChannels()) { welcomeChannels.put(channel.compile()); } - return new JSONObject() + return new SJSONObject() .put("description", description) .put("welcome_channels", welcomeChannels); } - public static WelcomeScreen decompile(JSONObject obj, DiscordJar discordJar) { + public static WelcomeScreen decompile(SJSONObject obj, DiscordJar discordJar) { List welcomeChannels = new ArrayList<>(); - JSONArray welcomeChannelsArray = obj.getJSONArray("welcome_channels"); + SJSONArray welcomeChannelsArray = obj.getJSONArray("welcome_channels"); for (int i = 0; i < welcomeChannelsArray.length(); i++) { welcomeChannels.add(WelcomeScreenChannel.decompile(welcomeChannelsArray.getJSONObject(i), discordJar)); } diff --git a/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreenChannel.java b/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreenChannel.java index a2c3a72e..130efdc7 100644 --- a/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreenChannel.java +++ b/src/main/java/com/seailz/discordjar/model/guild/welcome/WelcomeScreenChannel.java @@ -3,7 +3,7 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.channel.Channel; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; /** @@ -22,8 +22,8 @@ public record WelcomeScreenChannel( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("channel_id", channel.id()) .put("description", description) .put("emoji_id", emojiId) @@ -31,7 +31,7 @@ public JSONObject compile() { } @NonNull - public static WelcomeScreenChannel decompile(JSONObject obj, DiscordJar discordJar) { + public static WelcomeScreenChannel decompile(SJSONObject obj, DiscordJar discordJar) { return new WelcomeScreenChannel( discordJar.getChannelById(obj.getString("channel_id")), obj.getString("description"), diff --git a/src/main/java/com/seailz/discordjar/model/interaction/Interaction.java b/src/main/java/com/seailz/discordjar/model/interaction/Interaction.java index 5b1f6d23..7806464b 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/Interaction.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/Interaction.java @@ -9,16 +9,14 @@ import com.seailz.discordjar.model.message.Message; import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.flag.BitwiseUtil; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.permission.Permission; import com.seailz.discordjar.utils.rest.DiscordRequest; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.EnumSet; -import java.util.List; /** * Represents the data of an interaction @@ -151,8 +149,8 @@ public String raw() { } @Override - public JSONObject compile() { - JSONObject data = null; + public SJSONObject compile() { + SJSONObject data = null; if (this.data != null) { Class dataClass = this.data.getClass(); Method compileMethod = null; @@ -163,13 +161,13 @@ public JSONObject compile() { } try { - data = (JSONObject) compileMethod.invoke(this.data); + data = (SJSONObject) compileMethod.invoke(this.data); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } - return new JSONObject() + return new SJSONObject() .put("id", id) .put("application", application.id()) .put("type", type.getCode()) @@ -187,7 +185,7 @@ public JSONObject compile() { } @NotNull - public static Interaction decompile(JSONObject json, DiscordJar discordJar) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, DiscordRequest.UnhandledDiscordAPIErrorException { + public static Interaction decompile(SJSONObject json, DiscordJar discordJar) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, DiscordRequest.UnhandledDiscordAPIErrorException { String id = json.has("id") ? json.getString("id") : null; Application application = json.has("application") ? Application.decompile(json.getJSONObject("application"), discordJar) : null; InteractionType type = json.has("type") ? InteractionType.getType(json.getInt("type")) : null; diff --git a/src/main/java/com/seailz/discordjar/model/interaction/InteractionData.java b/src/main/java/com/seailz/discordjar/model/interaction/InteractionData.java index 6237bf71..c0ef8cb5 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/InteractionData.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/InteractionData.java @@ -5,7 +5,7 @@ import com.seailz.discordjar.model.interaction.data.message.MessageComponentInteractionData; import com.seailz.discordjar.model.interaction.data.modal.ModalSubmitInteractionData; import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.lang.reflect.InvocationTargetException; @@ -19,7 +19,7 @@ */ public class InteractionData { - public static InteractionData decompile(InteractionType type, JSONObject obj, DiscordJar jv) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, DiscordRequest.UnhandledDiscordAPIErrorException { + public static InteractionData decompile(InteractionType type, SJSONObject obj, DiscordJar jv) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException, DiscordRequest.UnhandledDiscordAPIErrorException { return switch (type) { case APPLICATION_COMMAND, APPLICATION_COMMAND_AUTOCOMPLETE -> new ApplicationCommandInteractionData(obj, jv); diff --git a/src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java b/src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java index d367fb02..8896ed41 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java @@ -6,9 +6,8 @@ import com.seailz.discordjar.model.interaction.callback.InteractionHandler; 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 lombok.SneakyThrows; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.HashMap; @@ -35,7 +34,7 @@ public Message getOriginalResponse() { try { return Message.decompile( new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.INTERACTIONS.GET_ORIGINAL_INTERACTION_RESPONSE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id()), discordJar, @@ -52,7 +51,7 @@ public Message getOriginalResponse() { public void deleteOriginalResponse() { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.INTERACTION.DELETE_ORIGINAL_INTERACTION_RESPONSE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id()), discordJar, @@ -69,7 +68,7 @@ public Message getFollowup(String id) { try { return Message.decompile( new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.GET.INTERACTIONS.GET_FOLLOWUP_MESSAGE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id()) .replace("{message.id}", id), @@ -87,7 +86,7 @@ public Message getFollowup(String id) { public void deleteFollowup(String id) { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.INTERACTION.DELETE_FOLLOWUP_MESSAGE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id()) .replace("{message.id}", id), @@ -126,7 +125,7 @@ public EditInteractionMessageAction editFollowup(String id) { public void defer(boolean ephemeral) { try { new DiscordRequest( - new JSONObject().put("type", 5).put("data", new JSONObject().put("flags", ephemeral ? 64 : 0)), + new SJSONObject().put("type", 5).put("data", new SJSONObject().put("flags", ephemeral ? 64 : 0)), new HashMap<>(), URLS.POST.INTERACTIONS.CALLBACK.replace("{interaction.id}", id).replace("{interaction.token}", token), discordJar, @@ -142,7 +141,7 @@ public void defer(boolean ephemeral) { public void deferEdit() { try { new DiscordRequest( - new JSONObject().put("type", 6), + new SJSONObject().put("type", 6), new HashMap<>(), URLS.POST.INTERACTIONS.CALLBACK.replace("{interaction.id}", id).replace("{interaction.token}", token), discordJar, diff --git a/src/main/java/com/seailz/discordjar/model/interaction/data/ResolvedData.java b/src/main/java/com/seailz/discordjar/model/interaction/data/ResolvedData.java index 8c2034f9..124df99b 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/data/ResolvedData.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/data/ResolvedData.java @@ -8,9 +8,9 @@ import com.seailz.discordjar.model.resolve.Resolvable; import com.seailz.discordjar.model.role.Role; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; import java.util.HashMap; @@ -86,7 +86,7 @@ public JSONObject compile() { } */ @NotNull - public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { + public static ResolvedData decompile(SJSONObject obj, DiscordJar discordJar) { HashMap users = new HashMap<>(); HashMap members = new HashMap<>(); HashMap roles = new HashMap<>(); @@ -95,7 +95,7 @@ public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { HashMap attachments = new HashMap<>(); if (obj.has("users") && !obj.isNull("users")) { - JSONObject usersObj = obj.getJSONObject("users"); + SJSONObject usersObj = obj.getJSONObject("users"); for (String s : usersObj.keySet()) { users.put(s, User.decompile(usersObj.getJSONObject(s), discordJar)); } @@ -104,7 +104,7 @@ public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { } if (obj.has("members") && !obj.isNull("members")) { - JSONObject membersObj = obj.getJSONObject("members"); + SJSONObject membersObj = obj.getJSONObject("members"); for (String s : membersObj.keySet()) { members.put(s, Member.decompile(membersObj.getJSONObject(s), discordJar, null, null)); } @@ -113,7 +113,7 @@ public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { } if (obj.has("roles") && !obj.isNull("roles")) { - JSONObject rolesObj = obj.getJSONObject("roles"); + SJSONObject rolesObj = obj.getJSONObject("roles"); for (String s : rolesObj.keySet()) { roles.put(s, Role.decompile(rolesObj.getJSONObject(s))); } @@ -122,7 +122,7 @@ public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { } if (obj.has("channels") && !obj.isNull("channels")) { - JSONObject channelsObj = obj.getJSONObject("channels"); + SJSONObject channelsObj = obj.getJSONObject("channels"); for (String s : channelsObj.keySet()) { channels.put(s, Channel.decompile(channelsObj.getJSONObject(s), discordJar)); } @@ -131,7 +131,7 @@ public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { } if (obj.has("messages") && !obj.isNull("messages")) { - JSONObject messagesObj = obj.getJSONObject("messages"); + SJSONObject messagesObj = obj.getJSONObject("messages"); for (String s : messagesObj.keySet()) { messages.put(s, Message.decompile(messagesObj.getJSONObject(s), discordJar)); } @@ -140,7 +140,7 @@ public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { } if (obj.has("attachments") && !obj.isNull("attachments")) { - JSONObject attachmentsObj = obj.getJSONObject("attachments"); + SJSONObject attachmentsObj = obj.getJSONObject("attachments"); for (String s : attachmentsObj.keySet()) { attachments.put(s, Attachment.decompile(attachmentsObj.getJSONObject(s))); } @@ -151,10 +151,10 @@ public static ResolvedData decompile(JSONObject obj, DiscordJar discordJar) { return new ResolvedData(users, members, roles, channels, messages, attachments); } - public static HashMap jsonToMap(JSONArray arr) { + public static HashMap jsonToMap(SJSONArray arr) { HashMap map = new HashMap<>(); for (int i = 0; i < arr.length(); i++) { - JSONObject obj = arr.getJSONObject(i); + SJSONObject obj = arr.getJSONObject(i); map.put(obj.keys().next(), (Resolvable) obj.getJSONObject(obj.keys().next())); } return map; diff --git a/src/main/java/com/seailz/discordjar/model/interaction/data/command/ApplicationCommandInteractionData.java b/src/main/java/com/seailz/discordjar/model/interaction/data/command/ApplicationCommandInteractionData.java index c4379913..8139420a 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/data/command/ApplicationCommandInteractionData.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/data/command/ApplicationCommandInteractionData.java @@ -5,9 +5,9 @@ import com.seailz.discordjar.model.interaction.InteractionData; import com.seailz.discordjar.model.interaction.data.ResolvedData; import com.seailz.discordjar.utils.Snowflake; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.rest.DiscordRequest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; import java.util.List; @@ -44,13 +44,13 @@ public ApplicationCommandInteractionData(String id, String name, ResolvedData re this.targetId = targetId; } - public ApplicationCommandInteractionData(JSONObject obj, DiscordJar discordJar) { + public ApplicationCommandInteractionData(SJSONObject obj, DiscordJar discordJar) { id = obj.has("id") ? obj.getString("id") : null; name = obj.has("name") ? obj.getString("name") : null; resolved = obj.has("resolved") ? ResolvedData.decompile(obj.getJSONObject("resolved"), discordJar) : null; if (obj.has("options") && this.options != null) { - JSONArray optionsArray = obj.getJSONArray("options"); + SJSONArray optionsArray = obj.getJSONArray("options"); for (int i = 0; i < optionsArray.length(); i++) { options.add(ResolvedCommandOption.decompile(optionsArray.getJSONObject(i), resolved)); } @@ -88,9 +88,9 @@ public String targetId() { return targetId; } - public JSONObject compile() { - JSONObject obj = new JSONObject(); - JSONArray options = new JSONArray(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); + SJSONArray options = new SJSONArray(); for (ResolvedCommandOption option : this.options) { options.put(option.compile()); } diff --git a/src/main/java/com/seailz/discordjar/model/interaction/data/command/ResolvedCommandOption.java b/src/main/java/com/seailz/discordjar/model/interaction/data/command/ResolvedCommandOption.java index be9397b0..1132c1ca 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/data/command/ResolvedCommandOption.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/data/command/ResolvedCommandOption.java @@ -6,9 +6,9 @@ import com.seailz.discordjar.model.message.Attachment; import com.seailz.discordjar.model.role.Role; import com.seailz.discordjar.model.user.User; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; import java.math.BigDecimal; import java.util.ArrayList; @@ -39,12 +39,12 @@ public ResolvedCommandOption(String name, Object data, CommandOptionType type, L } @Override - public JSONObject compile() { - JSONArray options = new JSONArray(); + public SJSONObject compile() { + SJSONArray options = new SJSONArray(); for (ResolvedCommandOption option : this.options) options.put(option.compile()); - return new JSONObject() + return new SJSONObject() .put("name", name) .put("value", data) .put("type", type.getCode()) @@ -53,10 +53,10 @@ public JSONObject compile() { } @NotNull - public static ResolvedCommandOption decompile(JSONObject obj, ResolvedData resolvedData) { + public static ResolvedCommandOption decompile(SJSONObject obj, ResolvedData resolvedData) { List options = new ArrayList<>(); if (obj.has("options")) { - JSONArray optionsArray = obj.getJSONArray("options"); + SJSONArray optionsArray = obj.getJSONArray("options"); for (int i = 0; i < optionsArray.length(); i++) { options.add(decompile(optionsArray.getJSONObject(i), resolvedData)); } diff --git a/src/main/java/com/seailz/discordjar/model/interaction/data/message/MessageComponentInteractionData.java b/src/main/java/com/seailz/discordjar/model/interaction/data/message/MessageComponentInteractionData.java index adaaa629..f54e324c 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/data/message/MessageComponentInteractionData.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/data/message/MessageComponentInteractionData.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.model.component.ComponentType; import com.seailz.discordjar.model.component.select.SelectOption; import com.seailz.discordjar.model.interaction.InteractionData; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -33,7 +33,7 @@ public MessageComponentInteractionData(String customId, ComponentType componentT this.snowflakes = snowflakes; } - public MessageComponentInteractionData(JSONObject obj) { + public MessageComponentInteractionData(SJSONObject obj) { this.customId = obj.getString("custom_id"); this.componentType = ComponentType.getType(obj.getInt("component_type")); @@ -62,12 +62,12 @@ public SelectOption.ResolvedSelectOption[] selectOptions() { return selectOptions; } - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("custom_id", customId); obj.put("component_type", componentType.toString().toLowerCase()); if (selectOptions != null && componentType.equals(ComponentType.STRING_SELECT)) { - JSONArray arr = new JSONArray(); + SJSONArray arr = new SJSONArray(); for (SelectOption.ResolvedSelectOption option : selectOptions) { } @@ -76,7 +76,7 @@ public JSONObject compile() { if (snowflakes != null) { if (componentType.equals(ComponentType.ROLE_SELECT) || componentType.equals(ComponentType.CHANNEL_SELECT) || componentType.equals(ComponentType.USER_SELECT) || componentType.equals(ComponentType.MENTIONABLE_SELECT)) { - JSONArray arr = new JSONArray(); + SJSONArray arr = new SJSONArray(); snowflakes.forEach(arr::put); obj.put("values", arr); } diff --git a/src/main/java/com/seailz/discordjar/model/interaction/data/modal/ModalSubmitInteractionData.java b/src/main/java/com/seailz/discordjar/model/interaction/data/modal/ModalSubmitInteractionData.java index 9eab7126..010b74d1 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/data/modal/ModalSubmitInteractionData.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/data/modal/ModalSubmitInteractionData.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.model.component.modal.ResolvedModalComponent; import com.seailz.discordjar.model.interaction.InteractionData; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -13,16 +13,16 @@ public class ModalSubmitInteractionData extends InteractionData { private final String customId; private final List components; - public ModalSubmitInteractionData(JSONObject obj) { + public ModalSubmitInteractionData(SJSONObject obj) { this.customId = obj.has("custom_id") ? obj.getString("custom_id") : null; List resolvedModalComponents = new ArrayList<>(); - JSONArray com = obj.getJSONArray("components"); + SJSONArray com = obj.getJSONArray("components"); for (Object o : com) { - JSONObject json = (JSONObject) o; - JSONArray components = json.getJSONArray("components"); + SJSONObject json = (SJSONObject) o; + SJSONArray components = json.getJSONArray("components"); for (Object comp : components) { - JSONObject jsonComp = (JSONObject) comp; + SJSONObject jsonComp = (SJSONObject) comp; ResolvedModalComponent decompiled = ResolvedModalComponent.decompile(jsonComp); resolvedModalComponents.add(decompiled); } diff --git a/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionMessageResponse.java b/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionMessageResponse.java index 27b404d7..e5024d7d 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionMessageResponse.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionMessageResponse.java @@ -5,7 +5,7 @@ import com.seailz.discordjar.model.mentions.AllowedMentions; import com.seailz.discordjar.model.message.Attachment; import com.seailz.discordjar.model.message.MessageFlag; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import java.io.File; import java.util.ArrayList; @@ -156,8 +156,8 @@ public boolean isSilent() { * Compiles this class up to be sent to Discord */ @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); if (this.tts) obj.put("tts", true); @@ -175,7 +175,7 @@ public JSONObject compile() { flags.add(MessageFlag.SUPPRESS_NOTICICATIONS); if (this.embeds != null) { - List embeds = new ArrayList<>(); + List embeds = new ArrayList<>(); for (Embeder embed : this.embeds) { embeds.add(embed.compile()); } @@ -191,7 +191,7 @@ public JSONObject compile() { if (this.components != null) { - List components = new ArrayList<>(); + List components = new ArrayList<>(); for (DisplayComponent component : this.components) { components.add(component.compile()); } @@ -199,7 +199,7 @@ public JSONObject compile() { } if (this.attachments != null) { - List attachments = new ArrayList<>(); + List attachments = new ArrayList<>(); for (Attachment attachment : this.attachments) { attachments.add(attachment.compile()); } diff --git a/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionModalResponse.java b/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionModalResponse.java index 159bc93c..29bcfc17 100644 --- a/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionModalResponse.java +++ b/src/main/java/com/seailz/discordjar/model/interaction/reply/InteractionModalResponse.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.model.component.DisplayComponent; import com.seailz.discordjar.model.component.RawComponent; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.io.File; import java.util.ArrayList; @@ -84,7 +84,7 @@ public void setComponents(DisplayComponent... components) { } @Override - public JSONObject compile() { + public SJSONObject compile() { if (components.size() < 1) throw new IllegalStateException("Modal must have at least 1 component"); @@ -104,10 +104,10 @@ public JSONObject compile() { } } - JSONObject json = new JSONObject(); + SJSONObject json = new SJSONObject(); json.put("title", title); - JSONArray components = new JSONArray(); + SJSONArray components = new SJSONArray(); for (DisplayComponent component : this.components) { components.put(component.compile()); } diff --git a/src/main/java/com/seailz/discordjar/model/invite/internal/InviteImpl.java b/src/main/java/com/seailz/discordjar/model/invite/internal/InviteImpl.java index c5fea256..b8cdc706 100644 --- a/src/main/java/com/seailz/discordjar/model/invite/internal/InviteImpl.java +++ b/src/main/java/com/seailz/discordjar/model/invite/internal/InviteImpl.java @@ -8,7 +8,7 @@ import com.seailz.discordjar.model.user.User; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public class InviteImpl implements Invite { @@ -36,23 +36,23 @@ public InviteImpl(String code, Guild guild, Channel channel, User inviter, Voice this.expiresAt = expiresAt; } - public static InviteImpl decompile(JSONObject obj, DiscordJar discordJar) { + public static InviteImpl decompile(SJSONObject obj, DiscordJar discordJar) { String code = obj.has("code") ? obj.getString("code") : null; - Guild guild = obj.has("guild") && obj.get("guild") != JSONObject.NULL ? Guild.decompile(obj.getJSONObject("guild"), discordJar) : null; - Channel channel = obj.has("channel") && obj.get("channel") != JSONObject.NULL ? Channel.decompile(obj.getJSONObject("channel"), discordJar) : null; - User inviter = obj.has("inviter") && obj.get("inviter") != JSONObject.NULL ? User.decompile(obj.getJSONObject("inviter"), discordJar) : null; + Guild guild = obj.has("guild") && obj.get("guild") != SJSONObject.NULL ? Guild.decompile(obj.getJSONObject("guild"), discordJar) : null; + Channel channel = obj.has("channel") && obj.get("channel") != SJSONObject.NULL ? Channel.decompile(obj.getJSONObject("channel"), discordJar) : null; + User inviter = obj.has("inviter") && obj.get("inviter") != SJSONObject.NULL ? User.decompile(obj.getJSONObject("inviter"), discordJar) : null; VoiceInviteTargetType voiceInviteTarget = obj.has("target_type") ? VoiceInviteTargetType.fromCode(obj.getInt("target_type")) : null; - User targetUserStream = obj.has("target_user") && obj.get("target_user") == JSONObject.NULL ? User.decompile(obj.getJSONObject("target_user"), discordJar) : null; - Application targetApplication = obj.has("target_application") && obj.get("target_application") == JSONObject.NULL ? Application.decompile(obj.getJSONObject("target_application"), discordJar) : null; + User targetUserStream = obj.has("target_user") && obj.get("target_user") == SJSONObject.NULL ? User.decompile(obj.getJSONObject("target_user"), discordJar) : null; + Application targetApplication = obj.has("target_application") && obj.get("target_application") == SJSONObject.NULL ? Application.decompile(obj.getJSONObject("target_application"), discordJar) : null; int approximatePresenceCount = obj.has("approximate_presence_count") ? obj.getInt("approximate_presence_count") : -1; int approximateMemberCount = obj.has("approximate_member_count") ? obj.getInt("approximate_member_count") : -1; - String expiresAt = obj.has("expires_at") && obj.get("expires_at") != JSONObject.NULL ? obj.getString("expires_at") : null; + String expiresAt = obj.has("expires_at") && obj.get("expires_at") != SJSONObject.NULL ? obj.getString("expires_at") : null; return new InviteImpl(code, guild, channel, inviter, voiceInviteTarget, targetUserStream, targetApplication, approximatePresenceCount, approximateMemberCount, expiresAt); } @Override - public JSONObject compile() { - JSONObject json = new JSONObject(); + public SJSONObject compile() { + SJSONObject json = new SJSONObject(); json.put("code", code); json.put("guild", guild.compile()); json.put("channel", channel.compile()); diff --git a/src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java b/src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java index 945d01c6..e281b104 100644 --- a/src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java +++ b/src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java @@ -6,7 +6,7 @@ import com.seailz.discordjar.model.guild.Guild; import com.seailz.discordjar.model.invite.InviteMetadata; import com.seailz.discordjar.model.user.User; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public class InviteMetadataImpl extends InviteImpl implements InviteMetadata { @@ -50,28 +50,28 @@ public String createdAt() { return createdAt; } - public static InviteMetadataImpl decompile(JSONObject obj, DiscordJar discordJar) { + public static InviteMetadataImpl decompile(SJSONObject obj, DiscordJar discordJar) { String code = obj.has("code") ? obj.getString("code") : null; - Guild guild = obj.has("guild") && obj.get("guild") != JSONObject.NULL ? Guild.decompile(obj.getJSONObject("guild"), discordJar) : null; - Channel channel = obj.has("channel") && obj.get("channel") != JSONObject.NULL ? Channel.decompile(obj.getJSONObject("channel"), discordJar) : null; - User inviter = obj.has("inviter") && obj.get("inviter") != JSONObject.NULL ? User.decompile(obj.getJSONObject("inviter"), discordJar) : null; + Guild guild = obj.has("guild") && obj.get("guild") != SJSONObject.NULL ? Guild.decompile(obj.getJSONObject("guild"), discordJar) : null; + Channel channel = obj.has("channel") && obj.get("channel") != SJSONObject.NULL ? Channel.decompile(obj.getJSONObject("channel"), discordJar) : null; + User inviter = obj.has("inviter") && obj.get("inviter") != SJSONObject.NULL ? User.decompile(obj.getJSONObject("inviter"), discordJar) : null; VoiceInviteTargetType voiceInviteTarget = obj.has("target_type") ? VoiceInviteTargetType.fromCode(obj.getInt("target_type")) : null; - User targetUserStream = obj.has("target_user") && obj.get("target_user") == JSONObject.NULL ? User.decompile(obj.getJSONObject("target_user"), discordJar) : null; - Application targetApplication = obj.has("target_application") && obj.get("target_application") == JSONObject.NULL ? Application.decompile(obj.getJSONObject("target_application"), discordJar) : null; + User targetUserStream = obj.has("target_user") && obj.get("target_user") == SJSONObject.NULL ? User.decompile(obj.getJSONObject("target_user"), discordJar) : null; + Application targetApplication = obj.has("target_application") && obj.get("target_application") == SJSONObject.NULL ? Application.decompile(obj.getJSONObject("target_application"), discordJar) : null; int approximatePresenceCount = obj.has("approximate_presence_count") ? obj.getInt("approximate_presence_count") : -1; int approximateMemberCount = obj.has("approximate_member_count") ? obj.getInt("approximate_member_count") : -1; - String expiresAt = obj.has("expires_at") && obj.get("expires_at") != JSONObject.NULL ? obj.getString("expires_at") : null; + String expiresAt = obj.has("expires_at") && obj.get("expires_at") != SJSONObject.NULL ? obj.getString("expires_at") : null; int uses = obj.has("uses") ? obj.getInt("uses") : -1; int maxUses = obj.has("max_uses") ? obj.getInt("max_uses") : -1; int maxAge = obj.has("max_age") ? obj.getInt("max_age") : -1; boolean temporary = obj.has("temporary") && obj.getBoolean("temporary"); - String createdAt = obj.has("created_at") && obj.get("created_at") != JSONObject.NULL ? obj.getString("created_at") : null; + String createdAt = obj.has("created_at") && obj.get("created_at") != SJSONObject.NULL ? obj.getString("created_at") : null; return new InviteMetadataImpl(code, guild, channel, inviter, voiceInviteTarget, targetUserStream, targetApplication, approximatePresenceCount, approximateMemberCount, expiresAt, uses, maxUses, maxAge, temporary, createdAt); } @Override - public JSONObject compile() { - JSONObject json = new JSONObject(); + public SJSONObject compile() { + SJSONObject json = new SJSONObject(); json.put("code", code()); json.put("guild", guild().compile()); json.put("channel", channel().compile()); diff --git a/src/main/java/com/seailz/discordjar/model/mentions/AllowedMentions.java b/src/main/java/com/seailz/discordjar/model/mentions/AllowedMentions.java index 32c347b3..874173dc 100644 --- a/src/main/java/com/seailz/discordjar/model/mentions/AllowedMentions.java +++ b/src/main/java/com/seailz/discordjar/model/mentions/AllowedMentions.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.core.Compilerable; import org.jetbrains.annotations.NotNull; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.List; import java.util.logging.Logger; @@ -35,8 +35,8 @@ public static AllowedMentions none() { } @Override - public JSONObject compile() { - JSONObject json = new JSONObject(); + public SJSONObject compile() { + SJSONObject json = new SJSONObject(); if (parse == null) { throw new IllegalArgumentException("Parse cannot be null"); } @@ -49,7 +49,7 @@ public JSONObject compile() { throw new IllegalArgumentException("Users cannot be null"); } - JSONArray parseArray = new JSONArray(); + SJSONArray parseArray = new SJSONArray(); if (parse.contains(Type.EVERYONE_MENTIONS) && !allowEveryone) { parse.remove(Type.EVERYONE_MENTIONS); Logger.getLogger(AllowedMentions.class.getName()).warning("Cannot parse everyone mentions if allowEveryone is false. Removing from parse list."); @@ -60,14 +60,14 @@ public JSONObject compile() { json.put("parse", parseArray); - JSONArray rolesArray = new JSONArray(); + SJSONArray rolesArray = new SJSONArray(); for (String role : roles) { rolesArray.put(role); } json.put("roles", rolesArray); - JSONArray usersArray = new JSONArray(); + SJSONArray usersArray = new SJSONArray(); for (String user : users) { usersArray.put(user); } diff --git a/src/main/java/com/seailz/discordjar/model/message/Attachment.java b/src/main/java/com/seailz/discordjar/model/message/Attachment.java index 82374e19..4b318c2f 100644 --- a/src/main/java/com/seailz/discordjar/model/message/Attachment.java +++ b/src/main/java/com/seailz/discordjar/model/message/Attachment.java @@ -2,7 +2,7 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.resolve.Resolvable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; import java.io.File; @@ -36,8 +36,8 @@ public record Attachment( @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("filename", fileName); obj.put("description", description); @@ -67,7 +67,7 @@ public static Attachment fromFile(int id, File file) { } @NonNull - public static Attachment decompile(JSONObject obj) { + public static Attachment decompile(SJSONObject obj) { int id; String fileName; String description; diff --git a/src/main/java/com/seailz/discordjar/model/message/Message.java b/src/main/java/com/seailz/discordjar/model/message/Message.java index b0c6dc92..d1679ab7 100644 --- a/src/main/java/com/seailz/discordjar/model/message/Message.java +++ b/src/main/java/com/seailz/discordjar/model/message/Message.java @@ -6,7 +6,6 @@ import com.seailz.discordjar.model.application.Application; import com.seailz.discordjar.model.channel.thread.Thread; import com.seailz.discordjar.model.channel.utils.ChannelMention; -import com.seailz.discordjar.model.component.ActionRow; import com.seailz.discordjar.model.component.Component; import com.seailz.discordjar.model.component.DisplayComponent; import com.seailz.discordjar.model.embed.Embed; @@ -19,11 +18,11 @@ import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.Snowflake; 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.JSONException; -import org.json.JSONObject; import org.springframework.lang.NonNull; import org.springframework.web.bind.annotation.RequestMethod; @@ -97,7 +96,7 @@ public record Message( ) implements Compilerable, Resolvable, Snowflake { @NonNull - public static Message decompile(JSONObject obj, DiscordJar discordJar) { + public static Message decompile(SJSONObject obj, DiscordJar discordJar) { String id; String channelId; User author; @@ -183,7 +182,7 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { }*/ try { - JSONArray mentionsArray = obj.getJSONArray("mentions"); + SJSONArray mentionsArray = obj.getJSONArray("mentions"); mentions = new User[mentionsArray.length()]; for (int i = 0; i < mentionsArray.length(); i++) { mentions[i] = User.decompile(mentionsArray.getJSONObject(i), discordJar); @@ -192,7 +191,7 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { mentions = null; } try { - JSONArray mentionRolesArray = obj.getJSONArray("mention_roles"); + SJSONArray mentionRolesArray = obj.getJSONArray("mention_roles"); mentionRoles = new Role[mentionRolesArray.length()]; for (int i = 0; i < mentionRolesArray.length(); i++) { mentionRoles[i] = Role.decompile(mentionRolesArray.getJSONObject(i)); @@ -201,7 +200,7 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { mentionRoles = null; } try { - JSONArray mentionChannelsArray = obj.getJSONArray("mention_channels"); + SJSONArray mentionChannelsArray = obj.getJSONArray("mention_channels"); ArrayList mentionChannelsDecompiled = new ArrayList<>(); for (int i = 0; i < mentionChannelsArray.length(); i++) { @@ -213,7 +212,7 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { } try { - JSONArray attachmentsArray = obj.getJSONArray("attachments"); + SJSONArray attachmentsArray = obj.getJSONArray("attachments"); attachments = new Attachment[attachmentsArray.length()]; for (int i = 0; i < attachmentsArray.length(); i++) { attachments[i] = Attachment.decompile(attachmentsArray.getJSONObject(i)); @@ -223,7 +222,7 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { } try { - JSONArray embedsArray = obj.getJSONArray("embeds"); + SJSONArray embedsArray = obj.getJSONArray("embeds"); embeds = new Embed[embedsArray.length()]; for (int i = 0; i < embedsArray.length(); i++) { embeds[i] = Embed.decompile(embedsArray.getJSONObject(i)); @@ -233,7 +232,7 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { } try { - JSONArray reactionsArray = obj.getJSONArray("reactions"); + SJSONArray reactionsArray = obj.getJSONArray("reactions"); reactions = new Reaction[reactionsArray.length()]; for (int i = 0; i < reactionsArray.length(); i++) { reactions[i] = Reaction.decompile(reactionsArray.getJSONObject(i), discordJar); @@ -324,9 +323,9 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { } if (obj.has("sticker_items") && !obj.isNull("sticker_items")) { - JSONArray stickerItemsArray = obj.getJSONArray("sticker_items"); + SJSONArray stickerItemsArray = obj.getJSONArray("sticker_items"); stickerItemsArray.forEach(stickerItem -> { - stickerItems.add(StickerItem.decompile((JSONObject) stickerItem)); + stickerItems.add(StickerItem.decompile((SJSONObject) stickerItem)); }); } @@ -337,62 +336,62 @@ public static Message decompile(JSONObject obj, DiscordJar discordJar) { } @Override - public JSONObject compile() { + public SJSONObject compile() { int flags = 0; for (MessageFlag flag : this.flags) { flags += flag.getLeftShiftId(); } - JSONArray mentionsArray = new JSONArray(); + SJSONArray mentionsArray = new SJSONArray(); if (mentions != null) { for (User mention : mentions) { mentionsArray.put(mention.compile()); } } - JSONArray mentionRolesArray = new JSONArray(); + SJSONArray mentionRolesArray = new SJSONArray(); if (mentionRoles != null) { for (Role mentionRole : mentionRoles) { mentionRolesArray.put(mentionRole.compile()); } } - JSONArray mentionChannelsArray = new JSONArray(); + SJSONArray mentionChannelsArray = new SJSONArray(); if (mentionChannels != null) { for (ChannelMention mentionChannel : mentionChannels) { mentionChannelsArray.put(mentionChannel.compile()); } } - JSONArray attachmentsArray = new JSONArray(); + SJSONArray attachmentsArray = new SJSONArray(); if (attachments != null) { for (Attachment attachment : attachments) { attachmentsArray.put(attachment.compile()); } } - JSONArray embedsArray = new JSONArray(); + SJSONArray embedsArray = new SJSONArray(); if (embeds != null) { for (Embed embed : embeds) { embedsArray.put(embed.compile()); } } - JSONArray reactionsArray = new JSONArray(); + SJSONArray reactionsArray = new SJSONArray(); if (reactions != null) { for (Reaction reaction : reactions) { reactionsArray.put(reaction.compile()); } } - JSONArray componentsArray = new JSONArray(); + SJSONArray componentsArray = new SJSONArray(); if (components != null) { for (Component component : components) { componentsArray.put(component.compile()); } } - return new JSONObject() + return new SJSONObject() .put("id", id) .put("channel_id", channelId) .put("author", author.compile()) @@ -411,20 +410,20 @@ public JSONObject compile() { .put("pinned", pinned) .put("webhook_id", webhookId) .put("type", type.getCode()) - .put("activity", activity == null ? JSONObject.NULL : activity.compile()) - .put("application", application == null ? JSONObject.NULL : application.compile()) + .put("activity", activity == null ? SJSONObject.NULL : activity.compile()) + .put("application", application == null ? SJSONObject.NULL : application.compile()) .put("application_id", applicationId) - .put("message_reference", messageReference == null ? JSONObject.NULL : messageReference.compile()) + .put("message_reference", messageReference == null ? SJSONObject.NULL : messageReference.compile()) .put("flags", flags) - .put("referenced_message", referencedMessage == null ? JSONObject.NULL : referencedMessage.compile()) - .put("interaction", interaction == null ? JSONObject.NULL : interaction.compile()) - .put("thread", thread == null ? JSONObject.NULL : thread.compile()) + .put("referenced_message", referencedMessage == null ? SJSONObject.NULL : referencedMessage.compile()) + .put("interaction", interaction == null ? SJSONObject.NULL : interaction.compile()) + .put("thread", thread == null ? SJSONObject.NULL : thread.compile()) .put("components", componentsArray); } public void delete() { try { - new DiscordRequest(new JSONObject(), new HashMap<>(), URLS.DELETE.CHANNEL.MESSAGE.DELETE_MESSAGE + new DiscordRequest(new SJSONObject(), new HashMap<>(), URLS.DELETE.CHANNEL.MESSAGE.DELETE_MESSAGE .replace("{channel.id}", channelId).replace("{message.id}", id), discordJar, URLS.DELETE.CHANNEL.MESSAGE.DELETE_MESSAGE, RequestMethod.DELETE).invoke(); } catch (DiscordRequest.UnhandledDiscordAPIErrorException e) { @@ -465,14 +464,14 @@ public record StickerItem( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("name", name) .put("format_type", format.getCode()); } - public static StickerItem decompile(JSONObject obj) { + public static StickerItem decompile(SJSONObject obj) { return new StickerItem( obj.getString("id"), obj.getString("name"), @@ -489,15 +488,15 @@ public record RoleSubscriptionData( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("role_subscription_listing_id", roleSubscriptionListingId) .put("tier_name", tierName) .put("total_months_subscribed", totalMonthsSubscribed) .put("is_renewal", isRenewal); } - public static RoleSubscriptionData decompile(JSONObject obj) { + public static RoleSubscriptionData decompile(SJSONObject obj) { return new RoleSubscriptionData( obj.getString("role_subscription_listing_id"), obj.getString("tier_name"), @@ -513,7 +512,7 @@ public static RoleSubscriptionData decompile(JSONObject obj) { public void pin() { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.PUT.CHANNELS.PINS.PIN_MESSAGE.replace("{channel.id}", channelId).replace("{message.id}", id), discordJar, @@ -531,7 +530,7 @@ public void pin() { public void unpin() { try { new DiscordRequest( - new JSONObject(), + new SJSONObject(), new HashMap<>(), URLS.DELETE.CHANNEL.PINS.UNPIN_MESSAGE.replace("{channel.id}", channelId).replace("{message.id}", id), discordJar, @@ -551,7 +550,7 @@ public void unpin() { public CompletableFuture startThreadFromMessage(String name, Thread.AutoArchiveDuration archiveAfter, int rateLimitPerUser) { CompletableFuture future = new CompletableFuture<>(); future.completeAsync(() -> { - JSONObject body = new JSONObject(); + SJSONObject body = new SJSONObject(); body.put("name", name); body.put("auto_archive_duration", archiveAfter.minutes()); body.put("rate_limit_per_user", rateLimitPerUser); diff --git a/src/main/java/com/seailz/discordjar/model/message/MessageReference.java b/src/main/java/com/seailz/discordjar/model/message/MessageReference.java index 93455182..fcb0fae8 100644 --- a/src/main/java/com/seailz/discordjar/model/message/MessageReference.java +++ b/src/main/java/com/seailz/discordjar/model/message/MessageReference.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.message; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; /** @@ -20,8 +20,8 @@ public record MessageReference( ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("message_id", messageId); obj.put("channel_id", channelId); obj.put("guild_id", guildId); @@ -30,7 +30,7 @@ public JSONObject compile() { } @NonNull - public static MessageReference decompile(JSONObject obj) { + public static MessageReference decompile(SJSONObject obj) { String messageId; String channelId; String guildId; diff --git a/src/main/java/com/seailz/discordjar/model/message/activity/MessageActivity.java b/src/main/java/com/seailz/discordjar/model/message/activity/MessageActivity.java index f792572c..c788fbb7 100644 --- a/src/main/java/com/seailz/discordjar/model/message/activity/MessageActivity.java +++ b/src/main/java/com/seailz/discordjar/model/message/activity/MessageActivity.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.message.activity; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record MessageActivity( @@ -10,15 +10,15 @@ public record MessageActivity( ) implements Compilerable { @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("type", type.getCode()); obj.put("party_id", partyId); return obj; } @NonNull - public static MessageActivity decompile(JSONObject obj) { + public static MessageActivity decompile(SJSONObject obj) { MessageActivityType type; String partyId; diff --git a/src/main/java/com/seailz/discordjar/model/permission/PermissionOverwrite.java b/src/main/java/com/seailz/discordjar/model/permission/PermissionOverwrite.java index 76f3ad01..cca956cf 100644 --- a/src/main/java/com/seailz/discordjar/model/permission/PermissionOverwrite.java +++ b/src/main/java/com/seailz/discordjar/model/permission/PermissionOverwrite.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.Snowflake; import com.seailz.discordjar.utils.flag.BitwiseUtil; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.permission.Permission; -import org.json.JSONObject; import org.springframework.lang.NonNull; import java.util.EnumSet; @@ -21,7 +21,7 @@ public PermissionOverwrite(String id, OverwriteType type) { } @Override - public JSONObject compile() { + public SJSONObject compile() { int allowInt = 0; int denyInt = 0; @@ -33,7 +33,7 @@ public JSONObject compile() { denyInt += permission.getLeftShiftId(); } - JSONObject obj = new JSONObject(); + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("type", type.getCode()); obj.put("allow", allowInt); @@ -42,7 +42,7 @@ public JSONObject compile() { } @NonNull - public static PermissionOverwrite decompile(JSONObject obj) { + public static PermissionOverwrite decompile(SJSONObject obj) { String id; OverwriteType type; int allow; diff --git a/src/main/java/com/seailz/discordjar/model/role/Role.java b/src/main/java/com/seailz/discordjar/model/role/Role.java index a91975f4..24abbdfe 100644 --- a/src/main/java/com/seailz/discordjar/model/role/Role.java +++ b/src/main/java/com/seailz/discordjar/model/role/Role.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.resolve.Resolvable; import com.seailz.discordjar.utils.Mentionable; +import com.seailz.discordjar.utils.json.SJSONObject; import org.json.JSONException; -import org.json.JSONObject; /** * Represents a Discord role in a guild. @@ -32,7 +32,7 @@ public record Role( boolean mentionable, RoleTag tags ) implements Compilerable, Resolvable, Mentionable { - public static Role decompile(JSONObject obj) { + public static Role decompile(SJSONObject obj) { String id; String name; int color; @@ -108,8 +108,8 @@ public static Role decompile(JSONObject obj) { } @Override - public JSONObject compile() { - JSONObject obj = new JSONObject(); + public SJSONObject compile() { + SJSONObject obj = new SJSONObject(); obj.put("id", id); obj.put("name", name); obj.put("color", color); diff --git a/src/main/java/com/seailz/discordjar/model/role/RoleTag.java b/src/main/java/com/seailz/discordjar/model/role/RoleTag.java index 6a58ac2e..373d6e14 100644 --- a/src/main/java/com/seailz/discordjar/model/role/RoleTag.java +++ b/src/main/java/com/seailz/discordjar/model/role/RoleTag.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.role; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; import org.springframework.lang.NonNull; public record RoleTag( @@ -14,15 +14,15 @@ public record RoleTag( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("bot_id", botId) .put("integration_id", integrationId) .put("is_premium_subscriber", isPremiumSubscriber); } @NonNull - public static RoleTag decompile(JSONObject obj) { + public static RoleTag decompile(SJSONObject obj) { String botId = null; String integrationId = null; boolean isPremiumSubscriber; diff --git a/src/main/java/com/seailz/discordjar/model/scopes/InstallParams.java b/src/main/java/com/seailz/discordjar/model/scopes/InstallParams.java index 51d1cf1f..e153f4d9 100644 --- a/src/main/java/com/seailz/discordjar/model/scopes/InstallParams.java +++ b/src/main/java/com/seailz/discordjar/model/scopes/InstallParams.java @@ -2,10 +2,9 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.flag.BitwiseUtil; +import com.seailz.discordjar.utils.json.SJSONObject; import com.seailz.discordjar.utils.permission.Permission; -import jakarta.el.MethodReference; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; import java.util.ArrayList; import java.util.EnumSet; @@ -15,7 +14,7 @@ public record InstallParams(EnumSet scopes, EnumSet permissions) implements Compilerable { @Override - public JSONObject compile() { + public SJSONObject compile() { int permissions = 0; for (Permission permission : this.permissions) { @@ -27,17 +26,17 @@ public JSONObject compile() { if (this.scopes == null) scopes = null; else scopes = this.scopes.stream().map(Scope::name).collect(Collectors.joining(" ")); - return new JSONObject() + return new SJSONObject() .put("scopes", scopes) .put("permissions", permissions); } - public static InstallParams decompile(JSONObject obj) { + public static InstallParams decompile(SJSONObject obj) { EnumSet scopes = EnumSet.noneOf(Scope.class); EnumSet permissions = EnumSet.noneOf(Permission.class); if (obj.has("scopes") && !obj.isNull("scopes")) { - JSONArray scopesArray = obj.getJSONArray("scopes"); + SJSONArray scopesArray = obj.getJSONArray("scopes"); List scopesList = new ArrayList<>(); for (int i = 0; i < scopesArray.length(); i++) { scopesList.add(scopesArray.get(i).toString()); diff --git a/src/main/java/com/seailz/discordjar/model/status/Status.java b/src/main/java/com/seailz/discordjar/model/status/Status.java index 4a1ce20f..cd0ab1f3 100644 --- a/src/main/java/com/seailz/discordjar/model/status/Status.java +++ b/src/main/java/com/seailz/discordjar/model/status/Status.java @@ -3,8 +3,8 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.status.activity.Activity; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; /** * Represents the status of a user or bot @@ -25,14 +25,14 @@ public record Status( ) implements Compilerable { @Override - public JSONObject compile() { - JSONArray activities = new JSONArray(); + public SJSONObject compile() { + SJSONArray activities = new SJSONArray(); for (Activity activity : this.activities) { activities.put(activity.compile()); } - return new JSONObject() - .put("since", since == 0 ? JSONObject.NULL : since) + return new SJSONObject() + .put("since", since == 0 ? SJSONObject.NULL : since) .put("activities", activities) .put("status", status.getCode()) .put("afk", afk); @@ -46,7 +46,7 @@ public Status(Activity activity, StatusType status) { this(0, new Activity[]{activity}, status, false); } - public static Status decompile(JSONObject obj, DiscordJar discordjv) { + public static Status decompile(SJSONObject obj, DiscordJar discordjv) { int since; Activity[] activities; StatusType status; diff --git a/src/main/java/com/seailz/discordjar/model/status/activity/Activity.java b/src/main/java/com/seailz/discordjar/model/status/activity/Activity.java index 267ab43c..f6749f54 100644 --- a/src/main/java/com/seailz/discordjar/model/status/activity/Activity.java +++ b/src/main/java/com/seailz/discordjar/model/status/activity/Activity.java @@ -4,8 +4,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.emoji.Emoji; import com.seailz.discordjar.model.status.Status; +import com.seailz.discordjar.utils.json.SJSONObject; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import java.util.EnumSet; @@ -86,19 +86,19 @@ public EnumSet flags() { } @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("name", name) .put("type", type.getCode()) .put("url", streamUrl) .put("application_id", applicationId) - .put("emoji", emoji == null ? JSONObject.NULL : emoji.compile()) + .put("emoji", emoji == null ? SJSONObject.NULL : emoji.compile()) .put("instance", instance) - .put("flags", flags == null ? JSONObject.NULL : new JSONObject().put("flags", flags)); + .put("flags", flags == null ? SJSONObject.NULL : new SJSONObject().put("flags", flags)); } @NotNull - public static Activity decompile(JSONObject obj, DiscordJar discordJar) { + public static Activity decompile(SJSONObject obj, DiscordJar discordJar) { String name; ActivityType type; String url; diff --git a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityAssets.java b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityAssets.java index a3a6f69d..e6458272 100644 --- a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityAssets.java +++ b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityAssets.java @@ -1,8 +1,8 @@ package com.seailz.discordjar.model.status.activity; import com.seailz.discordjar.core.Compilerable; +import com.seailz.discordjar.utils.json.SJSONObject; import org.json.JSONException; -import org.json.JSONObject; public record ActivityAssets( String largeImage, @@ -13,15 +13,15 @@ public record ActivityAssets( @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("large_image", largeImage) .put("large_text", largeText) .put("small_image", smallImage) .put("small_text", smallText); } - public static ActivityAssets decompile(JSONObject obj) { + public static ActivityAssets decompile(SJSONObject obj) { String largeImage; String largeText; String smallImage; diff --git a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityButton.java b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityButton.java index 1bb9f6cc..4522c225 100644 --- a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityButton.java +++ b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityButton.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.status.activity; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents a button in an activity @@ -15,13 +15,13 @@ public record ActivityButton( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("label", label) .put("url", url); } - public static ActivityButton decompile(JSONObject obj) { + public static ActivityButton decompile(SJSONObject obj) { return new ActivityButton( obj.getString("label"), obj.getString("url") diff --git a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityParty.java b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityParty.java index c8b7c071..004ae7ce 100644 --- a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityParty.java +++ b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityParty.java @@ -2,8 +2,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.utils.Snowflake; +import com.seailz.discordjar.utils.json.SJSONObject; import org.json.JSONException; -import org.json.JSONObject; /** * Represents the party of an activity @@ -22,14 +22,14 @@ public record ActivityParty( ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("id", id) .put("current_size", currentSize) .put("max_size", maxSize); } - public static ActivityParty decompile(JSONObject obj) { + public static ActivityParty decompile(SJSONObject obj) { String id; int currentSize; int maxSize; diff --git a/src/main/java/com/seailz/discordjar/model/status/activity/ActivitySecrets.java b/src/main/java/com/seailz/discordjar/model/status/activity/ActivitySecrets.java index 9538aafa..b084ca4f 100644 --- a/src/main/java/com/seailz/discordjar/model/status/activity/ActivitySecrets.java +++ b/src/main/java/com/seailz/discordjar/model/status/activity/ActivitySecrets.java @@ -1,8 +1,8 @@ package com.seailz.discordjar.model.status.activity; import com.seailz.discordjar.core.Compilerable; +import com.seailz.discordjar.utils.json.SJSONObject; import org.json.JSONException; -import org.json.JSONObject; /** * Represents the secrets of an activity @@ -20,14 +20,14 @@ public record ActivitySecrets( String match ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("join", join) .put("spectate", spectate) .put("match", match); } - public static ActivitySecrets decompile(JSONObject obj) { + public static ActivitySecrets decompile(SJSONObject obj) { String join; String spectate; String match; diff --git a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityTimestamp.java b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityTimestamp.java index 8c73d58a..fb8dd474 100644 --- a/src/main/java/com/seailz/discordjar/model/status/activity/ActivityTimestamp.java +++ b/src/main/java/com/seailz/discordjar/model/status/activity/ActivityTimestamp.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.model.status.activity; import com.seailz.discordjar.core.Compilerable; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; /** * Represents the timestamps of an activity @@ -18,13 +18,13 @@ public record ActivityTimestamp( ) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("start", start) .put("end", end); } - public static ActivityTimestamp decompile(JSONObject obj) { + public static ActivityTimestamp decompile(SJSONObject obj) { return new ActivityTimestamp( obj.getInt("start"), obj.getInt("end") diff --git a/src/main/java/com/seailz/discordjar/model/team/Team.java b/src/main/java/com/seailz/discordjar/model/team/Team.java index 3ad552e6..036b0b1c 100644 --- a/src/main/java/com/seailz/discordjar/model/team/Team.java +++ b/src/main/java/com/seailz/discordjar/model/team/Team.java @@ -4,8 +4,8 @@ import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.team.member.TeamMember; import com.seailz.discordjar.utils.Snowflake; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; import java.util.List; @@ -17,12 +17,12 @@ public record Team( String ownerUserId ) implements Compilerable, Snowflake { @Override - public JSONObject compile() { - JSONArray membersArray = new JSONArray(); + public SJSONObject compile() { + SJSONArray membersArray = new SJSONArray(); members.forEach(m -> { membersArray.put(m.compile()); }); - return new JSONObject() + return new SJSONObject() .put("icon", icon) .put("id", id) .put("name", name) @@ -30,7 +30,7 @@ public JSONObject compile() { .put("owner_user_id", ownerUserId); } - public static Team decompile(JSONObject obj, DiscordJar discordJar) { + public static Team decompile(SJSONObject obj, DiscordJar discordJar) { String icon; String id; String name; @@ -56,7 +56,7 @@ public static Team decompile(JSONObject obj, DiscordJar discordJar) { } try { - members = obj.getJSONArray("members").toList().stream().map(o -> TeamMember.decompile(new JSONObject(o.toString()), discordJar)).toList(); + members = obj.getJSONArray("members").toList().stream().map(o -> TeamMember.decompile(new SJSONObject(o.toString()), discordJar)).toList(); } catch (Exception e) { members = null; } diff --git a/src/main/java/com/seailz/discordjar/model/team/member/TeamMember.java b/src/main/java/com/seailz/discordjar/model/team/member/TeamMember.java index f02b3e0a..9687fd2e 100644 --- a/src/main/java/com/seailz/discordjar/model/team/member/TeamMember.java +++ b/src/main/java/com/seailz/discordjar/model/team/member/TeamMember.java @@ -3,20 +3,20 @@ import com.seailz.discordjar.DiscordJar; import com.seailz.discordjar.core.Compilerable; import com.seailz.discordjar.model.user.User; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONObject; public record TeamMember(MembershipState membershipState, String permissions, String teamId, User user) implements Compilerable { @Override - public JSONObject compile() { - return new JSONObject() + public SJSONObject compile() { + return new SJSONObject() .put("membership_state", membershipState.getCode()) .put("permissions", permissions) .put("team_id", teamId) .put("user", user.compile()); } - public static TeamMember decompile(JSONObject obj, DiscordJar discordJar) { + public static TeamMember decompile(SJSONObject obj, DiscordJar discordJar) { MembershipState membershipState; String permissions; String teamId; diff --git a/src/main/java/com/seailz/discordjar/model/user/User.java b/src/main/java/com/seailz/discordjar/model/user/User.java index d6692bf4..81f770b8 100644 --- a/src/main/java/com/seailz/discordjar/model/user/User.java +++ b/src/main/java/com/seailz/discordjar/model/user/User.java @@ -8,6 +8,7 @@ import com.seailz.discordjar.utils.Mentionable; import com.seailz.discordjar.utils.StringFormatter; 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.flag.BitwiseUtil; @@ -15,7 +16,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.json.JSONException; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMethod; import java.util.EnumSet; @@ -72,8 +72,8 @@ public record User( * @return a JSONObject consisting of the data in this User object */ @Override - public @NotNull JSONObject compile() { - JSONObject obj = new JSONObject() + public @NotNull SJSONObject compile() { + SJSONObject obj = new SJSONObject() .put("id", id) .put("username", username) .put("discriminator", discriminator) @@ -89,7 +89,7 @@ public record User( .put("global_name", displayName); if (premiumType == null) - obj.put("premium_type", JSONObject.NULL); + obj.put("premium_type", SJSONObject.NULL); else obj.put("premium_type", premiumType.getId()); return obj; @@ -102,7 +102,7 @@ public record User( * @return a User object consisting of the data in the JSONObject */ @Contract("_, _ -> new") - public static @NotNull User decompile(@NotNull JSONObject obj, DiscordJar discordJar) { + public static @NotNull User decompile(@NotNull SJSONObject obj, DiscordJar discordJar) { String id; String username; String discriminator; @@ -219,7 +219,7 @@ public record User( */ @Nullable public DMChannel createDM() { - JSONObject obj = new JSONObject() + SJSONObject obj = new SJSONObject() .put("recipient_id", id); DiscordResponse resp = null; try { diff --git a/src/main/java/com/seailz/discordjar/oauth2/LinkedRoles.java b/src/main/java/com/seailz/discordjar/oauth2/LinkedRoles.java index 4dfb97d2..8bb273a5 100644 --- a/src/main/java/com/seailz/discordjar/oauth2/LinkedRoles.java +++ b/src/main/java/com/seailz/discordjar/oauth2/LinkedRoles.java @@ -3,9 +3,9 @@ import com.seailz.databaseapi.Database; import com.seailz.discordjar.DiscordJar; 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.slf4j.bridge.SLF4JBridgeHandler; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -110,13 +110,13 @@ private void updateRoles(String userId, String platformName, String platformUser } if (authToken != null) headers.put("Authorization", "Bearer " + authToken); - JSONObject metadata = new JSONObject(); + SJSONObject metadata = new SJSONObject(); for (String key : values.keySet()) { metadata.put(key, values.get(key)); } DiscordRequest req = new DiscordRequest( - new JSONObject() + new SJSONObject() .put("platform_name", platformName) .put("platform_username", platformUsername) .put("metadata", metadata), @@ -127,7 +127,7 @@ private void updateRoles(String userId, String platformName, String platformUser URLS.OAUTH2.PUT.USERS.APPLICATIONS.ROLE_CONNECTIONS.UPDATE_USER_APPLICATION_ROLE_CONNECTION, RequestMethod.PUT ); - DiscordResponse res = req.invokeNoAuth(new JSONObject()); + DiscordResponse res = req.invokeNoAuth(new SJSONObject()); if (res.code() == 401) { if (attemptedRefreshToken) { throw new IllegalStateException("Could not updated roles for user - it's likely the user has de-authed the app."); @@ -156,7 +156,7 @@ private void updateRoles(String userId, String platformName, String platformUser if (refreshRes.statusCode() == 401) { throw new IllegalStateException("Could not updated roles for user - it's likely the user has de-authed the app."); } - JSONObject refreshResponseJson = new JSONObject(refreshRes); + SJSONObject refreshResponseJson = new SJSONObject(refreshRes.body()); updateRoles(null, platformName, platformUsername, values, refreshResponseJson.getString("access_token"), true); } } diff --git a/src/main/java/com/seailz/discordjar/oauth2/LinkedRolesRestController.java b/src/main/java/com/seailz/discordjar/oauth2/LinkedRolesRestController.java index c5806497..7d0ffeb8 100644 --- a/src/main/java/com/seailz/discordjar/oauth2/LinkedRolesRestController.java +++ b/src/main/java/com/seailz/discordjar/oauth2/LinkedRolesRestController.java @@ -10,11 +10,11 @@ import com.seailz.discordjar.oauth2.response.error.InvalidEndpointResponse; import com.seailz.discordjar.model.user.User; import com.seailz.discordjar.utils.URLS; +import com.seailz.discordjar.utils.json.SJSONObject; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.util.TriConsumer; import org.jetbrains.annotations.NotNull; -import org.json.JSONObject; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -90,14 +90,14 @@ protected Response request(@RequestParam Map reqParam, @NotNull // store refresh with user id in database String userId = getUser( - new JSONObject(res.body()).getString("access_token") + new SJSONObject(res.body()).getString("access_token") ).id(); - String refreshToken = new JSONObject(res.body()).getString("refresh_token"); + String refreshToken = new SJSONObject(res.body()).getString("refresh_token"); HashMap data = new HashMap<>(); data.put("refresh_token", refreshToken); data.put("user_id", userId); - data.put("acc_token", new JSONObject(res.body()).getString("access_token")); + data.put("acc_token", new SJSONObject(res.body()).getString("access_token")); if (database.getConnection() == null) database.connect(); @@ -114,7 +114,7 @@ protected Response request(@RequestParam Map reqParam, @NotNull } - String accessToken = new JSONObject(res.body()).getString("access_token"); + String accessToken = new SJSONObject(res.body()).getString("access_token"); if (onCodeReceived != null) onCodeReceived.accept(response, userId, accessToken); @@ -158,7 +158,7 @@ private User getUser(String accessToken) throws URISyntaxException, IOException, HttpResponse res = client.send(req, HttpResponse.BodyHandlers.ofString()); return User.decompile( - new JSONObject(res.body()), discordJar + new SJSONObject(res.body()), discordJar ); } } diff --git a/src/main/java/com/seailz/discordjar/utils/json/SJSONArray.java b/src/main/java/com/seailz/discordjar/utils/json/SJSONArray.java new file mode 100644 index 00000000..05071643 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/utils/json/SJSONArray.java @@ -0,0 +1,99 @@ +package com.seailz.discordjar.utils.json; + +import org.json.JSONArray; +import org.json.JSONException; + +import java.util.Collection; + +/** + * Similar story to {@link SJSONObject}, but for {@link JSONArray}. + * + * @since 1.0 + * @see SJSONObject + * @author Seailz + */ +public class SJSONArray extends JSONArray { + + public SJSONArray() { + super(); + } + + public SJSONArray(String json) { + super(json); + } + + public SJSONArray(Collection collection) { + super(collection); + } + + public SJSONArray(Iterable iter) { + super(iter); + } + + public SJSONArray(Object array) { + super(array); + } + + @Override + public boolean getBoolean(int index) { + Object o = get(index); + if (!(o instanceof Boolean)) return false; + return (boolean) o; + } + + @Override + public String getString(int index) { + Object o = get(index); + if (!(o instanceof String)) return null; + return (String) o; + } + + @Override + public int getInt(int index) { + Object o = get(index); + if (!(o instanceof Integer)) return 0; + return (int) o; + } + + @Override + public long getLong(int index) { + Object o = get(index); + if (!(o instanceof Long)) return 0; + return (long) o; + } + + @Override + public double getDouble(int index) { + Object o = get(index); + if (!(o instanceof Double)) return 0; + return (double) o; + } + + @Override + public float getFloat(int index) { + Object o = get(index); + if (!(o instanceof Float)) return 0; + return (float) o; + } + + @Override + public SJSONArray getJSONArray(int index) { + if (index >= length()) return null; + if (super.isNull(index)) return null; + return new SJSONArray(super.getJSONArray(index).toString()); + } + + @Override + public SJSONObject getJSONObject(int index) { + if (index >= length()) return null; + if (super.isNull(index)) return null; + return new SJSONObject(super.getJSONObject(index).toString()); + } + + @Override + public Object get(int index) { + if (index >= length()) return null; + if (super.isNull(index)) return null; + return super.get(index); + } +} diff --git a/src/main/java/com/seailz/discordjar/utils/json/SJSONObject.java b/src/main/java/com/seailz/discordjar/utils/json/SJSONObject.java new file mode 100644 index 00000000..7dd5f367 --- /dev/null +++ b/src/main/java/com/seailz/discordjar/utils/json/SJSONObject.java @@ -0,0 +1,175 @@ +package com.seailz.discordjar.utils.json; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Collection; +import java.util.Map; +import java.util.function.Function; + +/** + * Simplified implementation of {@link JSONObject} that is more suited for discord.jar's needs. + * The main point is that this class does not throw any exceptions, and instead returns null if the key is not found. + * + * @since 1.0 + * @author Seailz + */ +public class SJSONObject extends JSONObject { + + public SJSONObject() { + super(); + } + + public SJSONObject(String json) { + super(json); + } + + public SJSONObject(Map m) { + super(m); + } + + public SJSONObject(Object obj) { + super(obj); + } + + + @Override + public String getString(String key) { + Object o = get(key); + if (!(o instanceof String)) return null; + return (String) o; + } + + @Override + public int getInt(String key) { + Object o = get(key); + if (!(o instanceof Integer)) return 0; + return (int) o; + } + + @Override + public long getLong(String key) { + Object o = get(key); + if (!(o instanceof Long)) return 0; + return (long) o; + } + + @Override + public double getDouble(String key) { + Object o = get(key); + if (!(o instanceof Double)) return 0; + return (double) o; + } + + @Override + public boolean getBoolean(String key) { + Object o = get(key); + if (!(o instanceof Boolean)) return false; + return (boolean) o; + } + + @Override + public float getFloat(String key) { + Object o = get(key); + if (!(o instanceof Float)) return 0; + return (float) o; + } + + @Override + public SJSONArray getJSONArray(String key) { + if (!super.has(key)) return null; + if (super.isNull(key)) return null; + if (!(super.get(key) instanceof SJSONArray)) return null; + return new SJSONArray(super.getJSONArray(key).toString()); + } + + @Override + public SJSONObject getJSONObject(String key) { + if (!super.has(key)) return null; + if (super.isNull(key)) return null; + if (!(super.get(key) instanceof JSONObject)) return null; + return new SJSONObject(super.getJSONObject(key).toString()); + } + + @Override + public Object get(String key) { + if (!super.has(key)) return null; + if (super.isNull(key)) return null; + return super.get(key); + } + + + @Override + public SJSONObject put(String key, boolean value) { + super.put(key, value); + return this; + } + + @Override + public SJSONObject put(String key, double value) { + super.put(key, value); + return this; + } + + @Override + public SJSONObject put(String key, int value) { + super.put(key, value); + return this; + } + + @Override + public SJSONObject put(String key, long value) { + super.put(key, value); + return this; + } + + @Override + public SJSONObject put(String key, Object value) { + super.put(key, value); + return this; + } + + @Override + public SJSONObject put(String key, float value) { + super.put(key, value); + return this; + } + + @Override + public JSONObject putOpt(String key, Object value) throws JSONException { + super.putOpt(key, value); + return this; + } + + @Override + public JSONObject put(String key, Map value) throws JSONException { + super.put(key, value); + return this; + } + + /** + * Simple util that allows insertion of a list into a {@link JSONObject} with a function to convert the objects in the list. + *
You could do something like return a {@link SJSONObject} from the function to make the array a list of objects. + *
It really just simplifies the process of converting a list of objects into a {@link JSONArray}. + * + * @param key The key to insert the array into. + * @param value The list to convert. + * @param func The function to convert the objects in the list. + * @return The {@link SJSONObject} with the array inserted. + */ + public SJSONObject put(String key, Collection value, Function func) { + SJSONArray array = new SJSONArray(); + for (Object o : value) { + array.put(func.apply(o)); + } + super.put(key, array); + return this; + } + + @Override + public SJSONObject put(String key, Collection value) { + super.put(key, value); + return this; + } +} diff --git a/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java b/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java index 5b173869..ebff11af 100644 --- a/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java +++ b/src/main/java/com/seailz/discordjar/utils/rest/DiscordRequest.java @@ -2,13 +2,12 @@ import com.seailz.discordjar.DiscordJar; 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.ratelimit.Bucket; import okhttp3.Response; import okhttp3.*; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONObject; -import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.RequestMethod; import java.io.File; @@ -20,7 +19,6 @@ import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -29,17 +27,17 @@ public class DiscordRequest { - private JSONObject body; + private SJSONObject body; private final HashMap headers; private final String url; private final DiscordJar djv; private final String baseUrl; private final RequestMethod requestMethod; - private JSONArray aBody; + private SJSONArray aBody; // HashMap of endpoint to whether or not it can be requested (rate limited) private static HashMap canRequest = new HashMap<>(); - public DiscordRequest(JSONObject body, HashMap headers, String url, DiscordJar djv, String baseUrl, RequestMethod requestMethod) { + public DiscordRequest(SJSONObject body, HashMap headers, String url, DiscordJar djv, String baseUrl, RequestMethod requestMethod) { this.body = body; this.headers = headers; this.url = url; @@ -47,7 +45,7 @@ public DiscordRequest(JSONObject body, HashMap headers, String u this.baseUrl = baseUrl; this.requestMethod = requestMethod; } - public DiscordRequest(JSONArray body, HashMap headers, String url, DiscordJar djv, String baseUrl, RequestMethod requestMethod) { + public DiscordRequest(SJSONArray body, HashMap headers, String url, DiscordJar djv, String baseUrl, RequestMethod requestMethod) { this.aBody = body; this.headers = headers; this.url = url; @@ -125,9 +123,9 @@ public DiscordResponse invokeNoDiscordJar(String token) { try { if (sb.startsWith("[")) { - new JSONArray(sb); + new SJSONArray(sb); } else { - new JSONObject(sb); + new SJSONObject(sb); } } catch (JSONException err) { System.out.println(sb); @@ -136,16 +134,16 @@ public DiscordResponse invokeNoDiscordJar(String token) { if (responseCode == 200 || responseCode == 201) { Object body; if (sb.startsWith("[")) { - body = new JSONArray(sb); + body = new SJSONArray(sb); } else { try { - body = new JSONObject(sb); + body = new SJSONObject(sb); } catch (JSONException err) { throw new DiscordUnexpectedError(new RuntimeException("Invalid JSON response from Discord API: " + sb)); } } - return new DiscordResponse(responseCode, (body instanceof JSONObject) ? (JSONObject) body : null, headers, (body instanceof JSONArray) ? (JSONArray) body : null); + return new DiscordResponse(responseCode, (body instanceof SJSONObject) ? (SJSONObject) body : null, headers, (body instanceof SJSONArray) ? (SJSONArray) body : null); } if (responseCode == 204) { return null; @@ -161,7 +159,7 @@ public DiscordResponse invokeNoDiscordJar(String token) { return new DiscordResponse(404, null, null, null); } - throw new UnhandledDiscordAPIErrorException(new JSONObject(sb), responseCode); + throw new UnhandledDiscordAPIErrorException(new SJSONObject(sb), responseCode); } catch (IOException | UnhandledDiscordAPIErrorException e) { // attempt gateway reconnect throw new DiscordUnexpectedError(e); @@ -256,9 +254,9 @@ private DiscordResponse invoke(String contentType, boolean auth) throws Unhandle try { String responseBody = sb; if (responseBody.startsWith("[")) { - new JSONArray(responseBody); + new SJSONArray(responseBody); } else { - new JSONObject(responseBody); + new SJSONObject(responseBody); } } catch (JSONException err) { System.out.println(sb); @@ -289,7 +287,7 @@ private DiscordResponse invoke(String contentType, boolean auth) throws Unhandle Logger.getLogger("RateLimit").warning("[RATE LIMIT] Rate limit has been exceeded. Please make sure you are not sending too many requests."); } - float retryAfter = new JSONObject(sb).getFloat("retry_after"); + float retryAfter = new SJSONObject(sb).getFloat("retry_after"); if (retryAfter == -1) { Logger.getLogger("RateLimit").warning("[RATE LIMIT] Invalid rate limit response (?) - please contact Discord support. " + sb); return new DiscordResponse(429, body, headers, null); @@ -302,16 +300,16 @@ private DiscordResponse invoke(String contentType, boolean auth) throws Unhandle Object body; String responseBody = sb; if (responseBody.startsWith("[")) { - body = new JSONArray(responseBody); + body = new SJSONArray(responseBody); } else { try { - body = new JSONObject(responseBody); + body = new SJSONObject(responseBody); } catch (JSONException err) { throw new DiscordUnexpectedError(new RuntimeException("Invalid JSON response from Discord API: " + responseBody)); } } - return new DiscordResponse(responseCode, (body instanceof JSONObject) ? (JSONObject) body : null, headers, (body instanceof JSONArray) ? (JSONArray) body : null); + return new DiscordResponse(responseCode, (body instanceof SJSONObject) ? (SJSONObject) body : null, headers, (body instanceof SJSONArray) ? (SJSONArray) body : null); } if (responseCode == 204) { return null; @@ -321,8 +319,8 @@ private DiscordResponse invoke(String contentType, boolean auth) throws Unhandle return new DiscordResponse(401, null, null, null); } - JSONObject error = new JSONObject(sb); - JSONArray errorArray; + SJSONObject error = new SJSONObject(sb); + SJSONArray errorArray; if (responseCode == 404) { Logger.getLogger("DISCORDJAR").warning("Received 404 error from the Discord API. It's likely that you're trying to access a resource that doesn't exist."); @@ -330,7 +328,7 @@ private DiscordResponse invoke(String contentType, boolean auth) throws Unhandle return new DiscordResponse(404, null, null, null); } - throw new UnhandledDiscordAPIErrorException(new JSONObject(sb), responseCode); + throw new UnhandledDiscordAPIErrorException(new SJSONObject(sb), responseCode); } catch (IOException e) { // attempt gateway reconnect throw new DiscordUnexpectedError(e); @@ -347,11 +345,11 @@ public DiscordUnexpectedError(Throwable throwable) { } } - public DiscordResponse invoke(JSONObject body) throws UnhandledDiscordAPIErrorException { + public DiscordResponse invoke(SJSONObject body) throws UnhandledDiscordAPIErrorException { return invoke(null, true); } - public DiscordResponse invokeNoAuth(JSONObject body) throws UnhandledDiscordAPIErrorException { + public DiscordResponse invokeNoAuth(SJSONObject body) throws UnhandledDiscordAPIErrorException { return invoke(null, false); } @@ -359,7 +357,7 @@ public DiscordResponse invokeNoAuthCustomContent(String contentType) throws Unha return invoke(contentType, false); } - public DiscordResponse invoke(JSONArray arr) throws UnhandledDiscordAPIErrorException { + public DiscordResponse invoke(SJSONArray arr) throws UnhandledDiscordAPIErrorException { return invoke(null, true); } @@ -443,17 +441,17 @@ public DiscordResponse invokeWithFiles(File... files) { var bodyResponse = new Object(); if (response.body().startsWith("[")) { - bodyResponse = new JSONArray(response.body()); + bodyResponse = new SJSONArray(response.body()); } else { - bodyResponse = new JSONObject(response.body()); + bodyResponse = new SJSONObject(response.body()); } - return new DiscordResponse(responseCode, (bodyResponse instanceof JSONObject) ? (JSONObject) bodyResponse : null, headers, (bodyResponse instanceof JSONArray) ? (JSONArray) bodyResponse : null); + return new DiscordResponse(responseCode, (bodyResponse instanceof SJSONObject) ? (SJSONObject) bodyResponse : null, headers, (bodyResponse instanceof SJSONArray) ? (SJSONArray) bodyResponse : null); } if (responseCode == 204) return null; - JSONObject error = new JSONObject(response.body()); + SJSONObject error = new SJSONObject(response.body()); throw new UnhandledDiscordAPIErrorException(error, responseCode); } catch (Exception e) { @@ -471,10 +469,10 @@ public DiscordAPIErrorException(UnhandledDiscordAPIErrorException e) { public static class UnhandledDiscordAPIErrorException extends Exception { private int code; - private JSONObject body; + private SJSONObject body; private String error; private int httpCode; - public UnhandledDiscordAPIErrorException(JSONObject body, int httpCode) { + public UnhandledDiscordAPIErrorException(SJSONObject body, int httpCode) { this.body = body.has("errors") ? body.getJSONObject("errors") : body; this.code = body.getInt("code"); this.error = body.getString("message"); @@ -489,7 +487,7 @@ public int getHttpCode() { return httpCode; } - public JSONObject getBody() { + public SJSONObject getBody() { return body; } @@ -498,11 +496,11 @@ public String getError() { } } - public JSONObject body() { + public SJSONObject body() { return body; } - public JSONArray array() { + public SJSONArray array() { return aBody; } diff --git a/src/main/java/com/seailz/discordjar/utils/rest/DiscordResponse.java b/src/main/java/com/seailz/discordjar/utils/rest/DiscordResponse.java index 47ec03b3..92656bb6 100644 --- a/src/main/java/com/seailz/discordjar/utils/rest/DiscordResponse.java +++ b/src/main/java/com/seailz/discordjar/utils/rest/DiscordResponse.java @@ -1,14 +1,14 @@ package com.seailz.discordjar.utils.rest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.HashMap; public record DiscordResponse( int code, - JSONObject body, + SJSONObject body, HashMap headers, - JSONArray arr + SJSONArray arr ) { } diff --git a/src/main/java/com/seailz/discordjar/utils/rest/Response.java b/src/main/java/com/seailz/discordjar/utils/rest/Response.java index 4378a61b..6b826368 100644 --- a/src/main/java/com/seailz/discordjar/utils/rest/Response.java +++ b/src/main/java/com/seailz/discordjar/utils/rest/Response.java @@ -1,7 +1,7 @@ package com.seailz.discordjar.utils.rest; -import org.json.JSONArray; -import org.json.JSONObject; +import com.seailz.discordjar.utils.json.SJSONArray; +import com.seailz.discordjar.utils.json.SJSONObject; import java.util.ArrayList; import java.util.List; @@ -91,9 +91,9 @@ public Error getError() { public static class Error { private int code; private String message; - private JSONObject errors; + private SJSONObject errors; - public Error(int code, String message, JSONObject errors) { + public Error(int code, String message, SJSONObject errors) { this.code = code; this.message = message; this.errors = errors; @@ -111,7 +111,7 @@ public String getMessage() { return message; } - public JSONObject getErrors() { + public SJSONObject getErrors() { return errors; } @@ -139,13 +139,13 @@ public List getAllErrorMessages() { return errorResponses; } - private void findErrorResponsesRecursive(JSONObject jsonObject, List errorResponses) { + private void findErrorResponsesRecursive(SJSONObject jsonObject, List errorResponses) { for (String key : jsonObject.keySet()) { Object value = jsonObject.get(key); - if (value instanceof JSONObject) { - findErrorResponsesRecursive((JSONObject) value, errorResponses); - } else if (value instanceof JSONArray) { - findErrorResponsesInArray((JSONArray) value, errorResponses); + if (value instanceof SJSONObject) { + findErrorResponsesRecursive((SJSONObject) value, errorResponses); + } else if (value instanceof SJSONArray) { + findErrorResponsesInArray((SJSONArray) value, errorResponses); } else if (key.equals("message")) { int code = getCodeFromJSONObject(jsonObject); errorResponses.add(new ErroredResponse(value.toString(), code)); @@ -153,18 +153,18 @@ private void findErrorResponsesRecursive(JSONObject jsonObject, List errorResponses) { + private void findErrorResponsesInArray(SJSONArray jsonArray, List errorResponses) { for (int i = 0; i < jsonArray.length(); i++) { Object value = jsonArray.get(i); - if (value instanceof JSONObject) { - findErrorResponsesRecursive((JSONObject) value, errorResponses); - } else if (value instanceof JSONArray) { - findErrorResponsesInArray((JSONArray) value, errorResponses); + if (value instanceof SJSONObject) { + findErrorResponsesRecursive((SJSONObject) value, errorResponses); + } else if (value instanceof SJSONArray) { + findErrorResponsesInArray((SJSONArray) value, errorResponses); } } } - private int getCodeFromJSONObject(JSONObject jsonObject) { + private int getCodeFromJSONObject(SJSONObject jsonObject) { int code = -1; if (jsonObject.has("code") && jsonObject.get("code") instanceof Integer) { code = jsonObject.getInt("code");