Search in sources :

Example 1 with CaptchaResult

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

the class DiscordCaptchaKickJob method run.

@Override
protected CompletableFuture<JobStatus> run() {
    String name = Discord.getName(memberId);
    DiscordCaptcha verification = new DiscordCaptchaService().get();
    CaptchaResult result = verification.check(memberId);
    if (result != CaptchaResult.CONFIRMED) {
        Member member = Discord.getGuild().retrieveMemberById(memberId).complete();
        if (member != null) {
            Discord.staffLog("**[Captcha]** " + name + " - Kicking");
            member.kick("Please complete the verification process in your DMs with KodaBear").queue();
        } else
            Nexus.log("[Captcha] Kick scheduled for " + name + " cancelled, member not found");
    }
    return completed();
}
Also used : DiscordCaptchaService(gg.projecteden.nexus.models.discord.DiscordCaptchaService) CaptchaResult(gg.projecteden.nexus.models.discord.DiscordCaptcha.CaptchaResult) DiscordCaptcha(gg.projecteden.nexus.models.discord.DiscordCaptcha) Member(net.dv8tion.jda.api.entities.Member)

Example 2 with CaptchaResult

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

the class DiscordCaptchaListener method onMessageReactionAdd.

@Override
public void onMessageReactionAdd(@Nonnull MessageReactionAddEvent event) {
    Tasks.async(() -> {
        if (event.getChannelType() != ChannelType.PRIVATE)
            return;
        if (event.getUser() == null) {
            Nexus.log("[Captcha] Received reaction from null user");
            return;
        }
        final String id = event.getUser().getId();
        DiscordCaptchaService captchaService = new DiscordCaptchaService();
        DiscordCaptcha captcha = captchaService.get0();
        CaptchaResult result = captcha.check(id);
        if (result == CaptchaResult.UNCONFIRMED) {
            captcha.confirm(id);
            Member member = Discord.getGuild().retrieveMemberById(id).complete();
            PrivateChannel complete = event.getUser().openPrivateChannel().complete();
            if (member == null) {
                Message message = complete.getHistory().getMessageById(event.getMessageId());
                if (message == null)
                    Nexus.warn("[Captcha] Could not find original message");
                else
                    message.editMessage("Account confirmed. You may now join the server again: " + EdenSocialMediaSite.DISCORD.getUrl()).queue();
            } else
                complete.sendMessage("Account confirmed, thank you!").queue();
            captchaService.save(captcha);
        }
    });
}
Also used : PrivateChannel(net.dv8tion.jda.api.entities.PrivateChannel) DiscordCaptchaService(gg.projecteden.nexus.models.discord.DiscordCaptchaService) Message(net.dv8tion.jda.api.entities.Message) CaptchaResult(gg.projecteden.nexus.models.discord.DiscordCaptcha.CaptchaResult) DiscordCaptcha(gg.projecteden.nexus.models.discord.DiscordCaptcha) Member(net.dv8tion.jda.api.entities.Member)

Example 3 with CaptchaResult

use of gg.projecteden.nexus.models.discord.DiscordCaptcha.CaptchaResult 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)

Aggregations

DiscordCaptcha (gg.projecteden.nexus.models.discord.DiscordCaptcha)3 CaptchaResult (gg.projecteden.nexus.models.discord.DiscordCaptcha.CaptchaResult)3 DiscordCaptchaService (gg.projecteden.nexus.models.discord.DiscordCaptchaService)3 Member (net.dv8tion.jda.api.entities.Member)2 DiscordUser (gg.projecteden.nexus.models.discord.DiscordUser)1 DiscordUserService (gg.projecteden.nexus.models.discord.DiscordUserService)1 Message (net.dv8tion.jda.api.entities.Message)1 PrivateChannel (net.dv8tion.jda.api.entities.PrivateChannel)1