diff --git a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/SetExpRole.java b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/SetExpRole.java index 886f74323..97afdb984 100644 --- a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/SetExpRole.java +++ b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/SetExpRole.java @@ -53,7 +53,7 @@ public class SetExpRole extends AbstractConditionableCommand { public CommandConfiguration getConfiguration() { List 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") diff --git a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/UnSetExpRole.java b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/UnSetExpRole.java index 90312d9f7..0542786ee 100644 --- a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/UnSetExpRole.java +++ b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/java/dev/sheldan/abstracto/experience/commands/UnSetExpRole.java @@ -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 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") diff --git a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/setExpRole/setExpRole_usage_en_US.ftl b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/setExpRole/setExpRole_usage_en_US.ftl index 948b85275..6bbb4cfdd 100644 --- a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/setExpRole/setExpRole_usage_en_US.ftl +++ b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/setExpRole/setExpRole_usage_en_US.ftl @@ -1 +1 @@ -setExpRole \ No newline at end of file +setExpRole \ No newline at end of file diff --git a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/unSetExpRole/unSetExpRole_usage_en_US.ftl b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/unSetExpRole/unSetExpRole_usage_en_US.ftl index b6e218cd0..b95ee1ee0 100644 --- a/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/unSetExpRole/unSetExpRole_usage_en_US.ftl +++ b/abstracto-application/abstracto-modules/experience-tracking/experience-tracking-impl/src/main/resources/templates/commands/unSetExpRole/unSetExpRole_usage_en_US.ftl @@ -1 +1 @@ -unSetExpRole \ No newline at end of file +unSetExpRole \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/CommandReceivedHandler.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/CommandReceivedHandler.java index f77370d61..e37085df6 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/CommandReceivedHandler.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/CommandReceivedHandler.java @@ -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 channelIterator = message.getMentionedChannels().iterator(); Iterator emoteIterator = message.getEmotes().iterator(); Iterator memberIterator = message.getMentionedMembers().iterator(); + Iterator 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)) { diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/service/CommandServiceBean.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/service/CommandServiceBean.java index 84cb7336a..97cef6b67 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/service/CommandServiceBean.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/command/service/CommandServiceBean.java @@ -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())); } diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/AllowRole.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/AllowRole.java index fbb401290..6bffe7cc9 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/AllowRole.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/AllowRole.java @@ -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 parameters = Arrays.asList(featureName, role); HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); return CommandConfiguration.builder() diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/DisAllowRole.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/DisAllowRole.java index 1e37ffddd..e6ed68630 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/DisAllowRole.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/DisAllowRole.java @@ -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 parameters = Arrays.asList(featureName, role); HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); return CommandConfiguration.builder() diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeAffected.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeAffected.java index daee2618a..5c2888e98 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeAffected.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeAffected.java @@ -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 parameters = Arrays.asList(featureName, role); HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); return CommandConfiguration.builder() diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeImmune.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeImmune.java index 38d034885..a2b1431b6 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeImmune.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/features/MakeImmune.java @@ -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 parameters = Arrays.asList(featureName, role); HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); return CommandConfiguration.builder() diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_long_help_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_long_help_en_US.ftl index 67b89e911..f2975e27d 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_long_help_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_long_help_en_US.ftl @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_usage_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_usage_en_US.ftl index 006dd4823..606833232 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_usage_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/allowRole/allowRole_usage_en_US.ftl @@ -1 +1 @@ -allowRole \ No newline at end of file +allowRole \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_long_help_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_long_help_en_US.ftl index aee1afe79..b34aa64d3 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_long_help_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_long_help_en_US.ftl @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_usage_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_usage_en_US.ftl index 67b0e86a5..30e2ac447 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_usage_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/disAllowRole/disAllowRole_usage_en_US.ftl @@ -1 +1 @@ -disAllowRole \ No newline at end of file +disAllowRole \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_long_help_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_long_help_en_US.ftl index 606ac0f71..1f2d3f93b 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_long_help_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_long_help_en_US.ftl @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_usage_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_usage_en_US.ftl index 8eaafe098..1214b73d4 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_usage_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeAffected/makeAffected_usage_en_US.ftl @@ -1 +1 @@ -makeAffected roleId \ No newline at end of file +makeAffected \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_long_help_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_long_help_en_US.ftl index 17ee22fef..31305b9de 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_long_help_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_long_help_en_US.ftl @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_usage_en_US.ftl b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_usage_en_US.ftl index c6f13bf45..4ddfaa2d3 100644 --- a/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_usage_en_US.ftl +++ b/abstracto-application/core/core-impl/src/main/resources/seedData/templates/coreCommands/makeImmune/makeImmune_usage_en_US.ftl @@ -1 +1 @@ -makeImmune roleId \ No newline at end of file +makeImmune \ No newline at end of file