Class AbstractMentions
- All Implemented Interfaces:
Mentions
- Direct Known Subclasses:
InteractionMentions
,MessageMentionsImpl
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractMentions
(String content, JDAImpl jda, Guild guild, boolean mentionsEveryone) -
Method Summary
Modifier and TypeMethodDescriptionAn immutable list of all mentionedGuildChannels
.<T extends GuildChannel>
List<T> getChannels
(Class<T> clazz) An immutable list of all mentionedGuildChannels
of typeclazz
.org.apache.commons.collections4.Bag
<GuildChannel> ABag
of mentioned channels.<T extends GuildChannel>
org.apache.commons.collections4.Bag<T> getChannelsBag
(Class<T> clazz) ABag
of mentioned channels of typeclazz
.AllCustomEmojis
used.org.apache.commons.collections4.Bag
<CustomEmoji> ABag
of custom emojis used.getJDA()
The corresponding JDA instanceAn immutable list of all mentionedMembers
.org.apache.commons.collections4.Bag
<Member> ABag
of mentionedMembers
.getMentions
(Message.MentionType... types) Combines all instances ofIMentionable
filtered by the specifiedMentionType
values.getRoles()
An immutable list of all mentionedRoles
.org.apache.commons.collections4.Bag
<Role> ABag
of mentioned roles.An immutable list of all mentionedslash commands
.org.apache.commons.collections4.Bag
<SlashCommandReference> ABag
of mentionedslash commands
.getUsers()
An immutable list of all mentionedUsers
.org.apache.commons.collections4.Bag
<User> ABag
of mentionedUsers
.boolean
isMentioned
(IMentionable mentionable, Message.MentionType... types) Checks if givenIMentionable
was mentioned in any way (@User, @everyone, @here, @Role).boolean
Indicates if everyone is mentioned, by either using@everyone
or@here
.
-
Constructor Details
-
AbstractMentions
-
-
Method Details
-
getJDA
Description copied from interface:Mentions
The corresponding JDA instance -
mentionsEveryone
public boolean mentionsEveryone()Description copied from interface:Mentions
Indicates if everyone is mentioned, by either using@everyone
or@here
.This is different from checking if
@everyone
is in the string, since mentions require additional flags to trigger.- Specified by:
mentionsEveryone
in interfaceMentions
- Returns:
- True, if everyone is mentioned
-
getUsers
Description copied from interface:Mentions
An immutable list of all mentionedUsers
.
If no user was mentioned, this list is empty. Elements are sorted in order of appearance. This only counts direct mentions of the user and not mentions through roles or everyone mentions.This might also contain users which are not present in
Mentions.getMembers()
. -
getUsersBag
Description copied from interface:Mentions
ABag
of mentionedUsers
.
This can be used to retrieve the amount of times a user was mentioned. This only counts direct mentions of the user and not mentions through roles or everyone mentions. The count may be1
, if the user was mentioned through a message reply.This might also contain users which are not present in
Mentions.getMembers()
.Example
void sendCount(Message msg) { List<User> mentions = msg.getMentions().getUsers(); // distinct list, in order of appearance Bag<User> count = msg.getMentions().getUsersBag(); StringBuilder content = new StringBuilder(); for (User user : mentions) { content.append(user.getAsTag()) .append(": ") .append(count.getCount(user)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Specified by:
getUsersBag
in interfaceMentions
- Returns:
Bag
of mentioned users- See Also:
-
getChannels
Description copied from interface:Mentions
An immutable list of all mentionedGuildChannels
.
If none were mentioned, this list is empty. Elements are sorted in order of appearance.This may include GuildChannels from other
Guilds
- Specified by:
getChannels
in interfaceMentions
- Returns:
- Immutable list of mentioned GuildChannels
-
getChannelsBag
Description copied from interface:Mentions
ABag
of mentioned channels.
This can be used to retrieve the amount of times a channel was mentioned.This may include GuildChannels from other
Guilds
Example
void sendCount(Message msg) { Bag<GuildChannel> mentions = msg.getMentions().getChannelsBag(); StringBuilder content = new StringBuilder(); for (GuildChannel channel : mentions.uniqueSet()) { content.append("#") .append(channel.getName()) .append(": ") .append(mentions.getCount(channel)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Specified by:
getChannelsBag
in interfaceMentions
- Returns:
Bag
of mentioned channels- See Also:
-
getChannels
Description copied from interface:Mentions
An immutable list of all mentionedGuildChannels
of typeclazz
.
If none were mentioned, this list is empty. Elements are sorted in order of appearance.This may include GuildChannels from other
Guilds
Example
List<GuildMessageChannel> getCoolMessageChannels(Message msg) { List<GuildMessageChannel> channels = msg.getMentions().getChannels(GuildMessageChannel.class); return channels.stream() .filter(channel -> channel.getName().contains("cool")) .collect(Collectors.toList()); }
- Specified by:
getChannels
in interfaceMentions
- Parameters:
clazz
- TheGuildChannel
sub-classclass object
of the type of channel desired- Returns:
- Immutable list of mentioned GuildChannels that are of type
clazz
.
-
getChannelsBag
@Nonnull public <T extends GuildChannel> org.apache.commons.collections4.Bag<T> getChannelsBag(@Nonnull Class<T> clazz) Description copied from interface:Mentions
ABag
of mentioned channels of typeclazz
.
This can be used to retrieve the amount of times a channel was mentioned.This may include GuildChannels from other
Guilds
Example
void sendCount(Message msg) { Bag<GuildMessageChannel> mentions = msg.getMentions().getChannelsBag(GuildMessageChannel.class); StringBuilder content = new StringBuilder(); for (GuildMessageChannel channel : mentions.uniqueSet()) { content.append("#") .append(channel.getName()) .append(": ") .append(mentions.getCount(channel)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Specified by:
getChannelsBag
in interfaceMentions
- Parameters:
clazz
- TheGuildChannel
sub-classclass object
of the type of channel desired- Returns:
Bag
of mentioned channels of typeclazz
- See Also:
-
getRoles
Description copied from interface:Mentions
-
getRolesBag
Description copied from interface:Mentions
ABag
of mentioned roles.
This can be used to retrieve the amount of times a role was mentioned. This only counts direct mentions of the role and not mentions through everyone mentions.This may include Roles from other
Guilds
Example
void sendCount(Message msg) { List<Role> mentions = msg.getMentions().getRoles(); // distinct list, in order of appearance Bag<Role> count = msg.getMentions().getRolesBag(); StringBuilder content = new StringBuilder(); for (Role role : mentions) { content.append(role.getName()) .append(": ") .append(count.getCount(role)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Specified by:
getRolesBag
in interfaceMentions
- Returns:
Bag
of mentioned roles- See Also:
-
getCustomEmojis
Description copied from interface:Mentions
AllCustomEmojis
used.
This only includes Custom Emojis, not unicode Emojis. These are not the same as the unicode emojis that Discord also supports. Elements are sorted in order of appearance.Unicode emojis are not included as
CustomEmojis
!- Specified by:
getCustomEmojis
in interfaceMentions
- Returns:
- An immutable list of the Custom Emojis used (example match <:jda:230988580904763393>)
-
getCustomEmojisBag
Description copied from interface:Mentions
ABag
of custom emojis used.
This can be used to retrieve the amount of times an emoji was used.Example
void sendCount(Message msg) { List<CustomEmoji> emojis = msg.getMentions().getCustomEmojis(); // distinct list, in order of appearance Bag<CustomEmoji> count = msg.getMentions().getCustomEmojisBag(); StringBuilder content = new StringBuilder(); for (CustomEmoji emoji : emojis) { content.append(emojis.getName()) .append(": ") .append(count.getCount(emoji)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Specified by:
getCustomEmojisBag
in interfaceMentions
- Returns:
Bag
of used custom emojis- See Also:
-
getMembers
Description copied from interface:Mentions
An immutable list of all mentionedMembers
.
If none were mentioned, this list is empty. Elements are sorted in order of appearance. This only counts direct mentions of the role and not mentions through everyone mentions.This is always empty in
PrivateChannels
andGroupChannels
.- Specified by:
getMembers
in interfaceMentions
- Returns:
- Immutable list of mentioned Members, or an empty list
-
getMembersBag
Description copied from interface:Mentions
ABag
of mentionedMembers
.
This can be used to retrieve the amount of times a user was mentioned. This only counts direct mentions of the member and not mentions through roles or everyone mentions. The count may be1
, if the user was mentioned through a message reply.Example
void sendCount(Message msg) { List<Member> mentions = msg.getMentions().getMembers(); // distinct list, in order of appearance Bag<Member> count = msg.getMentions().getMembersBag(); StringBuilder content = new StringBuilder(); for (Member user : mentions) { content.append(member.getUser().getAsTag()) .append(": ") .append(count.getCount(member)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Specified by:
getMembersBag
in interfaceMentions
- Returns:
Bag
of mentioned members- See Also:
-
getSlashCommands
Description copied from interface:Mentions
An immutable list of all mentionedslash commands
.
If none were mentioned, this list is empty. Elements are sorted in order of appearance.Be aware these mentions could be mentioning a non-existent command
- Specified by:
getSlashCommands
in interfaceMentions
- Returns:
- Immutable list of mentioned slash commands, or an empty list
-
getSlashCommandsBag
Description copied from interface:Mentions
ABag
of mentionedslash commands
.
This can be used to retrieve the amount of times a slash commands was mentioned.Be aware these mentions could be mentioning a non-existent command
Example
void sendCount(Message msg) { List<SlashCommandReference> mentions = msg.getMentions().getSlashCommands(); // distinct list, in order of appearance Bag<SlashCommandReference> count = msg.getMentions().getSlashCommandsBag(); StringBuilder content = new StringBuilder(); for (SlashCommandReference commandRef : mentions) { content.append(commandRef.getAsMention()) .append(": ") .append(count.getCount(commandRef)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Specified by:
getSlashCommandsBag
in interfaceMentions
- Returns:
Bag
of mentioned slash commands- See Also:
-
getMentions
Description copied from interface:Mentions
Combines all instances ofIMentionable
filtered by the specifiedMentionType
values.
If aMember
is available, it will be taken in favor of aUser
. This only provides either the Member or the User instance, rather than both.If no MentionType values are given, all types are used.
- Specified by:
getMentions
in interfaceMentions
- Parameters:
types
-MentionTypes
to include- Returns:
- Immutable list of filtered
IMentionable
instances
-
isMentioned
public boolean isMentioned(@Nonnull IMentionable mentionable, @Nonnull Message.MentionType... types) Description copied from interface:Mentions
Checks if givenIMentionable
was mentioned in any way (@User, @everyone, @here, @Role).
If no filteringMentionTypes
are specified, all types are used.MentionType.HERE
andMentionType.EVERYONE
will only be checked, if the givenIMentionable
is of typeUser
orMember
.
Online status of Users/Members is NOT considered when checkingMentionType.HERE
.- Specified by:
isMentioned
in interfaceMentions
- Parameters:
mentionable
- The mentionable entity to check on.types
- The types to include when checking whether this type was mentioned. This will be used withgetMentions(MentionType...)
- Returns:
- True, if the given mentionable was mentioned in this message
-