Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c01b74c
Steal #1989
freya022 Sep 27, 2022
f7084bc
Add Guild object to GuildWelcomeScreen and GuildWelcomeScreen.Channel…
freya022 Sep 27, 2022
11b6215
Use EmojiUnion
freya022 Sep 27, 2022
4841160
Return null channel on null guild
freya022 Sep 27, 2022
2b957e1
Docs, give emoji from guild's cache if available
freya022 Sep 28, 2022
8bb4afd
Add welcome screen manager
freya022 Sep 29, 2022
31c41aa
Some docs
freya022 Sep 30, 2022
f04737d
More docs
freya022 Sep 30, 2022
98dd7e9
Use constants
freya022 Sep 30, 2022
c2e3004
Remove addWelcomeChannel and removeWelcomeChannel as their name do no…
freya022 Sep 30, 2022
fc90ef6
Finish docs
freya022 Sep 30, 2022
e26e40a
Fix docs
freya022 Sep 30, 2022
718c160
Apply suggestions from code review
freya022 Oct 19, 2022
bd03e1f
Merge branch 'master' into feature/welcome-screen
freya022 Oct 19, 2022
8def12e
Update src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.…
freya022 Oct 19, 2022
19bc4cf
Null checks
freya022 Oct 19, 2022
f798dfb
Check 5 channels max
freya022 Oct 19, 2022
9b5d70b
`Boolean` be gone
freya022 Oct 19, 2022
ba6d8ef
Preallocate array
freya022 Oct 19, 2022
8f547a6
Use createEmoji
freya022 Oct 19, 2022
3abea81
Typo
freya022 Oct 19, 2022
014165d
Consistency
freya022 Oct 19, 2022
bc05057
Nuke GuildWelcomeScreenManager#clearDescription
freya022 Oct 19, 2022
71fafd5
Separate GuildWelcomeScreen impl
freya022 Oct 19, 2022
ab14823
Separate GuildWelcomeScreen.Channel impl
freya022 Oct 19, 2022
65bdcd5
Fix example
freya022 Oct 20, 2022
b8938ea
Add GuildWelcomeScreen#getManager
freya022 Oct 20, 2022
b406c79
Specify null welcome screen if invite came from an event
freya022 Oct 20, 2022
511d69a
Update src/main/java/net/dv8tion/jda/api/managers/GuildWelcomeScreenM…
freya022 Oct 20, 2022
f6b8cd6
Fix compile
freya022 Oct 20, 2022
2523e5e
Merge branch 'master' into feature/welcome-screen
freya022 Oct 23, 2022
6b1ab93
Merge branch 'master' into feature/welcome-screen
freya022 Nov 10, 2022
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
35 changes: 35 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Original file line number Diff line number Diff line change
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 @@ -2269,6 +2270,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 @@ -4676,6 +4697,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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading