diff --git a/src/main/java/net/dv8tion/jda/api/entities/Guild.java b/src/main/java/net/dv8tion/jda/api/entities/Guild.java index 0d97ca44ec..c14f470aba 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/Guild.java +++ b/src/main/java/net/dv8tion/jda/api/entities/Guild.java @@ -915,7 +915,8 @@ default String getVanityUrl() /** * The description for this guild. - *
This is displayed in the server browser below the guild name for verified guilds. + *
This is displayed in the server browser below the guild name for verified guilds, + * and in embedded invite links. * *

The description can be modified using {@link GuildManager#setDescription(String)}. * diff --git a/src/main/java/net/dv8tion/jda/api/entities/Invite.java b/src/main/java/net/dv8tion/jda/api/entities/Invite.java index 7021de4968..82a0ea9049 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/Invite.java +++ b/src/main/java/net/dv8tion/jda/api/entities/Invite.java @@ -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. @@ -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. + *
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. + *
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. + *
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. + *
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. + *
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. * @@ -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 diff --git a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java index 03b9080e89..399e7af560 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -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); @@ -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"); diff --git a/src/main/java/net/dv8tion/jda/internal/entities/InviteImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/InviteImpl.java index 657026d081..a83c774662 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/InviteImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/InviteImpl.java @@ -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; @@ -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 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 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 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; @@ -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 @@ -408,7 +436,14 @@ public VerificationLevel getVerificationLevel() { return verificationLevel; } - + + @Nonnull + @Override + public NSFWLevel getNSFWLevel() + { + return nsfwLevel; + } + @Override public int getOnlineCount() {