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();
}
Aggregations