-
-
Notifications
You must be signed in to change notification settings - Fork 751
Add guild welcome screens #2264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MinnDevelopment
merged 32 commits into
discord-jda:master
from
freya022:feature/welcome-screen
Dec 6, 2022
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
c01b74c
Steal #1989
freya022 f7084bc
Add Guild object to GuildWelcomeScreen and GuildWelcomeScreen.Channel…
freya022 11b6215
Use EmojiUnion
freya022 4841160
Return null channel on null guild
freya022 2b957e1
Docs, give emoji from guild's cache if available
freya022 8bb4afd
Add welcome screen manager
freya022 31c41aa
Some docs
freya022 f04737d
More docs
freya022 98dd7e9
Use constants
freya022 c2e3004
Remove addWelcomeChannel and removeWelcomeChannel as their name do no…
freya022 fc90ef6
Finish docs
freya022 e26e40a
Fix docs
freya022 718c160
Apply suggestions from code review
freya022 bd03e1f
Merge branch 'master' into feature/welcome-screen
freya022 8def12e
Update src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.…
freya022 19bc4cf
Null checks
freya022 f798dfb
Check 5 channels max
freya022 9b5d70b
`Boolean` be gone
freya022 ba6d8ef
Preallocate array
freya022 8f547a6
Use createEmoji
freya022 3abea81
Typo
freya022 014165d
Consistency
freya022 bc05057
Nuke GuildWelcomeScreenManager#clearDescription
freya022 71fafd5
Separate GuildWelcomeScreen impl
freya022 ab14823
Separate GuildWelcomeScreen.Channel impl
freya022 65bdcd5
Fix example
freya022 b8938ea
Add GuildWelcomeScreen#getManager
freya022 b406c79
Specify null welcome screen if invite came from an event
freya022 511d69a
Update src/main/java/net/dv8tion/jda/api/managers/GuildWelcomeScreenM…
freya022 f6b8cd6
Fix compile
freya022 2523e5e
Merge branch 'master' into feature/welcome-screen
freya022 6b1ab93
Merge branch 'master' into feature/welcome-screen
freya022 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
src/main/java/net/dv8tion/jda/api/entities/GuildWelcomeScreen.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.