mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-30 15:11:38 +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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Changes a value of the bots configuration
|
||||
@@ -0,0 +1 @@
|
||||
Sets a value in the bots configuration to the given value.
|
||||
@@ -0,0 +1 @@
|
||||
setConfig <configKey> <value>
|
||||
@@ -1 +0,0 @@
|
||||
Changes the value of a numerical value of the bots configuration
|
||||
@@ -1 +0,0 @@
|
||||
Sets a numerical value in the bots configuration to the given value.
|
||||
@@ -1 +0,0 @@
|
||||
setNumber <configKey> <value>
|
||||
@@ -1 +0,0 @@
|
||||
Changes the value of a numerical value of the bots configuration
|
||||
@@ -1 +0,0 @@
|
||||
Sets a numerical value in the bots configuration to the given value.
|
||||
@@ -1 +0,0 @@
|
||||
setNumber <configKey> <value>
|
||||
Reference in New Issue
Block a user