mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +00:00
merged the config commands into one command for setting the appropriate value
This commit is contained in:
@@ -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)
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user