Search in sources :

Example 1 with GuildController

use of net.dv8tion.jda.core.managers.GuildController in project Rubicon by Rubicon-Bot.

the class CommandMoveAll method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    String[] args = parsedCommandInvocation.getArgs();
    Message message = parsedCommandInvocation.getMessage();
    Guild guild = parsedCommandInvocation.getMessage().getGuild();
    if (args.length == 0) {
        return createHelpMessage(parsedCommandInvocation);
    }
    if (!message.getMember().getVoiceState().inVoiceChannel())
        return new MessageBuilder().setEmbed(EmbedUtil.error("Not connected", "Please connect to a voice channel to use this command").build()).build();
    String name;
    name = message.getContentRaw().replace(parsedCommandInvocation.getCommandInvocation(), "");
    name = name.replace(parsedCommandInvocation.getPrefix(), "");
    name = name.substring(1);
    List<VoiceChannel> channels = message.getGuild().getVoiceChannelsByName(name, true);
    if (channels.isEmpty())
        return new MessageBuilder().setEmbed(EmbedUtil.error("Channel not found", "This channel doesen't exist").build()).build();
    VoiceChannel channel = channels.get(0);
    if (channel.equals(message.getMember().getVoiceState().getChannel()))
        return new MessageBuilder().setEmbed(EmbedUtil.error("Same channel", "You are already connected to that channel").build()).build();
    GuildController controller = message.getGuild().getController();
    if (!guild.getSelfMember().hasPermission(Permission.VOICE_MOVE_OTHERS)) {
        return new MessageBuilder().setEmbed(EmbedUtil.error("Cannot move you!", "Cannot move all members in the Channel").build()).build();
    }
    message.getMember().getVoiceState().getChannel().getMembers().forEach(m -> {
        if (!parsedCommandInvocation.getSelfMember().canInteract(m))
            return;
        controller.moveVoiceMember(m, channel).queue();
    });
    return new MessageBuilder().setEmbed(EmbedUtil.success("Connected", "Connected all users in your channel to `" + channel.getName() + "`").build()).build();
}
Also used : GuildController(net.dv8tion.jda.core.managers.GuildController) Message(net.dv8tion.jda.core.entities.Message) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Guild(net.dv8tion.jda.core.entities.Guild)

Example 2 with GuildController

use of net.dv8tion.jda.core.managers.GuildController in project Rubicon by Rubicon-Bot.

the class CommandRole method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    Message message = parsedCommandInvocation.getMessage();
    String[] args = parsedCommandInvocation.getArgs();
    if (args.length < 2 || message.getMentionedUsers().isEmpty())
        return createHelpMessage();
    GuildController controller = message.getGuild().getController();
    Member member = message.getGuild().getMember(message.getMentionedUsers().get(0));
    // Get Role
    int userNameArgsLength = message.getMentionedUsers().get(0).getAsMention().split(" ").length;
    String rolename = args[userNameArgsLength + 1];
    if (member.getGuild().getRolesByName(rolename, true).isEmpty())
        return new MessageBuilder().setEmbed(EmbedUtil.error("Unknown role", "That role doesn't exist").build()).build();
    Role role = member.getGuild().getRolesByName(rolename, true).get(0);
    Member issuer = message.getMember();
    if (!issuer.canInteract(role))
        return new MessageBuilder().setEmbed(EmbedUtil.error("Not permitted", "You are not permitted to assign or remove that role").build()).build();
    if (!message.getGuild().getSelfMember().canInteract(role))
        return new MessageBuilder().setEmbed(EmbedUtil.error("Not permitted", "I'm not permitted to assign or remove that role").build()).build();
    if (args[0].equals("add")) {
        controller.addRolesToMember(member, role).queue();
        return new MessageBuilder().setEmbed(EmbedUtil.success("Assigned role", "Successfully asigned role `" + role.getName() + "` to " + member.getAsMention()).build()).build();
    } else if (args[0].equals("remove")) {
        controller.removeRolesFromMember(member, role).queue();
        return new MessageBuilder().setEmbed(EmbedUtil.success("Removed role", "Successfully removed role `" + role.getName() + "` from " + member.getAsMention()).build()).build();
    } else
        return createHelpMessage();
}
Also used : Role(net.dv8tion.jda.core.entities.Role) GuildController(net.dv8tion.jda.core.managers.GuildController) Message(net.dv8tion.jda.core.entities.Message) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) Member(net.dv8tion.jda.core.entities.Member)

Aggregations

MessageBuilder (net.dv8tion.jda.core.MessageBuilder)2 Message (net.dv8tion.jda.core.entities.Message)2 GuildController (net.dv8tion.jda.core.managers.GuildController)2 Guild (net.dv8tion.jda.core.entities.Guild)1 Member (net.dv8tion.jda.core.entities.Member)1 Role (net.dv8tion.jda.core.entities.Role)1 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)1