Search in sources :

Example 1 with ReRoleConsumer

use of com.bot.consumers.ReRoleConsumer 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)

Aggregations

ReRoleConsumer (com.bot.consumers.ReRoleConsumer)1 Trace (datadog.trace.api.Trace)1 Invite (net.dv8tion.jda.api.entities.Invite)1 Member (net.dv8tion.jda.api.entities.Member)1 PrivateChannel (net.dv8tion.jda.api.entities.PrivateChannel)1 Role (net.dv8tion.jda.api.entities.Role)1