mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-26 23:17:31 +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:
@@ -38,7 +38,7 @@ public class BanId extends AbstractConditionableCommand {
|
||||
banLogModel.setBannedUserId(userId);
|
||||
banLogModel.setBanningUser(commandContext.getAuthor());
|
||||
banLogModel.setReason(reason);
|
||||
return banService.banMember(commandContext.getGuild().getIdLong(), userId, reason, banLogModel)
|
||||
return banService.banUserViaId(commandContext.getGuild().getIdLong(), userId, reason, banLogModel)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
|
||||
@@ -26,18 +26,14 @@ public class DecayAllWarnings extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
checkParameters(commandContext);
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
boolean logWarnings = !parameters.isEmpty() ? (Boolean) parameters.get(0) : Boolean.FALSE;
|
||||
return warnService.decayAllWarningsForServer(commandContext.getUserInitiatedContext().getServer(), logWarnings)
|
||||
return warnService.decayAllWarningsForServer(commandContext.getUserInitiatedContext().getServer())
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
Parameter logWarnings = Parameter.builder().optional(true).name("writeLog").templated(true).type(Boolean.class).build();
|
||||
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
|
||||
parameters.add(logWarnings);
|
||||
return CommandConfiguration.builder()
|
||||
.name("decayAllWarnings")
|
||||
.module(ModerationModule.MODERATION)
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Kick extends AbstractConditionableCommand {
|
||||
.module(ModerationModule.MODERATION)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.async(true)
|
||||
.causesReaction(true)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.concurrent.CompletableFuture;
|
||||
@Component
|
||||
public class UnMute extends AbstractConditionableCommand {
|
||||
|
||||
public static final String NO_ACTIVE_MUTE = "unMute_has_no_active_mute";
|
||||
@Autowired
|
||||
private MuteService muteService;
|
||||
|
||||
|
||||
@@ -3,8 +3,11 @@ package dev.sheldan.abstracto.moderation.service;
|
||||
import dev.sheldan.abstracto.core.exception.GuildNotFoundException;
|
||||
import dev.sheldan.abstracto.core.models.context.ServerContext;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.ModerationPostTarget;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
@@ -12,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -35,20 +39,36 @@ public class BanServiceBean implements BanService {
|
||||
@Autowired
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> banMember(Member member, String reason, ServerContext banLog) {
|
||||
CompletableFuture<Void> banFuture = banUser(member.getGuild(), member.getIdLong(), reason);
|
||||
MessageToSend banLogMessage = templateService.renderEmbedTemplate(BAN_LOG_TEMPLATE, banLog);
|
||||
List<CompletableFuture<Message>> notificationFutures = postTargetService.sendEmbedInPostTarget(banLogMessage, ModerationPostTarget.BAN_LOG, member.getGuild().getIdLong());
|
||||
return CompletableFuture.allOf(banFuture, FutureUtils.toSingleFutureGeneric(notificationFutures));
|
||||
CompletableFuture<Void> messageFuture = sendBanLogMessage(banLog, member.getGuild().getIdLong(), BAN_LOG_TEMPLATE);
|
||||
return CompletableFuture.allOf(banFuture, messageFuture);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompletableFuture<Void> sendBanLogMessage(ServerContext banLog, Long guildId, String template) {
|
||||
CompletableFuture<Void> completableFuture;
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.MODERATION, guildId, ModerationMode.BAN_LOG)) {
|
||||
MessageToSend banLogMessage = templateService.renderEmbedTemplate(template, banLog);
|
||||
log.trace("Sending ban log message in guild {}.", guildId);
|
||||
List<CompletableFuture<Message>> notificationFutures = postTargetService.sendEmbedInPostTarget(banLogMessage, ModerationPostTarget.BAN_LOG, guildId);
|
||||
completableFuture = FutureUtils.toSingleFutureGeneric(notificationFutures);
|
||||
} else {
|
||||
log.trace("Feature {} has mode {} for logging disabled for server {}. Not sending notification.", ModerationFeatures.MODERATION, ModerationMode.BAN_LOG, guildId);
|
||||
completableFuture = CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> banMember(Long guildId, Long userId, String reason, ServerContext banIdLog) {
|
||||
public CompletableFuture<Void> banUserViaId(Long guildId, Long userId, String reason, ServerContext banIdLog) {
|
||||
CompletableFuture<Void> banFuture = banUser(guildId, userId, reason);
|
||||
MessageToSend banLogMessage = templateService.renderEmbedTemplate(BAN_ID_LOG_TEMPLATE, banIdLog);
|
||||
List<CompletableFuture<Message>> notificationFutures = postTargetService.sendEmbedInPostTarget(banLogMessage, ModerationPostTarget.BAN_LOG, guildId);
|
||||
return CompletableFuture.allOf(banFuture, FutureUtils.toSingleFutureGeneric(notificationFutures));
|
||||
CompletableFuture<Void> messageFuture = sendBanLogMessage(banIdLog, guildId, BAN_ID_LOG_TEMPLATE);
|
||||
return CompletableFuture.allOf(banFuture, messageFuture);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> banUser(Long guildId, Long userId, String reason) {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.ModerationPostTarget;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.KickLogModel;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
@@ -26,6 +29,9 @@ public class KickServiceBean implements KickService {
|
||||
@Autowired
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> kickMember(Member member, String reason, KickLogModel kickLogModel) {
|
||||
Guild guild = member.getGuild();
|
||||
@@ -36,7 +42,15 @@ public class KickServiceBean implements KickService {
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> sendKickLog(KickLogModel kickLogModel) {
|
||||
MessageToSend warnLogMessage = templateService.renderEmbedTemplate(KICK_LOG_TEMPLATE, kickLogModel);
|
||||
return FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(warnLogMessage, ModerationPostTarget.KICK_LOG, kickLogModel.getGuild().getIdLong()));
|
||||
CompletableFuture<Void> completableFuture;
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.MODERATION, kickLogModel.getGuild().getIdLong(), ModerationMode.KICK_LOG)) {
|
||||
MessageToSend warnLogMessage = templateService.renderEmbedTemplate(KICK_LOG_TEMPLATE, kickLogModel);
|
||||
log.trace("Sending kick log message in guild {}.", kickLogModel.getGuild().getIdLong());
|
||||
completableFuture = FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(warnLogMessage, ModerationPostTarget.KICK_LOG, kickLogModel.getGuild().getIdLong()));
|
||||
} else {
|
||||
log.trace("Feature {} has mode {} for logging disabled for server {}. Not sending kick notification.", ModerationFeatures.MODERATION, ModerationMode.BAN_LOG, kickLogModel.getGuild().getIdLong());
|
||||
completableFuture = CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return completableFuture;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
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.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.MutingMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.MutingPostTarget;
|
||||
import dev.sheldan.abstracto.moderation.exception.MuteRoleNotSetupException;
|
||||
import dev.sheldan.abstracto.moderation.exception.NoMuteFoundException;
|
||||
@@ -39,7 +41,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -90,6 +91,9 @@ public class MuteServiceBean implements MuteService {
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
public static final String MUTE_LOG_TEMPLATE = "mute_log";
|
||||
public static final String UN_MUTE_LOG_TEMPLATE = "unmute_log";
|
||||
public static final String MUTE_NOTIFICATION_TEMPLATE = "mute_notification";
|
||||
@@ -212,12 +216,12 @@ public class MuteServiceBean implements MuteService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> muteMemberWithLog(MuteContext context) {
|
||||
log.trace("Muting member {} in server {} and sending a mute log.", context.getMutedUser().getId(), context.getMutedUser().getGuild().getId());
|
||||
log.trace("Muting member {} in server {}.", context.getMutedUser().getId(), context.getMutedUser().getGuild().getId());
|
||||
AServer server = serverManagementService.loadOrCreate(context.getContext().getServerId());
|
||||
Long nextCounterValue = counterService.getNextCounterValue(server, MUTE_COUNTER_KEY);
|
||||
context.setMuteId(nextCounterValue);
|
||||
CompletableFuture<Void> mutingFuture = muteMember(context.getMutedUser(), context.getMutingUser(), context.getReason(), context.getMuteTargetDate(), context.getContext());
|
||||
CompletableFuture<Void> muteLogFuture = sendMuteLog(context);
|
||||
CompletableFuture<Void> muteLogFuture = sendMuteLog(context, server);
|
||||
return CompletableFuture.allOf(mutingFuture, muteLogFuture).thenAccept(aVoid ->
|
||||
self.persistMute(context)
|
||||
);
|
||||
@@ -229,24 +233,38 @@ public class MuteServiceBean implements MuteService {
|
||||
createMuteObject(context, triggerKey);
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> sendMuteLog(MuteContext muteLogModel) {
|
||||
log.trace("Sending mute log to the mute posttarget.");
|
||||
MessageToSend message = templateService.renderEmbedTemplate(MUTE_LOG_TEMPLATE, muteLogModel);
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(message, MutingPostTarget.MUTE_LOG, muteLogModel.getContext().getServerId());
|
||||
return FutureUtils.toSingleFutureGeneric(completableFutures);
|
||||
private CompletableFuture<Void> sendMuteLog(MuteContext muteLogModel, AServer server) {
|
||||
CompletableFuture<Void> completableFuture;
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.MUTING, server, MutingMode.MUTE_LOGGING)) {
|
||||
log.trace("Sending mute log to the mute post target.");
|
||||
MessageToSend message = templateService.renderEmbedTemplate(MUTE_LOG_TEMPLATE, muteLogModel);
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(message, MutingPostTarget.MUTE_LOG, muteLogModel.getContext().getServerId());
|
||||
completableFuture = FutureUtils.toSingleFutureGeneric(completableFutures);
|
||||
} else {
|
||||
completableFuture = CompletableFuture.completedFuture(null);
|
||||
log.trace("Not sending mute log, because feature mode {} in feature {} has been disabled for server {}.", MutingMode.MUTE_LOGGING, ModerationFeatures.WARNING, server.getId());
|
||||
}
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> sendUnMuteLogMessage(UnMuteLog muteLogModel) {
|
||||
log.trace("Sending unMute log to the mute posttarget.");
|
||||
MessageToSend message = templateService.renderEmbedTemplate(UN_MUTE_LOG_TEMPLATE, muteLogModel);
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(message, MutingPostTarget.MUTE_LOG, muteLogModel.getServer().getId());
|
||||
return FutureUtils.toSingleFutureGeneric(completableFutures);
|
||||
private CompletableFuture<Void> sendUnMuteLogMessage(UnMuteLog muteLogModel, AServer server) {
|
||||
CompletableFuture<Void> completableFuture;
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.MUTING, server, MutingMode.MUTE_LOGGING)) {
|
||||
log.trace("Sending unMute log for mute {} to the mute posttarget in server {}", muteLogModel.getMute().getMuteId().getId(), server.getId());
|
||||
MessageToSend message = templateService.renderEmbedTemplate(UN_MUTE_LOG_TEMPLATE, muteLogModel);
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(message, MutingPostTarget.MUTE_LOG, muteLogModel.getServer().getId());
|
||||
completableFuture = FutureUtils.toSingleFutureGeneric(completableFutures);
|
||||
} else {
|
||||
completableFuture = CompletableFuture.completedFuture(null);
|
||||
log.trace("Not sending unMute log, because feature mode {} in feature {} has been disabled for server {}.", MutingMode.UN_MUTE_LOGGING, ModerationFeatures.WARNING, server.getId());
|
||||
}
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CompletableFuture<Void> unMuteUser(AUserInAServer aUserInAServer) {
|
||||
if(muteManagementService.hasActiveMute(aUserInAServer)) {
|
||||
if(!muteManagementService.hasActiveMute(aUserInAServer)) {
|
||||
throw new NoMuteFoundException();
|
||||
}
|
||||
Mute mute = muteManagementService.getAMuteOf(aUserInAServer);
|
||||
@@ -254,7 +272,27 @@ public class MuteServiceBean implements MuteService {
|
||||
log.info("Mute {} has ended already, user {} does not need to be unMuted anymore.", mute.getMuteId().getId(), mute.getMutedUser().getUserReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return endMute(mute);
|
||||
Long muteId = mute.getMuteId().getId();
|
||||
CompletableFuture<Member> mutingMemberFuture = botService.getMemberInServerAsync(mute.getMutingUser());
|
||||
CompletableFuture<Member> mutedMemberFuture = botService.getMemberInServerAsync(mute.getMutedUser());
|
||||
Guild guild = botService.getGuildById(mute.getServer().getId());
|
||||
return endMute(mute).thenCompose(unused ->
|
||||
CompletableFuture.allOf(mutingMemberFuture, mutedMemberFuture)
|
||||
).thenCompose(unused -> self.sendUnMuteLogForManualUnMute(muteId, mutingMemberFuture, mutedMemberFuture, guild));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CompletableFuture<Void> sendUnMuteLogForManualUnMute(Long muteId, CompletableFuture<Member> mutingMemberFuture, CompletableFuture<Member> mutedMemberFuture, Guild guild) {
|
||||
CompletableFuture<Void> completableFuture;
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.MUTING, guild.getIdLong(), MutingMode.MANUAL_UN_MUTE_LOGGING)) {
|
||||
completableFuture = self.sendUnmuteLog(muteId, guild, mutingMemberFuture, mutedMemberFuture);
|
||||
log.trace("Sending un mute notification for manual un mute for mute {} in server {}.", muteId, guild.getIdLong());
|
||||
} else {
|
||||
completableFuture = CompletableFuture.completedFuture(null);
|
||||
log.trace("Not sending unMute log, because feature mode {} in feature {} has been disabled for server {}.", MutingMode.MANUAL_UN_MUTE_LOGGING, ModerationFeatures.WARNING, guild.getIdLong());
|
||||
|
||||
}
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -287,7 +325,7 @@ public class MuteServiceBean implements MuteService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CompletionStage<Void> sendUnmuteLog(Long muteId, Guild guild, CompletableFuture<Member> mutingMemberFuture, CompletableFuture<Member> mutedMemberFuture) {
|
||||
public CompletableFuture<Void> sendUnmuteLog(Long muteId, Guild guild, CompletableFuture<Member> mutingMemberFuture, CompletableFuture<Member> mutedMemberFuture) {
|
||||
Mute mute = muteManagementService.findMute(muteId, guild.getIdLong());
|
||||
AServer mutingServer = serverManagementService.loadServer(guild.getIdLong());
|
||||
UnMuteLog unMuteLog = UnMuteLog
|
||||
@@ -298,7 +336,7 @@ public class MuteServiceBean implements MuteService {
|
||||
.guild(guild)
|
||||
.server(mutingServer)
|
||||
.build();
|
||||
CompletableFuture<Void> notificationFuture = sendUnMuteLogMessage(unMuteLog);
|
||||
CompletableFuture<Void> notificationFuture = sendUnMuteLogMessage(unMuteLog, mutingServer);
|
||||
return CompletableFuture.allOf(notificationFuture).thenAccept(aVoid ->
|
||||
self.endMuteInDatabase(muteId, guild.getIdLong())
|
||||
);
|
||||
|
||||
@@ -6,7 +6,10 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.*;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.WarnDecayMode;
|
||||
import dev.sheldan.abstracto.moderation.config.features.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.features.WarningMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.WarnDecayPostTarget;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.WarningPostTarget;
|
||||
import dev.sheldan.abstracto.moderation.models.template.job.WarnDecayLogModel;
|
||||
@@ -66,6 +69,9 @@ public class WarnServiceBean implements WarnService {
|
||||
@Autowired
|
||||
private ServerManagementService serverManagementService;
|
||||
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
@Autowired
|
||||
private WarnServiceBean self;
|
||||
|
||||
@@ -87,8 +93,13 @@ public class WarnServiceBean implements WarnService {
|
||||
String warnNotificationMessage = templateService.renderTemplate(WARN_NOTIFICATION_TEMPLATE, warnNotification);
|
||||
List<CompletableFuture<Message>> futures = new ArrayList<>();
|
||||
futures.add(messageService.sendMessageToUser(warnedMember.getUser(), warnNotificationMessage));
|
||||
MessageToSend message = templateService.renderEmbedTemplate(WARN_LOG_TEMPLATE, context);
|
||||
futures.addAll(postTargetService.sendEmbedInPostTarget(message, WarningPostTarget.WARN_LOG, context.getGuild().getIdLong()));
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.WARNING, server.getId(), WarningMode.WARN_LOG)) {
|
||||
log.trace("Logging warning for server {}.", server.getId());
|
||||
MessageToSend message = templateService.renderEmbedTemplate(WARN_LOG_TEMPLATE, context);
|
||||
futures.addAll(postTargetService.sendEmbedInPostTarget(message, WarningPostTarget.WARN_LOG, context.getGuild().getIdLong()));
|
||||
} else {
|
||||
log.trace("Not logging warning because of feature {} with feature mode {} in server {}.", ModerationFeatures.WARNING, WarningMode.WARN_LOG, server.getId());
|
||||
}
|
||||
|
||||
return FutureUtils.toSingleFutureGeneric(futures);
|
||||
}
|
||||
@@ -119,7 +130,15 @@ public class WarnServiceBean implements WarnService {
|
||||
List<Warning> warningsToDecay = warnManagementService.getActiveWarningsInServerOlderThan(server, cutOffDay);
|
||||
List<Long> warningIds = flattenWarnings(warningsToDecay);
|
||||
Long serverId = server.getId();
|
||||
return logDecayedWarnings(server, warningsToDecay).thenAccept(aVoid ->
|
||||
CompletableFuture<Void> completableFuture;
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.AUTOMATIC_WARN_DECAY, server, WarnDecayMode.AUTOMATIC_WARN_DECAY_LOG)) {
|
||||
log.trace("Sending log messages for automatic warn decay in server {}.", server.getId());
|
||||
completableFuture = logDecayedWarnings(server, warningsToDecay);
|
||||
} else {
|
||||
log.trace("Not logging automatic warn decay, because feature {} has its mode {} disabled in server {}.", ModerationFeatures.AUTOMATIC_WARN_DECAY, WarnDecayMode.AUTOMATIC_WARN_DECAY_LOG, server.getId());
|
||||
completableFuture = CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return completableFuture.thenAccept(aVoid ->
|
||||
self.decayWarnings(warningIds, serverId)
|
||||
);
|
||||
}
|
||||
@@ -187,8 +206,8 @@ public class WarnServiceBean implements WarnService {
|
||||
// TODO add ids to render in case any member left the server
|
||||
WarnDecayWarning warnDecayWarning = WarnDecayWarning
|
||||
.builder()
|
||||
.warnedMember(pair.getFirstMember().join())
|
||||
.warningMember(pair.getSecondMember().join())
|
||||
.warningMember(pair.getFirstMember().join())
|
||||
.warnedMember(pair.getSecondMember().join())
|
||||
.warning(warning)
|
||||
.build();
|
||||
warnDecayWarnings.add(warnDecayWarning);
|
||||
@@ -205,16 +224,18 @@ public class WarnServiceBean implements WarnService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> decayAllWarningsForServer(AServer server, boolean logWarnings) {
|
||||
public CompletableFuture<Void> decayAllWarningsForServer(AServer server) {
|
||||
List<Warning> warningsToDecay = warnManagementService.getActiveWarningsInServerOlderThan(server, Instant.now());
|
||||
List<Long> warnIds = flattenWarnings(warningsToDecay);
|
||||
log.info("Decaying ALL warning in server {} with logging {}.", server.getId(), logWarnings);
|
||||
log.info("Decaying ALL warning in server {}.", server.getId());
|
||||
Long serverId = server.getId();
|
||||
if(logWarnings) {
|
||||
if(featureModeService.featureModeActive(ModerationFeatures.WARNING, server, WarningMode.WARN_DECAY_LOG)) {
|
||||
log.trace("Logging warn decays in server {}", serverId);
|
||||
return logDecayedWarnings(server, warningsToDecay).thenAccept(aVoid ->
|
||||
self.decayWarnings(warnIds, serverId)
|
||||
);
|
||||
} else {
|
||||
log.trace("Not logging warn decays for manual decay in server {} because feature {} with feature mode: {}", serverId, ModerationFeatures.WARNING, WarningMode.WARN_DECAY_LOG);
|
||||
decayWarnings(warnIds, serverId);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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="moderationFeature" value="(SELECT id FROM feature WHERE key = 'moderation')"/>
|
||||
<property name="warningsFeature" value="(SELECT id FROM feature WHERE key = 'warnings')"/>
|
||||
<property name="warnDecayFeature" value="(SELECT id FROM feature WHERE key = 'warnDecay')"/>
|
||||
<property name="mutingFeature" value="(SELECT id FROM feature WHERE key = 'muting')"/>
|
||||
<property name="today" value="(SELECT NOW())"/>
|
||||
<changeSet author="Sheldan" id="moderation_default_feature_mode-insertion">
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="banLogging"/>
|
||||
<column name="feature_id" valueComputed="${moderationFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="kickLogging"/>
|
||||
<column name="feature_id" valueComputed="${moderationFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="warnLogging"/>
|
||||
<column name="feature_id" valueComputed="${warningsFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="warnDecayLogging"/>
|
||||
<column name="feature_id" valueComputed="${warningsFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="automaticWarnDecayLogging"/>
|
||||
<column name="feature_id" valueComputed="${warningsFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="muteLogging"/>
|
||||
<column name="feature_id" valueComputed="${mutingFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="unMuteLogging"/>
|
||||
<column name="feature_id" valueComputed="${mutingFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
<insert tableName="default_feature_mode">
|
||||
<column name="enabled" value="true"/>
|
||||
<column name="mode" value="manualUnMuteLogging"/>
|
||||
<column name="feature_id" valueComputed="${mutingFeature}" />
|
||||
<column name="created" valueComputed="${today}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
Reference in New Issue
Block a user