Skip to content

Commit

Permalink
Add Tags, Default Install Url, Scopes and Permissions to ApplicationI…
Browse files Browse the repository at this point in the history
…nfo (#1936)

Co-authored-by: Florian Spieß <business@minn.dev>
Co-authored-by: Olivia <chew@chew.pw>
  • Loading branch information
3 people committed Apr 14, 2022
1 parent 06060fe commit 4bf24ae
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
50 changes: 48 additions & 2 deletions src/main/java/net/dv8tion/jda/api/entities/ApplicationInfo.java
Expand Up @@ -22,8 +22,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.*;

/**
* Represents a Discord Application from its bot's point of view.
Expand Down Expand Up @@ -287,4 +286,51 @@ default String getInviteUrl(long guildId, @Nullable Permission... permissions)
* @return Whether the bot is public
*/
boolean isBotPublic();

/**
* A {@link java.util.List} containing the tags of this bot's application.
*
* <p>This List is empty if no tags are set in the <a href="https://discord.com/developers/applications" target="_blank">Developer Portal</a>.
*
* @return Immutable list containing the tags of this bot's application
*/
@Nonnull
List<String> getTags();

/**
* The custom Authorization URL of this bot's application.
*
* <p>This returns {@code null} if no custom URL is set in the <a href="https://discord.com/developers/applications" target="_blank">Developer Portal</a> or if In-app Authorization is enabled.
*
* @return Custom Authorization URL, or null if it has not been set
*/
@Nullable
String getCustomAuthorizationUrl();

/**
* A {@link java.util.List} of scopes the default authorization URL is set up with.
*
* <p>This List is empty if you set a custom URL in the <a href="https://discord.com/developers/applications" target="_blank">Developer Portal</a>.
*
* @return Immutable list of scopes the default authorization URL is set up with.
*/
@Nonnull
List<String> getScopes();

/**
* An {@link java.util.EnumSet} of permissions the default authorization URL is set up with.
*
* <p>This is empty if you set a custom URL in the <a href="https://discord.com/developers/applications" target="_blank">Developer Portal</a>.
*
* @return Set of permissions the default authorization URL is set up with.
*/
@Nonnull
EnumSet<Permission> getPermissions();

/**
* The {@code long} representation of the literal permissions the default authorization URL is set up with.
*
* @return Never-negative long containing offset permissions the default authorization URL is set up with.
*/
long getPermissionsRaw();
}
Expand Up @@ -24,7 +24,11 @@
import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

public class ApplicationInfoImpl implements ApplicationInfo
{
Expand All @@ -40,10 +44,15 @@ public class ApplicationInfoImpl implements ApplicationInfo
private final String name;
private final User owner;
private final ApplicationTeam team;
private final List<String> tags;
private final String customAuthUrl;
private final long defaultAuthUrlPerms;
private final List<String> defaultAuthUrlScopes;
private String scopes = "bot";

public ApplicationInfoImpl(JDA api, String description, boolean doesBotRequireCodeGrant, String iconId, long id,
boolean isBotPublic, String name, String termsOfServiceUrl, String privacyPolicyUrl, User owner, ApplicationTeam team)
boolean isBotPublic, String name, String termsOfServiceUrl, String privacyPolicyUrl, User owner, ApplicationTeam team,
List<String> tags, String customAuthUrl, long defaultAuthUrlPerms, List<String> defaultAuthUrlScopes)
{
this.api = api;
this.description = description;
Expand All @@ -56,6 +65,10 @@ public ApplicationInfoImpl(JDA api, String description, boolean doesBotRequireCo
this.privacyPolicyUrl = privacyPolicyUrl;
this.owner = owner;
this.team = team;
this.tags = Collections.unmodifiableList(tags);
this.customAuthUrl = customAuthUrl;
this.defaultAuthUrlPerms = defaultAuthUrlPerms;
this.defaultAuthUrlScopes = Collections.unmodifiableList(defaultAuthUrlScopes);
}

@Override
Expand Down Expand Up @@ -184,6 +197,40 @@ public final boolean isBotPublic()
return this.isBotPublic;
}

@Nonnull
@Override
public List<String> getTags()
{
return tags;
}

@Nullable
@Override
public String getCustomAuthorizationUrl()
{
return customAuthUrl;
}

@Nonnull
@Override
public EnumSet<Permission> getPermissions()
{
return Permission.getPermissions(defaultAuthUrlPerms);
}

@Override
public long getPermissionsRaw()
{
return defaultAuthUrlPerms;
}

@Nonnull
@Override
public List<String> getScopes()
{
return defaultAuthUrlScopes;
}

@Override
public String toString()
{
Expand Down
Expand Up @@ -2124,9 +2124,23 @@ public ApplicationInfo createApplicationInfo(DataObject object)
final boolean isBotPublic = object.getBoolean("bot_public");
final User owner = createUser(object.getObject("owner"));
final ApplicationTeam team = !object.isNull("team") ? createApplicationTeam(object.getObject("team")) : null;
final String customAuthUrl = object.getString("custom_install_url", null);
final List<String> tags = object.optArray("tags").orElseGet(DataArray::empty)
.stream(DataArray::getString)
.collect(Collectors.toList());

final Optional<DataObject> installParams = object.optObject("install_params");

final long defaultAuthUrlPerms = installParams.map(o -> o.getLong("permissions"))
.orElse(0L);

final List<String> defaultAuthUrlScopes = installParams.map(obj -> obj.getArray("scopes")
.stream(DataArray::getString)
.collect(Collectors.toList()))
.orElse(Collections.emptyList());

return new ApplicationInfoImpl(getJDA(), description, doesBotRequireCodeGrant, iconId, id, isBotPublic, name,
termsOfServiceUrl, privacyPolicyUrl, owner, team);
termsOfServiceUrl, privacyPolicyUrl, owner, team, tags, customAuthUrl, defaultAuthUrlPerms, defaultAuthUrlScopes);
}

public ApplicationTeam createApplicationTeam(DataObject object)
Expand Down

0 comments on commit 4bf24ae

Please sign in to comment.