merged the config commands into one command for setting the appropriate value

This commit is contained in:
Sheldan
2020-05-11 15:39:11 +02:00
parent e314ec178d
commit 6b37b9e8b7
14 changed files with 32 additions and 66 deletions

View File

@@ -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<Parameter> 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<Parameter> 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)

View File

@@ -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<Parameter> 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;
}
}

View File

@@ -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)) {

View File

@@ -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);
}

View File

@@ -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 <key> <value>`
* 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 <key> <emote>`
* Description: Sets the emote identified by `key` used by Abstracto on this server to `emote`.

View File

@@ -0,0 +1 @@
Sets a value in the bots configuration to the given value.

View File

@@ -1 +0,0 @@
Changes the value of a numerical value of the bots configuration

View File

@@ -1 +0,0 @@
Sets a numerical value in the bots configuration to the given value.

View File

@@ -1 +0,0 @@
Changes the value of a numerical value of the bots configuration

View File

@@ -1 +0,0 @@
Sets a numerical value in the bots configuration to the given value.