Commands no longer require mentioning of roles

This commit is contained in:
Savvy 2017-10-03 09:33:20 -04:00
parent a21ca45a7c
commit 6f1ddc19a9
5 changed files with 22 additions and 18 deletions

View File

@ -33,18 +33,18 @@ public class AddRoleCommand implements CommandExec {
return; return;
} }
String[] messages = event.getMessage().getContent().split(" "); String[] messages = event.getMessage().getContent().split(" ");
List<Member> memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), true);
List<Role> roleList = Utils.roleSearch(event.getGuild(), event.getMessage().getContent());
if (messages.length >= 3) { if (messages.length >= 3) {
if(event.getMessage().getMentionedRoles().size() < 1 || if(memberList.size() < 1 ||
event.getMessage().getMentionedUsers().size() < 1) { roleList.size() < 1) {
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " <role> <user>].").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " <role> <user>].").setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;
} }
try { try {
List<Role> roles = event.getMessage().getMentionedRoles();
int users = event.getMessage().getMentionedUsers().size(); int users = event.getMessage().getMentionedUsers().size();
List<Member> memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), true); memberList.forEach(user -> event.getGuild().getController().addRolesToMember(user, roleList).queue());
memberList.forEach(user -> event.getGuild().getController().addRolesToMember(user, roles).queue()); new MessageBuilder("Successfully given " + users + " `" + roleList.size() + "` role(s)").setColor(event.getMember().getColor()).queue(event.getChannel());
new MessageBuilder("Successfully given " + users + " `" + roles.size() + "` role(s)").setColor(event.getMember().getColor()).queue(event.getChannel());
} catch (PermissionException ex) { } catch (PermissionException ex) {
new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel());
} }

View File

@ -6,6 +6,7 @@ import me.savvy.rixa.commands.handlers.RixaPermission;
import me.savvy.rixa.guild.RixaGuild; import me.savvy.rixa.guild.RixaGuild;
import me.savvy.rixa.guild.management.Guilds; import me.savvy.rixa.guild.management.Guilds;
import me.savvy.rixa.utils.MessageBuilder; import me.savvy.rixa.utils.MessageBuilder;
import me.savvy.rixa.utils.Utils;
import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Role; import net.dv8tion.jda.core.entities.Role;
@ -31,12 +32,13 @@ public class BatchMoveCommand implements CommandExec {
new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", you do not have permission for this command.").setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;
} }
if(event.getMessage().getMentionedRoles().size() < 2) { List<Role> roleList = Utils.roleSearch(event.getGuild(), event.getMessage().getContent());
if(roleList.size() < 2) {
new MessageBuilder("You need to include two roles!").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder("You need to include two roles!").setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;
} }
Role old_role = event.getMessage().getMentionedRoles().get(0); Role old_role = roleList.get(0);
Role new_role = event.getMessage().getMentionedRoles().get(1); Role new_role = roleList.get(1);
List<Member> userWithRole = event.getGuild().getMembersWithRoles(old_role); List<Member> userWithRole = event.getGuild().getMembersWithRoles(old_role);
if(userWithRole.size() == 0) { if(userWithRole.size() == 0) {
new MessageBuilder("There are no users with the role " + old_role.getAsMention()).setColor(old_role.getColor()).queue(event.getChannel()); new MessageBuilder("There are no users with the role " + old_role.getAsMention()).setColor(old_role.getColor()).queue(event.getChannel());

View File

@ -16,7 +16,7 @@ public class InviteCommand implements CommandExec {
@Command( @Command(
description = "Receive an invite from a server", description = "Receive an invite from a server",
type = CommandType.USER, type = CommandType.BOT_OWNER,
channelType = ChannelType.TEXT, channelType = ChannelType.TEXT,
usage = "%pinvite", mainCommand = "invite") usage = "%pinvite", mainCommand = "invite")
public void execute(GuildMessageReceivedEvent event) { public void execute(GuildMessageReceivedEvent event) {

View File

@ -33,18 +33,18 @@ public class RemoveRoleCommand implements CommandExec {
return; return;
} }
String[] messages = event.getMessage().getContent().split(" "); String[] messages = event.getMessage().getContent().split(" ");
List<Member> memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), true);
List<Role> roleList = Utils.roleSearch(event.getGuild(), event.getMessage().getContent());
if (messages.length >= 3) { if (messages.length >= 3) {
if(event.getMessage().getMentionedRoles().size() < 1 || if(roleList.size() < 1 ||
event.getMessage().getMentionedUsers().size() < 1) { memberList.size() < 1) {
new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " <role> <user>].").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", incorrect usage try [" + messages[0] + " <role> <user>].").setColor(event.getMember().getColor()).queue(event.getChannel());
return; return;
} }
try { try {
List<Role> roles = event.getMessage().getMentionedRoles();
int users = event.getMessage().getMentionedUsers().size(); int users = event.getMessage().getMentionedUsers().size();
List<Member> memberList = Utils.memberSearch(event.getGuild(), event.getMessage().getContent(), true); memberList.forEach(user -> event.getGuild().getController().removeRolesFromMember(user, roleList).queue());
memberList.forEach(user -> event.getGuild().getController().removeRolesFromMember(user, roles).queue()); new MessageBuilder("Successfully removed `" + roleList.size() + "` role(s) from " + users + " user(s)!").setColor(event.getMember().getColor()).queue(event.getChannel());
new MessageBuilder("Successfully removed `" + roles.size() + "` role(s) from " + users + " user(s)!").setColor(event.getMember().getColor()).queue(event.getChannel());
} catch (PermissionException ex) { } catch (PermissionException ex) {
new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel()); new MessageBuilder(event.getMember().getAsMention() + ", sorry I do not have permission for this!").setColor(event.getMember().getColor()).queue(event.getChannel());
} }

View File

@ -29,7 +29,7 @@ public class Utils {
|| (member.getEffectiveName().toLowerCase().contains(finalString)) || (member.getEffectiveName().toLowerCase().contains(finalString))
|| finalString.contains(member.getUser().getId()) || finalString.contains(member.getUser().getId())
|| finalString.contains(member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator()) || finalString.contains(member.getUser().getName().toLowerCase() + "#" + member.getUser().getDiscriminator())
|| finalString.contains(member.getEffectiveName()) || finalString.contains(member.getEffectiveName().toLowerCase())
) { ) {
if (!bots && member.getUser().isBot()) continue; if (!bots && member.getUser().isBot()) continue;
@ -44,7 +44,9 @@ public class Utils {
List<Role> roles = new ArrayList<>(); List<Role> roles = new ArrayList<>();
guild.getRoles().forEach(role -> { guild.getRoles().forEach(role -> {
if (role.getName().toLowerCase().contains(string.toLowerCase()) if (role.getName().toLowerCase().contains(string.toLowerCase())
|| string.contains(role.getId())) || string.contains(role.getId())
|| string.toLowerCase().contains(role.getName().toLowerCase())
)
roles.add(role); roles.add(role);
}); });
return roles; return roles;