From b7505cac1c1d6e00d51b52f1e63d9b50f57eaa91 Mon Sep 17 00:00:00 2001 From: freya02 <41875020+freya022@users.noreply.github.com> Date: Tue, 6 Dec 2022 16:12:16 +0100 Subject: [PATCH] Add guild welcome screens (#2264) --- .../net/dv8tion/jda/api/entities/Guild.java | 35 +++ .../jda/api/entities/GuildWelcomeScreen.java | 198 +++++++++++++++++ .../net/dv8tion/jda/api/entities/Invite.java | 40 ++-- .../managers/GuildWelcomeScreenManager.java | 202 ++++++++++++++++++ .../jda/internal/entities/EntityBuilder.java | 25 ++- .../jda/internal/entities/GuildImpl.java | 21 ++ .../entities/GuildWelcomeScreenImpl.java | 150 +++++++++++++ .../jda/internal/entities/InviteImpl.java | 19 +- .../GuildWelcomeScreenManagerImpl.java | 169 +++++++++++++++ .../dv8tion/jda/internal/requests/Route.java | 3 + 10 files changed, 840 insertions(+), 22 deletions(-) create mode 100644 src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.java create mode 100644 src/main/java/net/dv8tion/jda/api/managers/GuildWelcomeScreenManager.java create mode 100644 src/main/java/net/dv8tion/jda/internal/entities/GuildWelcomeScreenImpl.java create mode 100644 src/main/java/net/dv8tion/jda/internal/managers/GuildWelcomeScreenManagerImpl.java 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 af21142f8e..0183a3d8e1 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/Guild.java +++ b/src/main/java/net/dv8tion/jda/api/entities/Guild.java @@ -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.*; @@ -2376,6 +2377,26 @@ default RestAction retrieveEmoji(@Nonnull CustomEmoji emoji) @CheckReturnValue RestAction> retrieveWebhooks(); + /** + * Retrieves the {@link GuildWelcomeScreen welcome screen} for this Guild. + *
The welcome screen is shown to all members after joining the Guild. + * + *

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

+ * + * @return {@link RestAction} - Type: {@link GuildWelcomeScreen} + *
The welcome screen for this Guild. + */ + @Nonnull + @CheckReturnValue + RestAction 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}. @@ -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. + *
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(); + ////////////////////////// /** diff --git a/src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.java b/src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.java new file mode 100644 index 0000000000..117943f437 --- /dev/null +++ b/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. + *
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 getChannels(); + + /** + * POJO for the recommended channels information provided by a welcome screen. + *
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 + *
    + *
  • If the channel is null
  • + *
  • If the description is null, blank, or longer than {@value #MAX_DESCRIPTION_LENGTH}
  • + *
+ * + * @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 + *
    + *
  • If the channel is null
  • + *
  • If the description is null, blank, or longer than {@value #MAX_DESCRIPTION_LENGTH}
  • + *
+ * + * @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. + *
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. + *
This will return {@code null} if no emoji was set + * + *

The emoji will always be from this guild, if not a unicode emoji + *
{@link CustomEmoji#isAnimated()} will always return {@code false} if: + *

    + *
  • This welcome screen came from an {@link Invite.Guild invite's guild}
  • + *
  • {@link net.dv8tion.jda.api.utils.cache.CacheFlag#EMOJI CacheFlag.EMOJI} is disabled
  • + *
+ * + * @return The emoji that is used for this recommended channel or {@code null} + */ + @Nullable + EmojiUnion getEmoji(); + } +} 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 9ced26ed0c..86dc67ec99 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/Invite.java +++ b/src/main/java/net/dv8tion/jda/api/entities/Invite.java @@ -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. *
You cannot resolve invites if you were banned from the origin Guild! * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include: @@ -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} *
The Invite object */ @Nonnull @@ -71,7 +71,7 @@ static RestAction 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. *
You cannot resolve invites if you were banned from the origin Guild! * *

Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} include: @@ -87,7 +87,7 @@ static RestAction 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} *
The Invite object */ @Nonnull @@ -111,7 +111,7 @@ static RestAction resolve(@Nonnull final JDA api, @Nonnull final String AuditableRestAction 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. *
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. *
Requires either {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} in the invite's guild or @@ -124,7 +124,7 @@ static RestAction 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} *
The expanded Invite object * * @see #getType() @@ -153,23 +153,23 @@ static RestAction 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(); @@ -181,7 +181,7 @@ static RestAction 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(); @@ -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(); @@ -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}. *

* Possible known features: *

    @@ -476,6 +476,16 @@ default ImageProxy getSplash() */ @Nonnull Set getFeatures(); + + /** + * The welcome screen of the {@link Invite.Guild Guild}. + *
    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(); } /** @@ -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(); diff --git a/src/main/java/net/dv8tion/jda/api/managers/GuildWelcomeScreenManager.java b/src/main/java/net/dv8tion/jda/api/managers/GuildWelcomeScreenManager.java new file mode 100644 index 0000000000..1cad304383 --- /dev/null +++ b/src/main/java/net/dv8tion/jda/api/managers/GuildWelcomeScreenManager.java @@ -0,0 +1,202 @@ +/* + * 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.managers; + +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.GuildWelcomeScreen; +import net.dv8tion.jda.internal.utils.Checks; + +import javax.annotation.CheckReturnValue; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +/** + * Manager providing functionality to update one or more fields for a {@link GuildWelcomeScreen}. + * + *

    Example + *

    {@code
    + * manager.setEnabled(false)
    + *        .setDescription(null)
    + *        .setWelcomeChannels()
    + *        .queue();
    + * manager.setEnabled(true)
    + *        .setDescription("Bot desc")
    + *        .setWelcomeChannels(Arrays.asList(
    + *                GuildWelcomeScreen.Channel.of(rulesChannel, "Read the rules first"),
    + *                GuildWelcomeScreen.Channel.of(generalChannel, "Go have a chat", Emoji.fromUnicode("U+1F4AC"))
    + *        ))
    + *        .queue();
    + * }
    + * + * @see Guild#modifyWelcomeScreen() + */ +public interface GuildWelcomeScreenManager extends Manager +{ + /** Used to reset the enabled field */ + long ENABLED = 1; + /** Used to reset the description field */ + long DESCRIPTION = 1 << 1; + /** Used to reset the channels field */ + long CHANNELS = 1 << 2; + + /** + * The {@link Guild} this Manager's {@link GuildWelcomeScreen} is in. + * + * @return The parent {@link Guild} + */ + @Nonnull + Guild getGuild(); + + /** + * Resets the fields specified by the provided bit-flag pattern. + * You can specify a combination by using a bitwise OR concat of the flag constants. + *
    Example: {@code manager.reset(GuildWelcomeScreenManager.DESCRIPTION | GuildWelcomeScreenManager.CHANNELS);} + * + *

    Flag Constants: + *

      + *
    • {@link #ENABLED}
    • + *
    • {@link #DESCRIPTION}
    • + *
    • {@link #CHANNELS}
    • + *
    + * + * @param fields + * Integer value containing the flags to reset. + * + * @return GuildWelcomeScreenManager for chaining convenience + */ + @Nonnull + @Override + GuildWelcomeScreenManager reset(long fields); + + /** + * Resets the specified fields. + *
    Example: {@code manager.reset(GuildWelcomeScreenManager.DESCRIPTION, GuildWelcomeScreenManager.CHANNELS);} + * + *

    Flag Constants: + *

      + *
    • {@link #ENABLED}
    • + *
    • {@link #DESCRIPTION}
    • + *
    • {@link #CHANNELS}
    • + *
    + * + * @param fields + * Integer value containing the flags to reset. + * + * @return GuildWelcomeScreenManager for chaining convenience + */ + @Nonnull + @Override + GuildWelcomeScreenManager reset(long... fields); + + /** + * Sets the enabled state of the welcome screen. + * + * @param enabled + * {@code True} if the welcome screen should be enabled + * + * @return GuildWelcomeScreenManager for chaining convenience + */ + @Nonnull + @CheckReturnValue + GuildWelcomeScreenManager setEnabled(boolean enabled); + + /** + * Sets the description of the welcome screen. + * + *

    The description must not be longer than {@value GuildWelcomeScreen#MAX_DESCRIPTION_LENGTH} + * + * @param description + * The new description of the welcome screen, or {@code null} to remove the description + * + * @throws IllegalArgumentException + * If the description longer than {@value GuildWelcomeScreen#MAX_DESCRIPTION_LENGTH} + * + * @return GuildWelcomeScreenManager for chaining convenience + */ + @Nonnull + @CheckReturnValue + GuildWelcomeScreenManager setDescription(@Nullable String description); + + /** + * Returns an immutable list of the welcome channels + *
    These channels are those which are being modified, not the ones currently shown on Discord + * + * @return An immutable list of the welcome channels to be set by the manager + */ + @Nonnull + List getWelcomeChannels(); + + /** + * Removes all welcome channels. + * + * @return GuildWelcomeScreenManager for chaining convenience + */ + @Nonnull + @CheckReturnValue + GuildWelcomeScreenManager clearWelcomeChannels(); + + /** + * Sets the welcome channels of the welcome screen. + * + *

    The order of the {@link Collection} defines in what order the channels appear on Discord. + * + * @param channels + * The new welcome channels to use, can be an empty list to remove all welcome channels. + * + * @throws IllegalArgumentException + *

      + *
    • If {@code channels} is {@code null}
    • + *
    • If more than {@value GuildWelcomeScreen#MAX_WELCOME_CHANNELS} welcome channels are set
    • + *
    + * + * @return GuildWelcomeScreenManager for chaining convenience + * + * @see #setWelcomeChannels(GuildWelcomeScreen.Channel...) + */ + @Nonnull + @CheckReturnValue + GuildWelcomeScreenManager setWelcomeChannels(@Nonnull Collection channels); + + /** + * Sets the welcome channels of the welcome screen. + * + *

    The order of the parameters defines in what order the channels appear on Discord. + * + * @param channels + * The new welcome channels to use, you can provide nothing in order to remove all welcome channels. + * + * @throws IllegalArgumentException + *

      + *
    • If {@code channels} is {@code null}
    • + *
    • If more than {@value GuildWelcomeScreen#MAX_WELCOME_CHANNELS} welcome channels are set
    • + *
    + * + * @return GuildWelcomeScreenManager for chaining convenience + * + * @see #setWelcomeChannels(Collection) + */ + @Nonnull + @CheckReturnValue + default GuildWelcomeScreenManager setWelcomeChannels(@Nonnull GuildWelcomeScreen.Channel... channels) + { + Checks.notNull(channels, "Welcome channels"); + return setWelcomeChannels(Arrays.asList(channels)); + } +} 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 93d1b97864..fb3fb6179e 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -2162,7 +2162,11 @@ else if (channelType.isGuild()) else guildFeatures = Collections.unmodifiableSet(StreamSupport.stream(guildObject.getArray("features").spliterator(), false).map(String::valueOf).collect(Collectors.toSet())); - guild = new InviteImpl.GuildImpl(guildId, guildIconId, guildName, guildSplashId, guildVerificationLevel, presenceCount, memberCount, guildFeatures); + final GuildWelcomeScreen welcomeScreen = guildObject.isNull("welcome_screen") + ? null + : createWelcomeScreen(null, guildObject.getObject("welcome_screen")); + + guild = new InviteImpl.GuildImpl(guildId, guildIconId, guildName, guildSplashId, guildVerificationLevel, presenceCount, memberCount, guildFeatures, welcomeScreen); final String channelName = channelObject.getString("name"); final long channelId = channelObject.getLong("id"); @@ -2233,6 +2237,25 @@ else if (channelType.isGuild()) uses, channel, guild, group, target, type); } + public GuildWelcomeScreen createWelcomeScreen(Guild guild, DataObject object) + { + final DataArray welcomeChannelsArray = object.getArray("welcome_channels"); + final List welcomeChannels = new ArrayList<>(welcomeChannelsArray.length()); + for (int i = 0; i < welcomeChannelsArray.length(); i++) + { + final DataObject welcomeChannelObj = welcomeChannelsArray.getObject(i); + final EmojiUnion emoji = createEmoji(welcomeChannelObj, "emoji_name", "emoji_id"); + + welcomeChannels.add(new GuildWelcomeScreenImpl.ChannelImpl( + guild, + welcomeChannelObj.getLong("channel_id"), + welcomeChannelObj.getString("description"), + emoji) + ); + } + return new GuildWelcomeScreenImpl(guild, object.getString("description", null), Collections.unmodifiableList(welcomeChannels)); + } + public Template createTemplate(DataObject object) { final String code = object.getString("code"); diff --git a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java index 3dcb4d8dd3..6c78abff16 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java @@ -46,6 +46,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.*; @@ -65,6 +66,7 @@ import net.dv8tion.jda.internal.managers.AudioManagerImpl; import net.dv8tion.jda.internal.managers.GuildManagerImpl; import net.dv8tion.jda.internal.managers.GuildStickerManagerImpl; +import net.dv8tion.jda.internal.managers.GuildWelcomeScreenManagerImpl; import net.dv8tion.jda.internal.requests.*; import net.dv8tion.jda.internal.requests.restaction.*; import net.dv8tion.jda.internal.requests.restaction.order.CategoryOrderActionImpl; @@ -1329,6 +1331,18 @@ public RestAction