Search in sources :

Example 11 with PrivateChannel

use of net.dv8tion.jda.api.entities.PrivateChannel in project Vinny by kikkia.

the class MemeKickCommand method executeCommand.

@Override
@Trace(operationName = "executeCommand", resourceName = "Memekick")
protected void executeCommand(CommandEvent commandEvent) {
    if (commandEvent.getMessage().getMentionedUsers().size() == 0) {
        commandEvent.replyWarning("You must specify at least one user to memekick");
    }
    for (Member member : commandEvent.getMessage().getMentionedMembers()) {
        if (member.getUser().isBot()) {
            commandEvent.replyWarning("I will not memekick bots");
            continue;
        }
        Invite invite = commandEvent.getTextChannel().createInvite().setMaxUses(1).complete();
        try {
            PrivateChannel channel = member.getUser().openPrivateChannel().complete();
            channel.sendMessage(invite.getUrl()).queue();
        } catch (Exception e) {
            commandEvent.replyWarning("Will not meme kick user: " + member.getEffectiveName() + " because I cannot send " + "them an invite to get back");
            continue;
        }
        List<Role> roles = member.getRoles();
        try {
            member.kick().queue();
        } catch (Exception e) {
            commandEvent.replyWarning("Failed to kick " + member.getEffectiveName() + " make sure the Vinny role is higher on the role hierarchy");
            continue;
        }
        waiter.waitForEvent(GuildMemberJoinEvent.class, e -> e.getUser().getId().equals(member.getUser().getId()), new ReRoleConsumer(roles, commandEvent.getTextChannel()), 1, TimeUnit.DAYS, () -> {
        });
    }
    commandEvent.reactSuccess();
}
Also used : PrivateChannel(net.dv8tion.jda.api.entities.PrivateChannel) Role(net.dv8tion.jda.api.entities.Role) ReRoleConsumer(com.bot.consumers.ReRoleConsumer) Member(net.dv8tion.jda.api.entities.Member) Invite(net.dv8tion.jda.api.entities.Invite) Trace(datadog.trace.api.Trace)

Example 12 with PrivateChannel

use of net.dv8tion.jda.api.entities.PrivateChannel 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 13 with PrivateChannel

use of net.dv8tion.jda.api.entities.PrivateChannel in project dDiscordBot by DenizenScript.

the class DiscordMessageReceivedScriptEvent method getContext.

@Override
public ObjectTag getContext(String name) {
    switch(name) {
        case "channel":
            return new DiscordChannelTag(botID, getEvent().getChannel());
        case "group":
            if (getEvent().isFromGuild()) {
                return new DiscordGroupTag(botID, getEvent().getGuild());
            }
            break;
        case "new_message":
            return new DiscordMessageTag(botID, getEvent().getMessage());
        case "message":
            DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
            return new ElementTag(getEvent().getMessage().getContentRaw());
        case "message_id":
            DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
            return new ElementTag(getEvent().getMessage().getId());
        case "no_mention_message":
            DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
            return new ElementTag(DiscordMessageTag.stripMentions(getEvent().getMessage().getContentRaw()));
        case "formatted_message":
            DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
            return new ElementTag(getEvent().getMessage().getContentDisplay());
        case "author":
            DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
            return new DiscordUserTag(botID, getEvent().getMessage().getAuthor());
        case "mentions":
            DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
            ListTag list = new ListTag();
            for (User user : getEvent().getMessage().getMentionedUsers()) {
                list.addObject(new DiscordUserTag(botID, user));
            }
            return list;
        case "is_direct":
            DenizenDiscordBot.oldMessageContexts.warn((TagContext) null);
            return new ElementTag(getEvent().getChannel() instanceof PrivateChannel);
    }
    return super.getContext(name);
}
Also used : PrivateChannel(net.dv8tion.jda.api.entities.PrivateChannel) DiscordUserTag(com.denizenscript.ddiscordbot.objects.DiscordUserTag) User(net.dv8tion.jda.api.entities.User) DiscordChannelTag(com.denizenscript.ddiscordbot.objects.DiscordChannelTag) DiscordGroupTag(com.denizenscript.ddiscordbot.objects.DiscordGroupTag) DiscordMessageTag(com.denizenscript.ddiscordbot.objects.DiscordMessageTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Aggregations

PrivateChannel (net.dv8tion.jda.api.entities.PrivateChannel)13 User (net.dv8tion.jda.api.entities.User)5 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)4 Message (net.dv8tion.jda.api.entities.Message)4 Arrays (java.util.Arrays)3 JDA (net.dv8tion.jda.api.JDA)3 TextChannel (net.dv8tion.jda.api.entities.TextChannel)3 MessageReactionAddEvent (net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent)3 DiscordChannelTag (com.denizenscript.ddiscordbot.objects.DiscordChannelTag)2 DiscordGroupTag (com.denizenscript.ddiscordbot.objects.DiscordGroupTag)2 DiscordMessageTag (com.denizenscript.ddiscordbot.objects.DiscordMessageTag)2 DiscordUserTag (com.denizenscript.ddiscordbot.objects.DiscordUserTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 Ban (com.gamebuster19901.excite.bot.audit.ban.Ban)2 Logger (com.yuhtin.lauren.core.logger.Logger)2 Player (com.yuhtin.lauren.core.player.Player)2 PlayerController (com.yuhtin.lauren.core.player.controller.PlayerController)2 EventWaiter (com.yuhtin.lauren.models.objects.EventWaiter)2 TaskHelper (com.yuhtin.lauren.utils.TaskHelper)2