Search in sources :

Example 11 with DiscordUserService

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

the class DiscordAppCommand method forcelink.

@Verify
@RequiredRole("Staff")
@Command("Force link a Minecraft and Discord account")
void forcelink(@Desc("Minecraft account") DiscordUser player, @Desc("Discord account") Member discordUser) {
    player.setUserId(discordUser.getId());
    new DiscordUserService().save(player);
    Discord.addRole(discordUser.getId(), DiscordId.Role.VERIFIED);
    Discord.staffLog("**%s** Discord account force linked to **%s** by %s via Discord".formatted(player.getNickname(), player.getNameAndDiscrim(), user().getNickname()));
}
Also used : DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) RequiredRole(gg.projecteden.discord.appcommands.annotations.RequiredRole) Command(gg.projecteden.discord.appcommands.annotations.Command) NexusAppCommand(gg.projecteden.nexus.features.discord.appcommands.NexusAppCommand) Verify(gg.projecteden.nexus.features.discord.appcommands.annotations.Verify)

Example 12 with DiscordUserService

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

the class DiscordAppCommand method link.

@Command("Link your Discord and Minecraft accounts")
void link(@Desc("Minecraft account") DiscordUser player) {
    DiscordUserService service = new DiscordUserService();
    DiscordUser author = service.getFromUserId(member().getId());
    if (author != null)
        // Author already linked
        if (!isNullOrEmpty(player.getUserId()))
            if (author.getUserId().equals(player.getUserId()))
                throw new InvalidInputException("You are already linked to that minecraft account");
            else
                throw new InvalidInputException("That minecraft account is already linked to a different Discord account. Type `/discord unlink` in-game to remove the link.");
        else
            throw new InvalidInputException("You are already linked to a different Minecraft account. Use `/discord unlink` in-game to remove the link.");
    if (!isNullOrEmpty(player.getUserId()))
        // Provided name is already linked
        if (player.getUserId().equals(member().getId()))
            // Lookup by user id failed?
            throw new InvalidInputException("This should never happen <@" + User.GRIFFIN.getId() + ">");
        else
            throw new InvalidInputException("That Minecraft account is already linked to a different discord account. Type `/discord unlink` in-game to remove the link.");
    String code = RandomStringUtils.randomAlphabetic(6);
    Discord.getCodes().put(code, new DiscordUser(player.getUuid(), member().getId()));
    Koda.console("Generated key " + code + " for " + Discord.getName(member().getId()));
    replyEphemeral("Copy and paste the following command into minecraft to confirm the link ```/discord link %s```".formatted(code));
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Command(gg.projecteden.discord.appcommands.annotations.Command) NexusAppCommand(gg.projecteden.nexus.features.discord.appcommands.NexusAppCommand)

Example 13 with DiscordUserService

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

the class DiscordCaptchaListener method onGuildMemberJoin.

@Override
public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
    Tasks.async(() -> {
        final String id = event.getUser().getId();
        DiscordCaptchaService captchaService = new DiscordCaptchaService();
        DiscordCaptcha captcha = captchaService.get0();
        CaptchaResult result = captcha.check(id);
        if (result == CaptchaResult.CONFIRMED) {
            Tasks.waitAsync(1, () -> {
                Discord.addRole(id, Role.NERD);
                DiscordUser user = new DiscordUserService().getFromUserId(id);
                if (user != null)
                    Discord.addRole(id, Role.VERIFIED);
            });
            return;
        }
        Discord.staffLog("**[Captcha]** " + Discord.getName(event.getMember()) + " - Requiring verification");
        captcha.require(id);
        captchaService.save(captcha);
    });
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) DiscordCaptchaService(gg.projecteden.nexus.models.discord.DiscordCaptchaService) CaptchaResult(gg.projecteden.nexus.models.discord.DiscordCaptcha.CaptchaResult) DiscordCaptcha(gg.projecteden.nexus.models.discord.DiscordCaptcha) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService)

Example 14 with DiscordUserService

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

the class BridgeCommand method archive_editMessages_removeReference.

@Async
@Path("archive editMessages removeReference <roleId> [name]")
void archive_editMessages_removeReference(String roleId, String name) {
    if (archive == null)
        error("No archive loaded");
    DiscordUser user = new DiscordUserService().getFromRoleId(roleId);
    if (name == null)
        if (user == null)
            error("Role is not tied to a user, you must provide the name to use");
        else
            name = Nerd.of(user).getName();
    List<String> messageIds = archive.getRoleMap().get(roleId);
    send(PREFIX + "Editing " + messageIds.size() + " messages for user " + name);
    for (String messageId : messageIds) updateRoleMention(roleId, "**" + name + "**", messageId);
    send(json(PREFIX + "Done. Click here to remove the role").command("/bridge archive deleteRole " + roleId));
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Async(gg.projecteden.annotations.Async)

Example 15 with DiscordUserService

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

the class DiscordBridgeListener method onMessageReceived.

@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
    Tasks.sync(() -> {
        Optional<PublicChannel> channel = ChatManager.getChannelByDiscordId(event.getChannel().getId());
        if (!channel.isPresent())
            return;
        if (event.getAuthor().isBot())
            if (!event.getAuthor().getId().equals(User.UBER.getId()))
                return;
        final Message message = event.getMessage();
        String content = stripColor(message.getContentDisplay().trim());
        try {
            content = EmojiParser.parseToAliases(content);
        } catch (Throwable ignore) {
        }
        DiscordChatEvent discordChatEvent = new DiscordChatEvent(event.getMember(), channel.get(), content, content, !message.getAttachments().isEmpty(), channel.get().getPermission());
        if (!discordChatEvent.callEvent()) {
            Tasks.async(() -> message.delete().queue());
            return;
        }
        content = discordChatEvent.getMessage();
        DiscordUser user = new DiscordUserService().getFromUserId(event.getAuthor().getId());
        JsonBuilder builder = new JsonBuilder();
        builder.next(" " + channel.get().getDiscordColor() + "&l>&f");
        if (content.length() > 0)
            builder.next(" " + colorize(content.replaceAll("&", "&&f")));
        for (Message.Attachment attachment : message.getAttachments()) builder.group().next(" &f&l[View Attachment]").url(attachment.getUrl());
        Identity identity = user == null ? Identity.nil() : user.identity();
        Broadcast.ingame().channel(channel.get()).sender(identity).message(viewer -> {
            JsonBuilder json = new JsonBuilder(channel.get().getDiscordColor() + "[D]").hover("&5&lDiscord &fChannel").hover("&fMessages sent in &c#bridge &fon our").hover("&c/discord &fare shown in this channel").group().next(" ").group();
            if (user != null)
                json.next(Nerd.of(user.getUuid()).getChatFormat(viewer == null ? null : new ChatterService().get(viewer)));
            else
                json.next("&f" + Discord.getName(event.getMember(), event.getAuthor()));
            return json.next(builder);
        }).messageType(MessageType.CHAT).send();
    });
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Message(net.dv8tion.jda.api.entities.Message) DiscordChatEvent(gg.projecteden.nexus.features.chat.events.DiscordChatEvent) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Identity(net.kyori.adventure.identity.Identity) ChatterService(gg.projecteden.nexus.models.chat.ChatterService) PublicChannel(gg.projecteden.nexus.models.chat.PublicChannel)

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