Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/main/java/net/dv8tion/jda/api/entities/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,8 @@ default String getVanityUrl()

/**
* The description for this guild.
* <br>This is displayed in the server browser below the guild name for verified guilds.
* <br>This is displayed in the server browser below the guild name for verified guilds,
* and in embedded invite links.
*
* <p>The description can be modified using {@link GuildManager#setDescription(String)}.
*
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Invite.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import java.util.List;
import java.util.Set;

import static net.dv8tion.jda.api.entities.Guild.BANNER_URL;
import static net.dv8tion.jda.api.entities.Guild.NSFWLevel;

/**
* Representation of a Discord Invite.
* This class is immutable.
Expand Down Expand Up @@ -358,6 +361,77 @@ interface Channel extends ISnowflake
*/
interface Guild extends ISnowflake
{
/**
* The vanity url code for this Guild. The vanity url is the custom invite code of partnered / official / boosted Guilds.
* <br>The returned String will be the code that can be provided to {@code discord.gg/{code}} to get the invite link.
*
* @return The vanity code or null
*
* @see #getVanityUrl()
*/
@Nullable
String getVanityCode();

/**
* The vanity url for this Guild. The vanity url is the custom invite code of partnered / official / boosted Guilds.
* <br>The returned String will be the vanity invite link to this guild.
*
* @return The vanity url or null
*/
@Nullable
default String getVanityUrl()
{
return getVanityCode() == null ? null : "https://discord.gg/" + getVanityCode();
}

/**
* The guild banner id.
* <br>This is shown in guilds below the guild name.
*
* @return The guild banner id or null
*
* @see #getBannerUrl()
*/
@Nullable
String getBannerId();

/**
* The guild banner url.
* <br>This is shown in guilds below the guild name.
*
* @return The guild banner url or null
*/
@Nullable
default String getBannerUrl()
{
String bannerId = getBannerId();
return bannerId == null ? null : String.format(BANNER_URL, getId(), bannerId, bannerId.startsWith("a_") ? "gif" : "png");
}

/**
* Returns an {@link ImageProxy} for this guild's banner image.
*
* @return Possibly-null {@link ImageProxy} of this guild's banner image
*
* @see #getBannerUrl()
*/
@Nullable
default ImageProxy getBanner()
{
final String bannerUrl = getBannerUrl();
return bannerUrl == null ? null : new ImageProxy(bannerUrl);
}

/**
* The description for this guild.
* <br>This is displayed in the server browser below the guild name for verified guilds,
* and in embedded invite links.
*
* @return The guild's description
*/
@Nullable
String getDescription();

/**
* The icon id of this guild.
*
Expand Down Expand Up @@ -441,6 +515,9 @@ default ImageProxy getSplash()
*/
@Nonnull
VerificationLevel getVerificationLevel();

@Nonnull
NSFWLevel getNSFWLevel();

/**
* Returns the approximate count of online members in the guild. If the online member count was not included in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2320,11 +2320,15 @@ else if (channelType.isGuild())

final DataObject guildObject = object.getObject("guild");

final String guildVanityCode = guildObject.getString("vanity_url_code", null);
final String guildBannerId = guildObject.getString("banner", null);
final String guildIconId = guildObject.getString("icon", null);
final long guildId = guildObject.getLong("id");
final String guildName = guildObject.getString("name");
final String guildSplashId = guildObject.getString("splash", null);
final String description = guildObject.getString("description", null);
final VerificationLevel guildVerificationLevel = VerificationLevel.fromKey(guildObject.getInt("verification_level", -1));
final Guild.NSFWLevel guildNsfwLevel = Guild.NSFWLevel.fromKey(guildObject.getInt("nsfw_level", -1));
final int presenceCount = object.getInt("approximate_presence_count", -1);
final int memberCount = object.getInt("approximate_member_count", -1);

Expand All @@ -2338,7 +2342,7 @@ else if (channelType.isGuild())
? null
: createWelcomeScreen(null, guildObject.getObject("welcome_screen"));

guild = new InviteImpl.GuildImpl(guildId, guildIconId, guildName, guildSplashId, guildVerificationLevel, presenceCount, memberCount, guildFeatures, welcomeScreen);
guild = new InviteImpl.GuildImpl(guildId, guildVanityCode, guildBannerId, guildIconId, guildName, guildSplashId, description, guildVerificationLevel, guildNsfwLevel, presenceCount, memberCount, guildFeatures, welcomeScreen);

final String channelName = channelObject.getString("name");
final long channelId = channelObject.getLong("id");
Expand Down
47 changes: 41 additions & 6 deletions src/main/java/net/dv8tion/jda/internal/entities/InviteImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.List;
import java.util.Set;

import static net.dv8tion.jda.api.entities.Guild.NSFWLevel;

public class InviteImpl implements Invite
{
private final JDAImpl api;
Expand Down Expand Up @@ -335,22 +337,27 @@ public String toString()

public static class GuildImpl implements Guild
{
private final String iconId, name, splashId;
private final String vanityCode, bannerId, iconId, name, splashId, description;
private final int presenceCount, memberCount;
private final long id;
private final VerificationLevel verificationLevel;
private final NSFWLevel nsfwLevel;
private final Set<String> features;
private final GuildWelcomeScreen welcomeScreen;

public GuildImpl(final long id, final String iconId, final String name, final String splashId,
final VerificationLevel verificationLevel, final int presenceCount, final int memberCount, final Set<String> features,
public GuildImpl(final long id, final String vanityCode, final String bannerId, final String iconId, final String name, final String splashId, final String description,
final VerificationLevel verificationLevel, final NSFWLevel nsfwLevel, final int presenceCount, final int memberCount, final Set<String> features,
final GuildWelcomeScreen welcomeScreen)
{
this.id = id;
this.vanityCode = vanityCode;
this.bannerId = bannerId;
this.iconId = iconId;
this.name = name;
this.splashId = splashId;
this.description = description;
this.verificationLevel = verificationLevel;
this.nsfwLevel = nsfwLevel;
this.presenceCount = presenceCount;
this.memberCount = memberCount;
this.features = features;
Expand All @@ -359,8 +366,29 @@ public GuildImpl(final long id, final String iconId, final String name, final St

public GuildImpl(final net.dv8tion.jda.api.entities.Guild guild)
{
this(guild.getIdLong(), guild.getIconId(), guild.getName(), guild.getSplashId(),
guild.getVerificationLevel(), -1, -1, guild.getFeatures(), null);
this(guild.getIdLong(), guild.getVanityCode(), guild.getBannerId(), guild.getIconId(), guild.getName(), guild.getSplashId(), guild.getDescription(),
guild.getVerificationLevel(), guild.getNSFWLevel(), -1, -1, guild.getFeatures(), null);
}

@Nullable
@Override
public String getVanityCode()
{
return vanityCode;
}

@Nullable
@Override
public String getBannerId()
{
return bannerId;
}

@Nullable
@Override
public String getDescription()
{
return description;
}

@Override
Expand Down Expand Up @@ -408,7 +436,14 @@ public VerificationLevel getVerificationLevel()
{
return verificationLevel;
}


@Nonnull
@Override
public NSFWLevel getNSFWLevel()
{
return nsfwLevel;
}

@Override
public int getOnlineCount()
{
Expand Down