From 6b37b9e8b7e7554cce8a9269ad22749303b20087 Mon Sep 17 00:00:00 2001 From: Sheldan <5037282+Sheldan@users.noreply.github.com> Date: Mon, 11 May 2020 15:39:11 +0200 Subject: [PATCH] merged the config commands into one command for setting the appropriate value --- .../config/{SetFloat.java => SetConfig.java} | 15 +++--- .../core/commands/config/SetLong.java | 53 ------------------- .../core/service/ConfigServiceBean.java | 17 ++++++ .../abstracto/core/service/ConfigService.java | 1 + .../src/main/docs/asciidoc/features/core.adoc | 3 ++ .../help/setConfig_description_en_US.ftl | 1 + .../help/setConfig_long_help_en_US.ftl | 1 + .../setConfig/help/setConfig_usage_en_US.ftl | 1 + .../help/setFloat_description_en_US.ftl | 1 - .../help/setFloat_long_help_en_US.ftl | 1 - .../setFloat/help/setFloat_usage_en_US.ftl | 1 - .../help/setLong_description_en_US.ftl | 1 - .../setLong/help/setLong_long_help_en_US.ftl | 1 - .../core/setLong/help/setLong_usage_en_US.ftl | 1 - 14 files changed, 32 insertions(+), 66 deletions(-) rename abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/{SetFloat.java => SetConfig.java} (73%) delete mode 100644 abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetLong.java create mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_description_en_US.ftl create mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_long_help_en_US.ftl create mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_usage_en_US.ftl delete mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_description_en_US.ftl delete mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_long_help_en_US.ftl delete mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_usage_en_US.ftl delete mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_description_en_US.ftl delete mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_long_help_en_US.ftl delete mode 100644 abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_usage_en_US.ftl diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetFloat.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetConfig.java similarity index 73% rename from abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetFloat.java rename to abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetConfig.java index aa84a6926..ae27ee240 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetFloat.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetConfig.java @@ -16,28 +16,29 @@ import java.util.Arrays; import java.util.List; @Component -public class SetFloat extends AbstractConditionableCommand { +public class SetConfig extends AbstractConditionableCommand { @Autowired private ConfigService configService; + @Override public CommandResult execute(CommandContext commandContext) { String key = (String) commandContext.getParameters().getParameters().get(0); - Double value = (Double) commandContext.getParameters().getParameters().get(1); - configService.setDoubleValue(key, commandContext.getGuild().getIdLong(), value); + String value = (String) commandContext.getParameters().getParameters().get(1); + configService.setConfigValue(key, commandContext.getGuild().getIdLong(), value); return CommandResult.fromSuccess(); } @Override public CommandConfiguration getConfiguration() { - Parameter channelGroupName = Parameter.builder().name("key").type(String.class).description("The key to change.").build(); - Parameter channelToAdd = Parameter.builder().name("value").type(Double.class).description("The numeric value to use for the config.").build(); - List parameters = Arrays.asList(channelGroupName, channelToAdd); + Parameter keyToChange = Parameter.builder().name("key").type(String.class).description("The key to change.").build(); + Parameter valueToSet = Parameter.builder().name("value").type(String.class).description("The value to set the key to.").build(); + List parameters = Arrays.asList(keyToChange, valueToSet); HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); return CommandConfiguration.builder() - .name("setFloat") + .name("setConfig") .module(ConfigModuleInterface.CONFIG) .parameters(parameters) .templated(true) diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetLong.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetLong.java deleted file mode 100644 index 1f1e79a15..000000000 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/commands/config/SetLong.java +++ /dev/null @@ -1,53 +0,0 @@ -package dev.sheldan.abstracto.core.commands.config; - -import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand; -import dev.sheldan.abstracto.core.command.config.CommandConfiguration; -import dev.sheldan.abstracto.core.command.config.HelpInfo; -import dev.sheldan.abstracto.core.command.config.Parameter; -import dev.sheldan.abstracto.core.command.execution.CommandContext; -import dev.sheldan.abstracto.core.command.execution.CommandResult; -import dev.sheldan.abstracto.core.config.FeatureEnum; -import dev.sheldan.abstracto.core.config.features.CoreFeatures; -import dev.sheldan.abstracto.core.service.ConfigService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; - -@Component -public class SetLong extends AbstractConditionableCommand { - - @Autowired - private ConfigService configService; - - @Override - public CommandResult execute(CommandContext commandContext) { - String key = (String) commandContext.getParameters().getParameters().get(0); - Long value = (Long) commandContext.getParameters().getParameters().get(1); - configService.setLongValue(key, commandContext.getGuild().getIdLong(), value); - - return CommandResult.fromSuccess(); - } - - @Override - public CommandConfiguration getConfiguration() { - Parameter channelGroupName = Parameter.builder().name("key").type(String.class).description("The key to change.").build(); - Parameter channelToAdd = Parameter.builder().name("value").type(Long.class).description("The numeric value to use for the config.").build(); - List parameters = Arrays.asList(channelGroupName, channelToAdd); - HelpInfo helpInfo = HelpInfo.builder().templated(true).build(); - return CommandConfiguration.builder() - .name("setLong") - .module(ConfigModuleInterface.CONFIG) - .parameters(parameters) - .templated(true) - .help(helpInfo) - .causesReaction(true) - .build(); - } - - @Override - public FeatureEnum getFeature() { - return CoreFeatures.CORE_FEATURE; - } -} diff --git a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/service/ConfigServiceBean.java b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/service/ConfigServiceBean.java index 86143bbd1..0fea4e8de 100644 --- a/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/service/ConfigServiceBean.java +++ b/abstracto-application/core/core-impl/src/main/java/dev/sheldan/abstracto/core/service/ConfigServiceBean.java @@ -67,6 +67,23 @@ public class ConfigServiceBean implements ConfigService{ } } + @Override + public void setConfigValue(String name, Long serverId, String value) { + if(configManagementService.configExists(serverId, name)) { + AConfig existing = configManagementService.loadConfig(serverId, name); + if(existing.getDoubleValue() != null) { + setDoubleValue(name, serverId, Double.parseDouble(value)); + } else if(existing.getLongValue() != null) { + setLongValue(name, serverId, Long.parseLong(value)); + } else { + setStringValue(name, serverId, value); + } + } else { + throw new ConfigurationException(String.format("Key %s does not exist.", name)); + } + + } + @Override public void setStringValue(String name, Long serverId, String value) { if(configManagementService.configExists(serverId, name)) { diff --git a/abstracto-application/core/core-interface/src/main/java/dev/sheldan/abstracto/core/service/ConfigService.java b/abstracto-application/core/core-interface/src/main/java/dev/sheldan/abstracto/core/service/ConfigService.java index dd2529a69..3f9fa86aa 100644 --- a/abstracto-application/core/core-interface/src/main/java/dev/sheldan/abstracto/core/service/ConfigService.java +++ b/abstracto-application/core/core-interface/src/main/java/dev/sheldan/abstracto/core/service/ConfigService.java @@ -8,6 +8,7 @@ public interface ConfigService { Long getLongValue(String name, Long serverId, Long defaultValue); void setDoubleValue(String name, Long serverId, Double value); void setLongValue(String name, Long serverId, Long value); + void setConfigValue(String name, Long serverId, String value); void setStringValue(String name, Long serverId, String value); } diff --git a/abstracto-application/documentation/src/main/docs/asciidoc/features/core.adoc b/abstracto-application/documentation/src/main/docs/asciidoc/features/core.adoc index 3ee0b28d5..050d81971 100644 --- a/abstracto-application/documentation/src/main/docs/asciidoc/features/core.adoc +++ b/abstracto-application/documentation/src/main/docs/asciidoc/features/core.adoc @@ -14,6 +14,9 @@ This information includes a description and the available commands of this modul The module matching takes precedence over command matching. This information includes the a short description, a more detailed description, aliases (if any), parameters (if any), which roles are allowed to execute the command, or if it is not restricted and which roles are immune against the command. +Changing the system configuration:: +* Usage `setConfig ` +* Description: Changes the value of this configuration identified by `key` to `value`. Some of these configurations have separate commands, but this works in general. Changing emotes Abstracto uses:: * Usage: `setEmote ` * Description: Sets the emote identified by `key` used by Abstracto on this server to `emote`. diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_description_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_description_en_US.ftl new file mode 100644 index 000000000..89b198df1 --- /dev/null +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_description_en_US.ftl @@ -0,0 +1 @@ +Changes a value of the bots configuration \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_long_help_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_long_help_en_US.ftl new file mode 100644 index 000000000..1fc24bba0 --- /dev/null +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_long_help_en_US.ftl @@ -0,0 +1 @@ +Sets a value in the bots configuration to the given value. \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_usage_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_usage_en_US.ftl new file mode 100644 index 000000000..def1d432d --- /dev/null +++ b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setConfig/help/setConfig_usage_en_US.ftl @@ -0,0 +1 @@ +setConfig \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_description_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_description_en_US.ftl deleted file mode 100644 index cd98b92a6..000000000 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_description_en_US.ftl +++ /dev/null @@ -1 +0,0 @@ -Changes the value of a numerical value of the bots configuration \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_long_help_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_long_help_en_US.ftl deleted file mode 100644 index a62f53500..000000000 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_long_help_en_US.ftl +++ /dev/null @@ -1 +0,0 @@ -Sets a numerical value in the bots configuration to the given value. \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_usage_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_usage_en_US.ftl deleted file mode 100644 index cab8588e0..000000000 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setFloat/help/setFloat_usage_en_US.ftl +++ /dev/null @@ -1 +0,0 @@ -setNumber \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_description_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_description_en_US.ftl deleted file mode 100644 index cd98b92a6..000000000 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_description_en_US.ftl +++ /dev/null @@ -1 +0,0 @@ -Changes the value of a numerical value of the bots configuration \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_long_help_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_long_help_en_US.ftl deleted file mode 100644 index a62f53500..000000000 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_long_help_en_US.ftl +++ /dev/null @@ -1 +0,0 @@ -Sets a numerical value in the bots configuration to the given value. \ No newline at end of file diff --git a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_usage_en_US.ftl b/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_usage_en_US.ftl deleted file mode 100644 index cab8588e0..000000000 --- a/abstracto-application/template-config/src/main/resources/templates/en_US/commands/core/setLong/help/setLong_usage_en_US.ftl +++ /dev/null @@ -1 +0,0 @@ -setNumber \ No newline at end of file