mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-10 01:19:07 +00:00
[AB-205] making exception message for command not found configurable
making feature config classes more unified in the naming
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
@@ -8,7 +8,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class LinkEmbedFeature implements FeatureConfig {
|
||||
public class LinkEmbedFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.moderation.job;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeatureConfig;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
@@ -31,7 +31,7 @@ public class WarnDecayJob extends QuartzJobBean {
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private WarningDecayFeature warningDecayFeature;
|
||||
private WarningDecayFeatureConfig warningDecayFeatureConfig;
|
||||
|
||||
@Autowired
|
||||
private WarnService warnService;
|
||||
@@ -42,7 +42,7 @@ public class WarnDecayJob extends QuartzJobBean {
|
||||
List<AServer> allServers = serverManagementService.getAllServers();
|
||||
log.info("Executing warn decay job.");
|
||||
allServers.forEach(server -> {
|
||||
boolean featureEnabled = featureFlagService.isFeatureEnabled(warningDecayFeature, server);
|
||||
boolean featureEnabled = featureFlagService.isFeatureEnabled(warningDecayFeatureConfig, server);
|
||||
if(featureEnabled) {
|
||||
log.info("Executing warn decay for server {}.", server.getId());
|
||||
warnService.decayWarningsForServer(server);
|
||||
|
||||
@@ -11,7 +11,7 @@ import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeatureConfig;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.mode.WarnDecayMode;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.mode.WarningMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttarget.WarnDecayPostTarget;
|
||||
@@ -130,8 +130,8 @@ public class WarnServiceBean implements WarnService {
|
||||
@Override
|
||||
@Transactional
|
||||
public CompletableFuture<Void> decayWarningsForServer(AServer server) {
|
||||
Long defaultDays = defaultConfigManagementService.getDefaultConfig(WarningDecayFeature.DECAY_DAYS_KEY).getLongValue();
|
||||
Long days = configService.getLongValue(WarningDecayFeature.DECAY_DAYS_KEY, server.getId(), defaultDays);
|
||||
Long defaultDays = defaultConfigManagementService.getDefaultConfig(WarningDecayFeatureConfig.DECAY_DAYS_KEY).getLongValue();
|
||||
Long days = configService.getLongValue(WarningDecayFeatureConfig.DECAY_DAYS_KEY, server.getId(), defaultDays);
|
||||
Instant cutOffDay = Instant.now().minus(days, ChronoUnit.DAYS);
|
||||
log.info("Decaying warnings on server {} which are older than {}.", server.getId(), cutOffDay);
|
||||
List<Warning> warningsToDecay = warnManagementService.getActiveWarningsInServerOlderThan(server, cutOffDay);
|
||||
|
||||
@@ -8,7 +8,7 @@ import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeatureConfig;
|
||||
import dev.sheldan.abstracto.moderation.model.template.command.MyWarningsModel;
|
||||
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
|
||||
import org.junit.Assert;
|
||||
@@ -35,7 +35,7 @@ public class MyWarningsTest {
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Mock
|
||||
private WarningDecayFeature warningDecayFeature;
|
||||
private WarningDecayFeatureConfig warningDecayFeatureConfig;
|
||||
|
||||
@Mock
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.moderation.job;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeatureConfig;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -34,7 +34,7 @@ public class WarnDecayJobTest {
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Mock
|
||||
private WarningDecayFeature warningDecayFeature;
|
||||
private WarningDecayFeatureConfig warningDecayFeatureConfig;
|
||||
|
||||
@Mock
|
||||
private WarnService warnService;
|
||||
@@ -52,7 +52,7 @@ public class WarnDecayJobTest {
|
||||
public void executeJobForNoServers() throws JobExecutionException {
|
||||
when(serverManagementService.getAllServers()).thenReturn(Collections.emptyList());
|
||||
testUnit.executeInternal(null);
|
||||
verify(featureFlagService, times(0)).isFeatureEnabled(eq(warningDecayFeature), any(AServer.class));
|
||||
verify(featureFlagService, times(0)).isFeatureEnabled(eq(warningDecayFeatureConfig), any(AServer.class));
|
||||
verify(warnService, times(0)).decayWarningsForServer(any(AServer.class));
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class WarnDecayJobTest {
|
||||
public void executeJobForAEnabledServer() throws JobExecutionException {
|
||||
when(firstServer.getId()).thenReturn(SERVER_ID);
|
||||
when(serverManagementService.getAllServers()).thenReturn(Arrays.asList(firstServer));
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeature, firstServer)).thenReturn(true);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeatureConfig, firstServer)).thenReturn(true);
|
||||
testUnit.executeInternal(null);
|
||||
verify(warnService, times(1)).decayWarningsForServer(eq(firstServer));
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class WarnDecayJobTest {
|
||||
@Test
|
||||
public void executeJobForADisabledServer() throws JobExecutionException {
|
||||
when(serverManagementService.getAllServers()).thenReturn(Arrays.asList(firstServer));
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeature, firstServer)).thenReturn(false);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeatureConfig, firstServer)).thenReturn(false);
|
||||
testUnit.executeInternal(null);
|
||||
verify(warnService, times(0)).decayWarningsForServer(eq(firstServer));
|
||||
}
|
||||
@@ -77,8 +77,8 @@ public class WarnDecayJobTest {
|
||||
public void executeJobForMixedServers() throws JobExecutionException {
|
||||
when(firstServer.getId()).thenReturn(SERVER_ID);
|
||||
when(serverManagementService.getAllServers()).thenReturn(Arrays.asList(firstServer, secondServer));
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeature, firstServer)).thenReturn(true);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeature, secondServer)).thenReturn(false);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeatureConfig, firstServer)).thenReturn(true);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeatureConfig, secondServer)).thenReturn(false);
|
||||
testUnit.executeInternal(null);
|
||||
verify(warnService, times(1)).decayWarningsForServer(eq(firstServer));
|
||||
}
|
||||
@@ -88,8 +88,8 @@ public class WarnDecayJobTest {
|
||||
when(firstServer.getId()).thenReturn(SERVER_ID);
|
||||
when(secondServer.getId()).thenReturn(SERVER_ID_2);
|
||||
when(serverManagementService.getAllServers()).thenReturn(Arrays.asList(firstServer, secondServer));
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeature, firstServer)).thenReturn(true);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeature, secondServer)).thenReturn(true);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeatureConfig, firstServer)).thenReturn(true);
|
||||
when(featureFlagService.isFeatureEnabled(warningDecayFeatureConfig, secondServer)).thenReturn(true);
|
||||
testUnit.executeInternal(null);
|
||||
ArgumentCaptor<AServer> serverCaptor = ArgumentCaptor.forClass(AServer.class);
|
||||
verify(warnService, times(2)).decayWarningsForServer(serverCaptor.capture());
|
||||
|
||||
@@ -10,7 +10,7 @@ import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementServ
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.ModerationFeatureDefinition;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.WarningDecayFeatureConfig;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.mode.WarnDecayMode;
|
||||
import dev.sheldan.abstracto.moderation.config.feature.mode.WarningMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttarget.WarningPostTarget;
|
||||
@@ -254,8 +254,8 @@ public class WarnServiceBeanTest {
|
||||
SystemConfigProperty defaultDecayDays = Mockito.mock(SystemConfigProperty.class);
|
||||
Long defaultDayCount = 4L;
|
||||
when(defaultDecayDays.getLongValue()).thenReturn(defaultDayCount);
|
||||
when(defaultConfigManagementService.getDefaultConfig(WarningDecayFeature.DECAY_DAYS_KEY)).thenReturn(defaultDecayDays);
|
||||
when(configService.getLongValue(WarningDecayFeature.DECAY_DAYS_KEY, SERVER_ID, defaultDayCount)).thenReturn(5L);
|
||||
when(defaultConfigManagementService.getDefaultConfig(WarningDecayFeatureConfig.DECAY_DAYS_KEY)).thenReturn(defaultDecayDays);
|
||||
when(configService.getLongValue(WarningDecayFeatureConfig.DECAY_DAYS_KEY, SERVER_ID, defaultDayCount)).thenReturn(5L);
|
||||
List<Warning> warnings = Arrays.asList(firstWarning, secondWarning);
|
||||
when(memberService.getMemberInServerAsync(warningUser)).thenReturn(CompletableFuture.completedFuture(warningMember));
|
||||
when(memberService.getMemberInServerAsync(firstWarnedUser)).thenReturn(CompletableFuture.completedFuture(warnedMember));
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class InviteFilterFeature implements FeatureConfig {
|
||||
public class InviteFilterFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ModerationFeatureDefinition.INVITE_FILTER;
|
||||
@@ -10,7 +10,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class LoggingFeature implements FeatureConfig {
|
||||
public class LoggingFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -12,7 +12,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ModerationFeature implements FeatureConfig {
|
||||
public class ModerationFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -12,7 +12,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class MutingFeature implements FeatureConfig {
|
||||
public class MutingFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class UserNoteFeature implements FeatureConfig {
|
||||
public class UserNoteFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return ModerationFeatureDefinition.USER_NOTES;
|
||||
@@ -13,12 +13,12 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class WarningDecayFeature implements FeatureConfig {
|
||||
public class WarningDecayFeatureConfig implements FeatureConfig {
|
||||
|
||||
public static final String DECAY_DAYS_KEY = "decayDays";
|
||||
@Autowired
|
||||
private WarningFeature warningFeature;
|
||||
|
||||
@Autowired
|
||||
private WarningFeatureConfig warningFeatureConfig;
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -32,7 +32,7 @@ public class WarningDecayFeature implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public List<FeatureConfig> getRequiredFeatures() {
|
||||
return Arrays.asList(warningFeature);
|
||||
return Arrays.asList(warningFeatureConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -13,10 +13,10 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class WarningFeature implements FeatureConfig {
|
||||
public class WarningFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Autowired
|
||||
private WarningDecayFeature warningDecayFeature;
|
||||
private WarningDecayFeatureConfig warningDecayFeatureConfig;
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -25,7 +25,7 @@ public class WarningFeature implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public List<FeatureConfig> getDependantFeatures() {
|
||||
return Arrays.asList(warningDecayFeature);
|
||||
return Arrays.asList(warningDecayFeatureConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.modmail.condition.ModMailContextCondition;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeatureConfig;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeatureDefinition;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailMode;
|
||||
import dev.sheldan.abstracto.modmail.model.database.ModMailThread;
|
||||
@@ -26,7 +27,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* This command closes a mod mail thread without logging the closing and the contents of the {@link ModMailThread}.
|
||||
* This command is only available if the server has the {@link dev.sheldan.abstracto.modmail.config.ModMailFeature}
|
||||
* This command is only available if the server has the {@link ModMailFeatureConfig}
|
||||
* 'LOGGING' mode enabled, because else the normal close command behaves the same way.
|
||||
*/
|
||||
@Component
|
||||
|
||||
@@ -18,7 +18,7 @@ import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeature;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeatureConfig;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeatureDefinition;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailMode;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailPostTargets;
|
||||
@@ -109,7 +109,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private ModMailFeature modMailFeature;
|
||||
private ModMailFeatureConfig modMailFeatureConfig;
|
||||
|
||||
@Autowired
|
||||
private ModMailRoleManagementService modMailRoleManagementService;
|
||||
@@ -295,7 +295,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
AUserInAServer aUserInAServer = knownServers.get(i);
|
||||
// only take the servers in which mod mail is actually enabled, would not make much sense to make the
|
||||
// other servers available
|
||||
if(featureFlagService.isFeatureEnabled(modMailFeature, aUserInAServer.getServerReference())) {
|
||||
if(featureFlagService.isFeatureEnabled(modMailFeatureConfig, aUserInAServer.getServerReference())) {
|
||||
AServer serverReference = aUserInAServer.getServerReference();
|
||||
FullGuild guild = FullGuild
|
||||
.builder()
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
* General instance of {@link FeatureConfig} to establish the mod mail feature
|
||||
*/
|
||||
@Component
|
||||
public class ModMailFeature implements FeatureConfig {
|
||||
public class ModMailFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Autowired
|
||||
private ModMailFeatureValidator modMailFeatureValidator;
|
||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RemindFeature implements FeatureConfig {
|
||||
public class RemindFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -8,7 +8,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class RepostDetectionFeature implements FeatureConfig {
|
||||
public class RepostDetectionFeatureConfig implements FeatureConfig {
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return RepostDetectionFeatureDefinition.REPOST_DETECTION;
|
||||
@@ -8,7 +8,7 @@ import dev.sheldan.abstracto.core.metric.service.MetricTag;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedReactions;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.listener.ReactionAddedModel;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeature;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureConfig;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureDefinition;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -33,7 +33,7 @@ public class StarAddedListener extends StarboardListener implements AsyncReactio
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Long serverId = model.getServerId();
|
||||
AEmote aEmote = emoteService.getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, serverId);
|
||||
AEmote aEmote = emoteService.getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, serverId);
|
||||
if(emoteService.isReactionEmoteAEmote(model.getReaction().getReactionEmote(), aEmote)) {
|
||||
metricService.incrementCounter(STARBOARD_STARS_ADDED);
|
||||
log.info("User {} in server {} reacted with star to put a message {} from channel {} on starboard.",
|
||||
|
||||
@@ -9,7 +9,7 @@ import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedReactions;
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.listener.ReactionRemovedModel;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeature;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureConfig;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureDefinition;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -37,7 +37,7 @@ public class StarRemovedListener extends StarboardListener implements AsyncReact
|
||||
return DefaultListenerResult.IGNORED;
|
||||
}
|
||||
Long guildId = model.getServerId();
|
||||
AEmote aEmote = emoteService.getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, guildId);
|
||||
AEmote aEmote = emoteService.getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, guildId);
|
||||
if(emoteService.isReactionEmoteAEmote(model.getReaction().getReactionEmote(), aEmote)) {
|
||||
metricService.incrementCounter(STARBOARD_STARS_REMOVED);
|
||||
log.info("User {} in server {} removed star reaction from message {} on starboard.",
|
||||
|
||||
@@ -16,7 +16,7 @@ import dev.sheldan.abstracto.core.service.management.UserInServerManagementServi
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeature;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureConfig;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardPostTarget;
|
||||
import dev.sheldan.abstracto.starboard.model.database.StarboardPost;
|
||||
import dev.sheldan.abstracto.starboard.model.template.*;
|
||||
@@ -261,19 +261,19 @@ public class StarboardServiceBean implements StarboardService {
|
||||
}
|
||||
|
||||
private String buildBadgeName(Integer position) {
|
||||
return StarboardFeature.STAR_BADGE_EMOTE_PREFIX + position;
|
||||
return StarboardFeatureConfig.STAR_BADGE_EMOTE_PREFIX + position;
|
||||
}
|
||||
|
||||
private String getAppropriateEmote(Long serverId, Integer starCount) {
|
||||
int maxLevels = defaultConfigManagementService.getDefaultConfig(StarboardFeature.STAR_LEVELS_CONFIG_KEY).getLongValue().intValue();
|
||||
int maxLevels = defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LEVELS_CONFIG_KEY).getLongValue().intValue();
|
||||
for(int i = maxLevels; i > 0; i--) {
|
||||
String key = StarboardFeature.STAR_LVL_CONFIG_PREFIX + i;
|
||||
String key = StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + i;
|
||||
SystemConfigProperty defaultStars = defaultConfigManagementService.getDefaultConfig(key);
|
||||
Long starMinimum = configService.getLongValue(key, serverId, defaultStars.getLongValue());
|
||||
if(starCount >= starMinimum) {
|
||||
return emoteService.getUsableEmoteOrDefault(serverId, StarboardFeature.STAR_EMOTE_PREFIX + i);
|
||||
return emoteService.getUsableEmoteOrDefault(serverId, StarboardFeatureConfig.STAR_EMOTE_PREFIX + i);
|
||||
}
|
||||
}
|
||||
return emoteService.getUsableEmoteOrDefault(serverId, StarboardFeature.STAR_EMOTE_PREFIX);
|
||||
return emoteService.getUsableEmoteOrDefault(serverId, StarboardFeatureConfig.STAR_EMOTE_PREFIX);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import dev.sheldan.abstracto.core.models.listener.ReactionAddedModel;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.management.ConfigManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeature;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureConfig;
|
||||
import dev.sheldan.abstracto.starboard.model.database.StarboardPost;
|
||||
import dev.sheldan.abstracto.starboard.service.StarboardService;
|
||||
import dev.sheldan.abstracto.starboard.service.management.StarboardPostManagementService;
|
||||
@@ -110,7 +110,7 @@ public class StarAddedListenerTest {
|
||||
when(model.getMessage()).thenReturn(cachedMessage);
|
||||
when(model.getUserReacting()).thenReturn(serverUserActing);
|
||||
testUnit.execute(model);
|
||||
verify(emoteService, times(0)).getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(0)).getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,7 +124,7 @@ public class StarAddedListenerTest {
|
||||
when(model.getReaction()).thenReturn(reaction);
|
||||
when(reaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
testUnit.execute(model);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(0)).getReactionFromMessageByEmote(any(CachedMessage.class), eq(starEmote));
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class StarAddedListenerTest {
|
||||
when(cachedMessage.getAuthor()).thenReturn(cachedAuthor);
|
||||
when(reaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
when(emoteService.isReactionEmoteAEmote(reactionEmote, starEmote)).thenReturn(true);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID)).thenReturn(starEmote);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID)).thenReturn(starEmote);
|
||||
when(serverUserActing.getUserId()).thenReturn(USER_ACTING_ID);
|
||||
when(serverUserActing.getServerId()).thenReturn(SERVER_ID);
|
||||
when(starboardPostManagementService.findByMessageId(MESSAGE_ID)).thenReturn(Optional.ofNullable(postToUse));
|
||||
@@ -197,7 +197,7 @@ public class StarAddedListenerTest {
|
||||
when(model.getReaction()).thenReturn(reaction);
|
||||
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||
testUnit.execute(model);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(1)).getReactionFromMessageByEmote(cachedMessage, starEmote);
|
||||
}
|
||||
|
||||
@@ -205,6 +205,6 @@ public class StarAddedListenerTest {
|
||||
when(cachedAuthor.getAuthorId()).thenReturn(authorId);
|
||||
when(cachedMessage.getAuthor()).thenReturn(cachedAuthor);
|
||||
when(reaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, serverId)).thenReturn(starEmote);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, serverId)).thenReturn(starEmote);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import dev.sheldan.abstracto.core.models.listener.ReactionRemovedModel;
|
||||
import dev.sheldan.abstracto.core.service.EmoteService;
|
||||
import dev.sheldan.abstracto.core.service.management.ConfigManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeature;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureConfig;
|
||||
import dev.sheldan.abstracto.starboard.model.database.StarboardPost;
|
||||
import dev.sheldan.abstracto.starboard.service.StarboardService;
|
||||
import dev.sheldan.abstracto.starboard.service.management.StarboardPostManagementService;
|
||||
@@ -112,7 +112,7 @@ public class StarRemovedListenerTest {
|
||||
when(model.getMessage()).thenReturn(cachedMessage);
|
||||
when(model.getUserRemoving()).thenReturn(serverUserActing);
|
||||
testUnit.execute(model);
|
||||
verify(emoteService, times(0)).getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(0)).getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,7 +125,7 @@ public class StarRemovedListenerTest {
|
||||
when(reaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||
testUnit.execute(model);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(0)).getReactionFromMessageByEmote(any(CachedMessage.class), eq(starEmote));
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public class StarRemovedListenerTest {
|
||||
when(cachedMessage.getAuthor()).thenReturn(cachedAuthor);
|
||||
when(reaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
when(emoteService.isReactionEmoteAEmote(reactionEmote, starEmote)).thenReturn(true);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID)).thenReturn(starEmote);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID)).thenReturn(starEmote);
|
||||
when(cachedReactions.getUsers()).thenReturn(remainingUsers);
|
||||
when(emoteService.getReactionFromMessageByEmote(cachedMessage, starEmote)).thenReturn(Optional.of(cachedReactions));
|
||||
when(starboardPostManagementService.findByMessageId(MESSAGE_ID)).thenReturn(Optional.ofNullable(post));
|
||||
@@ -196,7 +196,7 @@ public class StarRemovedListenerTest {
|
||||
when(model.getReaction()).thenReturn(reaction);
|
||||
when(model.getServerId()).thenReturn(SERVER_ID);
|
||||
testUnit.execute(model);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(1)).getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, SERVER_ID);
|
||||
verify(emoteService, times(1)).getReactionFromMessageByEmote(cachedMessage, starEmote);
|
||||
}
|
||||
|
||||
@@ -205,6 +205,6 @@ public class StarRemovedListenerTest {
|
||||
when(cachedAuthor.getAuthorId()).thenReturn(authorId);
|
||||
when(cachedMessage.getAuthor()).thenReturn(cachedAuthor);
|
||||
when(reaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeature.STAR_EMOTE, serverId)).thenReturn(starEmote);
|
||||
when(emoteService.getEmoteOrDefaultEmote(StarboardFeatureConfig.STAR_EMOTE, serverId)).thenReturn(starEmote);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import dev.sheldan.abstracto.core.service.management.PostTargetManagement;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeature;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardFeatureConfig;
|
||||
import dev.sheldan.abstracto.starboard.config.StarboardPostTarget;
|
||||
import dev.sheldan.abstracto.starboard.model.database.StarboardPost;
|
||||
import dev.sheldan.abstracto.starboard.model.database.StarboardPostReaction;
|
||||
@@ -158,12 +158,12 @@ public class StarboardServiceBeanTest {
|
||||
SystemConfigProperty config = Mockito.mock(SystemConfigProperty.class);
|
||||
Long defaultValue = 3L;
|
||||
when(config.getLongValue()).thenReturn(defaultValue);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeature.STAR_LEVELS_CONFIG_KEY)).thenReturn(config);
|
||||
when(configService.getLongValue(StarboardFeature.STAR_LVL_CONFIG_PREFIX + "2", SERVER_ID, defaultValue)).thenReturn(2L);
|
||||
when(configService.getLongValue(StarboardFeature.STAR_LVL_CONFIG_PREFIX + "3", SERVER_ID, defaultValue)).thenReturn(3L);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeature.STAR_LVL_CONFIG_PREFIX + "2")).thenReturn(config);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeature.STAR_LVL_CONFIG_PREFIX + "3")).thenReturn(config);
|
||||
when(emoteService.getUsableEmoteOrDefault(SERVER_ID, StarboardFeature.STAR_EMOTE_PREFIX + "2")).thenReturn("b");
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LEVELS_CONFIG_KEY)).thenReturn(config);
|
||||
when(configService.getLongValue(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + "2", SERVER_ID, defaultValue)).thenReturn(2L);
|
||||
when(configService.getLongValue(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + "3", SERVER_ID, defaultValue)).thenReturn(3L);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + "2")).thenReturn(config);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + "3")).thenReturn(config);
|
||||
when(emoteService.getUsableEmoteOrDefault(SERVER_ID, StarboardFeatureConfig.STAR_EMOTE_PREFIX + "2")).thenReturn("b");
|
||||
when(self.sendStarboardPostAndStore(eq(message), eq(STARRED_SERVER_USER_ID), anyList(), any(), eq(STARRING_USER_ID))).thenReturn(CompletableFuture.completedFuture(null));
|
||||
CompletableFuture<Void> createPostFuture = testUnit.createStarboardPost(message, userExceptAuthor, userReacting, starredUser);
|
||||
createPostFuture.join();
|
||||
@@ -240,8 +240,8 @@ public class StarboardServiceBeanTest {
|
||||
when(sendPost.getIdLong()).thenReturn(newPostId);
|
||||
SystemConfigProperty config = Mockito.mock(SystemConfigProperty.class);
|
||||
when(config.getLongValue()).thenReturn(1L);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeature.STAR_LEVELS_CONFIG_KEY)).thenReturn(config);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeature.STAR_LVL_CONFIG_PREFIX + 1)).thenReturn(config);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LEVELS_CONFIG_KEY)).thenReturn(config);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + 1)).thenReturn(config);
|
||||
when(starboardPostManagementService.findByStarboardPostMessageId(starboardPostId)).thenReturn(Optional.of(post));
|
||||
when(userService.retrieveUserForId(STARRED_USER_ID)).thenReturn(CompletableFuture.completedFuture(starredJdaUser));
|
||||
List<AUserInAServer > userExceptAuthor = new ArrayList<>();
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class StarboardFeature implements FeatureConfig {
|
||||
public class StarboardFeatureConfig implements FeatureConfig {
|
||||
|
||||
public static final String STAR_LVL_CONFIG_PREFIX = "starLvl";
|
||||
public static final String STAR_EMOTE_PREFIX = "star";
|
||||
@@ -38,7 +38,7 @@ public class StarboardFeature implements FeatureConfig {
|
||||
List<String> configKeys = new ArrayList<>();
|
||||
int maxLevels = getMaxLevels();
|
||||
for(int i = maxLevels; i > 0; i--) {
|
||||
configKeys.add(StarboardFeature.STAR_LVL_CONFIG_PREFIX + i);
|
||||
configKeys.add(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + i);
|
||||
}
|
||||
return configKeys;
|
||||
}
|
||||
@@ -48,11 +48,11 @@ public class StarboardFeature implements FeatureConfig {
|
||||
List<String> emoteNames = new ArrayList<>();
|
||||
int maxLevels = getMaxLevels();
|
||||
for(int i = maxLevels; i > 0; i--) {
|
||||
emoteNames.add(StarboardFeature.STAR_EMOTE_PREFIX + i);
|
||||
emoteNames.add(StarboardFeatureConfig.STAR_EMOTE_PREFIX + i);
|
||||
}
|
||||
emoteNames.add(StarboardFeature.STAR_BADGE_EMOTE_PREFIX + 1);
|
||||
emoteNames.add(StarboardFeature.STAR_BADGE_EMOTE_PREFIX + 2);
|
||||
emoteNames.add(StarboardFeature.STAR_BADGE_EMOTE_PREFIX + 3);
|
||||
emoteNames.add(StarboardFeatureConfig.STAR_BADGE_EMOTE_PREFIX + 1);
|
||||
emoteNames.add(StarboardFeatureConfig.STAR_BADGE_EMOTE_PREFIX + 2);
|
||||
emoteNames.add(StarboardFeatureConfig.STAR_BADGE_EMOTE_PREFIX + 3);
|
||||
return emoteNames;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
* {@link FeatureConfig} implementation to define the EmoteTracking feature.
|
||||
*/
|
||||
@Component
|
||||
public class EmoteTrackingFeature implements FeatureConfig {
|
||||
public class EmoteTrackingFeatureConfig implements FeatureConfig {
|
||||
|
||||
/**
|
||||
* {@link FeatureDefinition} represents the feature uniquely
|
||||
@@ -24,7 +24,7 @@ public class EmoteTrackingFeature implements FeatureConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* This feature contains three feature modes. For explanation of them check {@link EmoteTrackingFeature}
|
||||
* This feature contains three feature modes. For explanation of them check {@link EmoteTrackingFeatureConfig}
|
||||
* @return list of {@link FeatureMode} handled by this feature.
|
||||
*/
|
||||
@Override
|
||||
@@ -4,7 +4,7 @@ import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* {@link FeatureMode}s for {@link EmoteTrackingFeature}. These modes include:
|
||||
* {@link FeatureMode}s for {@link EmoteTrackingFeatureConfig}. These modes include:
|
||||
* AUTO_TRACK: This controls a listener which listens for the emote events of a server, and automatically creates/updates/marks as deleted instances in the database if the respective event happens
|
||||
* Influences:
|
||||
* EXTERNAL_EMOTES: Enables the tracking of emotes which are not from the server the feature is enabled in. This feature alone only enables to track emotes with the `trackEmote` command and makes the command `externalEmoteStats` (and more) available
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.statistic.emote.model.database;
|
||||
import dev.sheldan.abstracto.core.models.Fakeable;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.statistic.emote.config.EmoteTrackingFeatureConfig;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
@@ -10,7 +11,7 @@ import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* The instance of an emote which is being tracked by {@link dev.sheldan.abstracto.statistic.emote.config.EmoteTrackingFeature}.
|
||||
* The instance of an emote which is being tracked by {@link EmoteTrackingFeatureConfig}.
|
||||
* This represents an emote by its unique ID and the respective server its being tracked in. This emote might not be part of the server
|
||||
* and might have been deleted.
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class SuggestionFeature implements FeatureConfig {
|
||||
public class SuggestionFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class UtilitiesFeature implements FeatureConfig {
|
||||
public class UtilityFeatureConfig implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.post;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureConfig;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
||||
@@ -14,7 +15,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ConditionPostExecution implements PostCommandExecution {
|
||||
public static final String WARN_REACTION_EMOTE = "warnReaction";
|
||||
public static final String GENERIC_COMMAND_EXCEPTION_MODEL_KEY = "generic_condition_notification";
|
||||
|
||||
@Autowired
|
||||
@@ -26,7 +26,7 @@ public class ConditionPostExecution implements PostCommandExecution {
|
||||
@Override
|
||||
public void execute(CommandContext commandContext, CommandResult commandResult, Command command) {
|
||||
if(commandResult.getResult().equals(ResultState.CONDITION) && commandResult.getConditionResult() != null && !commandResult.getConditionResult().isResult() && commandResult.getConditionResult().getConditionDetail() != null) {
|
||||
reactionService.addReactionToMessage(WARN_REACTION_EMOTE, commandContext.getGuild().getIdLong(), commandContext.getMessage());
|
||||
reactionService.addReactionToMessage(CoreFeatureConfig.WARN_REACTION_KEY, commandContext.getGuild().getIdLong(), commandContext.getMessage());
|
||||
GenericConditionModel conditionModel = GenericConditionModel
|
||||
.builder()
|
||||
.conditionDetail(commandResult.getConditionResult().getConditionDetail())
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.command.post;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureConfig;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
||||
import dev.sheldan.abstracto.core.command.service.ExceptionService;
|
||||
import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -17,12 +21,21 @@ public class ExceptionPostExecution implements PostCommandExecution {
|
||||
@Autowired
|
||||
private ExceptionService exceptionService;
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Override
|
||||
public void execute(CommandContext commandContext, CommandResult commandResult, Command command) {
|
||||
ResultState result = commandResult.getResult();
|
||||
if(result.equals(ResultState.ERROR)) {
|
||||
Throwable throwable = commandResult.getThrowable();
|
||||
if(throwable != null) {
|
||||
if(throwable instanceof CommandNotFoundException){
|
||||
String configValue = configService.getStringValueOrConfigDefault(CoreFeatureConfig.NO_COMMAND_REPORTING_CONFIG_KEY, commandContext.getGuild().getIdLong());
|
||||
if(!BooleanUtils.toBoolean(configValue)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
log.info("Exception handling for exception {}.", throwable.getClass().getSimpleName());
|
||||
exceptionService.reportExceptionToContext(throwable, commandContext, command);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,47 @@
|
||||
package dev.sheldan.abstracto.core.command.post;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureConfig;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
||||
import dev.sheldan.abstracto.core.command.service.PostCommandExecution;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.ReactionService;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ReactionPostExecution implements PostCommandExecution {
|
||||
|
||||
public static final String WARN_REACTION_EMOTE = "warnReaction";
|
||||
public static final String SUCCESS_REACTION_EMOTE = "successReaction";
|
||||
@Autowired
|
||||
private ReactionService reactionService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Override
|
||||
public void execute(CommandContext commandContext, CommandResult commandResult, Command command) {
|
||||
ResultState result = commandResult.getResult();
|
||||
if(result.equals(ResultState.ERROR) || result.equals(ResultState.REPORTED_ERROR)) {
|
||||
reactionService.addReactionToMessage(WARN_REACTION_EMOTE, commandContext.getGuild().getIdLong(), commandContext.getMessage());
|
||||
if(commandResult.getThrowable() instanceof CommandNotFoundException){
|
||||
String configValue = configService.getStringValueOrConfigDefault(CoreFeatureConfig.NO_COMMAND_REPORTING_CONFIG_KEY, commandContext.getGuild().getIdLong());
|
||||
if(!BooleanUtils.toBoolean(configValue)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
reactionService.addReactionToMessage(CoreFeatureConfig.WARN_REACTION_KEY, commandContext.getGuild().getIdLong(), commandContext.getMessage());
|
||||
if(commandResult.getMessage() != null && commandResult.getThrowable() == null){
|
||||
channelService.sendTextToChannel(commandResult.getMessage(), commandContext.getChannel());
|
||||
}
|
||||
} else if(result.equals(ResultState.SUCCESSFUL) && command.getConfiguration().isCausesReaction()) {
|
||||
reactionService.addReactionToMessage(SUCCESS_REACTION_EMOTE, commandContext.getGuild().getIdLong(), commandContext.getMessage());
|
||||
reactionService.addReactionToMessage(CoreFeatureConfig.SUCCESS_REACTION_KEY, commandContext.getGuild().getIdLong(), commandContext.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ConfigServiceBean implements ConfigService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getDoubleValueOrConfigDefault(String name, Long serverId, Double defaultValue) {
|
||||
public Double getDoubleValueOrConfigDefault(String name, Long serverId) {
|
||||
return getDoubleValue(name, serverId, defaultConfigManagementService.getDefaultConfig(name).getDoubleValue());
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ConfigServiceBean implements ConfigService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStringValueOrConfigDefault(String name, Long serverId, String defaultValue) {
|
||||
public String getStringValueOrConfigDefault(String name, Long serverId) {
|
||||
return getStringValue(name, serverId, defaultConfigManagementService.getDefaultConfig(name).getStringValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ public class ListenerServiceBean implements ListenerService {
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
@Autowired
|
||||
private ListenerServiceBean self;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public <T extends FeatureAwareListenerModel, R extends ListenerExecutionResult> void executeFeatureAwareListener(FeatureAwareListener<T, R> listener, T model) {
|
||||
@@ -52,7 +55,7 @@ public class ListenerServiceBean implements ListenerService {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
CompletableFuture.runAsync(() -> listener.execute(model), executor).exceptionally(throwable -> {
|
||||
CompletableFuture.runAsync(() -> self.executeFeatureListenerInTransaction(listener, model), executor).exceptionally(throwable -> {
|
||||
log.error("Feature aware async Listener {} failed with async exception:", listener.getClass().getName(), throwable);
|
||||
return null;
|
||||
});
|
||||
@@ -61,6 +64,11 @@ public class ListenerServiceBean implements ListenerService {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public <T extends FeatureAwareListenerModel, R extends ListenerExecutionResult> void executeFeatureListenerInTransaction(FeatureAwareListener<T, R> listener, T model) {
|
||||
listener.execute(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public <T extends ListenerModel, R extends ListenerExecutionResult> void executeListener(AbstractoListener<T, R> listener, T model) {
|
||||
@@ -72,10 +80,9 @@ public class ListenerServiceBean implements ListenerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public <T extends ListenerModel, R extends ListenerExecutionResult> void executeListener(AbstractoListener<T, R> listener, T model, TaskExecutor executor) {
|
||||
try {
|
||||
CompletableFuture.runAsync(() -> listener.execute(model), executor).exceptionally(throwable -> {
|
||||
CompletableFuture.runAsync(() -> self.executeListenerInTransaction(listener, model), executor).exceptionally(throwable -> {
|
||||
log.error("Async Listener {} failed with async exception:", listener.getClass().getName(), throwable);
|
||||
return null;
|
||||
});
|
||||
@@ -84,4 +91,9 @@ public class ListenerServiceBean implements ListenerService {
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public <T extends ListenerModel, R extends ListenerExecutionResult> void executeListenerInTransaction(AbstractoListener<T, R> listener, T model) {
|
||||
listener.execute(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ abstracto.startup.synchronize=true
|
||||
abstracto.eventWaiter.threads=10
|
||||
server.port=8080
|
||||
|
||||
|
||||
abstracto.allowedmention.everyone=false
|
||||
abstracto.allowedmention.role=true
|
||||
abstracto.allowedmention.user=true
|
||||
|
||||
|
||||
|
||||
abstracto.systemConfigs.prefix.name=prefix
|
||||
abstracto.systemConfigs.prefix.stringValue=!
|
||||
|
||||
abstracto.systemConfigs.noCommandFoundReporting.name=noCommandFoundReporting
|
||||
abstracto.systemConfigs.noCommandFoundReporting.stringValue=true
|
||||
|
||||
abstracto.featureFlags.core.featureName=core
|
||||
abstracto.featureFlags.core.enabled=true
|
||||
@@ -1,22 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.command.config.features;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CoreFeature implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CoreFeatureDefinition.CORE_FEATURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredEmotes() {
|
||||
return Arrays.asList("warnReaction", "successReaction");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.sheldan.abstracto.core.command.config.features;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CoreFeatureConfig implements FeatureConfig {
|
||||
|
||||
public static final String NO_COMMAND_REPORTING_CONFIG_KEY = "noCommandFoundReporting";
|
||||
public static final String SUCCESS_REACTION_KEY = "successReaction";
|
||||
public static final String WARN_REACTION_KEY = "warnReaction";
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CoreFeatureDefinition.CORE_FEATURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredEmotes() {
|
||||
return Arrays.asList(WARN_REACTION_KEY, SUCCESS_REACTION_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRequiredSystemConfigKeys() {
|
||||
return Arrays.asList(NO_COMMAND_REPORTING_CONFIG_KEY);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@ public interface ConfigService {
|
||||
Long getLongValue(String name, Long serverId);
|
||||
Long getLongValueOrConfigDefault(String name, Long serverId);
|
||||
Double getDoubleValue(String name, Long serverId, Double defaultValue);
|
||||
Double getDoubleValueOrConfigDefault(String name, Long serverId, Double defaultValue);
|
||||
Double getDoubleValueOrConfigDefault(String name, Long serverId);
|
||||
String getStringValue(String name, Long serverId, String defaultValue);
|
||||
String getStringValueOrConfigDefault(String name, Long serverId, String defaultValue);
|
||||
String getStringValueOrConfigDefault(String name, Long serverId);
|
||||
Long getLongValue(String name, Long serverId, Long defaultValue);
|
||||
AConfig setOrCreateConfigValue(Long serverId, String name, AConfig value);
|
||||
void setDoubleValue(String name, Long serverId, Double value);
|
||||
|
||||
Reference in New Issue
Block a user