mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-05 00:53:04 +00:00
[AB-73] adding different feature modes to define whether or not certain actions should be logged, changing name of setup, disable and enable command to show that they are supposed to be for features
This commit is contained in:
@@ -14,7 +14,7 @@ import dev.sheldan.abstracto.core.exception.FeatureNotFoundException;
|
||||
import dev.sheldan.abstracto.core.interactive.InteractiveService;
|
||||
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.SetupService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureSetupService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class Setup extends AbstractConditionableCommand {
|
||||
public class SetupFeature extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private InteractiveService interactiveService;
|
||||
@@ -35,7 +35,7 @@ public class Setup extends AbstractConditionableCommand {
|
||||
private FeatureConfigService featureConfigService;
|
||||
|
||||
@Autowired
|
||||
private SetupService setupService;
|
||||
private FeatureSetupService setupService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
@@ -48,7 +48,7 @@ public class Setup extends AbstractConditionableCommand {
|
||||
.channelId(commandContext.getChannel().getIdLong())
|
||||
.userId(commandContext.getAuthor().getIdLong())
|
||||
.build();
|
||||
return setupService.performSetup(feature, initiatingUser, commandContext.getMessage().getIdLong())
|
||||
return setupService.performFeatureSetup(feature, initiatingUser, commandContext.getMessage().getIdLong())
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
throw new FeatureNotFoundException(name, featureConfigService.getFeaturesAsList());
|
||||
@@ -60,7 +60,7 @@ public class Setup extends AbstractConditionableCommand {
|
||||
List<Parameter> parameters = Arrays.asList(newPrefixParameter);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("setup")
|
||||
.name("setupFeature")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.templated(true)
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class Disable extends AbstractConditionableCommand {
|
||||
public class DisableFeature extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private FeatureConfigService featureConfigService;
|
||||
@@ -67,7 +67,7 @@ public class Disable extends AbstractConditionableCommand {
|
||||
List<Parameter> parameters = Arrays.asList(featureName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).hasExample(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("disable")
|
||||
.name("disableFeature")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.async(true)
|
||||
@@ -28,7 +28,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Enable extends AbstractConditionableCommand {
|
||||
public class EnableFeature extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private FeatureConfigService featureConfigService;
|
||||
@@ -75,7 +75,7 @@ public class Enable extends AbstractConditionableCommand {
|
||||
List<Parameter> parameters = Arrays.asList(featureName);
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).hasExample(true).build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("enable")
|
||||
.name("enableFeature")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.async(true)
|
||||
@@ -10,7 +10,7 @@ public class NoChannelProvidedException extends AbstractoRunTimeException implem
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "setup_no_channel_provided_exception";
|
||||
return "feature_setup_no_channel_provided_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ public class PostTargetDelayedActionConfig implements DelayedActionConfig {
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "setup_post_target_action";
|
||||
return "feature_setup_post_target_action";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.function.Consumer;
|
||||
@Slf4j
|
||||
public class PostTargetSetupStep extends AbstractConfigSetupStep {
|
||||
|
||||
public static final String FEATURE_SETUP_POST_TARGET_MESSAGE_TEMPLATE_KEY = "feature_setup_post_target_message";
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@@ -66,8 +67,7 @@ public class PostTargetSetupStep extends AbstractConfigSetupStep {
|
||||
.postTargetKey(postTargetStepParameter.getPostTargetKey())
|
||||
.currentTextChannel(currentTextChannel)
|
||||
.build();
|
||||
String messageTemplateKey = "setup_post_target_message";
|
||||
String messageText = templateService.renderTemplate(messageTemplateKey, model);
|
||||
String messageText = templateService.renderTemplate(FEATURE_SETUP_POST_TARGET_MESSAGE_TEMPLATE_KEY, model);
|
||||
AChannel channel = channelManagementService.loadChannel(user.getChannelId());
|
||||
CompletableFuture<SetupStepResult> future = new CompletableFuture<>();
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(user.getGuildId(), user.getUserId());
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.function.Consumer;
|
||||
@Slf4j
|
||||
public class SetupSummaryStep extends AbstractConfigSetupStep {
|
||||
|
||||
public static final String FEATURE_SETUP_CONFIRMATION_TEMPLATE_KEY = "feature_setup_confirmation";
|
||||
@Autowired
|
||||
private InteractiveService interactiveService;
|
||||
|
||||
@@ -45,7 +46,7 @@ public class SetupSummaryStep extends AbstractConfigSetupStep {
|
||||
.builder()
|
||||
.actionConfigs(parameter.getDelayedActionList())
|
||||
.build();
|
||||
String messageToSend = templateService.renderTemplate("setup_confirmation", model);
|
||||
String messageToSend = templateService.renderTemplate(FEATURE_SETUP_CONFIRMATION_TEMPLATE_KEY, model);
|
||||
AChannel channel = channelManagementService.loadChannel(user.getChannelId());
|
||||
CompletableFuture<SetupStepResult> future = new CompletableFuture<>();
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(user.getGuildId(), user.getUserId());
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SystemConfigDelayedActionConfig implements DelayedActionConfig {
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "setup_system_config_action";
|
||||
return "feature_setup_system_config_action";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.function.Consumer;
|
||||
@Slf4j
|
||||
public class SystemConfigSetupStep extends AbstractConfigSetupStep {
|
||||
|
||||
public static final String SETUP_SYSTEM_CONFIG_MESSAGE_TEMPLATE_KEY = "feature_setup_system_config_message";
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@@ -57,8 +58,7 @@ public class SystemConfigSetupStep extends AbstractConfigSetupStep {
|
||||
.configKey(systemConfigStepParameter.getConfigKey())
|
||||
.defaultConfig(defaultConfig)
|
||||
.build();
|
||||
String messageTemplateKey = "setup_system_config_message";
|
||||
String messageText = templateService.renderTemplate(messageTemplateKey, model);
|
||||
String messageText = templateService.renderTemplate(SETUP_SYSTEM_CONFIG_MESSAGE_TEMPLATE_KEY, model);
|
||||
AChannel channel = channelManagementService.loadChannel(user.getChannelId());
|
||||
CompletableFuture<SetupStepResult> future = new CompletableFuture<>();
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(user.getGuildId(), user.getUserId());
|
||||
|
||||
@@ -10,6 +10,7 @@ import dev.sheldan.abstracto.core.models.template.commands.FeatureModeDisplay;
|
||||
import dev.sheldan.abstracto.core.service.management.DefaultFeatureModeManagement;
|
||||
import dev.sheldan.abstracto.core.service.management.FeatureFlagManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.FeatureModeManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -38,6 +39,9 @@ public class FeatureModeServiceBean implements FeatureModeService {
|
||||
@Autowired
|
||||
private DefaultFeatureModeManagement defaultFeatureModeManagement;
|
||||
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Override
|
||||
public void enableFeatureModeForFeature(FeatureEnum featureEnum, AServer server, FeatureMode mode) {
|
||||
AFeature feature = featureManagementService.getFeature(featureEnum.getKey());
|
||||
@@ -81,6 +85,12 @@ public class FeatureModeServiceBean implements FeatureModeService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean featureModeActive(FeatureEnum featureEnum, Long serverId, FeatureMode mode) {
|
||||
AServer server = serverManagementService.loadServer(serverId);
|
||||
return featureModeActive(featureEnum, server, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureMode getFeatureModeForKey(String key) {
|
||||
return getAllAvailableFeatureModes().stream().filter(mode -> mode.getKey().equalsIgnoreCase(key)).findAny().orElseThrow(() -> new FeatureModeNotFoundException(key, getFeatureModesAsStrings()));
|
||||
|
||||
@@ -22,8 +22,11 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SetupServiceBean implements SetupService {
|
||||
public class FeatureSetupServiceBean implements FeatureSetupService {
|
||||
|
||||
public static final String FEATURE_SETUP_CANCELLATION_NOTIFICATION_TEMPLATE = "feature_setup_cancellation_notification";
|
||||
public static final String FEATURE_SETUP_COMPLETION_NOTIFICATION_TEMPLATE = "feature_setup_completion_notification";
|
||||
public static final String FEATURE_SETUP_INITIAL_MESSAGE_TEMPLATE_KEY = "feature_setup_initial_message";
|
||||
@Autowired
|
||||
private SystemConfigSetupStep systemConfigSetupStep;
|
||||
|
||||
@@ -34,7 +37,7 @@ public class SetupServiceBean implements SetupService {
|
||||
private DelayedActionService delayedActionService;
|
||||
|
||||
@Autowired
|
||||
private SetupServiceBean self;
|
||||
private FeatureSetupServiceBean self;
|
||||
|
||||
@Autowired
|
||||
private SetupSummaryStep setupSummaryStep;
|
||||
@@ -52,7 +55,7 @@ public class SetupServiceBean implements SetupService {
|
||||
private ExceptionService exceptionService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> performSetup(FeatureConfig featureConfig, AServerChannelUserId user, Long initialMessageId) {
|
||||
public CompletableFuture<Void> performFeatureSetup(FeatureConfig featureConfig, AServerChannelUserId user, Long initialMessageId) {
|
||||
log.info("Performing setup of feature {} for user {} in channel {} in server {}.",
|
||||
featureConfig.getFeature().getKey(), user.getUserId(), user.getChannelId(), user.getGuildId());
|
||||
Optional<TextChannel> textChannelInGuild = channelService.getTextChannelInGuild(user.getGuildId(), user.getChannelId());
|
||||
@@ -99,15 +102,15 @@ public class SetupServiceBean implements SetupService {
|
||||
.featureConfig(featureConfig)
|
||||
.build();
|
||||
TextChannel textChannel = textChannelInGuild.get();
|
||||
String text = templateService.renderTemplate("setup_initial_message", setupInitialMessageModel);
|
||||
String text = templateService.renderTemplate(FEATURE_SETUP_INITIAL_MESSAGE_TEMPLATE_KEY, setupInitialMessageModel);
|
||||
channelService.sendTextToChannel(text, textChannel);
|
||||
return executeSetup(featureConfig, steps, user, new ArrayList<>());
|
||||
return executeFeatureSetup(featureConfig, steps, user, new ArrayList<>());
|
||||
}
|
||||
throw new ChannelNotFoundException(user.getChannelId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> executeSetup(FeatureConfig featureConfig, List<SetupExecution> steps, AServerChannelUserId user, List<DelayedActionConfig> delayedActionConfigs) {
|
||||
public CompletableFuture<Void> executeFeatureSetup(FeatureConfig featureConfig, List<SetupExecution> steps, AServerChannelUserId user, List<DelayedActionConfig> delayedActionConfigs) {
|
||||
SetupExecution nextStep = steps.get(0);
|
||||
return executeStep(user, nextStep, delayedActionConfigs, featureConfig);
|
||||
}
|
||||
@@ -162,7 +165,7 @@ public class SetupServiceBean implements SetupService {
|
||||
public void notifyAboutCompletion(AServerChannelUserId aServerChannelUserId, FeatureConfig featureConfig) {
|
||||
log.trace("Notifying user {} in channel {} in server {} about completion of setup for feature {}.",
|
||||
aServerChannelUserId.getUserId(), aServerChannelUserId.getChannelId(), aServerChannelUserId.getGuildId(), featureConfig.getFeature().getKey());
|
||||
notifyUserWithTemplate(aServerChannelUserId, featureConfig, "setup_completion_notification");
|
||||
notifyUserWithTemplate(aServerChannelUserId, featureConfig, FEATURE_SETUP_COMPLETION_NOTIFICATION_TEMPLATE);
|
||||
}
|
||||
|
||||
private void notifyUserWithTemplate(AServerChannelUserId aServerChannelUserId, FeatureConfig featureConfig, String templateName) {
|
||||
@@ -179,6 +182,6 @@ public class SetupServiceBean implements SetupService {
|
||||
public void notifyAboutCancellation(AServerChannelUserId aServerChannelUserId, FeatureConfig featureConfig) {
|
||||
log.trace("Notifying user {} in channel {} in server {} about cancellation of setup for feature {}.",
|
||||
aServerChannelUserId.getUserId(), aServerChannelUserId.getChannelId(), aServerChannelUserId.getGuildId(), featureConfig.getFeature().getKey());
|
||||
notifyUserWithTemplate(aServerChannelUserId, featureConfig, "setup_cancellation_notification");
|
||||
notifyUserWithTemplate(aServerChannelUserId, featureConfig, FEATURE_SETUP_CANCELLATION_NOTIFICATION_TEMPLATE);
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="setup"/>
|
||||
<column name="name" value="setupFeature"/>
|
||||
<column name="module_id" valueComputed="${configModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
@@ -128,7 +128,7 @@
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="disable"/>
|
||||
<column name="name" value="disableFeature"/>
|
||||
<column name="module_id" valueComputed="${configModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
@@ -140,7 +140,7 @@
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="enable"/>
|
||||
<column name="name" value="enableFeature"/>
|
||||
<column name="module_id" valueComputed="${configModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Arrays;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DisableModeTest {
|
||||
public class DisableFeatureModeTest {
|
||||
|
||||
@InjectMocks
|
||||
private DisableMode testUnit;
|
||||
@@ -26,7 +26,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EnableModeTest {
|
||||
public class EnableFeatureModeTest {
|
||||
|
||||
@InjectMocks
|
||||
private EnableMode testUnit;
|
||||
Reference in New Issue
Block a user