mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-04 23:40:36 +00:00
added a condition to check for the correct feature mode
merged mod mail logging back into the mod mail feature and set it up as a mode
This commit is contained in:
@@ -7,8 +7,10 @@ import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
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.FeatureMode;
|
||||
import dev.sheldan.abstracto.modmail.commands.condition.RequiresModMailCondition;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeatures;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailMode;
|
||||
import dev.sheldan.abstracto.modmail.models.database.ModMailThread;
|
||||
import dev.sheldan.abstracto.modmail.service.ModMailThreadService;
|
||||
import dev.sheldan.abstracto.modmail.service.management.ModMailThreadManagementService;
|
||||
@@ -16,6 +18,7 @@ import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@@ -54,7 +57,7 @@ public class CloseNoLog extends AbstractConditionableCommand {
|
||||
|
||||
@Override
|
||||
public FeatureEnum getFeature() {
|
||||
return ModMailFeatures.MOD_MAIL_LOGGING;
|
||||
return ModMailFeatures.MOD_MAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,4 +66,9 @@ public class CloseNoLog extends AbstractConditionableCommand {
|
||||
conditions.add(requiresModMailCondition);
|
||||
return conditions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getFeatureModeLimitations() {
|
||||
return Arrays.asList(ModMailMode.LOGGING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerService;
|
||||
import dev.sheldan.abstracto.core.utils.CompletableFutureList;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailFeature;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailLoggingFeature;
|
||||
import dev.sheldan.abstracto.modmail.config.ModMailPostTargets;
|
||||
import dev.sheldan.abstracto.modmail.config.*;
|
||||
import dev.sheldan.abstracto.modmail.exception.ModMailThreadNotFoundException;
|
||||
import dev.sheldan.abstracto.modmail.models.database.*;
|
||||
import dev.sheldan.abstracto.modmail.models.dto.ServerChoice;
|
||||
@@ -97,7 +95,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
private EventWaiter eventWaiter;
|
||||
|
||||
@Autowired
|
||||
private ModMailLoggingFeature modMailLoggingFeature;
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
|
||||
@Autowired
|
||||
@@ -354,8 +352,9 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
|
||||
@Override
|
||||
public synchronized void closeModMailThread(ModMailThread modMailThread, MessageChannel feedBack, String note, Boolean notifyUser) {
|
||||
boolean loggingEnabled = featureFlagService.isFeatureEnabled(modMailLoggingFeature, modMailThread.getServer());
|
||||
closeModMailThread(modMailThread, feedBack, note, notifyUser, loggingEnabled);
|
||||
AFeatureMode aFeatureMode = featureModeService.getFeatureMode(ModMailFeatures.MOD_MAIL, modMailThread.getServer());
|
||||
boolean loggingMode = aFeatureMode.getMode().equalsIgnoreCase(ModMailMode.LOGGING.getKey());
|
||||
closeModMailThread(modMailThread, feedBack, note, notifyUser, loggingMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,5 +3,3 @@ abstracto.emoteNames.readReaction=readReaction
|
||||
abstracto.defaultEmotes.readReaction=\uD83D\uDC40
|
||||
abstracto.features.modmail.enabled=false
|
||||
abstracto.features.modmail.defaultMode=log
|
||||
|
||||
abstracto.features.modmail_logging.enabled=false
|
||||
@@ -18,19 +18,11 @@ public class ModMailFeature implements FeatureConfig {
|
||||
@Autowired
|
||||
private ModMailFeatureValidator modMailFeatureValidator;
|
||||
|
||||
@Autowired
|
||||
private ModMailLoggingFeature modMailLoggingFeature;
|
||||
|
||||
@Override
|
||||
public FeatureEnum getFeature() {
|
||||
return ModMailFeatures.MOD_MAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureConfig> getDependantFeatures() {
|
||||
return Arrays.asList(modMailLoggingFeature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostTargetEnum> getRequiredPostTargets() {
|
||||
return Arrays.asList(ModMailPostTargets.MOD_MAIL_PING);
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.modmail.config;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
|
||||
public enum ModMailFeatures implements FeatureEnum {
|
||||
MOD_MAIL("modmail"), MOD_MAIL_LOGGING("modmail_logging");
|
||||
MOD_MAIL("modmail");
|
||||
|
||||
private String key;
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package dev.sheldan.abstracto.modmail.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ModMailLoggingFeature implements FeatureConfig {
|
||||
|
||||
@Autowired
|
||||
private ModMailFeature modMailFeature;
|
||||
|
||||
@Override
|
||||
public FeatureEnum getFeature() {
|
||||
return ModMailFeatures.MOD_MAIL_LOGGING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureConfig> getRequiredFeatures() {
|
||||
return Arrays.asList(modMailFeature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostTargetEnum> getRequiredPostTargets() {
|
||||
return Arrays.asList(ModMailPostTargets.MOD_MAIL_LOG);
|
||||
}
|
||||
}
|
||||
@@ -49,12 +49,16 @@ public class FeatureFlagListener implements ServerConfigListener {
|
||||
featureFlagService.getAllFeatureConfigs().forEach((featureFlagKey) -> {
|
||||
String featureKey = featureFlagKey.getFeature().getKey();
|
||||
AFeature feature = featureManagementService.getFeature(featureKey);
|
||||
FeaturePropertiesConfig featurePropertiesConfig = featureConfigLoader.getFeatures().get(featureKey);
|
||||
if(service.getFeatureFlag(feature, server.getId()) == null) {
|
||||
service.createFeatureFlag(feature, server.getId(), featurePropertiesConfig.getEnabled());
|
||||
}
|
||||
if(featurePropertiesConfig.getDefaultMode() != null && !featureModeManagementService.featureModeSet(feature, server)) {
|
||||
featureModeService.createMode(feature, server, featurePropertiesConfig.getDefaultMode());
|
||||
if(featureConfigLoader.getFeatures().containsKey(featureKey)) {
|
||||
FeaturePropertiesConfig featurePropertiesConfig = featureConfigLoader.getFeatures().get(featureKey);
|
||||
if(service.getFeatureFlag(feature, server.getId()) == null) {
|
||||
service.createFeatureFlag(feature, server.getId(), featurePropertiesConfig.getEnabled());
|
||||
}
|
||||
if(featurePropertiesConfig.getDefaultMode() != null && !featureModeManagementService.featureModeSet(feature, server)) {
|
||||
featureModeService.createMode(feature, server, featurePropertiesConfig.getDefaultMode());
|
||||
}
|
||||
} else {
|
||||
log.warn("Feature {} was found as interface, but not in the properties configuration. It will not be setup.", featureKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,5 +117,17 @@ public class FeatureModeServiceBean implements FeatureModeService {
|
||||
return featureModeManagementService.createMode(featureFlag, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AFeatureMode getFeatureMode(FeatureEnum featureEnum, AServer server) {
|
||||
AFeature feature = featureManagementService.getFeature(featureEnum.getKey());
|
||||
return getFeatureMode(feature, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AFeatureMode getFeatureMode(AFeature feature, AServer server) {
|
||||
AFeatureFlag featureFlag = featureFlagManagementService.getFeatureFlag(feature, server);
|
||||
return featureModeManagementService.getModeForFeature(featureFlag);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<#assign featureName><#include "${featureConfig.feature.key}_feature"></#assign><#assign featureKey>${featureConfig.feature.key}</#assign><#assign requiredModes><#list command.featureModeLimitations as mode>`${mode.key}`<sep>, </#list></#assign><#include "feature_mode_not_correct_text">
|
||||
@@ -22,9 +22,12 @@ public abstract class AbstractConditionableCommand implements ConditionalCommand
|
||||
@Autowired
|
||||
protected ImmuneUserCondition immuneUserCondition;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeCondition featureModeCondition;
|
||||
|
||||
|
||||
@Override
|
||||
public List<CommandCondition> getConditions() {
|
||||
return new ArrayList<>(Arrays.asList(featureEnabledCondition, commandDisabledCondition, commandDisallowedCondition));
|
||||
return new ArrayList<>(Arrays.asList(featureEnabledCondition, commandDisabledCondition, commandDisallowedCondition, featureModeCondition));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package dev.sheldan.abstracto.core.command.condition;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.models.IncorrectFeatureModeMessage;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.models.database.AFeatureMode;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FeatureModeCondition implements CommandCondition {
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private FeatureConfigService featureConfigService;
|
||||
|
||||
@Autowired
|
||||
private FeatureFlagService featureFlagService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService modeService;
|
||||
|
||||
@Override
|
||||
public ConditionResult shouldExecute(CommandContext context, Command command) {
|
||||
String reason = "";
|
||||
boolean featureModeFits = true;
|
||||
if(!command.getFeatureModeLimitations().isEmpty()){
|
||||
FeatureEnum feature = command.getFeature();
|
||||
if(feature != null) {
|
||||
AFeatureMode featureMode = modeService.getFeatureMode(feature, context.getUserInitiatedContext().getServer());
|
||||
featureModeFits = command.getFeatureModeLimitations().stream().anyMatch(featureMode1 -> featureMode1.getKey().equalsIgnoreCase(featureMode.getMode()));
|
||||
if(!featureModeFits) {
|
||||
IncorrectFeatureModeMessage featureDisabledMessage = IncorrectFeatureModeMessage
|
||||
.builder()
|
||||
.featureConfig(featureConfigService.getFeatureDisplayForFeature(feature))
|
||||
.command(command)
|
||||
.build();
|
||||
reason = templateService.renderTemplate("feature_mode_not_correct_message", featureDisabledMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ConditionResult.builder().reason(reason).result(featureModeFits).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.command.models;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
public class IncorrectFeatureModeMessage {
|
||||
private FeatureConfig featureConfig;
|
||||
private Command command;
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.config.FeatureMode;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public interface FeatureAware {
|
||||
FeatureEnum getFeature();
|
||||
default List<FeatureMode> getFeatureModeLimitations() { return Collections.emptyList();}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class AFeatureMode {
|
||||
|
||||
@Column
|
||||
@Setter
|
||||
@Getter
|
||||
private String mode;
|
||||
|
||||
@Column(name = "created")
|
||||
|
||||
@@ -23,4 +23,7 @@ public interface FeatureModeService {
|
||||
AFeatureMode createMode(FeatureEnum featureEnum, AServer server, FeatureMode mode);
|
||||
AFeatureMode createMode(AFeature feature, AServer server, FeatureMode mode);
|
||||
AFeatureMode createMode(AFeatureFlag featureFlag, FeatureMode mode);
|
||||
|
||||
AFeatureMode getFeatureMode(FeatureEnum featureEnum, AServer server);
|
||||
AFeatureMode getFeatureMode(AFeature feature, AServer server);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ Feature key: `modmail`
|
||||
|
||||
==== Post targets
|
||||
`modmailPing`:: Will be used to send the notification when a new thread is opened.
|
||||
`modmailLog`:: Will be used to log the interactions when a thread is closed.
|
||||
|
||||
=== Modes
|
||||
`log`:: The messages should be logged into the `modmailLog` post target when the thread is closed (by the respective commands)
|
||||
`nogLog`:: The messages should not be logged into the `modmailLog` post target when the thread is closed.
|
||||
|
||||
|
||||
==== Emotes
|
||||
@@ -58,13 +63,13 @@ Closing the mod mail thread without notifying the user::
|
||||
* Usage: `closeSilently [note]`
|
||||
* Description: Closes the thread, deletes the text channel containing the thread and logs the interactions between the member and the moderators in the `modmailLog` post target. (only if `modmail_logging` is enabled)
|
||||
When closing a thread, a closing header with general information will be send and the note will be displayed there.
|
||||
|
||||
Close a thread without logging
|
||||
* Usage: `closeNoLog`
|
||||
* Description: Closes the thread without notifying the user and without logging the messages.
|
||||
* Mode Restriction: This command is only available when mod mail is in the mode `log`.
|
||||
|
||||
=== Mod mail thread logging
|
||||
|
||||
This feature enables the logging of mod mail threads into a channel when they are closed. The individual log messages will have a mod mail header which contains some information about the thread.
|
||||
|
||||
Feature key: `modmail_logging`
|
||||
|
||||
==== Post targets
|
||||
`modmailLog`:: Will be used to log the interactions when a thread is closed.
|
||||
@@ -0,0 +1 @@
|
||||
The feature `${featureName}` (with the key `${featureKey}`) is in the wrong mode to execute this command. One of the following is required: ${requiredModes}.
|
||||
Reference in New Issue
Block a user