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