[AB-200] fixing link embeds not working for users who left the server

fixing some issues with optional dependencies (autowired creates null instances etc)
fixing roll and roulette using not the proper default values
fixing setPrefix not creating an instance, in case it originated from a default config
fixing too many configuration properties in utility
This commit is contained in:
Sheldan
2021-03-16 01:18:31 +01:00
parent 94d6497995
commit cfe7786d4d
15 changed files with 87 additions and 84 deletions

View File

@@ -26,7 +26,7 @@ public class SetPrefix extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
String prefixValue = (String) commandContext.getParameters().getParameters().get(0);
configService.setStringValue("prefix", commandContext.getGuild().getIdLong(), prefixValue);
configService.setOrCreateConfigValue("prefix", commandContext.getGuild().getIdLong(), prefixValue);
return CommandResult.fromSuccess();
}

View File

@@ -36,6 +36,9 @@ public class DefaultConfigProperties {
}
private <T> void makeKeysLowerCase(Map<String, T> map) {
if(map == null) {
return;
}
Set<String> keys = new HashSet<>(map.keySet());
List<Pair<String, T>> pairs = new ArrayList<>();
keys.forEach(s ->

View File

@@ -15,11 +15,14 @@ import java.util.Optional;
@Slf4j
public class ConditionServiceBean implements ConditionService {
@Autowired
@Autowired(required = false)
private List<SystemCondition> conditionList;
@Override
public boolean checkConditions(ConditionContextInstance context) {
if(conditionList == null || conditionList.isEmpty()) {
return true;
}
Optional<SystemCondition> matchingCondition = conditionList
.stream()
.filter(systemCondition -> systemCondition.getConditionName().equalsIgnoreCase(context.getConditionName()))

View File

@@ -31,6 +31,11 @@ public class ConfigServiceBean implements ConfigService {
return getLongValue(name, serverId, 0L);
}
@Override
public Long getLongValueOrConfigDefault(String name, Long serverId) {
return getLongValue(name, serverId, defaultConfigManagementService.getDefaultConfig(name).getLongValue());
}
@Override
public Double getDoubleValue(String name, Long serverId, Double defaultValue) {
AConfig config = configManagementService.loadConfig(serverId, name);
@@ -40,6 +45,11 @@ public class ConfigServiceBean implements ConfigService {
return config.getDoubleValue();
}
@Override
public Double getDoubleValueOrConfigDefault(String name, Long serverId, Double defaultValue) {
return getDoubleValue(name, serverId, defaultConfigManagementService.getDefaultConfig(name).getDoubleValue());
}
@Override
public String getStringValue(String name, Long serverId, String defaultValue) {
AConfig config = configManagementService.loadConfig(serverId, name);
@@ -49,6 +59,11 @@ public class ConfigServiceBean implements ConfigService {
return config.getStringValue();
}
@Override
public String getStringValueOrConfigDefault(String name, Long serverId, String defaultValue) {
return getStringValue(name, serverId, defaultConfigManagementService.getDefaultConfig(name).getStringValue());
}
@Override
public Long getLongValue(String name, Long serverId, Long defaultValue) {
AConfig config = configManagementService.loadConfig(serverId, name);

View File

@@ -0,0 +1,19 @@
package dev.sheldan.abstracto.core.service;
import net.dv8tion.jda.api.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
@Component
public class UserServiceBean implements UserService {
@Autowired
private BotService botService;
@Override
public CompletableFuture<User> retrieveUserForId(Long id) {
return botService.getInstance().retrieveUserById(id).submit();
}
}