mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-08 10:02:27 +00:00
[AB-248] rejecting the everyone role as a valid parameter for a role parameter
This commit is contained in:
@@ -26,12 +26,13 @@ public class RoleParameterHandlerImpl implements RoleParameterHandler {
|
|||||||
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Parameter param, Message context, Command command) {
|
public Object handle(UnparsedCommandParameterPiece input, CommandParameterIterators iterators, Parameter param, Message context, Command command) {
|
||||||
String inputString = ((String) input.getValue()).trim();
|
String inputString = ((String) input.getValue()).trim();
|
||||||
Matcher matcher = Message.MentionType.ROLE.getPattern().matcher(inputString);
|
Matcher matcher = Message.MentionType.ROLE.getPattern().matcher(inputString);
|
||||||
|
Role foundRole;
|
||||||
if(matcher.matches() && iterators.getRoleIterator().hasNext()) {
|
if(matcher.matches() && iterators.getRoleIterator().hasNext()) {
|
||||||
return iterators.getRoleIterator().next();
|
foundRole = iterators.getRoleIterator().next();
|
||||||
} else {
|
} else {
|
||||||
if(NumberUtils.isParsable(inputString)) {
|
if(NumberUtils.isParsable(inputString)) {
|
||||||
long roleId = Long.parseLong(inputString);
|
long roleId = Long.parseLong(inputString);
|
||||||
return context.getGuild().getRoleById(roleId);
|
foundRole = context.getGuild().getRoleById(roleId);
|
||||||
} else {
|
} else {
|
||||||
List<Role> roles = context.getGuild().getRolesByName(inputString, true);
|
List<Role> roles = context.getGuild().getRolesByName(inputString, true);
|
||||||
if(roles.isEmpty()) {
|
if(roles.isEmpty()) {
|
||||||
@@ -40,9 +41,13 @@ public class RoleParameterHandlerImpl implements RoleParameterHandler {
|
|||||||
if(roles.size() > 1) {
|
if(roles.size() > 1) {
|
||||||
throw new AbstractoTemplatedException("Multiple roles found with name.", "multiple_roles_found_by_name_exception");
|
throw new AbstractoTemplatedException("Multiple roles found with name.", "multiple_roles_found_by_name_exception");
|
||||||
}
|
}
|
||||||
return roles.get(0);
|
foundRole = roles.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(foundRole != null && foundRole.isPublicRole()) {
|
||||||
|
throw new AbstractoTemplatedException("Public role cannot be used for role parameter.", "everyone_role_not_allowed_exception");
|
||||||
|
}
|
||||||
|
return foundRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user