-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from discord-jar/main
main
- Loading branch information
Showing
19 changed files
with
803 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/main/java/com/seailz/discordjar/action/sku/ListEntitlementRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
try { | ||
req = new DiscordRequest( | ||
new JSONObject(), | ||
new HashMap<>(), | ||
urlWithQuery.replace("{application.id}", jar.getSelfInfo().id()), | ||
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; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/seailz/discordjar/model/component/select/AutoPopulatedSelect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
|
||
} |
Oops, something went wrong.