Search in sources :

Example 16 with DiscordUserService

use of gg.projecteden.nexus.models.discord.DiscordUserService in project Nexus by ProjectEdenGG.

the class IngameBridgeListener method parseMentions.

public static String parseMentions(String message) {
    if (message != null && message.contains("@")) {
        Matcher matcher = Pattern.compile("@[\\w]+").matcher(message);
        while (matcher.find()) {
            String group = matcher.group();
            String search = group.replace("@", "");
            Nerd nerd = new NerdService().findExact(search);
            if (nerd != null) {
                DiscordUser mentioned = new DiscordUserService().get(nerd);
                if (mentioned.getUserId() != null) {
                    message = message.replace(group, "<@" + mentioned.getUserId() + ">");
                } else {
                    Nickname fromNickname = new NicknameService().getFromNickname(search);
                    if (fromNickname != null) {
                        mentioned = new DiscordUserService().get(fromNickname);
                        if (mentioned.getUserId() != null)
                            message = message.replace(group, "<@" + mentioned.getUserId() + ">");
                    }
                }
            }
        }
    }
    return message;
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Matcher(java.util.regex.Matcher) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) NicknameService(gg.projecteden.nexus.models.nickname.NicknameService) Nerd(gg.projecteden.nexus.models.nerd.Nerd) NerdService(gg.projecteden.nexus.models.nerd.NerdService) Nickname(gg.projecteden.nexus.models.nickname.Nickname)

Aggregations

DiscordUserService (gg.projecteden.nexus.models.discord.DiscordUserService)16 DiscordUser (gg.projecteden.nexus.models.discord.DiscordUser)15 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)5 Async (gg.projecteden.annotations.Async)4 Nexus (gg.projecteden.nexus.Nexus)3 Discord (gg.projecteden.nexus.features.discord.Discord)3 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)3 Nickname (gg.projecteden.nexus.models.nickname.Nickname)3 JsonBuilder (gg.projecteden.nexus.utils.JsonBuilder)3 List (java.util.List)3 Role (net.dv8tion.jda.api.entities.Role)3 Component (net.kyori.adventure.text.Component)3 Command (gg.projecteden.discord.appcommands.annotations.Command)2 NexusAppCommand (gg.projecteden.nexus.features.discord.appcommands.NexusAppCommand)2 BadgeUserService (gg.projecteden.nexus.models.badge.BadgeUserService)2 Name (gg.projecteden.nexus.utils.Name)2 DiscordId (gg.projecteden.utils.DiscordId)2 TextChannel (gg.projecteden.utils.DiscordId.TextChannel)2 Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2