mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-09 10:12:19 +00:00
allowed the Arole parameter type to be either an id or the role mention
fixed adding/removing allowed roles, the compare did not work changed a few commands to use the Arole parameter
This commit is contained in:
@@ -53,7 +53,7 @@ public class SetExpRole extends AbstractConditionableCommand {
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("level").type(Integer.class).build());
|
||||
parameters.add(Parameter.builder().name("roleId").type(Long.class).build());
|
||||
parameters.add(Parameter.builder().name("role").type(ARole.class).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("setExpRole")
|
||||
|
||||
@@ -28,8 +28,7 @@ public class UnSetExpRole extends AbstractConditionableCommand {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
Long roleId = (Long) commandContext.getParameters().getParameters().get(0);
|
||||
ARole role = roleManagementService.findRole(roleId);
|
||||
ARole role = (ARole) commandContext.getParameters().getParameters().get(0);
|
||||
// do not check for the existence of the role, because if the role was deleted, users should be able
|
||||
// to get rid of it in the configuration
|
||||
experienceRoleService.unsetRole(role, commandContext.getUserInitiatedContext().getServer(), commandContext.getUserInitiatedContext().getChannel());
|
||||
@@ -39,7 +38,7 @@ public class UnSetExpRole extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
parameters.add(Parameter.builder().name("roleId").type(Long.class).build());
|
||||
parameters.add(Parameter.builder().name("role").type(ARole.class).build());
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("unSetExpRole")
|
||||
|
||||
@@ -1 +1 @@
|
||||
setExpRole <level> <roleId>
|
||||
setExpRole <level> <role>
|
||||
@@ -1 +1 @@
|
||||
unSetExpRole <roleId>
|
||||
unSetExpRole <role>
|
||||
@@ -23,12 +23,10 @@ import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.utils.ParseUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -157,6 +155,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
Iterator<TextChannel> channelIterator = message.getMentionedChannels().iterator();
|
||||
Iterator<Emote> emoteIterator = message.getEmotes().iterator();
|
||||
Iterator<Member> memberIterator = message.getMentionedMembers().iterator();
|
||||
Iterator<Role> roleIterator = message.getMentionedRoles().iterator();
|
||||
Parameter param = command.getConfiguration().getParameters().get(0);
|
||||
boolean reminderActive = false;
|
||||
for (int i = 0; i < unParsedCommandParameter.getParameters().size(); i++) {
|
||||
@@ -189,7 +188,11 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
parsedParameters.add(value);
|
||||
}
|
||||
} else if(param.getType().equals(ARole.class)) {
|
||||
parsedParameters.add(roleManagementService.findRole(Long.parseLong(value)));
|
||||
if(StringUtils.isNumeric(value)) {
|
||||
parsedParameters.add(roleManagementService.findRole(Long.parseLong(value)));
|
||||
} else {
|
||||
parsedParameters.add(roleManagementService.findRole(roleIterator.next().getIdLong()));
|
||||
}
|
||||
} else if(param.getType().equals(Boolean.class)) {
|
||||
parsedParameters.add(Boolean.valueOf(value));
|
||||
} else if (param.getType().equals(Duration.class)) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CommandServiceBean implements CommandService {
|
||||
@Override
|
||||
public void allowCommandForRole(ACommand aCommand, ARole role) {
|
||||
ACommandInAServer commandForServer = commandInServerManagementService.getCommandForServer(aCommand, role.getServer());
|
||||
if(!commandForServer.getAllowedRoles().contains(role)) {
|
||||
if(commandForServer.getAllowedRoles().stream().noneMatch(role1 -> role1.getId().equals(role.getId()))) {
|
||||
commandForServer.getAllowedRoles().add(role);
|
||||
}
|
||||
commandForServer.setRestricted(true);
|
||||
@@ -53,7 +53,7 @@ public class CommandServiceBean implements CommandService {
|
||||
@Override
|
||||
public void makeRoleImmuneForCommand(ACommand aCommand, ARole role) {
|
||||
ACommandInAServer commandForServer = commandInServerManagementService.getCommandForServer(aCommand, role.getServer());
|
||||
if(!commandForServer.getImmuneRoles().contains(role)) {
|
||||
if(commandForServer.getImmuneRoles().stream().noneMatch(role1 -> role1.getId().equals(role.getId()))) {
|
||||
commandForServer.getImmuneRoles().add(role);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class CommandServiceBean implements CommandService {
|
||||
@Override
|
||||
public void makeRoleAffectedByCommand(ACommand aCommand, ARole role) {
|
||||
ACommandInAServer commandForServer = commandInServerManagementService.getCommandForServer(aCommand, role.getServer());
|
||||
commandForServer.getImmuneRoles().remove(role);
|
||||
commandForServer.getImmuneRoles().removeIf(role1 -> role1.getId().equals(role.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,7 +80,7 @@ public class CommandServiceBean implements CommandService {
|
||||
public void disAllowCommandForRole(ACommand aCommand, ARole role) {
|
||||
ACommandInAServer commandForServer = commandInServerManagementService.getCommandForServer(aCommand, role.getServer());
|
||||
commandForServer.setRestricted(true);
|
||||
commandForServer.getAllowedRoles().remove(role);
|
||||
commandForServer.getAllowedRoles().removeIf(role1 -> role1.getId().equals(role.getId()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ public class AllowRole extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
String name = (String) commandContext.getParameters().getParameters().get(0);
|
||||
Long roleId = (Long) commandContext.getParameters().getParameters().get(1);
|
||||
ARole role = roleManagementService.findRole(roleId);
|
||||
ARole role = (ARole) commandContext.getParameters().getParameters().get(1);
|
||||
if(featureManagementService.featureExists(name)) {
|
||||
AFeature feature = featureManagementService.getFeature(name);
|
||||
feature.getCommands().forEach(command ->
|
||||
@@ -59,7 +58,7 @@ public class AllowRole extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter featureName = Parameter.builder().name("feature|commandName").type(String.class).description("The command/feature the role should be able to execute.").build();
|
||||
Parameter role = Parameter.builder().name("roleId").type(Long.class).description("The roleId to allow it for.").build();
|
||||
Parameter role = Parameter.builder().name("role").type(ARole.class).description("The role to allow it for.").build();
|
||||
List<Parameter> parameters = Arrays.asList(featureName, role);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
|
||||
@@ -40,8 +40,7 @@ public class DisAllowRole extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
String name = (String) commandContext.getParameters().getParameters().get(0);
|
||||
Long roleId = (Long) commandContext.getParameters().getParameters().get(1);
|
||||
ARole role = roleManagementService.findRole(roleId);
|
||||
ARole role = (ARole) commandContext.getParameters().getParameters().get(1);
|
||||
if(featureManagementService.featureExists(name)) {
|
||||
AFeature feature = featureManagementService.getFeature(name);
|
||||
feature.getCommands().forEach(command ->
|
||||
@@ -59,7 +58,7 @@ public class DisAllowRole extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter featureName = Parameter.builder().name("feature|commandName").type(String.class).description("The command/feature the role should not be able to execute.").build();
|
||||
Parameter role = Parameter.builder().name("roleId").type(Long.class).description("The roleId to disallow it for.").build();
|
||||
Parameter role = Parameter.builder().name("role").type(ARole.class).description("The roleId to disallow it for.").build();
|
||||
List<Parameter> parameters = Arrays.asList(featureName, role);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MakeAffected extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter featureName = Parameter.builder().name("feature|commandName").type(String.class).description("The command/feature name to make the role affected by.").build();
|
||||
Parameter role = Parameter.builder().name("roleId").type(Long.class).description("The roleId to make affected.").build();
|
||||
Parameter role = Parameter.builder().name("role").type(ARole.class).description("The role to make affected.").build();
|
||||
List<Parameter> parameters = Arrays.asList(featureName, role);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
|
||||
@@ -40,8 +40,7 @@ public class MakeImmune extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
String name = (String) commandContext.getParameters().getParameters().get(0);
|
||||
Long roleId = (Long) commandContext.getParameters().getParameters().get(1);
|
||||
ARole role = roleManagementService.findRole(roleId);
|
||||
ARole role = (ARole) commandContext.getParameters().getParameters().get(1);
|
||||
if(featureManagementService.featureExists(name)) {
|
||||
AFeature feature = featureManagementService.getFeature(name);
|
||||
feature.getCommands().forEach(command ->
|
||||
@@ -59,7 +58,7 @@ public class MakeImmune extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter featureName = Parameter.builder().name("feature|commandName").type(String.class).description("The command/feature name to make the role immune for.").build();
|
||||
Parameter role = Parameter.builder().name("roleId").type(Long.class).description("The roleId to make immune.").build();
|
||||
Parameter role = Parameter.builder().name("role").type(ARole.class).description("The roleId to make immune.").build();
|
||||
List<Parameter> parameters = Arrays.asList(featureName, role);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
Allows the role to execute all commands in the given feature or the command directly.
|
||||
In case the names coincide, the the feature will be taken first. The restriction of commands to certain roles is only in effect, if the command is restricted (see `restrict`).
|
||||
When executing this command, the affected commands are automatically set to restricted.
|
||||
When executing this command, the affected commands are automatically set to restricted.
|
||||
The provided role can either be a role ID or a the mention of the role.
|
||||
@@ -1 +1 @@
|
||||
allowRole <command/feature> <roleId>
|
||||
allowRole <command/feature> <role>
|
||||
@@ -1,4 +1,5 @@
|
||||
Forbids the role to execute all commands in the given feature or the command directly.
|
||||
Does nothing in case the role was not allowed in the first place.
|
||||
In case the names coincide, the the feature will be taken first. The restriction of commands to certain roles is only in effect, if the command is restricted (see `restrict`).
|
||||
When executing this command, the affected commands are automatically set to restricted.
|
||||
When executing this command, the affected commands are automatically set to restricted.
|
||||
The provided role can either be a role ID or a the mention of the role.
|
||||
@@ -1 +1 @@
|
||||
disAllowRole <command/feature> <roleId>
|
||||
disAllowRole <command/feature> <role>
|
||||
@@ -1,4 +1,5 @@
|
||||
Makes the given role affected by certain commands like `ban`, `warn` or `mute`.
|
||||
When a feature name is used, all commands of this feature will be changed.
|
||||
Not all commands actually support this functionality.
|
||||
By default all roles are affected by the commands.
|
||||
By default all roles are affected by the commands.
|
||||
The provided role can either be a role ID or a the mention of the role.
|
||||
@@ -1 +1 @@
|
||||
makeAffected <feature/command> roleId
|
||||
makeAffected <feature/command> <role>
|
||||
@@ -1,4 +1,5 @@
|
||||
Makes the given role immune to certain commands like `ban`, `warn` or `mute`.
|
||||
When a feature name is used, all commands of this feature will be changed.
|
||||
Not all commands actually support this functionality.
|
||||
By default all roles are affected by the commands.
|
||||
By default all roles are affected by the commands.
|
||||
The provided role can either be a role ID or a the mention of the role.
|
||||
@@ -1 +1 @@
|
||||
makeImmune <feature/command> roleId
|
||||
makeImmune <feature/command> <role>
|
||||
Reference in New Issue
Block a user