Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main #251

Merged
merged 4 commits into from
Oct 30, 2023
Merged

main #251

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/seailz/discordjar/DiscordJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
this.intents = intents;
this.apiVersion = version;
this.cacheTypes = cacheTypes;
new URLS(release, version);

Check warning on line 224 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Instantiation of utility class

Instantiation of utility class `URLS`
logger = Logger.getLogger("DISCORD.JAR");
this.commandDispatcher = new CommandDispatcher();
this.queuedRequests = new ArrayList<>();
Expand Down Expand Up @@ -270,7 +270,7 @@
// Print cpu usage every 5 seconds
while (true) {
try {
Thread.sleep(5000);

Check warning on line 273 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Busy wait

Call to `Thread.sleep()` in a loop, probably busy-waiting
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -340,7 +340,7 @@
new Thread(() -> {
while (true) {
try {
Thread.sleep(1000);

Check warning on line 343 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Busy wait

Call to `Thread.sleep()` in a loop, probably busy-waiting
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -378,7 +378,7 @@
// If the user is a bot, we just want to update it for the guild since bots can be in multiple guilds and have different voice states for each.
// If it's not a bot, then we globally want to remove all other voice states for the user and replace it with the new one.
User user = getUserById(state.userId());
if (user.bot()) {

Check warning on line 381 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `bot` may produce `NullPointerException`
voiceStates.put(state.guildId(), state);
} else {
voiceStates.values().removeIf(s -> s.userId().equals(user.id()));
Expand Down Expand Up @@ -477,14 +477,14 @@
@Nullable
public User getSelfUser() {
if (this.getSelfUserCache != null && getSelfUserCache.get() != null)
return User.decompile(getSelfUserCache.get(), this);

Check warning on line 480 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Argument `getSelfUserCache.get()` might be null

DiscordRequest req = new DiscordRequest(
new JSONObject(), new HashMap<>(),
URLS.GET.USER.GET_USER.replace("{user.id}", "@me"),
this, URLS.GET.USER.GET_USER, RequestMethod.GET
);
DiscordResponse response = null;

Check warning on line 487 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `response` initializer `null` is redundant
try {
response = req.invoke();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -494,7 +494,7 @@

if (getSelfUserCache == null) {
getSelfUserCache = JsonCache.newc(response.body(), req);
getSelfUserCache.reset(60000);
getSelfUserCache.reset(60000, "self-user-cache");
}
this.getSelfUserCache.update(response.body());
return User.decompile(response.body(), this);
Expand Down Expand Up @@ -543,7 +543,7 @@
@Nullable
public MessagingChannel getTextChannelById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 546 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -564,7 +564,7 @@
@Nullable
public AudioChannel getAudioChannelById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 567 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -585,7 +585,7 @@
@Nullable
public com.seailz.discordjar.model.channel.thread.Thread getThreadById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 588 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -606,7 +606,7 @@
@Nullable
public DMChannel getDmChannelById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 609 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -627,7 +627,7 @@
@Nullable
public ForumChannel getForumChannelById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 630 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -648,7 +648,7 @@
@Nullable
public MediaChannel getMediaChannelById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 651 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -667,7 +667,7 @@
@Nullable
public Category getCategoryById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 670 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -688,7 +688,7 @@
@Nullable
public VoiceChannel getVoiceChannelById(String id) {
Checker.isSnowflake(id, "Given id is not a snowflake");
JSONObject raw = null;

Check warning on line 691 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `raw` initializer `null` is redundant
try {
raw = getChannelCache().getById(id).raw();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand Down Expand Up @@ -813,7 +813,7 @@
URLS.GET.APPLICATION.APPLICATION_INFORMATION,
this, URLS.GET.APPLICATION.APPLICATION_INFORMATION, RequestMethod.GET
);
DiscordResponse response = null;

Check warning on line 816 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `response` initializer `null` is redundant
try {
response = request.invoke();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand Down Expand Up @@ -971,7 +971,7 @@
* @return A member if one can be found, or null if one can't be found
*/
private Member getMemberManuallyOrNull(@NotNull String guildId, @NotNull String userId) {
DiscordResponse req = null;

Check warning on line 974 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `req` initializer `null` is redundant
try {
req = new DiscordRequest(
new JSONObject(),
Expand Down Expand Up @@ -1138,7 +1138,7 @@
DiscordRequest commandReq = new DiscordRequest(
command.compile(),
new HashMap<>(),
URLS.POST.COMMANDS.GLOBAL_COMMANDS.replace("{application.id}", getSelfInfo().id() == null ? "0" : getSelfInfo().id()),

Check warning on line 1141 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.BASE_URL,
RequestMethod.POST);
Expand All @@ -1157,7 +1157,7 @@
DiscordRequest cmdDelReq = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.POST.COMMANDS.GLOBAL_COMMANDS.replace("{application.id}", getSelfInfo().id()),

Check warning on line 1160 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.BASE_URL,
RequestMethod.PUT
Expand All @@ -1179,12 +1179,12 @@
DiscordRequest req = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMANDS.replace("{application.id}", getSelfInfo().id()) + (withLocalizations ? "?with_localizations=true" : ""),

Check warning on line 1182 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMANDS,
RequestMethod.GET
);
JSONArray res = null;

Check warning on line 1187 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke().arr();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -1210,12 +1210,12 @@
DiscordRequest req = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{command.id}", commandId),

Check warning on line 1213 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.GET.APPLICATION.COMMANDS.GET_GLOBAL_APPLICATION_COMMAND,
RequestMethod.GET
);
JSONObject res = null;

Check warning on line 1218 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke().body();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -1235,12 +1235,12 @@
DiscordRequest req = new DiscordRequest(
newCommand.compile(),
new HashMap<>(),
URLS.PATCH.APPLICATIONS.COMMANDS.EDIT_GLOBAL_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{command.id}", commandId),

Check warning on line 1238 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.PATCH.APPLICATIONS.COMMANDS.EDIT_GLOBAL_COMMAND,
RequestMethod.PATCH
);
JSONObject res = null;

Check warning on line 1243 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke().body();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -1257,7 +1257,7 @@
DiscordRequest req = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.DELETE.APPLICATION.COMMANDS.DELETE_GLOBAL_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{command.id}", commandId),

Check warning on line 1260 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.DELETE.APPLICATION.COMMANDS.DELETE_GLOBAL_COMMAND,
RequestMethod.DELETE
Expand All @@ -1280,7 +1280,7 @@
DiscordRequest req = new DiscordRequest(
arr,
new HashMap<>(),
URLS.POST.COMMANDS.GLOBAL_COMMANDS.replace("{application.id}", getSelfInfo().id()),

Check warning on line 1283 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.BASE_URL,
RequestMethod.PUT
Expand All @@ -1303,12 +1303,12 @@
DiscordRequest req = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMANDS.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId) + (withLocalizations ? "?with_localizations=true" : ""),

Check warning on line 1306 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMANDS,
RequestMethod.GET
);
JSONArray res = null;

Check warning on line 1311 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke().arr();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -1335,12 +1335,12 @@
DiscordRequest req = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId).replace("{command.id}", commandId),

Check warning on line 1338 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.GET.APPLICATION.COMMANDS.GET_GUILD_APPLICATION_COMMAND,
RequestMethod.GET
);
JSONObject res = null;

Check warning on line 1343 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke().body();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -1361,12 +1361,12 @@
DiscordRequest req = new DiscordRequest(
newCommand.compile(),
new HashMap<>(),
URLS.PATCH.APPLICATIONS.COMMANDS.EDIT_GUILD_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId).replace("{command.id}", commandId),

Check warning on line 1364 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.PATCH.APPLICATIONS.COMMANDS.EDIT_GUILD_COMMAND,
RequestMethod.PATCH
);
JSONObject res = null;

Check warning on line 1369 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke().body();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -1384,7 +1384,7 @@
DiscordRequest req = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.DELETE.APPLICATION.COMMANDS.DELETE_GUILD_COMMAND.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId).replace("{command.id}", commandId),

Check warning on line 1387 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.DELETE.APPLICATION.COMMANDS.DELETE_GUILD_COMMAND,
RequestMethod.DELETE
Expand All @@ -1407,7 +1407,7 @@
DiscordRequest req = new DiscordRequest(
arr,
new HashMap<>(),
URLS.POST.COMMANDS.GUILD_COMMANDS.replace("{application.id}", getSelfInfo().id()).replace("{guild.id}", guildId),

Check warning on line 1410 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.BASE_URL,
RequestMethod.PUT
Expand Down Expand Up @@ -1453,7 +1453,7 @@
URLS.GET.VOICE.REGIONS.GET_VOICE_REGIONS,
RequestMethod.GET
);
JSONArray response = null;

Check warning on line 1456 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `response` initializer `null` is redundant
try {
response = request.invoke().arr();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand All @@ -1479,7 +1479,7 @@
URLS.BASE_URL,
RequestMethod.GET
);
DiscordResponse res = null;

Check warning on line 1482 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand Down Expand Up @@ -1512,12 +1512,12 @@
DiscordRequest req = new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.APPLICATION.GET_APPLICATION_SKUS.replace("{application.id}", getSelfInfo().id()),

Check warning on line 1515 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
this,
URLS.GET.APPLICATION.GET_APPLICATION_SKUS,
RequestMethod.GET
);
JSONArray res = null;

Check warning on line 1520 in src/main/java/com/seailz/discordjar/DiscordJar.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `res` initializer `null` is redundant
try {
res = req.invoke().arr();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
url += "with_counts=true&";
}

DiscordResponse response = null;

Check warning on line 100 in src/main/java/com/seailz/discordjar/action/guild/GetCurrentUserGuildsAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `response` initializer `null` is redundant
try {
response = new DiscordRequest(
new JSONObject(),
Expand All @@ -112,7 +112,7 @@
}

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

returnGuilds.forEach(g -> discordJar.getGuildCache().cache(g));
return returnGuilds;
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/seailz/discordjar/cache/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* @param t The object to add
*/
public void cache(@NotNull T t) {
if (t == null) return;

Check warning on line 57 in src/main/java/com/seailz/discordjar/cache/Cache.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant values

Condition `t == null` is always `false`
try {
if (!discordJar.getCacheTypes().contains(type) && !discordJar.getCacheTypes().contains(CacheType.ALL)) return;
String id;
Expand All @@ -79,10 +79,10 @@
cache.remove(cacheMember);
}
}
} catch (Exception e) {}

Check warning on line 82 in src/main/java/com/seailz/discordjar/cache/Cache.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Catch block may ignore exception

Empty `catch` block
synchronized (cache) {
try {
if (cache.size() == -1) {

Check warning on line 85 in src/main/java/com/seailz/discordjar/cache/Cache.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Constant values

Condition `cache.size() == -1` is always `false`
Logger.getLogger("DiscordJar").warning("[discord.jar] Failed to add obj to cache - cache size is -1");
return;
}; // Also this seems impossible, recent exceptions prove otherwise, so I'm leaving it in. Please ignore your IDE.
Expand Down Expand Up @@ -119,7 +119,20 @@
}

/**
* Gets an item from the cache
* This method is used to get an item from the cache by its ID.
* <br>Unlike {@link #getById(String)}, <b>this method will not make a request to Discord if the item is not in the cache,</b> and will instead return null.
* @param id The ID of the item to get
* @return The item, or null if it is not in the cache
*/
public T returnFromCache(String id) {
if (!discordJar.getCacheTypes().contains(type) && !discordJar.getCacheTypes().contains(CacheType.ALL)) return null;
return getFromCacheByIdOrNull(id);
}

/**
* Gets an item from the cache.
* <br>If the provided ID matches no items in the cache, a request will be made to Discord to get the item.
* <br>If the item is not in the cache, and the request to Discord fails, null will be returned.
*
* @param id The id of the item to get
* @return The item
Expand Down Expand Up @@ -151,7 +164,7 @@
}
}
});
} catch (Exception e ) {}

Check warning on line 167 in src/main/java/com/seailz/discordjar/cache/Cache.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Catch block may ignore exception

Empty `catch` block
}


Expand Down Expand Up @@ -230,7 +243,7 @@
}

public JSONObject getFresh(String id) {
DiscordResponse response = null;

Check warning on line 246 in src/main/java/com/seailz/discordjar/cache/Cache.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `response` initializer `null` is redundant
try {
response = new DiscordRequest(
discordRequest.body(), discordRequest.headers(), discordRequest.url().replaceAll("%s", id), discordJar, discordRequest.url(), RequestMethod.GET
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/seailz/discordjar/cache/JsonCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONObject;

import java.util.Random;
import java.util.logging.Logger;

/**
* A cache that can be used to store JSON objects.
Expand Down Expand Up @@ -62,11 +63,12 @@
*
* @param interval The interval on which to invalidate the cache.
*/
default void reset(int interval) {
default void reset(int interval, String origin) {
Logger.getLogger(origin).info("Starting cache invalidation timer for " + origin + " with interval " + interval + "ms");
new Thread(() -> {
while (true) {
try {
Thread.sleep(interval);

Check warning on line 71 in src/main/java/com/seailz/discordjar/cache/JsonCache.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Busy wait

Call to `Thread.sleep()` in a loop, probably busy-waiting
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -75,6 +77,18 @@
}, "djar--CacheInvalidate" + new Random().nextInt(999)).start();
}

default void resetSingle(int interval, String origin) {
Logger.getLogger(origin).info("Starting cache invalidation timer for " + origin + " with interval " + interval + "ms");
new Thread(() -> {
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
e.printStackTrace();
}
invalidate();
}, "djar--CacheInvalidate" + new Random().nextInt(999)).start();
}

/**
* Updates the cached object.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public GuildCreateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObj

@NotNull
public Guild getGuild() {
return Guild.decompile(getJson().getJSONObject("d"), getBot());
return Guild.decompile(getJson().getJSONObject("d"), getBot(), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public GuildUpdateEvent(@NotNull DiscordJar bot, long sequence, @NotNull JSONObj

@NotNull
public Guild getGuild() {
return Guild.decompile(getJson().getJSONObject("d"), getBot());
return Guild.decompile(getJson().getJSONObject("d"), getBot(), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public MessageInteractionCallbackAction replyWithEmbeds(Embeder... embeds) {
return new MessageInteractionCallbackAction(InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE, new InteractionMessageResponse(embeds), getInteraction().token(), getInteraction().id(), getBot());
}

/**
* Replies to this interaction with a button that will re-direct users to the premium payment window.
* <br>This is type {@link InteractionCallbackType#PREMIUM_REQUIRED} (10), part of app monetization/subscriptions, and will only work if the bot is monetized.
*/
public void replyRequirePremium(boolean ephemeral) {
getHandler().requirePremium(ephemeral);
}

@NotNull
public InteractionHandler getHandler() {
return InteractionHandler.from(getInteraction().token(), getInteraction().id(), getBot());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
if (p.getJSONObject("d").has("unavailable") && p.getJSONObject("d").getBoolean("unavailable"))
// Guild is unavailable, don't cache it
return GuildCreateEvent.class;
Guild guild = Guild.decompile(p.getJSONObject("d"), g);
Guild guild = Guild.decompile(p.getJSONObject("d"), g, true);
g.getGuildCache().cache(guild);

JSONArray arr = p.getJSONObject("d").getJSONArray("channels");
Expand Down Expand Up @@ -153,14 +153,14 @@
}),
GUILD_UPDATE((p, g, d) -> {
// modify cached guild, if it exists
Guild guild = Guild.decompile(p.getJSONObject("d"), d);
Guild guild = Guild.decompile(p.getJSONObject("d"), d, true);
d.getGuildCache().cache(guild);

return GuildUpdateEvent.class;
}),
GUILD_DELETE((p, g, d) -> {
// remove cached guild, if it exists
Guild guild = Guild.decompile(p.getJSONObject("d"), d);
Guild guild = Guild.decompile(p.getJSONObject("d"), d, true);
d.getGuildCache().remove(guild);

return GuildDeleteEvent.class;
Expand Down Expand Up @@ -252,7 +252,7 @@
case APPLICATION_COMMAND -> {
CommandInteractionEvent event = null;

switch (CommandType.fromCode(p.getJSONObject("d").getJSONObject("data").getInt("type"))) {

Check warning on line 255 in src/main/java/com/seailz/discordjar/gateway/events/DispatchedEvents.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Dereference of `CommandType.fromCode(p.getJSONObject("d").getJSONObject("data").getInt("type"))` may produce `NullPointerException`
case SLASH_COMMAND ->
event = new SlashCommandInteractionEvent(d, Gateway.lastSequenceNumber, p);
case USER -> event = new UserContextCommandInteractionEvent(d, Gateway.lastSequenceNumber, p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@

try {
flagsRaw = obj.getInt("flags");
flags = flags = new BitwiseUtil<Flag>().get(flagsRaw, Flag.class);

Check warning on line 244 in src/main/java/com/seailz/discordjar/model/application/Application.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Variable is already assigned to this value
} catch (JSONException e) {
flagsRaw = 0;
}
Expand Down Expand Up @@ -277,7 +277,7 @@
}

try {
guild = Guild.decompile(obj.getJSONObject("guild"), discordJar);
guild = Guild.decompile(obj.getJSONObject("guild"), discordJar, false);
} catch (JSONException e) {
guild = null;
}
Expand Down Expand Up @@ -318,7 +318,7 @@
*/
@Nullable
public List<ApplicationRoleConnectionMetadata> getRoleConnections() {
DiscordResponse response = null;

Check warning on line 321 in src/main/java/com/seailz/discordjar/model/application/Application.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `response` initializer `null` is redundant
try {
response = new DiscordRequest(
new JSONObject(),
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/seailz/discordjar/model/guild/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,16 @@
}

@NotNull
public static Guild decompile(JSONObject obj, DiscordJar discordJar) {
public static Guild decompile(JSONObject obj, DiscordJar discordJar, boolean bypassCache) {
System.out.println("decomp guild");

// If the cache happens to contain the current guild, we'll use that instead of creating a new one.
// Helpful for slight memory optimization & performance.
Guild cachedGuild = discordJar.getGuildCache().returnFromCache(obj.getString("id"));
if (cachedGuild != null && !bypassCache) {
return cachedGuild;
}

long nano = System.nanoTime();
String id;
String name;
Expand Down Expand Up @@ -544,7 +553,7 @@
}

try {
features = GuildFeature.getGuildFeatures(obj.getJSONArray("features").toList().toArray(new String[0]));

Check warning on line 556 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Suspicious 'Collection.toArray()' call

Array of type 'java.lang.Object\[\]' expected, 'java.lang.String\[\]' found
} catch (JSONException e) {
features = null;
}
Expand Down Expand Up @@ -628,9 +637,9 @@
}

try {
approximateMemberCount = obj.getInt("approximate_member_count");

Check warning on line 640 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

The value `obj.getInt("approximate_member_count")` assigned to `approximateMemberCount` is never used
} catch (JSONException e) {
approximateMemberCount = 0;

Check warning on line 642 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

The value `0` assigned to `approximateMemberCount` is never used
}

try {
Expand Down Expand Up @@ -717,13 +726,12 @@
JsonCache.newc(new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.GUILDS.ROLES.GET_GUILD_ROLES.replace("{guild.id}", id),

Check warning on line 729 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Argument `id` might be null
discordJar,
URLS.GET.GUILDS.ROLES.GET_GUILD_ROLES,
RequestMethod.GET
))
);
g.roleCache.reset(60000);
return g;
}

Expand Down Expand Up @@ -953,7 +961,7 @@
public List<Member> 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;

Check warning on line 964 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `arr` initializer `null` is redundant
try {
arr = new DiscordRequest(
new JSONObject(),
Expand All @@ -979,7 +987,7 @@
}

public List<Member> getMembers() {
JSONArray arr = null;

Check warning on line 990 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `arr` initializer `null` is redundant
try {
arr = new DiscordRequest(
new JSONObject(),
Expand Down Expand Up @@ -1066,7 +1074,7 @@
@NotNull
public List<GuildChannel> getChannels() {
List<GuildChannel> channels = new ArrayList<>();
DiscordResponse req = null;

Check warning on line 1077 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `req` initializer `null` is redundant
try {
req = new DiscordRequest(
new JSONObject(),
Expand Down Expand Up @@ -1099,7 +1107,7 @@
public List<Role> roles() {
if (roleCache != null && !roleCache.isEmpty()) {
List<Role> roles = new ArrayList<>();
roleCache.get().getJSONArray("data").forEach(

Check warning on line 1110 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `getJSONArray` may produce `NullPointerException`
o -> roles.add(Role.decompile((JSONObject) o))
);
return roles;
Expand All @@ -1115,7 +1123,7 @@
RequestMethod.GET
);
JSONArray res;
DiscordResponse response = null;

Check warning on line 1126 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `response` initializer `null` is redundant
try {
response = req.invoke();
res = response.arr();
Expand All @@ -1126,10 +1134,11 @@
System.out.println(response.code() + " " + (response.body() == null ? "null" : response.body().toString()));
}

res.forEach(o -> roles.add(Role.decompile((JSONObject) o)));

Check warning on line 1137 in src/main/java/com/seailz/discordjar/model/guild/Guild.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `forEach` may produce `NullPointerException`

if (roleCache != null) {
roleCache.update(new JSONObject().put("data", res));
roleCache.resetSingle(60000, "roles");
}
return roles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import com.seailz.discordjar.model.guild.Guild;
import com.seailz.discordjar.model.guild.Member;
import com.seailz.discordjar.model.message.Message;
import com.seailz.discordjar.model.monetization.Entitlement;
import com.seailz.discordjar.model.user.User;
import com.seailz.discordjar.utils.flag.BitwiseUtil;
import com.seailz.discordjar.utils.permission.Permission;
import com.seailz.discordjar.utils.rest.DiscordRequest;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONObject;

import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -59,12 +61,14 @@
private final String locale;
// Guild's preferred locale, if invoked in a guild
private final String guildLocale;
// For monetized apps, array of Entitlements for the invoking user
private List<Entitlement> entitlements;
private final String raw;
private final DiscordJar djar;
@Deprecated
private final String channelId;

public Interaction(String id, Application application, InteractionType type, InteractionData data, String guild, Channel channel, JSONObject member, User user, String token, int version, Message message, String appPermissions, String locale, String guildLocale, String raw, String channelId, DiscordJar discordJar) {
public Interaction(String id, Application application, InteractionType type, InteractionData data, String guild, Channel channel, JSONObject member, User user, String token, int version, Message message, String appPermissions, String locale, String guildLocale, List<Entitlement> entitlements, String raw, String channelId, DiscordJar discordJar) {
this.id = id;
this.application = application;
this.type = type;
Expand All @@ -87,6 +91,7 @@
this.raw = raw;
this.channelId = channelId;
this.djar = discordJar;
this.entitlements = entitlements;
}

@Deprecated
Expand Down Expand Up @@ -161,12 +166,16 @@
return raw;
}

public List<Entitlement> entitlements() {
return entitlements;
}

@Override
public JSONObject compile() {
JSONObject data = null;
if (this.data != null) {
Class<? extends InteractionData> dataClass = this.data.getClass();
Method compileMethod = null;

Check warning on line 178 in src/main/java/com/seailz/discordjar/model/interaction/Interaction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `compileMethod` initializer `null` is redundant
try {
compileMethod = dataClass.getMethod("compile");
} catch (NoSuchMethodException e) {
Expand All @@ -180,6 +189,13 @@
}
}

JSONArray entitlements = new JSONArray();
if (this.entitlements != null) {
for (Entitlement entitlement : this.entitlements) {
entitlements.put(entitlement.compile());
}
}

return new JSONObject()
.put("id", id)
.put("application", application.id())
Expand All @@ -194,7 +210,8 @@
.put("app_permissions", appPermissions)
.put("locale", locale)
.put("guild_locale", guildLocale)
.put("channel_id", channelId);
.put("channel_id", channelId)
.put("entitlements", entitlements);
}

@NotNull
Expand All @@ -202,7 +219,7 @@
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;
InteractionData data = json.has("data") ? InteractionData.decompile(type, json.getJSONObject("data"), discordJar) : null;

Check warning on line 222 in src/main/java/com/seailz/discordjar/model/interaction/Interaction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Argument `type` might be null
String guildId = json.has("guild_id") ? json.getString("guild_id") : null;
Channel channel = json.has("channel") ? Channel.decompile(json.getJSONObject("channel"), discordJar) : null;
Member member = json.has("member") ? Member.decompile(json.getJSONObject("member"), discordJar, guildId, null) : null;
Expand All @@ -215,7 +232,15 @@
String guildLocale = json.has("guild_locale") ? json.getString("guild_locale") : null;
String channelId = json.has("channel_id") ? json.getString("channel_id") : null;

return new Interaction(id, application, type, data, guildId, channel, json.has("member") ? json.getJSONObject("member") : null, user, token, version, message, appPermissions, locale, guildLocale, json.toString(), channelId, discordJar);
JSONArray entitlements = json.has("entitlements") ? json.getJSONArray("entitlements") : null;
List<Entitlement> entitlementList = new ArrayList<>();
if (entitlements != null) {
for (int i = 0; i < entitlements.length(); i++) {
entitlementList.add(Entitlement.decompile(discordJar, entitlements.getJSONObject(i)));
}
}

return new Interaction(id, application, type, data, guildId, channel, json.has("member") ? json.getJSONObject("member") : null, user, token, version, message, appPermissions, locale, guildLocale, entitlementList, json.toString(), channelId, discordJar);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum InteractionCallbackType {
APPLICATION_COMMAND_AUTOCOMPLETE_RESULT(8),
// respond to an interaction with a popup modal
MODAL(9),
// Respond to an interaction with an upgrade button. Only available for monetized apps.
PREMIUM_REQUIRED(10),
UNKNOWN(-1);

private final int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface InteractionHandler {
Message getFollowup(String id);

void deleteFollowup(String id);
void requirePremium(boolean ephemeral);

EditInteractionMessageAction editOriginalResponse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.seailz.discordjar.DiscordJar;
import com.seailz.discordjar.action.interaction.EditInteractionMessageAction;
import com.seailz.discordjar.action.interaction.followup.InteractionFollowupAction;
import com.seailz.discordjar.model.interaction.callback.InteractionCallbackType;
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.rest.DiscordRequest;
import lombok.SneakyThrows;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

Expand Down Expand Up @@ -37,7 +37,7 @@
new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.INTERACTIONS.GET_ORIGINAL_INTERACTION_RESPONSE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id()),

Check warning on line 40 in src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
discordJar,
URLS.GET.INTERACTIONS.GET_ORIGINAL_INTERACTION_RESPONSE,
RequestMethod.GET
Expand All @@ -54,7 +54,7 @@
new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.DELETE.INTERACTION.DELETE_ORIGINAL_INTERACTION_RESPONSE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id()),

Check warning on line 57 in src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
discordJar,
URLS.DELETE.INTERACTION.DELETE_ORIGINAL_INTERACTION_RESPONSE,
RequestMethod.DELETE
Expand All @@ -71,7 +71,7 @@
new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.GET.INTERACTIONS.GET_FOLLOWUP_MESSAGE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id())

Check warning on line 74 in src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
.replace("{message.id}", id),
discordJar,
URLS.GET.INTERACTIONS.GET_FOLLOWUP_MESSAGE,
Expand All @@ -89,7 +89,7 @@
new DiscordRequest(
new JSONObject(),
new HashMap<>(),
URLS.DELETE.INTERACTION.DELETE_FOLLOWUP_MESSAGE.replace("{interaction.token}", token).replace("{application.id}", discordJar.getSelfInfo().id())

Check warning on line 92 in src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
.replace("{message.id}", id),
discordJar,
URLS.DELETE.INTERACTION.DELETE_FOLLOWUP_MESSAGE,
Expand All @@ -103,7 +103,7 @@
@Override
public EditInteractionMessageAction editOriginalResponse() {
return new EditInteractionMessageAction(
discordJar.getSelfInfo().id(),

Check warning on line 106 in src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
token,
discordJar,
true,
Expand All @@ -114,7 +114,7 @@
@Override
public EditInteractionMessageAction editFollowup(String id) {
return new EditInteractionMessageAction(
discordJar.getSelfInfo().id(),

Check warning on line 117 in src/main/java/com/seailz/discordjar/model/interaction/callback/internal/InteractionHandlerImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
token,
discordJar,
false,
Expand All @@ -138,6 +138,22 @@
}
}

@Override
public void requirePremium(boolean ephemeral) {
try {
new DiscordRequest(
new JSONObject().put("type", InteractionCallbackType.PREMIUM_REQUIRED.getCode()).put("data",new JSONObject().put("flags", ephemeral ? 64 : 0)),
new HashMap<>(),
URLS.POST.INTERACTIONS.CALLBACK.replace("{interaction.id}", id).replace("{interaction.token}", token),
discordJar,
URLS.POST.INTERACTIONS.CALLBACK,
RequestMethod.POST
).invoke();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
throw new DiscordRequest.DiscordAPIErrorException(e);
}
}

@Override
public void deferEdit() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public InviteImpl(String code, Guild guild, Channel channel, User inviter, Voice

public static InviteImpl decompile(JSONObject 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;
Guild guild = obj.has("guild") && obj.get("guild") != JSONObject.NULL ? Guild.decompile(obj.getJSONObject("guild"), discordJar, false) : 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;
VoiceInviteTargetType voiceInviteTarget = obj.has("target_type") ? VoiceInviteTargetType.fromCode(obj.getInt("target_type")) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

public static InviteMetadataImpl decompile(JSONObject 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;
Guild guild = obj.has("guild") && obj.get("guild") != JSONObject.NULL ? Guild.decompile(obj.getJSONObject("guild"), discordJar, false) : 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;
VoiceInviteTargetType voiceInviteTarget = obj.has("target_type") ? VoiceInviteTargetType.fromCode(obj.getInt("target_type")) : null;
Expand All @@ -73,12 +73,12 @@
public JSONObject compile() {
JSONObject json = new JSONObject();
json.put("code", code());
json.put("guild", guild().compile());

Check warning on line 76 in src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `compile` may produce `NullPointerException`
json.put("channel", channel().compile());
json.put("inviter", inviter().compile());

Check warning on line 78 in src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `compile` may produce `NullPointerException`
json.put("target_type", voiceInviteTarget().getCode());

Check warning on line 79 in src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `getCode` may produce `NullPointerException`
json.put("target_user", targetUserStream().compile());

Check warning on line 80 in src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `compile` may produce `NullPointerException`
json.put("target_application", targetApplication().compile());

Check warning on line 81 in src/main/java/com/seailz/discordjar/model/invite/internal/InviteMetadataImpl.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `compile` may produce `NullPointerException`
json.put("approximate_presence_count", approximatePresenceCount());
json.put("approximate_member_count", approximateMemberCount());
json.put("expires_at", expiresAt());
Expand Down
Loading