[AB-205] making exception message for command not found configurable

making feature config classes more unified in the naming
This commit is contained in:
Sheldan
2021-03-21 22:59:01 +01:00
parent 5eefc3909e
commit f53f0cb66c
44 changed files with 176 additions and 129 deletions

View File

@@ -12,7 +12,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
import dev.sheldan.abstracto.core.service.ChannelService;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.core.utils.FutureUtils;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeature;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureConfig;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureDefinition;
import dev.sheldan.abstracto.entertainment.config.EntertainmentModuleDefinition;
import dev.sheldan.abstracto.entertainment.model.RollResponseModel;
@@ -42,7 +42,7 @@ public class Roll extends AbstractConditionableCommand {
@Override
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
List<Object> parameters = commandContext.getParameters().getParameters();
Integer high = configService.getLongValueOrConfigDefault(EntertainmentFeature.ROLL_DEFAULT_HIGH_KEY, commandContext.getGuild().getIdLong()).intValue();
Integer high = configService.getLongValueOrConfigDefault(EntertainmentFeatureConfig.ROLL_DEFAULT_HIGH_KEY, commandContext.getGuild().getIdLong()).intValue();
Integer low = 1;
if(parameters.size() > 1) {
low = (Integer) parameters.get(1);

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.entertainment.service;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeature;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureConfig;
import net.dv8tion.jda.api.entities.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -45,7 +45,7 @@ public class EntertainmentServiceBean implements EntertainmentService {
@Override
public boolean executeRoulette(Member memberExecuting) {
Long possibilities = configService.getLongValueOrConfigDefault(EntertainmentFeature.ROULETTE_BULLETS_CONFIG_KEY, memberExecuting.getGuild().getIdLong());
Long possibilities = configService.getLongValueOrConfigDefault(EntertainmentFeatureConfig.ROULETTE_BULLETS_CONFIG_KEY, memberExecuting.getGuild().getIdLong());
// 1/possibilities of chance, we don't have a state, each time its reset
return secureRandom.nextInt(possibilities.intValue()) == 0;
}

View File

@@ -20,7 +20,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import static dev.sheldan.abstracto.entertainment.config.EntertainmentFeature.ROLL_DEFAULT_HIGH_KEY;
import static dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureConfig.ROLL_DEFAULT_HIGH_KEY;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

View File

@@ -1,7 +1,7 @@
package dev.sheldan.abstracto.entertainment.service;
import dev.sheldan.abstracto.core.service.ConfigService;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeature;
import dev.sheldan.abstracto.entertainment.config.EntertainmentFeatureConfig;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import org.junit.Assert;
@@ -79,7 +79,7 @@ public class EntertainmentServiceBeanTest {
when(guild.getIdLong()).thenReturn(serverId);
when(member.getGuild()).thenReturn(guild);
Long sides = 6L;
when(configService.getLongValue(EntertainmentFeature.ROULETTE_BULLETS_CONFIG_KEY, serverId)).thenReturn(sides);
when(configService.getLongValue(EntertainmentFeatureConfig.ROULETTE_BULLETS_CONFIG_KEY, serverId)).thenReturn(sides);
when(secureRandom.nextInt(sides.intValue())).thenReturn(randomValue);
boolean shot = testUnit.executeRoulette(member);
Assert.assertEquals(randomValue == 0, shot);

View File

@@ -8,7 +8,7 @@ import java.util.Arrays;
import java.util.List;
@Component
public class EntertainmentFeature implements FeatureConfig {
public class EntertainmentFeatureConfig implements FeatureConfig {
public static final String ROULETTE_BULLETS_CONFIG_KEY = "rouletteBullets";
public static final String ROLL_DEFAULT_HIGH_KEY = "rollDefaultHigh";