diff --git a/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java index 22a3d240a3..9b39711fac 100644 --- a/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/core/entities/EntityBuilder.java @@ -28,6 +28,7 @@ import net.dv8tion.jda.core.audit.ActionType; import net.dv8tion.jda.core.audit.AuditLogChange; import net.dv8tion.jda.core.audit.AuditLogEntry; +import net.dv8tion.jda.core.entities.Guild.VerificationLevel; import net.dv8tion.jda.core.entities.MessageEmbed.*; import net.dv8tion.jda.core.entities.impl.*; import net.dv8tion.jda.core.exceptions.AccountTypeException; @@ -1260,8 +1261,11 @@ public Invite createInvite(JSONObject object) final long guildId = guildObject.getLong("id"); final String guildName = guildObject.getString("name"); final String guildSplashId = guildObject.optString("splash", null); + final VerificationLevel guildVerificationLevel = VerificationLevel.fromKey(Helpers.optInt(guildObject, "verification_level", -1)); + final int presenceCount = Helpers.optInt(object, "approximate_presence_count", -1); + final int memberCount = Helpers.optInt(object, "approximate_member_count", -1); - final Invite.Guild guild = new InviteImpl.GuildImpl(guildId, guildIconId, guildName, guildSplashId); + final Invite.Guild guild = new InviteImpl.GuildImpl(guildId, guildIconId, guildName, guildSplashId, guildVerificationLevel, presenceCount, memberCount); final int maxAge; final int maxUses; @@ -1289,7 +1293,9 @@ public Invite createInvite(JSONObject object) timeCreated = null; } - return new InviteImpl(api, code, expanded, inviter, maxAge, maxUses, temporary, timeCreated, uses, channel, guild); + return new InviteImpl(api, code, expanded, inviter, + maxAge, maxUses, temporary, + timeCreated, uses, channel, guild); } public void clearCache() diff --git a/src/main/java/net/dv8tion/jda/core/entities/Invite.java b/src/main/java/net/dv8tion/jda/core/entities/Invite.java index 7acb48d53d..00b83793df 100644 --- a/src/main/java/net/dv8tion/jda/core/entities/Invite.java +++ b/src/main/java/net/dv8tion/jda/core/entities/Invite.java @@ -17,6 +17,7 @@ package net.dv8tion.jda.core.entities; import net.dv8tion.jda.core.JDA; +import net.dv8tion.jda.core.entities.Guild.VerificationLevel; import net.dv8tion.jda.core.entities.impl.InviteImpl; import net.dv8tion.jda.core.requests.RestAction; import net.dv8tion.jda.core.requests.restaction.AuditableRestAction; @@ -53,7 +54,32 @@ public interface Invite */ static RestAction resolve(final JDA api, final String code) { - return InviteImpl.resolve(api, code); + return resolve(api, code, false); + } + + /** + * Retrieves a new {@link net.dv8tion.jda.core.entities.Invite Invite} instance for the given invite code. + *
You cannot resolve invites if you were banned from the origin Guild! + * + *

Possible {@link net.dv8tion.jda.core.requests.ErrorResponse ErrorResponses} include: + *

+ * + * @param api + * The JDA instance + * @param code + * A valid invite code + * @param withCounts + * Whether or not to include online and member counts + * + * @return {@link net.dv8tion.jda.core.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.core.entities.Invite Invite} + *
The Invite object + */ + static RestAction resolve(final JDA api, final String code, final boolean withCounts) + { + return InviteImpl.resolve(api, code, withCounts); } /** @@ -296,5 +322,32 @@ interface Guild extends ISnowflake * @see #getSplashId() */ String getSplashUrl(); + + /** + * Returns the {@link net.dv8tion.jda.core.entities.Guild.VerificationLevel VerificationLevel} of this guild. + * + * @return the verification level of the guild + */ + VerificationLevel getVerificationLevel(); + + /** + * Returns the approximate count of online members in the guild. If the online member count was not included in the + * invite, this will return -1. Counts will usually only be returned when resolving the invite via the + * {@link #resolve(net.dv8tion.jda.core.JDA, java.lang.String, boolean) Invite.resolve()} method with the + * withCounts boolean set to {@code true} + * + * @return the approximate count of online members in the guild, or -1 if not present in the invite + */ + int getOnlineCount(); + + /** + * Returns the approximate count of total members in the guild. If the total member count was not included in the + * invite, this will return -1. Counts will usually only be returned when resolving the invite via the + * {@link #resolve(net.dv8tion.jda.core.JDA, java.lang.String, boolean) Invite.resolve()} method with the + * withCounts boolean set to {@code true} + * + * @return the approximate count of total members in the guild, or -1 if not present in the invite + */ + int getMemberCount(); } } diff --git a/src/main/java/net/dv8tion/jda/core/entities/impl/InviteImpl.java b/src/main/java/net/dv8tion/jda/core/entities/impl/InviteImpl.java index c4ef079d24..bb37373c69 100644 --- a/src/main/java/net/dv8tion/jda/core/entities/impl/InviteImpl.java +++ b/src/main/java/net/dv8tion/jda/core/entities/impl/InviteImpl.java @@ -19,6 +19,7 @@ import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.*; +import net.dv8tion.jda.core.entities.Guild.VerificationLevel; import net.dv8tion.jda.core.exceptions.InsufficientPermissionException; import net.dv8tion.jda.core.requests.Request; import net.dv8tion.jda.core.requests.Response; @@ -62,12 +63,15 @@ public InviteImpl(final JDAImpl api, final String code, final boolean expanded, this.guild = guild; } - public static RestAction resolve(final JDA api, final String code) + public static RestAction resolve(final JDA api, final String code, final boolean withCounts) { Checks.notNull(code, "code"); Checks.notNull(api, "api"); - final Route.CompiledRoute route = Route.Invites.GET_INVITE.compile(code); + Route.CompiledRoute route = Route.Invites.GET_INVITE.compile(code); + + if (withCounts) + route = route.withQueryParams("with_counts", "true"); return new RestAction(api, route) { @@ -282,16 +286,21 @@ public ChannelType getType() public static class GuildImpl implements Guild { - private final String iconId, name, splashId; + private final int presenceCount, memberCount; private final long id; + private final VerificationLevel verificationLevel; - public GuildImpl(final long id, final String iconId, final String name, final String splashId) + public GuildImpl(final long id, final String iconId, final String name, final String splashId, + final VerificationLevel verificationLevel, final int presenceCount, final int memberCount) { this.id = id; this.iconId = iconId; this.name = name; this.splashId = splashId; + this.verificationLevel = verificationLevel; + this.presenceCount = presenceCount; + this.memberCount = memberCount; } @Override @@ -332,6 +341,23 @@ public String getSplashUrl() : "https://cdn.discordapp.com/splashes/" + this.id + "/" + this.splashId + ".jpg"; } + @Override + public VerificationLevel getVerificationLevel() + { + return verificationLevel; + } + + @Override + public int getOnlineCount() + { + return presenceCount; + } + + @Override + public int getMemberCount() + { + return memberCount; + } } }