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 #250

Merged
merged 23 commits into from
Oct 26, 2023
Merged

main #250

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1a0bd18
feat(monetization): implemented support for the new premium apps system
seailz Sep 27, 2023
feab6af
removed no longer needed // todo
seailz Sep 27, 2023
1636a2b
Merge pull request #239 from discord-jar/feature/sku
seailz Sep 27, 2023
794ad87
fixed using files in interaction followups
seailz Oct 1, 2023
f892df8
Merge remote-tracking branch 'origin/main'
seailz Oct 1, 2023
2092ef0
feat(selects): added support for the new `default_values` field on au…
seailz Oct 4, 2023
3b90cd6
Merge pull request #244 from discord-jar/feature/autodefaultvalues
seailz Oct 4, 2023
9939a85
feat(interactions): added support for the `resolved` field in message…
seailz Oct 7, 2023
db585ae
Merge pull request #245 from discord-jar/feature/message-component-re…
seailz Oct 7, 2023
aaa67dc
build(deps): bump org.json:json from 20230618 to 20231013
dependabot[bot] Oct 16, 2023
2187865
build(deps): bump com.squareup.okhttp3:okhttp from 4.11.0 to 4.12.0
dependabot[bot] Oct 17, 2023
9abd110
Merge pull request #247 from discord-jar/dependabot/maven/com.squareu…
seailz Oct 17, 2023
fb5c1f4
Update codeql.yml
seailz Oct 18, 2023
519dc0d
Update codeql.yml
seailz Oct 18, 2023
1f86432
Update codeql.yml
seailz Oct 18, 2023
36896e3
Create qodana.yml
seailz Oct 18, 2023
86795aa
test workflow
seailz Oct 18, 2023
f93e762
Merge remote-tracking branch 'origin/main'
seailz Oct 18, 2023
a74be4b
build(deps): bump org.springframework.boot:spring-boot-starter-websocket
dependabot[bot] Oct 20, 2023
146b038
Merge pull request #248 from discord-jar/dependabot/maven/org.springf…
seailz Oct 20, 2023
8ce0e8f
build(deps): bump org.jsoup:jsoup from 1.16.1 to 1.16.2
dependabot[bot] Oct 23, 2023
7db123f
Merge pull request #246 from discord-jar/dependabot/maven/org.json-js…
seailz Oct 23, 2023
1b5cd00
Merge pull request #249 from discord-jar/dependabot/maven/org.jsoup-j…
seailz Oct 23, 2023
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
4 changes: 3 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
category: "/language:${{matrix.language}}"


25 changes: 25 additions & 0 deletions .github/workflows/qodana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Qodana
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
qodana:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
checks: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2023.2
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230618</version>
<version>20231013</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -105,7 +105,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</dependency>
<!-- Used for marking methods and params -->
<dependency>
Expand All @@ -129,12 +129,12 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.16.1</version>
<version>1.16.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.11.0</version>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/com/seailz/discordjar/DiscordJar.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.seailz.discordjar;

import com.seailz.discordjar.action.guild.GetCurrentUserGuildsAction;
import com.seailz.discordjar.action.sku.ListEntitlementRequest;
import com.seailz.discordjar.cache.Cache;
import com.seailz.discordjar.cache.CacheType;
import com.seailz.discordjar.cache.JsonCache;
Expand Down Expand Up @@ -34,6 +35,7 @@
import com.seailz.discordjar.model.guild.Member;
import com.seailz.discordjar.model.invite.Invite;
import com.seailz.discordjar.model.invite.internal.InviteImpl;
import com.seailz.discordjar.model.monetization.SKU;
import com.seailz.discordjar.model.status.Status;
import com.seailz.discordjar.model.user.User;
import com.seailz.discordjar.utils.Checker;
Expand Down Expand Up @@ -219,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 @@ -268,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 @@ -304,7 +306,6 @@
.setTransportCompressionType(gwCompressionType)
.build();
}

}

