Skip to content

Commit

Permalink
Add guild welcome screens (#2264)
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Dec 6, 2022
1 parent 00f4226 commit b7505ca
Show file tree
Hide file tree
Showing 10 changed files with 840 additions and 22 deletions.
35 changes: 35 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Expand Up @@ -44,6 +44,7 @@
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.managers.GuildManager;
import net.dv8tion.jda.api.managers.GuildStickerManager;
import net.dv8tion.jda.api.managers.GuildWelcomeScreenManager;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.*;
Expand Down Expand Up @@ -2376,6 +2377,26 @@ default RestAction<RichCustomEmoji> retrieveEmoji(@Nonnull CustomEmoji emoji)
@CheckReturnValue
RestAction<List<Webhook>> retrieveWebhooks();

/**
* Retrieves the {@link GuildWelcomeScreen welcome screen} for this Guild.
* <br>The welcome screen is shown to all members after joining the Guild.
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_GUILD_WELCOME_SCREEN Unknown Guild Welcome Screen}
* <br>The guild has no welcome screen</li>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS Missing Permissions}
* <br>The guild's welcome screen is disabled
* and the currently logged in account doesn't have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission</li>
* </ul>
*
* @return {@link RestAction} - Type: {@link GuildWelcomeScreen}
* <br>The welcome screen for this Guild.
*/
@Nonnull
@CheckReturnValue
RestAction<GuildWelcomeScreen> retrieveWelcomeScreen();

/**
* A list containing the {@link net.dv8tion.jda.api.entities.GuildVoiceState GuildVoiceState} of every {@link net.dv8tion.jda.api.entities.Member Member}
* in this {@link net.dv8tion.jda.api.entities.Guild Guild}.
Expand Down Expand Up @@ -4939,6 +4960,20 @@ default RoleOrderAction modifyRolePositions()
@CheckReturnValue
RoleOrderAction modifyRolePositions(boolean useAscendingOrder);

/**
* The {@link GuildWelcomeScreenManager Manager} for this guild's welcome screen, used to modify
* properties of the welcome screen like if the welcome screen is enabled, the description and welcome channels.
* <br>You modify multiple fields in one request by chaining setters before calling {@link net.dv8tion.jda.api.requests.RestAction#queue() RestAction.queue()}.
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER Permission.MANAGE_SERVER}
*
* @return The GuildWelcomeScreenManager for this guild's welcome screen
*/
@Nonnull
@CheckReturnValue
GuildWelcomeScreenManager modifyWelcomeScreen();

//////////////////////////

/**
Expand Down
198 changes: 198 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.java
@@ -0,0 +1,198 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.api.entities;

import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildChannel;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.entities.emoji.EmojiUnion;
import net.dv8tion.jda.api.managers.GuildWelcomeScreenManager;
import net.dv8tion.jda.api.utils.data.SerializableData;
import net.dv8tion.jda.internal.entities.GuildWelcomeScreenImpl;
import net.dv8tion.jda.internal.utils.Checks;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

/**
* The welcome screen of a {@link Guild}.
* This welcome screen will be shown to all members after joining the Guild.
*
* @see Guild#retrieveWelcomeScreen()
* @see Invite.Guild#getWelcomeScreen()
*/
public interface GuildWelcomeScreen
{
/** The maximum length of a welcome screen description ({@value}) */
int MAX_DESCRIPTION_LENGTH = 140;

/** The maximum amount of welcome channel a welcome screen can show ({@value}) */
int MAX_WELCOME_CHANNELS = 5;

/**
* The {@link Guild Guild}, or {@code null} if this welcome screen came from an {@link Invite}
*
* @return The Guild, or {@code null}
*/
@Nullable
Guild getGuild();

/**
* Returns the {@link GuildWelcomeScreenManager Manager} for this guild's welcome screen.
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the currently logged in account does not have {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER Permission.MANAGE_SERVER}
* @throws IllegalStateException
* If welcome screen came from an {@link Invite}
*
* @return The GuildWelcomeScreenManager for this guild's welcome screen
*
* @see Guild#modifyWelcomeScreen()
*/
@Nonnull
GuildWelcomeScreenManager getManager();

/**
* The server description shown in the welcome screen.
* <br>This will be {@code null} if the welcome screen has no description.
*
* @return The server description shown in the welcome screen or {@code null}
*/
@Nullable
String getDescription();

/**
* The channels shown in the welcome screen.
*
* @return Possibly-empty, unmodifiable list of the channels shown in the welcome screen
*/
@Nonnull
List<Channel> getChannels();

/**
* POJO for the recommended channels information provided by a welcome screen.
* <br>Recommended channels are shown in the welcome screen after joining a server.
*
* @see GuildWelcomeScreen#getChannels()
*/
interface Channel extends ISnowflake, SerializableData
{
/** Maximum length of a channel description ({@value}) */
int MAX_DESCRIPTION_LENGTH = 42;

/**
* Constructs a new welcome channel.
*
* @param channel
* The Discord channel to be presented to the user
* @param description
* The description of the channel, must not be longer than {@value #MAX_DESCRIPTION_LENGTH}
*
* @throws IllegalArgumentException
* <ul>
* <li>If the channel is null</li>
* <li>If the description is null, blank, or longer than {@value #MAX_DESCRIPTION_LENGTH}</li>
* </ul>
*
* @return The new welcome channel
*/
@Nonnull
static Channel of(@Nonnull StandardGuildChannel channel, @Nonnull String description)
{
return of(channel, description, null);
}

/**
* Constructs a new welcome channel.
*
* @param channel
* The Discord channel to be presented the user
* @param description
* The description of the channel, must not be longer than {@value #MAX_DESCRIPTION_LENGTH}
* @param emoji
* The emoji to show beside the channel
*
* @throws IllegalArgumentException
* <ul>
* <li>If the channel is null</li>
* <li>If the description is null, blank, or longer than {@value #MAX_DESCRIPTION_LENGTH}</li>
* </ul>
*
* @return The new welcome channel
*/
@Nonnull
static Channel of(@Nonnull StandardGuildChannel channel, @Nonnull String description, @Nullable Emoji emoji)
{
Checks.notNull(channel, "Channel");
Checks.notBlank(description, "Description");
Checks.notLonger(description, MAX_DESCRIPTION_LENGTH, "Description");

return new GuildWelcomeScreenImpl.ChannelImpl(channel.getGuild(), channel.getIdLong(), description, (EmojiUnion) emoji);
}

/**
* The {@link Guild Guild}, or {@code null} if this welcome channel came from an {@link Invite}
*
* @return The Guild, or {@code null}
*/
@Nullable
Guild getGuild();

/**
* The id of this recommended channel.
*
* @return The id of this recommended channel
*/
@Override
long getIdLong();

/**
* Returns the {@link GuildChannel} that is linked to this recommended channel.
* <br>This will be {@code null} if the linked channel was deleted, or if the welcome screen comes from an {@link Invite.Guild invite guild}.
*
* @return The {@link GuildChannel} that is linked to this recommended channel or {@code null}
*/
@Nullable
GuildChannel getChannel();

/**
* The description of this recommended channel shown in the welcome screen.
*
* @return The description of this recommended channel
*/
@Nonnull
String getDescription();

/**
* The emoji that is used for this recommended channel.
* <br>This will return {@code null} if no emoji was set
*
* <p>The emoji will always be from this guild, if not a unicode emoji
* <br><b>{@link CustomEmoji#isAnimated()} will always return {@code false} if:</b>
* <ul>
* <li>This welcome screen came from an {@link Invite.Guild invite's guild}</li>
* <li>{@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI CacheFlag.EMOJI} is disabled</li>
* </ul>
*
* @return The emoji that is used for this recommended channel or {@code null}
*/
@Nullable
EmojiUnion getEmoji();
}
}
40 changes: 25 additions & 15 deletions src/main/java/net/dv8tion/jda/api/entities/Invite.java
Expand Up @@ -47,7 +47,7 @@
public interface Invite
{
/**
* Retrieves a new {@link net.dv8tion.jda.api.entities.Invite Invite} instance for the given invite code.
* Retrieves a new {@link Invite Invite} instance for the given invite code.
* <br><b>You cannot resolve invites if you were banned from the origin Guild!</b>
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include:
Expand All @@ -61,7 +61,7 @@ public interface Invite
* @param code
* A valid invite code
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Invite Invite}
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link Invite Invite}
* <br>The Invite object
*/
@Nonnull
Expand All @@ -71,7 +71,7 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
}

/**
* Retrieves a new {@link net.dv8tion.jda.api.entities.Invite Invite} instance for the given invite code.
* Retrieves a new {@link Invite Invite} instance for the given invite code.
* <br><b>You cannot resolve invites if you were banned from the origin Guild!</b>
*
* <p>Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include:
Expand All @@ -87,7 +87,7 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
* @param withCounts
* Whether or not to include online and member counts for guild invites or users for group invites
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Invite Invite}
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link Invite Invite}
* <br>The Invite object
*/
@Nonnull
Expand All @@ -111,7 +111,7 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
AuditableRestAction<Void> delete();

/**
* Tries to retrieve a new expanded {@link net.dv8tion.jda.api.entities.Invite Invite} with more info.
* Tries to retrieve a new expanded {@link Invite Invite} with more info.
* <br>As bots can't be in groups this is only available for guild invites and will throw an {@link java.lang.IllegalStateException IllegalStateException}
* for other types.
* <br>Requires either {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in the invite's guild or
Expand All @@ -124,7 +124,7 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
* @throws java.lang.IllegalStateException
* If this is a group invite
*
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.Invite Invite}
* @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link Invite Invite}
* <br>The expanded Invite object
*
* @see #getType()
Expand Down Expand Up @@ -153,23 +153,23 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
Invite.TargetType getTargetType();

/**
* An {@link net.dv8tion.jda.api.entities.Invite.Channel Invite.Channel} object
* An {@link Invite.Channel Invite.Channel} object
* containing information about this invite's origin channel.
*
* @return Information about this invite's origin channel or null in case of a group invite
*
* @see net.dv8tion.jda.api.entities.Invite.Channel
* @see Invite.Channel
*/
@Nullable
Channel getChannel();

/**
* An {@link net.dv8tion.jda.api.entities.Invite.Group Invite.Group} object
* An {@link Invite.Group Invite.Group} object
* containing information about this invite's origin group.
*
* @return Information about this invite's origin group or null in case of a guild invite
*
* @see net.dv8tion.jda.api.entities.Invite.Group
* @see Invite.Group
*/
@Nullable
Group getGroup();
Expand All @@ -181,7 +181,7 @@ static RestAction<Invite> resolve(@Nonnull final JDA api, @Nonnull final String
*
* @return Information about this invite's target or {@code null}
*
* @see net.dv8tion.jda.api.entities.Invite.InviteTarget
* @see Invite.InviteTarget
*/
@Nullable
InviteTarget getTarget();
Expand All @@ -207,12 +207,12 @@ default String getUrl()
}

/**
* An {@link net.dv8tion.jda.api.entities.Invite.Guild Invite.Guild} object
* An {@link Invite.Guild Invite.Guild} object
* containing information about this invite's origin guild.
*
* @return Information about this invite's origin guild or null in case of a group invite
*
* @see net.dv8tion.jda.api.entities.Invite.Guild
* @see Invite.Guild
*/
@Nullable
Guild getGuild();
Expand Down Expand Up @@ -461,7 +461,7 @@ default ImageProxy getSplash()
int getMemberCount();

/**
* The Features of the {@link net.dv8tion.jda.api.entities.Invite.Guild Guild}.
* The Features of the {@link Invite.Guild Guild}.
* <p>
* <b>Possible known features:</b>
* <ul>
Expand All @@ -476,6 +476,16 @@ default ImageProxy getSplash()
*/
@Nonnull
Set<String> getFeatures();

/**
* The welcome screen of the {@link Invite.Guild Guild}.
* <br>This will be {@code null} if the Guild has no welcome screen,
* or if the invite came from a {@link net.dv8tion.jda.api.events.guild.invite.GuildInviteCreateEvent GuildInviteCreateEvent}.
*
* @return The welcome screen of this Guild or {@code null}
*/
@Nullable
GuildWelcomeScreen getWelcomeScreen();
}

/**
Expand Down Expand Up @@ -591,7 +601,7 @@ interface InviteTarget
*
* @return The target application of this invite
*
* @see net.dv8tion.jda.api.entities.Invite.EmbeddedApplication
* @see Invite.EmbeddedApplication
*/
@Nullable
EmbeddedApplication getApplication();
Expand Down

0 comments on commit b7505ca

Please sign in to comment.