Package com.mewna.catnip.entity.message
Class MessageOptions
java.lang.Object
com.mewna.catnip.entity.message.MessageOptions
Options used for creating a new message.
- Since:
- 10/10/2018
- Author:
- SamOphis
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddComponent
(ActionRow component) Adds the specified row to the message.Adds a file, used when sending messages.Adds raw data/a file, used when sending messages.Adds a file, used when sending messages.addFile
(String name, InputStream stream) Adds an input stream/file, used when sending messages.clear()
Resets this MessageOptions class back to its initial state where there is no content, no embeds or no files.components
(List<MessageComponent> components) content()
embeds()
files()
Constructs a new immutable list containing all of the raw file data.flags()
A set of flags that can be set on this message.boolean
hasFiles()
Checks to see whether or not this MessageOptions instance has any files attached.Nullifies theroles
set to mark as mention all.Nullifies theusers
set to mark as mention all.A whitelist of mentioned roles.A whitelist of mentioned users.mentionMember
(Member member) Adds a user to the mention whitelist.mentionMembers
(Member... users) Adds users to the mention whitelist.mentionMembers
(Collection<Member> users) Adds users to the mention whitelist.Clearsroles
or sets it to an empty set to mark as mention none.Clearsusers
or sets it to an empty set to mark as mention none.mentionRole
(Role role) Adds a role to the mention whitelist.mentionRoleById
(long id) Adds a role to the mention whitelist.Adds a role to the mention whitelist.mentionRoles
(Role... roles) Adds roles to the mention whitelist.mentionRoles
(Collection<Role> roles) Adds roles to the mention whitelist.mentionRolesById
(long... roles) Adds roles to the mention whitelist.mentionRolesById
(String... roles) Adds roles to the mention whitelist.mentionRolesById
(Collection<String> roles) Adds roles to the mention whitelist.mentionUser
(User user) Adds a user to the mention whitelist.mentionUserById
(long id) Adds a user to the mention whitelist.Adds a user to the mention whitelist.mentionUsers
(User... users) Adds users to the mention whitelist.mentionUsers
(Collection<User> users) Adds users to the mention whitelist.mentionUsersById
(long... users) Adds users to the mention whitelist.mentionUsersById
(String... users) Adds users to the mention whitelist.mentionUsersById
(Collection<String> users) Adds users to the mention whitelist.boolean
override()
Whether or not to forcibly set fields even if they aren't set (read: are null).override
(boolean override) Whether or not to forcibly set fields even if they aren't set (read: are null).Nullifies theparse flags
set to mark as mention all.Restricts who get mentioned by this message.parseMention
(MentionParseFlag flag) Add a restriction on who gets mentioned by this message.parseMentionByName
(String flag) Add a restriction on who gets mentioned by this message.parseMentions
(MentionParseFlag... flags) Add a restriction on who gets mentioned by this message.parseMentions
(Collection<MentionParseFlag> flags) Add a restriction on who gets mentioned by this message.parseMentionsByName
(String... flags) Add a restriction on who gets mentioned by this message.parseMentionsByName
(Collection<String> flags) Add a restriction on who gets mentioned by this message.Clearsparse flags
or sets it to an empty set to mark as mention none.boolean
Whether or not the message should ping the person it is replying to.pingReply
(boolean pingReply) Whether or not the message should ping the person it is replying to.A reference to the message to reply to.referenceMessage
(MessageReference reference) Sets the reference on this message.withFlags
(Set<MessageFlag> flags) Set flags on this message.
-
Constructor Details
-
MessageOptions
-
MessageOptions
-
MessageOptions
public MessageOptions()
-
-
Method Details
-
addFile
Adds a file, used when sending messages. Files are NOT added to constructedMessage
instances.The name of the file/attachment is taken from
File.getName()
.- Parameters:
file
- A non-null, existing, readableFile
instance.- Returns:
- Itself.
- See Also:
-
addFile
Adds a file, used when sending messages. Files are NOT added to constructedMessage
instances.This allows you to specify a custom name for the file, unlike
addFile(File)
.- Parameters:
name
- A not-null name for the file.file
- A not-null, existing, readableFile
instance.- Returns:
- Itself.
- See Also:
-
addFile
@CheckReturnValue @Nonnull public MessageOptions addFile(@Nonnull String name, @Nonnull InputStream stream) Adds an input stream/file, used when sending messages. Files are NOT added to constructedMessage
instances.This allows you to specify a custom name for the input stream data, unlike
addFile(File)
.- Parameters:
name
- A not-null name for the file.stream
- A not-null, readableInputStream
.- Returns:
- Itself.
- See Also:
-
referenceMessage
@Nonnull @CheckReturnValue public MessageOptions referenceMessage(@Nullable MessageReference reference) Sets the reference on this message. Reference may be null. Used for things like inline replies. [- Parameters:
reference
- The nullable reference to set- Returns:
- Itself.
-
withFlags
Set flags on this message. Flags are used for things like embed suppression.- Parameters:
flags
- The flags to set, or an empty set for none.- Returns:
- Itself.
-
addFile
@CheckReturnValue @Nonnull public MessageOptions addFile(@Nonnull String name, @Nonnull byte[] data) Adds raw data/a file, used when sending messages. Files are NOT added to constructedMessage
instances.This allows you to specify a custom name for the raw data, unlike
addFile(File)
.- Parameters:
name
- A not-null name for the file.data
- A not-null byte array containing the raw data for the file.- Returns:
- Itself.
- See Also:
-
hasFiles
@CheckReturnValue public boolean hasFiles()Checks to see whether or not this MessageOptions instance has any files attached.This should be used over
!files().isEmpty()
because it doesn't construct a new list for each read.- Returns:
- True or false.
-
files
@CheckReturnValue @Nonnull public List<org.apache.commons.lang3.tuple.ImmutablePair<String,byte[]>> files()Constructs a new immutable list containing all of the raw file data. Each immutable pair contains the name and the data buffer.This method is expensive! It constructs a new list each time and should be used sparingly.
- Returns:
- A copy of the raw file list.
-
parseNoMentions
Clearsparse flags
or sets it to an empty set to mark as mention none. This may be overwritten byuser
androle
mention whitelists.- Returns:
- Itself.
-
parseAllMentions
Nullifies theparse flags
set to mark as mention all. This may be overwritten byuser
androle
mention whitelists.- Returns:
- Itself.
-
parseMentionsByName
Add a restriction on who gets mentioned by this message. This does NOT get added to constructedMessage
instances.- Parameters:
flags
- A collection of mentions to allow parsing for.- Returns:
- Itself.
-
parseMentionsByName
Add a restriction on who gets mentioned by this message. This does NOT get added to constructedMessage
instances.- Parameters:
flags
- An array of mentions to allow parsing for.- Returns:
- Itself.
-
parseMentions
Add a restriction on who gets mentioned by this message. This does NOT get added to constructedMessage
instances.- Parameters:
flags
- A collection of mentions to allow parsing for.- Returns:
- Itself.
-
parseMentions
Add a restriction on who gets mentioned by this message. This does NOT get added to constructedMessage
instances.- Parameters:
flags
- An array of mentions to allow parsing for.- Returns:
- Itself.
-
parseMentionByName
Add a restriction on who gets mentioned by this message. This does NOT get added to constructedMessage
instances.- Parameters:
flag
- A mention to allow parsing for.- Returns:
- Itself.
-
parseMention
Add a restriction on who gets mentioned by this message. This does NOT get added to constructedMessage
instances.- Parameters:
flag
- A mention to allow parsing for.- Returns:
- Itself.
-
mentionNoUsers
Clearsusers
or sets it to an empty set to mark as mention none. This has no effect ifusers
is present in theparse flags
set.- Returns:
- Itself.
-
mentionAllUsers
Nullifies theusers
set to mark as mention all. This has no effect ifusers
is present in theparse flags
set.- Returns:
- Itself.
-
mentionMembers
Adds users to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
users
- A collection of members to add.- Returns:
- Itself.
-
mentionMembers
Adds users to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
users
- An array of members to add.- Returns:
- Itself.
-
mentionUsers
Adds users to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
users
- A collection of users to add.- Returns:
- Itself.
-
mentionUsers
Adds users to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
users
- An array of users to add.- Returns:
- Itself.
-
mentionUsersById
Adds users to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set. There is NO validation of if any of these strings are a proper snowflake.- Parameters:
users
- A collection of user IDs to add.- Returns:
- Itself.
-
mentionUsersById
Adds users to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set. There is NO validation of if any of these strings are a proper snowflake.- Parameters:
users
- An array of user IDs to add.- Returns:
- Itself.
-
mentionUsersById
Adds users to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
users
- An array of user IDs to add.- Returns:
- Itself.
-
mentionMember
Adds a user to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
member
- A member to add.- Returns:
- Itself.
-
mentionUser
Adds a user to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
user
- A user to add.- Returns:
- Itself.
-
mentionUserById
Adds a user to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set. There is NO validation of if the string is a proper snowflake.- Parameters:
id
- A user ID to add.- Returns:
- Itself.
-
mentionUserById
Adds a user to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set.- Parameters:
id
- A user ID to add.- Returns:
- Itself.
-
mentionedUsers
A whitelist of mentioned users. Mentions returned from here are NOT added to constructedMessage
instances. This list has no effect ifusers
is present in theparse flags
set. There is NO validation of if any of the strings are a proper snowflake.- Returns:
- Mutable whitelist of user IDs, or null for all.
-
mentionNoRoles
Clearsroles
or sets it to an empty set to mark as mention none. This has no effect ifroles
is present in theparse flags
set.- Returns:
- Itself.
-
mentionAllRoles
Nullifies theroles
set to mark as mention all. This has no effect ifroles
is present in theparse flags
set.- Returns:
- Itself.
-
mentionRoles
Adds roles to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set.- Parameters:
roles
- A collection of roles to add.- Returns:
- Itself.
-
mentionRoles
Adds roles to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set.- Parameters:
roles
- An array of roles to add.- Returns:
- Itself.
-
mentionRolesById
Adds roles to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set. There is NO validation of if any of the strings are a proper snowflake.- Parameters:
roles
- A collection of role IDs to add.- Returns:
- Itself.
-
mentionRolesById
Adds roles to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set. There is NO validation of if any of the strings are a proper snowflake.- Parameters:
roles
- An array of role IDs to add.- Returns:
- Itself.
-
mentionRolesById
Adds roles to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set.- Parameters:
roles
- An array of role IDs to add.- Returns:
- Itself.
-
mentionRole
Adds a role to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set.- Parameters:
role
- A role to add.- Returns:
- Itself.
-
mentionRoleById
Adds a role to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set. There is NO validation of if the string is a proper snowflake.- Parameters:
id
- An ID for a role to add.- Returns:
- Itself.
-
mentionRoleById
Adds a role to the mention whitelist. Mentions are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set.- Parameters:
id
- A role ID to add.- Returns:
- Itself.
-
mentionedRoles
A whitelist of mentioned roles. Mentions returned from here are NOT added to constructedMessage
instances. This list has no effect ifroles
is present in theparse flags
set. There is NO validation of if any of the strings are a proper snowflake.- Returns:
- Mutable whitelist of roles IDs, or null for all.
-
clear
Resets this MessageOptions class back to its initial state where there is no content, no embeds or no files.- Returns:
- Itself (but with a clean state).
-
addEmbed
-
addComponent
Adds the specified row to the message. Currently, onlyActionRow
s can be top-level components.- Parameters:
component
- The component to add.- Returns:
- Itself.
-
buildMessage
Constructs a newMessage
from the content andEmbed
this MessageOptions class stores.Creating messages this way does NOT include the added files, only the content and the embed. Try to pass the actual options class instead of a
Message
when sending messages, as otherwise you'll be performing unnecessary operations. -
content
-
embeds
-
parseFlags
Restricts who get mentioned by this message. This does NOT get added to constructedmessage
instances. Set toan empty enum set
orclear
to disable all parsing of mentions except for whitelisteduser
androle
mentions. Set to null to allow all mentions. This may be overwritten byuser
androle
mention whitelists. -
flags
A set of flags that can be set on this message. Flags are used for a number of things, including, but not limited to:- Indicating if a message is crossposted
- Indicating if a message is urgent
- Suppressing embeds on a message
-
reference
A reference to the message to reply to. Setting this will make the message be created as an inline reply. -
pingReply
@CheckReturnValue @Nullable public boolean pingReply()Whether or not the message should ping the person it is replying to. This is useless ifreference
is not set. -
override
@CheckReturnValue @Nullable public boolean override()Whether or not to forcibly set fields even if they aren't set (read: are null). -
components
-
content
- Returns:
this
.
-
pingReply
Whether or not the message should ping the person it is replying to. This is useless ifreference
is not set.- Returns:
this
.
-
override
Whether or not to forcibly set fields even if they aren't set (read: are null).- Returns:
this
.
-
components
- Returns:
this
.
-