/**
Expand Down Expand Up @@ -339,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 @@ -377,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 @@ -476,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 Down Expand Up @@ -542,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 @@ -563,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 @@ -584,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 @@ -605,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 @@ -626,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 @@ -647,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 @@ -666,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 @@ -687,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 @@ -812,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 @@ -970,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 @@ -1137,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 @@ -1156,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 @@ -1178,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 @@ -1209,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 @@ -1234,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 @@ -1256,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 @@ -1279,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 @@ -1302,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

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 @@ -1334,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 @@ -1360,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 @@ -1383,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`

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 @@ -1406,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 @@ -1452,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 @@ -1478,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 @@ -1507,6 +1508,36 @@
}
}

public List<SKU> getApplicationSkus() {
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) {
throw new DiscordRequest.DiscordAPIErrorException(e);
}
List<SKU> skus = new ArrayList<>();
for (int i = 0; i < res.length(); i++) {
skus.add(SKU.decompile(res.getJSONObject(i), this));
}
return skus;
}

public SKU getSKUById(String id) {
return getApplicationSkus().stream().filter(s -> s.id().equals(id)).findFirst().orElse(null);
}

public ListEntitlementRequest getEntitlements() {
return new ListEntitlementRequest(this);
}

public boolean isDebug() {
return debug;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.seailz.discordjar.utils.rest.Response;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.File;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -129,6 +130,11 @@
return this;
}

public InteractionFollowupAction addFiles(File... files) {
this.getReply().addFiles(files);
return this;
}

public InteractionFollowupAction setAllowedMentions(AllowedMentions allowedMentions) {
this.getReply().setAllowedMentions(allowedMentions);
return this;
Expand All @@ -146,16 +152,20 @@
public Response<InteractionHandler> run() {
Response<InteractionHandler> response = new Response<>();
try {
new DiscordRequest(
DiscordRequest req = new DiscordRequest(
getReply().compile(),
new HashMap<>(),
URLS.POST.INTERACTIONS.FOLLOWUP
.replaceAll("application.id", discordJar.getSelfInfo().id())

Check warning on line 159 in src/main/java/com/seailz/discordjar/action/interaction/followup/InteractionFollowupAction.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
.replaceAll("interaction.token", token),
discordJar,
URLS.POST.INTERACTIONS.FOLLOWUP,
RequestMethod.POST
).invoke();
);

if (getReply().useFiles()) req.invokeWithFiles(getReply().getFiles().toArray(new File[0]));
else req.invoke();

response.complete(InteractionHandler.from(token, id, discordJar));
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
response.completeError(new Response.Error(e.getCode(), e.getMessage(), e.getBody()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.seailz.discordjar.action.sku;

import com.seailz.discordjar.DiscordJar;
import com.seailz.discordjar.model.monetization.Entitlement;
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.rest.Response;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ListEntitlementRequest {

private final DiscordJar jar;
private String userId;
private List<String> skuIds;
private String before;
private String after;
private int limit = 100;
private String guildId;
private boolean excludeEnded = false;

public ListEntitlementRequest(DiscordJar jar) {
this.jar = jar;
}

/**
* Sets the user ID to get entitlements for.
*/
public ListEntitlementRequest setUserId(String userId) {
this.userId = userId;
return this;
}

/**
* Sets the SKU IDs to get entitlements for.
*/
public ListEntitlementRequest setSkuIds(List<String> skuIds) {
this.skuIds = skuIds;
return this;
}

public ListEntitlementRequest addSkuId(String skuId) {
if (this.skuIds == null) this.skuIds = new ArrayList<>();
this.skuIds.add(skuId);
return this;
}

/**
* Limits entitlements to before this ID.
*/
public ListEntitlementRequest setBefore(String before) {
this.before = before;
return this;
}

/**
* Limits entitlements to after this ID.
*/
public ListEntitlementRequest setAfter(String after) {
this.after = after;
return this;
}

/**
* Limits entitlements to this amount. 1-100
*/
public ListEntitlementRequest setLimit(int limit) {
this.limit = limit;
return this;
}

/**
* Limits entitlements to this guild ID.
*/
public ListEntitlementRequest setGuildId(String guildId) {
this.guildId = guildId;
return this;
}

/**
* Whether or not to exclude ended entitlements.
*/
public ListEntitlementRequest setExcludeEnded(boolean excludeEnded) {
this.excludeEnded = excludeEnded;
return this;
}

public Response<List<Entitlement>> run() {
Response<List<Entitlement>> response = new Response<>();
if (limit < 1 || limit > 100) throw new IllegalArgumentException("Limit must be between 1 and 100");
new Thread(() -> {
String urlWithQuery = URLS.GET.APPLICATION.LIST_ENTITLEMENTS;
urlWithQuery += "?";
if (userId != null) urlWithQuery += "user_id=" + userId + "&";
if (skuIds != null) {
StringBuilder skuIdsString = new StringBuilder();
for (String skuId : skuIds) {
skuIdsString.append(skuId).append(",");
}
skuIdsString = new StringBuilder(skuIdsString.substring(0, skuIdsString.length() - 1));
urlWithQuery += "sku_ids=" + skuIdsString + "&";
}
if (before != null) urlWithQuery += "before=" + before + "&";
if (after != null) urlWithQuery += "after=" + after + "&";
urlWithQuery += "limit=" + limit + "&";
if (guildId != null) urlWithQuery += "guild_id=" + guildId + "&";
urlWithQuery += "exclude_ended=" + excludeEnded;

DiscordResponse req = null;

Check warning on line 114 in src/main/java/com/seailz/discordjar/action/sku/ListEntitlementRequest.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused assignment

Variable `req` initializer `null` is redundant

Check warning on line 114 in src/main/java/com/seailz/discordjar/action/sku/ListEntitlementRequest.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(),
new HashMap<>(),
urlWithQuery.replace("{application.id}", jar.getSelfInfo().id()),

Check warning on line 119 in src/main/java/com/seailz/discordjar/action/sku/ListEntitlementRequest.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`

Check warning on line 119 in src/main/java/com/seailz/discordjar/action/sku/ListEntitlementRequest.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `id` may produce `NullPointerException`
jar,
URLS.GET.APPLICATION.LIST_ENTITLEMENTS,
RequestMethod.GET
).invoke();
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
response.completeError(new Response.Error(e));
return;
}

List<Entitlement> entitlements = new ArrayList<>();
for (Object o : req.arr()) {
entitlements.add(Entitlement.decompile(jar, (JSONObject) o));
}
response.complete(entitlements);
}).start();
return response;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.seailz.discordjar.model.component.select;

import java.util.List;

/**
* Represents a select menu that is auto populated, such as a {@link com.seailz.discordjar.model.component.select.entity.ChannelSelectMenu ChannelSelectMenu}.
* @author Seailz
* @see AutoPopulatedSelect
*/
public interface AutoPopulatedSelect extends SelectMenu {

List<String> defaultValues();

}
Loading
Loading