mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-26 05:44:42 +00:00
[AB-78] adding new concept of feature modes, with splitting it up to new commands and default mode concept
refactoring command received handler to only load the entities in the same thread as the actual executed commands, so that user initiated context contains valid references from the same thread updating documentation fixing issue when the result of role calculation result in no experience role id
This commit is contained in:
@@ -48,7 +48,7 @@ public class Close extends AbstractConditionableCommand {
|
||||
// the default value of the note is configurable via template
|
||||
String note = parameters.size() == 1 ? (String) parameters.get(0) : templateService.renderTemplate("modmail_close_default_note", new Object());
|
||||
ModMailThread thread = modMailThreadManagementService.getByChannel(commandContext.getUserInitiatedContext().getChannel());
|
||||
return modMailThreadService.closeModMailThread(thread, note, true, commandContext.getUndoActions())
|
||||
return modMailThreadService.closeModMailThread(thread, note, true, commandContext.getUndoActions(), true)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,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}
|
||||
* in the 'LOGGING' mode, because else the normal close command behaves the same way.
|
||||
* 'LOGGING' mode enabled, because else the normal close command behaves the same way.
|
||||
*/
|
||||
@Component
|
||||
public class CloseNoLog extends AbstractConditionableCommand {
|
||||
@@ -46,7 +46,7 @@ public class CloseNoLog extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
ModMailThread thread = modMailThreadManagementService.getByChannel(commandContext.getUserInitiatedContext().getChannel());
|
||||
// we don't have a note, therefore we cant pass any, the method handles this accordingly
|
||||
return modMailThreadService.closeModMailThread(thread, null, false, commandContext.getUndoActions())
|
||||
return modMailThreadService.closeModMailThread(thread, null, false, commandContext.getUndoActions(), false)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class CloseNoLog extends AbstractConditionableCommand {
|
||||
}
|
||||
|
||||
/**
|
||||
* This command is only available in the LOGGING mod mail feature mode
|
||||
* This command is only available if the LOGGING feature mode is enabled
|
||||
*/
|
||||
@Override
|
||||
public List<FeatureMode> getFeatureModeLimitations() {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class CloseSilently extends AbstractConditionableCommand {
|
||||
// default note text is configurable via template, because the note is optional
|
||||
String note = parameters.size() == 1 ? (String) parameters.get(0) : templateService.renderTemplate("modmail_close_default_note", new Object());
|
||||
ModMailThread thread = modMailThreadManagementService.getByChannel(commandContext.getUserInitiatedContext().getChannel());
|
||||
return modMailThreadService.closeModMailThread(thread, note, false, commandContext.getUndoActions())
|
||||
return modMailThreadService.closeModMailThread(thread, note, false, commandContext.getUndoActions(), true)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
|
||||
@@ -452,10 +452,10 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> closeModMailThread(ModMailThread modMailThread, String note, boolean notifyUser, List<UndoActionInstance> undoActions) {
|
||||
AFeatureMode aFeatureMode = featureModeService.getFeatureMode(ModMailFeatures.MOD_MAIL, modMailThread.getServer());
|
||||
boolean loggingMode = aFeatureMode.getMode().equalsIgnoreCase(ModMailMode.LOGGING.getKey());
|
||||
return closeModMailThread(modMailThread, note, notifyUser, loggingMode, undoActions);
|
||||
public CompletableFuture<Void> closeModMailThread(ModMailThread modMailThread, String note, boolean notifyUser, List<UndoActionInstance> undoActions, Boolean log) {
|
||||
boolean loggingMode = featureModeService.featureModeActive(ModMailFeatures.MOD_MAIL, modMailThread.getServer(), ModMailMode.LOGGING);
|
||||
boolean shouldLogThread = log && loggingMode;
|
||||
return closeModMailThread(modMailThread, note, notifyUser, shouldLogThread, undoActions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,4 +13,5 @@
|
||||
<include file="default_posttarget.xml" relativeToChangelogFile="true"/>
|
||||
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||
<include file="default_emote.xml" relativeToChangelogFile="true"/>
|
||||
<include file="default_feature_mode.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -8,11 +8,10 @@
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<property name="modmailFeature" value="(SELECT id FROM feature WHERE key = 'modmail')"/>
|
||||
<property name="today" value="(SELECT NOW())"/>
|
||||
<changeSet author="Sheldan" id="modmaildefau_default_feature_flag-insertion">
|
||||
<changeSet author="Sheldan" id="modmail_default_feature_flag-insertion">
|
||||
<insert tableName="default_feature_flag">
|
||||
<column name="enabled" value="false"/>
|
||||
<column name="feature_id" valueComputed="${modmailFeature}" />
|
||||
<column name="mode" value="log"/>
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<property name="modmailFeature" value="(SELECT id FROM feature WHERE key = 'modmail')"/>
|
||||
<property name="today" value="(SELECT NOW())"/>
|
||||
<changeSet author="Sheldan" id="modmail_default_feature_mode-insertion">
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="false"/>
|
||||
<column name="mode" value="log"/>
|
||||
<column name="feature_id" valueComputed="${modmailFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -48,7 +48,7 @@ public class ModMailFeature implements FeatureConfig {
|
||||
|
||||
@Override
|
||||
public List<FeatureMode> getAvailableModes() {
|
||||
return Arrays.asList(ModMailMode.LOGGING, ModMailMode.NO_LOG);
|
||||
return Arrays.asList(ModMailMode.LOGGING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@Getter
|
||||
public enum ModMailMode implements FeatureMode {
|
||||
LOGGING("log"), NO_LOG("nolog");
|
||||
LOGGING("log");
|
||||
|
||||
private String key;
|
||||
|
||||
|
||||
@@ -75,8 +75,9 @@ public interface ModMailThreadService {
|
||||
* @param modMailThread The {@link ModMailThread} which is being closed.
|
||||
* @param note The text of the note used for the header message of the logged mod mail thread.
|
||||
* @param notifyUser Whether or not the user should be notified
|
||||
* @param log whether or not the closed {@link ModMailThread} should be logged (if the {@link dev.sheldan.abstracto.core.config.FeatureMode} is enabled)
|
||||
*/
|
||||
CompletableFuture<Void> closeModMailThread(ModMailThread modMailThread, String note, boolean notifyUser, List<UndoActionInstance> undoActions);
|
||||
CompletableFuture<Void> closeModMailThread(ModMailThread modMailThread, String note, boolean notifyUser, List<UndoActionInstance> undoActions, Boolean log);
|
||||
|
||||
/**
|
||||
* Closes the mod mail thread which means: deletes the {@link net.dv8tion.jda.api.entities.TextChannel} associated with the mod mail thread,
|
||||
|
||||
Reference in New Issue
Block a user