mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-20 21:29:08 +00:00
[AB-184] adding various metrics to the system, organizing imports, changing some transactional behaviour
adding okhttp metrics, split bot service into multiple services (guild, message), unified some places that services are used in order to interact with the api, and not directly the objects (this is to make it easier for metric to be accurate)
This commit is contained in:
@@ -2,10 +2,12 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.moderation.config.ModerationModule;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.moderation.config.ModerationModule;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
|
||||
@@ -2,10 +2,12 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.moderation.config.ModerationModule;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MyWarnings extends AbstractConditionableCommand {
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
MyWarningsModel model = (MyWarningsModel) ContextConverter.fromCommandContext(commandContext, MyWarningsModel.class);
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadUser(commandContext.getAuthor());
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(commandContext.getAuthor());
|
||||
Long currentWarnCount = warnManagementService.getActiveWarnsForUser(userInAServer);
|
||||
model.setCurrentWarnCount(currentWarnCount);
|
||||
Long totalWarnCount = warnManagementService.getTotalWarnsForUser(userInAServer);
|
||||
|
||||
@@ -3,8 +3,8 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
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.utils.ParseUtils;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class UserNoteCommand extends AbstractConditionableCommand {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Member member = (Member) parameters.get(0);
|
||||
String text = (String) parameters.get(1);
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadUser(member);
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
userNoteManagementService.createUserNote(userInAServer, text);
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class UserNotes extends AbstractConditionableCommand {
|
||||
ListNotesModel model = (ListNotesModel) ContextConverter.fromCommandContext(commandContext, ListNotesModel.class);
|
||||
if(parameters.size() == 1) {
|
||||
Member member = (Member) parameters.get(0);
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadUser(member);
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadOrCreateUser(member);
|
||||
userNotes = userNoteManagementService.loadNotesForUser(userInAServer);
|
||||
FullUserInServer specifiedUser = FullUserInServer
|
||||
.builder()
|
||||
|
||||
@@ -2,10 +2,12 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.condition.CommandCondition;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ContextConverter;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.moderation.config.ModerationModule;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class Warnings extends AbstractConditionableCommand {
|
||||
List<Warning> warnsToDisplay;
|
||||
if(!commandContext.getParameters().getParameters().isEmpty()) {
|
||||
Member member = (Member) commandContext.getParameters().getParameters().get(0);
|
||||
warnsToDisplay = warnManagementService.getAllWarnsForUser(userInServerManagementService.loadUser(member));
|
||||
warnsToDisplay = warnManagementService.getAllWarnsForUser(userInServerManagementService.loadOrCreateUser(member));
|
||||
} else {
|
||||
AServer server = serverManagementService.loadServer(commandContext.getGuild());
|
||||
warnsToDisplay = warnManagementService.getAllWarningsOfServer(server);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class UnMute extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Member member = (Member) parameters.get(0);
|
||||
AUserInAServer userToUnMute = userInServerManagementService.loadUser(member);
|
||||
AUserInAServer userToUnMute = userInServerManagementService.loadOrCreateUser(member);
|
||||
return muteService.unMuteUser(userToUnMute).thenApply(aVoid ->
|
||||
CommandResult.fromSuccess()
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.moderation.converter;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.models.database.UserNote;
|
||||
@@ -15,8 +15,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@@ -25,7 +25,7 @@ public class UserNotesConverter {
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private UserNotesConverter self;
|
||||
@@ -38,7 +38,7 @@ public class UserNotesConverter {
|
||||
List<CompletableFuture<Member>> memberFutures = new ArrayList<>();
|
||||
HashMap<ServerSpecificId, CompletableFuture<Member>> noteMemberMap = new HashMap<>();
|
||||
userNotes.forEach(userNote -> {
|
||||
CompletableFuture<Member> memberFuture = botService.getMemberInServerAsync(userNote.getUser());
|
||||
CompletableFuture<Member> memberFuture = memberService.getMemberInServerAsync(userNote.getUser());
|
||||
memberFutures.add(memberFuture);
|
||||
noteMemberMap.put(userNote.getUserNoteId(), memberFuture);
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.moderation.converter;
|
||||
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
||||
import dev.sheldan.abstracto.core.models.FutureMemberPair;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
@@ -16,15 +16,15 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class WarnEntryConverter {
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
@@ -40,8 +40,8 @@ public class WarnEntryConverter {
|
||||
List<CompletableFuture<Member>> allFutures = new ArrayList<>();
|
||||
// TODO maybe optimize to not need to look into the cache twice
|
||||
warnings.forEach(warning -> {
|
||||
CompletableFuture<Member> warningMemberFuture = botService.getMemberInServerAsync(warning.getWarningUser());
|
||||
CompletableFuture<Member> warnedMemberFuture = botService.getMemberInServerAsync(warning.getWarnedUser());
|
||||
CompletableFuture<Member> warningMemberFuture = memberService.getMemberInServerAsync(warning.getWarningUser());
|
||||
CompletableFuture<Member> warnedMemberFuture = memberService.getMemberInServerAsync(warning.getWarnedUser());
|
||||
FutureMemberPair futurePair = FutureMemberPair.builder().firstMember(warningMemberFuture).secondMember(warnedMemberFuture).build();
|
||||
loadedWarnings.put(warning.getWarnId(), futurePair);
|
||||
allFutures.add(warningMemberFuture);
|
||||
@@ -62,14 +62,14 @@ public class WarnEntryConverter {
|
||||
FullUserInServer warnedUser = FullUserInServer
|
||||
.builder()
|
||||
.member(warnedMember)
|
||||
.aUserInAServer(userInServerManagementService.loadUser(warnedMember))
|
||||
.aUserInAServer(userInServerManagementService.loadOrCreateUser(warnedMember))
|
||||
.build();
|
||||
|
||||
Member warningMember = memberPair.getFirstMember().join();
|
||||
FullUserInServer warningUser = FullUserInServer
|
||||
.builder()
|
||||
.member(warningMember)
|
||||
.aUserInAServer(userInServerManagementService.loadUser(warningMember))
|
||||
.aUserInAServer(userInServerManagementService.loadOrCreateUser(warningMember))
|
||||
.build();
|
||||
WarnEntry entry = WarnEntry
|
||||
.builder()
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.quartz.PersistJobDataAfterExecution;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
@@ -36,7 +37,7 @@ public class WarnDecayJob extends QuartzJobBean {
|
||||
private WarnService warnService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional(isolation = Isolation.SERIALIZABLE)
|
||||
public void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
||||
List<AServer> allServers = serverManagementService.getAllServers();
|
||||
log.info("Executing warn decay job.");
|
||||
|
||||
@@ -4,8 +4,12 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.config.ListenerPriority;
|
||||
import dev.sheldan.abstracto.core.execution.result.MessageReceivedListenerResult;
|
||||
import dev.sheldan.abstracto.core.listener.sync.jda.MessageReceivedListener;
|
||||
import dev.sheldan.abstracto.core.metrics.service.CounterMetric;
|
||||
import dev.sheldan.abstracto.core.metrics.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.metrics.service.MetricTag;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
@@ -20,7 +24,9 @@ import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -41,6 +47,22 @@ public class InviteLinkFilterListener implements MessageReceivedListener {
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private MetricService metricService;
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
|
||||
public static final String MODERATION_PURGE_METRIC = "invite.filter";
|
||||
public static final String CONSEQUENCE = "consequence";
|
||||
|
||||
private static final CounterMetric MESSAGE_INVITE_FILTERED =
|
||||
CounterMetric
|
||||
.builder()
|
||||
.tagList(Arrays.asList(MetricTag.getTag(CONSEQUENCE, "filtered")))
|
||||
.name(MODERATION_PURGE_METRIC)
|
||||
.build();
|
||||
|
||||
public static final String INVITE_LINK_DELETED_NOTIFICATION_EMBED_TEMPLATE_KEY = "invite_link_deleted_notification";
|
||||
|
||||
@Override
|
||||
@@ -60,7 +82,8 @@ public class InviteLinkFilterListener implements MessageReceivedListener {
|
||||
}
|
||||
|
||||
if(toDelete) {
|
||||
message.delete().queue();
|
||||
metricService.incrementCounter(MESSAGE_INVITE_FILTERED);
|
||||
messageService.deleteMessage(message);
|
||||
boolean trackUsages = featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, serverId, InviteFilterMode.TRACK_USES);
|
||||
if(trackUsages) {
|
||||
codesToTrack.forEach(s -> inviteLinkFilterService.storeFilteredInviteLinkUsage(s, author));
|
||||
@@ -111,4 +134,9 @@ public class InviteLinkFilterListener implements MessageReceivedListener {
|
||||
public Integer getPriority() {
|
||||
return ListenerPriority.HIGH;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
metricService.registerCounter(MESSAGE_INVITE_FILTERED, "Amount of messages containing an invite filtered");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.moderation.listener.async;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncJoinListener;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.LoggingPostTarget;
|
||||
@@ -30,7 +30,7 @@ public class JoinLogger implements AsyncJoinListener {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private JoinLogger self;
|
||||
@@ -44,7 +44,7 @@ public class JoinLogger implements AsyncJoinListener {
|
||||
@Override
|
||||
public void execute(ServerUser serverUser) {
|
||||
log.info("User {} joined server {}.", serverUser.getUserId(), serverUser.getServerId());
|
||||
botService.getMemberInServerAsync(serverUser.getServerId(), serverUser.getUserId()).thenAccept(member ->
|
||||
memberService.getMemberInServerAsync(serverUser.getServerId(), serverUser.getUserId()).thenAccept(member ->
|
||||
self.sendJoinLog(serverUser, member)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class JoinMuteListener implements AsyncJoinListener {
|
||||
|
||||
@Override
|
||||
public void execute(ServerUser serverUser) {
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(serverUser.getServerId(), serverUser.getUserId());
|
||||
AUserInAServer aUserInAServer = userInServerManagementService.loadOrCreateUser(serverUser.getServerId(), serverUser.getUserId());
|
||||
if(muteManagementService.hasActiveMute(aUserInAServer)) {
|
||||
log.info("Re-muting user {} which joined the server {}, because the mute has not ended yet.", serverUser.getUserId(), serverUser.getServerId());
|
||||
muteService.applyMuteRole(aUserInAServer);
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.moderation.listener.async;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncLeaveListener;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.LoggingPostTarget;
|
||||
@@ -32,7 +32,7 @@ public class LeaveLogger implements AsyncLeaveListener {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private LeaveLogger self;
|
||||
@@ -48,7 +48,7 @@ public class LeaveLogger implements AsyncLeaveListener {
|
||||
@Override
|
||||
public void execute(ServerUser serverUser) {
|
||||
log.info("User {} left server {}.", serverUser.getUserId(), serverUser.getServerId());
|
||||
botService.getMemberInServerAsync(serverUser.getServerId(), serverUser.getUserId()).thenAccept(member ->
|
||||
memberService.getMemberInServerAsync(serverUser.getServerId(), serverUser.getUserId()).thenAccept(member ->
|
||||
self.executeJoinLogging(serverUser, member)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ package dev.sheldan.abstracto.moderation.listener.async;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageDeletedListener;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
@@ -39,7 +40,10 @@ public class MessageDeleteLogListener implements AsyncMessageDeletedListener {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private ChannelManagementService channelManagementService;
|
||||
@@ -55,7 +59,7 @@ public class MessageDeleteLogListener implements AsyncMessageDeletedListener {
|
||||
|
||||
@Override
|
||||
public void execute(CachedMessage messageFromCache) {
|
||||
botService.getMemberInServerAsync(messageFromCache.getServerId(), messageFromCache.getAuthor().getAuthorId()).thenAccept(member ->
|
||||
memberService.getMemberInServerAsync(messageFromCache.getServerId(), messageFromCache.getAuthor().getAuthorId()).thenAccept(member ->
|
||||
self.executeListener(messageFromCache, member)
|
||||
);
|
||||
}
|
||||
@@ -64,7 +68,7 @@ public class MessageDeleteLogListener implements AsyncMessageDeletedListener {
|
||||
public void executeListener(CachedMessage messageFromCache, Member authorMember) {
|
||||
log.trace("Message {} in channel {} in guild {} was deleted.", messageFromCache.getMessageId(), messageFromCache.getChannelId(), messageFromCache.getServerId());
|
||||
|
||||
TextChannel textChannel = botService.getTextChannelFromServer(messageFromCache.getServerId(), messageFromCache.getChannelId());
|
||||
TextChannel textChannel = channelService.getTextChannelFromServer(messageFromCache.getServerId(), messageFromCache.getChannelId());
|
||||
MessageDeletedLog logModel = MessageDeletedLog
|
||||
.builder()
|
||||
.cachedMessage(messageFromCache)
|
||||
|
||||
@@ -3,7 +3,8 @@ package dev.sheldan.abstracto.moderation.listener.async;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.listener.async.jda.AsyncMessageTextUpdatedListener;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.LoggingPostTarget;
|
||||
@@ -28,7 +29,10 @@ public class MessageEditedListener implements AsyncMessageTextUpdatedListener {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public void execute(CachedMessage messageBefore, CachedMessage messageAfter) {
|
||||
@@ -36,9 +40,9 @@ public class MessageEditedListener implements AsyncMessageTextUpdatedListener {
|
||||
log.trace("Message content was the same. Possible reason was: message was not in cache.");
|
||||
return;
|
||||
}
|
||||
botService.getMemberInServerAsync(messageAfter.getServerId(), messageAfter.getAuthor().getAuthorId()).thenAccept(author -> {
|
||||
memberService.getMemberInServerAsync(messageAfter.getServerId(), messageAfter.getAuthor().getAuthorId()).thenAccept(author -> {
|
||||
log.trace("Message {} in channel {} in guild {} was edited.", messageBefore.getMessageId(), messageBefore.getChannelId(), messageBefore.getServerId());
|
||||
TextChannel textChannel = botService.getTextChannelFromServer(messageAfter.getServerId(), messageAfter.getChannelId());
|
||||
TextChannel textChannel = channelService.getTextChannelFromServer(messageAfter.getServerId(), messageAfter.getChannelId());
|
||||
MessageEditedLog log = MessageEditedLog
|
||||
.builder()
|
||||
.messageAfter(messageAfter)
|
||||
|
||||
@@ -2,8 +2,8 @@ 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.GuildService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
@@ -31,7 +31,7 @@ public class BanServiceBean implements BanService {
|
||||
public static final String BAN_ID_LOG_TEMPLATE = "banId_log";
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
@@ -72,7 +72,7 @@ public class BanServiceBean implements BanService {
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> banUser(Long guildId, Long userId, String reason) {
|
||||
Optional<Guild> guildByIdOptional = botService.getGuildByIdOptional(guildId);
|
||||
Optional<Guild> guildByIdOptional = guildService.getGuildByIdOptional(guildId);
|
||||
if(guildByIdOptional.isPresent()) {
|
||||
return banUser(guildByIdOptional.get(), userId, reason);
|
||||
} else {
|
||||
|
||||
@@ -27,7 +27,10 @@ import dev.sheldan.abstracto.scheduling.service.SchedulerService;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -67,7 +70,10 @@ public class MuteServiceBean implements MuteService {
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
@@ -94,6 +100,9 @@ public class MuteServiceBean implements MuteService {
|
||||
@Autowired
|
||||
private FeatureModeService featureModeService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
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";
|
||||
@@ -103,13 +112,13 @@ public class MuteServiceBean implements MuteService {
|
||||
public CompletableFuture<Void> muteMember(Member memberToMute, Member mutingMember, String reason, Instant unMuteDate, ServerChannelMessage message) {
|
||||
FullUserInServer mutedUser = FullUserInServer
|
||||
.builder()
|
||||
.aUserInAServer(userInServerManagementService.loadUser(memberToMute))
|
||||
.aUserInAServer(userInServerManagementService.loadOrCreateUser(memberToMute))
|
||||
.member(memberToMute)
|
||||
.build();
|
||||
|
||||
FullUserInServer mutingUser = FullUserInServer
|
||||
.builder()
|
||||
.aUserInAServer(userInServerManagementService.loadUser(mutingMember))
|
||||
.aUserInAServer(userInServerManagementService.loadOrCreateUser(mutingMember))
|
||||
.member(mutingMember)
|
||||
.build();
|
||||
return muteUserInServer(mutedUser, mutingUser, reason, unMuteDate, message);
|
||||
@@ -153,8 +162,8 @@ public class MuteServiceBean implements MuteService {
|
||||
String muteNotificationMessage = templateService.renderTemplate(MUTE_NOTIFICATION_TEMPLATE, muteNotification);
|
||||
CompletableFuture<Message> messageCompletableFuture = messageService.sendMessageToUser(memberBeingMuted.getUser(), muteNotificationMessage);
|
||||
messageCompletableFuture.exceptionally(throwable -> {
|
||||
TextChannel feedBackChannel = botService.getTextChannelFromServer(message.getServerId(), message.getChannelId());
|
||||
feedBackChannel.sendMessage(throwable.getMessage()).submit().whenComplete((exceptionMessage, innerThrowable) -> {
|
||||
TextChannel feedBackChannel = channelService.getTextChannelFromServer(message.getServerId(), message.getChannelId());
|
||||
channelService.sendTextToChannel(throwable.getMessage(), feedBackChannel).whenComplete((exceptionMessage, innerThrowable) -> {
|
||||
notificationFuture.complete(null);
|
||||
log.info("Successfully notified user {} in server {} about mute.", memberBeingMuted.getId(), memberBeingMuted.getGuild().getId());
|
||||
});
|
||||
@@ -174,8 +183,8 @@ public class MuteServiceBean implements MuteService {
|
||||
.server(channel.getServer())
|
||||
.messageId(muteContext.getContext().getMessageId())
|
||||
.build();
|
||||
AUserInAServer userInServerBeingMuted = userInServerManagementService.loadUser(muteContext.getMutedUser());
|
||||
AUserInAServer userInServerMuting = userInServerManagementService.loadUser(muteContext.getMutedUser());
|
||||
AUserInAServer userInServerBeingMuted = userInServerManagementService.loadOrCreateUser(muteContext.getMutedUser());
|
||||
AUserInAServer userInServerMuting = userInServerManagementService.loadOrCreateUser(muteContext.getMutedUser());
|
||||
muteManagementService.createMute(userInServerBeingMuted, userInServerMuting, muteContext.getReason(), muteContext.getMuteTargetDate(), origin, triggerKey, muteContext.getMuteId());
|
||||
}
|
||||
|
||||
@@ -269,9 +278,9 @@ public class MuteServiceBean implements MuteService {
|
||||
}
|
||||
Mute mute = muteManagementService.getAMuteOf(aUserInAServer);
|
||||
Long muteId = mute.getMuteId().getId();
|
||||
CompletableFuture<Member> mutingMemberFuture = botService.getMemberInServerAsync(mute.getMutingUser());
|
||||
CompletableFuture<Member> mutedMemberFuture = botService.getMemberInServerAsync(mute.getMutedUser());
|
||||
Guild guild = botService.getGuildById(mute.getMuteId().getServerId());
|
||||
CompletableFuture<Member> mutingMemberFuture = memberService.getMemberInServerAsync(mute.getMutingUser());
|
||||
CompletableFuture<Member> mutedMemberFuture = memberService.getMemberInServerAsync(mute.getMutedUser());
|
||||
Guild guild = guildService.getGuildById(mute.getMuteId().getServerId());
|
||||
return endMute(mute, false).thenCompose(unused ->
|
||||
CompletableFuture.allOf(mutingMemberFuture, mutedMemberFuture)
|
||||
).thenCompose(unused -> self.sendUnMuteLogForManualUnMute(muteId, mutingMemberFuture, mutedMemberFuture, guild));
|
||||
@@ -302,17 +311,17 @@ public class MuteServiceBean implements MuteService {
|
||||
log.info("UnMuting {} in server {}", mute.getMutedUser().getUserReference().getId(), mutingServer.getId());
|
||||
MuteRole muteRole = muteRoleManagementService.retrieveMuteRoleForServer(mutingServer);
|
||||
log.trace("Using the mute role {} mapping to role {}", muteRole.getId(), muteRole.getRole().getId());
|
||||
Guild guild = botService.getGuildById(mutingServer.getId());
|
||||
Guild guild = guildService.getGuildById(mutingServer.getId());
|
||||
CompletableFuture<Void> roleRemovalFuture;
|
||||
// TODO replace with future, because caching
|
||||
if(botService.isUserInGuild(guild, mute.getMutedUser())) {
|
||||
if(memberService.isUserInGuild(guild, mute.getMutedUser())) {
|
||||
roleRemovalFuture = roleService.removeRoleFromUserFuture(mute.getMutedUser(), muteRole.getRole());
|
||||
} else {
|
||||
roleRemovalFuture = CompletableFuture.completedFuture(null);
|
||||
log.info("User to unMute left the guild.");
|
||||
}
|
||||
CompletableFuture<Member> mutingMemberFuture = botService.getMemberInServerAsync(mute.getMutingUser());
|
||||
CompletableFuture<Member> mutedMemberFuture = botService.getMemberInServerAsync(mute.getMutedUser());
|
||||
CompletableFuture<Member> mutingMemberFuture = memberService.getMemberInServerAsync(mute.getMutingUser());
|
||||
CompletableFuture<Member> mutedMemberFuture = memberService.getMemberInServerAsync(mute.getMutedUser());
|
||||
CompletableFuture<Void> finalFuture = new CompletableFuture<>();
|
||||
CompletableFuture.allOf(mutingMemberFuture, mutedMemberFuture, roleRemovalFuture, mutingMemberFuture, mutedMemberFuture).handle((aVoid, throwable) -> {
|
||||
if(sendNotification) {
|
||||
@@ -379,6 +388,7 @@ public class MuteServiceBean implements MuteService {
|
||||
|
||||
@Override
|
||||
public void completelyUnMuteMember(Member member) {
|
||||
completelyUnMuteUser(userInServerManagementService.loadUser(member));
|
||||
completelyUnMuteUser(userInServerManagementService.loadOrCreateUser(member));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.metrics.service.CounterMetric;
|
||||
import dev.sheldan.abstracto.core.metrics.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import dev.sheldan.abstracto.moderation.exception.NoMessageFoundException;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.PurgeStatusUpdateModel;
|
||||
@@ -15,6 +18,7 @@ import net.dv8tion.jda.api.utils.TimeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -32,6 +36,20 @@ public class PurgeServiceBean implements PurgeService {
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private MetricService metricService;
|
||||
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
public static final String MODERATION_PURGE_METRIC = "moderation.purge";
|
||||
|
||||
private static final CounterMetric PURGE_MESSAGE_COUNTER_METRIC =
|
||||
CounterMetric
|
||||
.builder()
|
||||
.name(MODERATION_PURGE_METRIC)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> purgeMessagesInChannel(Integer amountToDelete, TextChannel channel, Long startId, Member purgedMember) {
|
||||
return purgeMessages(amountToDelete, channel, startId, purgedMember, amountToDelete, 0, 0L);
|
||||
@@ -45,9 +63,10 @@ public class PurgeServiceBean implements PurgeService {
|
||||
} else {
|
||||
toDeleteInThisIteration = amountToDelete % PURGE_MAX_MESSAGES;
|
||||
}
|
||||
metricService.incrementCounter(PURGE_MESSAGE_COUNTER_METRIC, (long) toDeleteInThisIteration);
|
||||
log.info("Purging {} this iteration ({}/{}) messages in channel {} in server {}.", toDeleteInThisIteration, currentCount, totalCount, channel.getId(), channel.getGuild().getId());
|
||||
|
||||
CompletableFuture<MessageHistory> historyFuture = channel.getHistoryBefore(startId, toDeleteInThisIteration).submit();
|
||||
CompletableFuture<MessageHistory> historyFuture = channelService.getHistoryOfChannel(channel, startId, toDeleteInThisIteration);
|
||||
CompletableFuture<Long> statusMessageFuture = getOrCreatedStatusMessage(channel, totalCount, statusMessageId);
|
||||
|
||||
CompletableFuture<Void> deletionFuture = new CompletableFuture<>();
|
||||
@@ -60,6 +79,7 @@ public class PurgeServiceBean implements PurgeService {
|
||||
if(messagesToDeleteNow.size() == 0) {
|
||||
log.warn("No messages found to delete, all were filtered.");
|
||||
deletionFuture.completeExceptionally(new NoMessageFoundException());
|
||||
// TODO move to message service
|
||||
channel.deleteMessageById(currentStatusMessageId).queueAfter(5, TimeUnit.SECONDS);
|
||||
return;
|
||||
}
|
||||
@@ -71,7 +91,7 @@ public class PurgeServiceBean implements PurgeService {
|
||||
if (messagesToDeleteNow.size() > 1) {
|
||||
bulkDeleteMessages(channel, deletionFuture, messagesToDeleteNow, consumer);
|
||||
} else if (messagesToDeleteNow.size() == 1) {
|
||||
latestMessage.delete().queue(consumer, deletionFuture::completeExceptionally);
|
||||
messageService.deleteMessage(latestMessage).queue(consumer, deletionFuture::completeExceptionally);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -88,9 +108,9 @@ public class PurgeServiceBean implements PurgeService {
|
||||
|
||||
private void bulkDeleteMessages(TextChannel channel, CompletableFuture<Void> deletionFuture, List<Message> messagesToDeleteNow, Consumer<Void> consumer) {
|
||||
try {
|
||||
channel.deleteMessages(messagesToDeleteNow).queue(consumer, deletionFuture::completeExceptionally);
|
||||
channelService.deleteMessagesInChannel(channel, messagesToDeleteNow).queue(consumer, deletionFuture::completeExceptionally);
|
||||
} catch (IllegalArgumentException e) {
|
||||
channel.sendMessage(e.getMessage()).queue();
|
||||
channelService.sendTextToChannel(e.getMessage(), channel);
|
||||
log.warn("Failed to bulk delete, message was most likely too old to delete by bulk.", e);
|
||||
deletionFuture.complete(null);
|
||||
}
|
||||
@@ -145,6 +165,7 @@ public class PurgeServiceBean implements PurgeService {
|
||||
);
|
||||
} else {
|
||||
log.trace("Completed purging of {} messages.", totalCount);
|
||||
// Todo Move to message service
|
||||
channel.deleteMessageById(currentStatusMessageId).queueAfter(5, TimeUnit.SECONDS);
|
||||
deletionFuture.complete(null);
|
||||
}
|
||||
@@ -159,4 +180,9 @@ public class PurgeServiceBean implements PurgeService {
|
||||
public CompletableFuture<Void> purgeMessagesInChannel(Integer count, TextChannel channel, Message origin, Member purgingRestriction) {
|
||||
return purgeMessagesInChannel(count, channel, origin.getIdLong(), purgingRestriction);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
metricService.registerCounter(PURGE_MESSAGE_COUNTER_METRIC, "Amount of messages deleted by purge.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,16 +17,16 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class SlowModeServiceBean implements SlowModeService {
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private ChannelService channelService;
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> setSlowMode(TextChannel channel, Duration duration) {
|
||||
log.info("Setting slow mode to {} in channel {} in server {}", duration.toString(), channel.getIdLong(), channel.getGuild().getId());
|
||||
long seconds = duration.getSeconds();
|
||||
int seconds = (int) duration.getSeconds();
|
||||
if(seconds > TextChannel.MAX_SLOWMODE) {
|
||||
throw new IllegalArgumentException("Slow mode duration must be < " + TextChannel.MAX_SLOWMODE + " seconds.");
|
||||
}
|
||||
return channel.getManager().setSlowmode((int) seconds).submit();
|
||||
return channelService.setSlowModeInChannel(channel, seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,7 +36,7 @@ public class SlowModeServiceBean implements SlowModeService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> setSlowMode(AChannel channel, Duration duration) {
|
||||
Optional<TextChannel> textChannelOptional = botService.getTextChannelFromServerOptional(channel.getServer().getId(), channel.getId());
|
||||
Optional<TextChannel> textChannelOptional = channelService.getTextChannelFromServerOptional(channel.getServer().getId(), channel.getId());
|
||||
if(textChannelOptional.isPresent()) {
|
||||
TextChannel textChannel = textChannelOptional.get();
|
||||
return this.setSlowMode(textChannel, duration);
|
||||
|
||||
@@ -3,38 +3,36 @@ package dev.sheldan.abstracto.moderation.service;
|
||||
import dev.sheldan.abstracto.core.models.FutureMemberPair;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.*;
|
||||
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.mode.WarnDecayMode;
|
||||
import dev.sheldan.abstracto.moderation.config.features.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.WarnDecayMode;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.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;
|
||||
import dev.sheldan.abstracto.moderation.models.template.job.WarnDecayWarning;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.WarnContext;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.WarnNotification;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.models.template.job.WarnDecayLogModel;
|
||||
import dev.sheldan.abstracto.moderation.models.template.job.WarnDecayWarning;
|
||||
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
@@ -55,7 +53,10 @@ public class WarnServiceBean implements WarnService {
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Autowired
|
||||
private GuildService guildService;
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
@@ -115,8 +116,8 @@ public class WarnServiceBean implements WarnService {
|
||||
public void persistWarning(WarnContext context) {
|
||||
log.info("Persisting warning {} in server {} for user {} by user {}.",
|
||||
context.getWarnId(), context.getGuild().getId(), context.getWarnedMember().getId(), context.getMember().getId());
|
||||
AUserInAServer warnedUser = userInServerManagementService.loadUser(context.getWarnedMember());
|
||||
AUserInAServer warningUser = userInServerManagementService.loadUser(context.getMember());
|
||||
AUserInAServer warnedUser = userInServerManagementService.loadOrCreateUser(context.getWarnedMember());
|
||||
AUserInAServer warningUser = userInServerManagementService.loadOrCreateUser(context.getMember());
|
||||
warnManagementService.createWarning(warnedUser, warningUser, context.getReason(), context.getWarnId());
|
||||
|
||||
}
|
||||
@@ -179,8 +180,8 @@ public class WarnServiceBean implements WarnService {
|
||||
List<CompletableFuture<Member>> allFutures = new ArrayList<>();
|
||||
Long serverId = server.getId();
|
||||
warningsToDecay.forEach(warning -> {
|
||||
CompletableFuture<Member> warningMember = botService.getMemberInServerAsync(warning.getWarningUser());
|
||||
CompletableFuture<Member> warnedMember = botService.getMemberInServerAsync(warning.getWarnedUser());
|
||||
CompletableFuture<Member> warningMember = memberService.getMemberInServerAsync(warning.getWarningUser());
|
||||
CompletableFuture<Member> warnedMember = memberService.getMemberInServerAsync(warning.getWarnedUser());
|
||||
FutureMemberPair futurePair = FutureMemberPair.builder().firstMember(warningMember).secondMember(warnedMember).build();
|
||||
warningMembers.put(warning.getWarnId(), futurePair);
|
||||
});
|
||||
@@ -214,7 +215,7 @@ public class WarnServiceBean implements WarnService {
|
||||
});
|
||||
WarnDecayLogModel warnDecayLogModel = WarnDecayLogModel
|
||||
.builder()
|
||||
.guild(botService.getGuildById(server.getId()))
|
||||
.guild(guildService.getGuildById(server.getId()))
|
||||
.warnings(warnDecayWarnings)
|
||||
.build();
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(WARN_DECAY_LOG_TEMPLATE_KEY, warnDecayLogModel);
|
||||
|
||||
@@ -71,7 +71,7 @@ public class MuteManagementServiceBean implements MuteManagementService {
|
||||
|
||||
@Override
|
||||
public boolean hasActiveMute(Member member) {
|
||||
return muteRepository.existsByMutedUserAndMuteEndedFalse(userInServerManagementService.loadUser(member));
|
||||
return muteRepository.existsByMutedUserAndMuteEndedFalse(userInServerManagementService.loadOrCreateUser(member));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,7 +81,7 @@ public class MuteManagementServiceBean implements MuteManagementService {
|
||||
|
||||
@Override
|
||||
public Mute getAMuteOf(Member member) {
|
||||
return getAMuteOf(userInServerManagementService.loadUser(member));
|
||||
return getAMuteOf(userInServerManagementService.loadOrCreateUser(member));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,9 +3,9 @@ package dev.sheldan.abstracto.moderation.service.management;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.repository.WarnRepository;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -2,21 +2,25 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.BanIdLog;
|
||||
import dev.sheldan.abstracto.moderation.service.BanService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BanIdTest {
|
||||
|
||||
@@ -2,22 +2,26 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.BanLog;
|
||||
import dev.sheldan.abstracto.moderation.service.BanService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BanTest {
|
||||
|
||||
@@ -4,9 +4,9 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -16,7 +16,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DecayAllWarningsTest {
|
||||
|
||||
@@ -4,9 +4,9 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -17,7 +17,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@Slf4j
|
||||
|
||||
@@ -5,10 +5,10 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.ResultState;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.service.management.UserNoteManagementService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.service.management.UserNoteManagementService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -4,11 +4,11 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
@@ -2,11 +2,11 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.KickLogModel;
|
||||
import dev.sheldan.abstracto.moderation.service.KickServiceBean;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -20,7 +20,8 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class KickTest {
|
||||
|
||||
@@ -6,11 +6,11 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
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.features.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.MyWarningsModel;
|
||||
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -48,7 +48,7 @@ public class MyWarningsTest {
|
||||
CommandContext noParameter = CommandTestUtilities.getNoParameters();
|
||||
Long activeWarnCount = 8L;
|
||||
AUserInAServer aUserInAServer = Mockito.mock(AUserInAServer.class);
|
||||
when(userInServerManagementService.loadUser(noParameter.getAuthor())).thenReturn(aUserInAServer);
|
||||
when(userInServerManagementService.loadOrCreateUser(noParameter.getAuthor())).thenReturn(aUserInAServer);
|
||||
when(warnManagementService.getActiveWarnsForUser(aUserInAServer)).thenReturn(activeWarnCount);
|
||||
Long totalWarnCount = 10L;
|
||||
when(warnManagementService.getTotalWarnsForUser(aUserInAServer)).thenReturn(totalWarnCount);
|
||||
|
||||
@@ -3,10 +3,10 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
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.moderation.service.PurgeService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.service.PurgeService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -19,7 +19,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PurgeTest {
|
||||
|
||||
@@ -2,9 +2,9 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.moderation.service.SlowModeService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.service.SlowModeService;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -17,7 +17,7 @@ import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SlowModeTest {
|
||||
|
||||
@@ -5,10 +5,10 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.service.management.UserNoteManagementService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.service.management.UserNoteManagementService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -40,7 +40,7 @@ public class UserNoteCommandTest {
|
||||
AUserInAServer userInAServer = MockUtils.getUserObject(4L, server);
|
||||
String note = "note";
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(member, note));
|
||||
when(userInServerManagementService.loadUser(member)).thenReturn(userInAServer);
|
||||
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(userInAServer);
|
||||
CommandResult result = testUnit.execute(parameters);
|
||||
verify(userNoteManagementService, times(1)).createUserNote(userInAServer, note);
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
|
||||
@@ -7,15 +7,15 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.converter.UserNotesConverter;
|
||||
import dev.sheldan.abstracto.moderation.models.database.UserNote;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.ListNotesModel;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.NoteEntryModel;
|
||||
import dev.sheldan.abstracto.moderation.service.management.UserNoteManagementService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -62,7 +62,7 @@ public class UserNotesTest {
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(member));
|
||||
AServer server = Mockito.mock(AServer.class);
|
||||
AUserInAServer userNoteUser = MockUtils.getUserObject(4L, server);
|
||||
when(userInServerManagementService.loadUser(member)).thenReturn(userNoteUser);
|
||||
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(userNoteUser);
|
||||
UserNote firstNote = UserNote.builder().build();
|
||||
UserNote secondNote = UserNote.builder().build();
|
||||
List<UserNote> userNotes = Arrays.asList(firstNote, secondNote);
|
||||
|
||||
@@ -2,11 +2,11 @@ package dev.sheldan.abstracto.moderation.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.WarnContext;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -17,7 +17,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class WarnTest {
|
||||
|
||||
@@ -9,13 +9,13 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.PaginatorService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
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.converter.WarnEntryConverter;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.WarnEntry;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.WarningsModel;
|
||||
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -104,7 +104,7 @@ public class WarningsTest {
|
||||
WarnEntry secondModelWarning = Mockito.mock(WarnEntry.class);
|
||||
List<Warning> warningsToDisplay = Arrays.asList(firstWarning, secondWarning);
|
||||
List<WarnEntry> modelWarnings = Arrays.asList(firstModelWarning, secondModelWarning);
|
||||
when(userInServerManagementService.loadUser(member)).thenReturn(warnedUser);
|
||||
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(warnedUser);
|
||||
when(warnManagementService.getAllWarnsForUser(warnedUser)).thenReturn(warningsToDisplay);
|
||||
when(warnEntryConverter.fromWarnings(warningsToDisplay)).thenReturn(CompletableFuture.completedFuture(modelWarnings));
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ package dev.sheldan.abstracto.moderation.commands.mute;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.MuteContext;
|
||||
import dev.sheldan.abstracto.moderation.service.MuteService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.MuteContext;
|
||||
import dev.sheldan.abstracto.moderation.service.MuteService;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -17,7 +17,7 @@ import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MuteTest {
|
||||
|
||||
@@ -6,9 +6,9 @@ import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.service.management.MuteRoleManagementService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.service.management.MuteRoleManagementService;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -4,12 +4,12 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
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.exception.NoMuteFoundException;
|
||||
import dev.sheldan.abstracto.moderation.service.MuteService;
|
||||
import dev.sheldan.abstracto.moderation.service.management.MuteManagementService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -17,11 +17,10 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UnMuteTest {
|
||||
@@ -48,7 +47,7 @@ public class UnMuteTest {
|
||||
public void testUnMuteCommand() {
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(memberToUnMute));
|
||||
AUserInAServer user = AUserInAServer.builder().build();
|
||||
when(userInServerManagementService.loadUser(memberToUnMute)).thenReturn(user);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberToUnMute)).thenReturn(user);
|
||||
when(muteService.unMuteUser(user)).thenReturn(CompletableFuture.completedFuture(null));
|
||||
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
|
||||
CommandTestUtilities.checkSuccessfulCompletionAsync(result);
|
||||
@@ -58,7 +57,7 @@ public class UnMuteTest {
|
||||
public void testUnMuteCommandWithoutExistingMute() {
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(memberToUnMute));
|
||||
AUserInAServer user = AUserInAServer.builder().build();
|
||||
when(userInServerManagementService.loadUser(memberToUnMute)).thenReturn(user);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberToUnMute)).thenReturn(user);
|
||||
when(muteService.unMuteUser(user)).thenThrow(new NoMuteFoundException());
|
||||
testUnit.executeAsync(parameters);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package dev.sheldan.abstracto.moderation.converter;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.models.database.UserNote;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.NoteEntryModel;
|
||||
import dev.sheldan.abstracto.moderation.service.management.UserNoteManagementService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -36,7 +36,7 @@ public class UserNotesConverterTest {
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private UserNotesConverter self;
|
||||
@@ -55,7 +55,7 @@ public class UserNotesConverterTest {
|
||||
AServer server = MockUtils.getServer();
|
||||
AUserInAServer userInAServer = MockUtils.getUserObject(4L, server);
|
||||
Member member = Mockito.mock(Member.class);
|
||||
when(botService.getMemberInServerAsync(userInAServer)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
when(memberService.getMemberInServerAsync(userInAServer)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
UserNote firstNote = UserNote.builder().userNoteId(new ServerSpecificId(3L, 4L)).user(userInAServer).build();
|
||||
UserNote secondNote = UserNote.builder().userNoteId(new ServerSpecificId(3L, 5L)).user(userInAServer).build();
|
||||
testUnit.fromNotes(Arrays.asList(firstNote, secondNote));
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.moderation.converter;
|
||||
import dev.sheldan.abstracto.core.models.FutureMemberPair;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.WarnEntry;
|
||||
@@ -34,7 +34,7 @@ public class WarnEntryConverterTest {
|
||||
private WarnEntryConverter testUnit;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private WarnEntryConverter self;
|
||||
@@ -61,8 +61,8 @@ public class WarnEntryConverterTest {
|
||||
AUserInAServer warningUser = Mockito.mock(AUserInAServer.class);
|
||||
Member warnedMember = Mockito.mock(Member.class);
|
||||
Member warningMember = Mockito.mock(Member.class);
|
||||
when(botService.getMemberInServerAsync(warnedUser)).thenReturn(CompletableFuture.completedFuture(warnedMember));
|
||||
when(botService.getMemberInServerAsync(warningUser)).thenReturn(CompletableFuture.completedFuture(warningMember));
|
||||
when(memberService.getMemberInServerAsync(warnedUser)).thenReturn(CompletableFuture.completedFuture(warnedMember));
|
||||
when(memberService.getMemberInServerAsync(warningUser)).thenReturn(CompletableFuture.completedFuture(warningMember));
|
||||
Warning firstNote = Warning.builder().warnId(new ServerSpecificId(3L, 4L)).warnedUser(warnedUser).warningUser(warningUser).build();
|
||||
Warning secondNote = Warning.builder().warnId(new ServerSpecificId(3L, 5L)).warnedUser(warnedUser).warningUser(warningUser).build();
|
||||
testUnit.fromWarnings(Arrays.asList(firstNote, secondNote));
|
||||
@@ -87,8 +87,8 @@ public class WarnEntryConverterTest {
|
||||
map.put(secondWarnId, memberPair);
|
||||
when(warnManagementService.findById(WARN_ID_1, SERVER_ID)).thenReturn(warning1);
|
||||
when(warnManagementService.findById(WARN_ID_2, SERVER_ID)).thenReturn(warning2);
|
||||
when(userInServerManagementService.loadUser(warnedMember)).thenReturn(warnedUser);
|
||||
when(userInServerManagementService.loadUser(warningMember)).thenReturn(warningUser);
|
||||
when(userInServerManagementService.loadOrCreateUser(warnedMember)).thenReturn(warnedUser);
|
||||
when(userInServerManagementService.loadOrCreateUser(warningMember)).thenReturn(warningUser);
|
||||
List<WarnEntry> models = testUnit.loadFullWarnEntries(map);
|
||||
Assert.assertEquals(2, models.size());
|
||||
WarnEntry firstEntry = models.get(0);
|
||||
|
||||
@@ -3,9 +3,9 @@ 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.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.service.WarnService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package dev.sheldan.abstracto.moderation.listener.async;
|
||||
|
||||
import dev.sheldan.abstracto.core.execution.result.MessageReceivedListenerResult;
|
||||
import dev.sheldan.abstracto.core.metrics.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
@@ -12,7 +14,10 @@ import dev.sheldan.abstracto.moderation.models.template.listener.InviteDeletedMo
|
||||
import dev.sheldan.abstracto.moderation.service.InviteLinkFilterService;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -45,6 +50,9 @@ public class InviteLinkFilterListenerTest {
|
||||
@Mock
|
||||
private TemplateService templateService;
|
||||
|
||||
@Mock
|
||||
private MessageService messageService;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
|
||||
@@ -57,6 +65,9 @@ public class InviteLinkFilterListenerTest {
|
||||
@Mock
|
||||
private Guild guild;
|
||||
|
||||
@Mock
|
||||
private MetricService metricService;
|
||||
|
||||
private static final Long SERVER_ID = 1L;
|
||||
private static final Long CHANNEL_ID = 2L;
|
||||
private static final Long USER_ID = 3L;
|
||||
@@ -85,20 +96,21 @@ public class InviteLinkFilterListenerTest {
|
||||
public void testExecutionWithOneNotAllowedInviteNoTrackNoNotification() {
|
||||
when(message.getContentRaw()).thenReturn(INVITE_LINK);
|
||||
AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class);
|
||||
when(message.delete()).thenReturn(auditableRestAction);
|
||||
when(messageService.deleteMessage(message)).thenReturn(auditableRestAction);
|
||||
when(inviteLinkFilterService.isCodeFiltered(eq(INVITE_CODE), any(ServerUser.class))).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.TRACK_USES)).thenReturn(false);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.FILTER_NOTIFICATIONS)).thenReturn(false);
|
||||
setupBasicMessage();
|
||||
MessageReceivedListenerResult result = testUnit.execute(message);
|
||||
Assert.assertEquals(MessageReceivedListenerResult.DELETED, result);
|
||||
verify(metricService, times(1)).incrementCounter(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutionWithOneNotAllowedInviteTrackNoNotification() {
|
||||
when(message.getContentRaw()).thenReturn(INVITE_LINK);
|
||||
AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class);
|
||||
when(message.delete()).thenReturn(auditableRestAction);
|
||||
when(messageService.deleteMessage(message)).thenReturn(auditableRestAction);
|
||||
when(inviteLinkFilterService.isCodeFiltered(eq(INVITE_CODE), any(ServerUser.class))).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.TRACK_USES)).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.FILTER_NOTIFICATIONS)).thenReturn(false);
|
||||
@@ -106,13 +118,14 @@ public class InviteLinkFilterListenerTest {
|
||||
MessageReceivedListenerResult result = testUnit.execute(message);
|
||||
Assert.assertEquals(MessageReceivedListenerResult.DELETED, result);
|
||||
verifyTracking();
|
||||
verify(metricService, times(1)).incrementCounter(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutionWithOneNotAllowedInviteTrackNotification() {
|
||||
when(message.getContentRaw()).thenReturn(INVITE_LINK);
|
||||
AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class);
|
||||
when(message.delete()).thenReturn(auditableRestAction);
|
||||
when(messageService.deleteMessage(message)).thenReturn(auditableRestAction);
|
||||
when(inviteLinkFilterService.isCodeFiltered(eq(INVITE_CODE), any(ServerUser.class))).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.TRACK_USES)).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.FILTER_NOTIFICATIONS)).thenReturn(true);
|
||||
@@ -121,19 +134,21 @@ public class InviteLinkFilterListenerTest {
|
||||
MessageReceivedListenerResult result = testUnit.execute(message);
|
||||
Assert.assertEquals(MessageReceivedListenerResult.DELETED, result);
|
||||
verifyTracking();
|
||||
verify(metricService, times(1)).incrementCounter(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutionWithOneNotAllowedInviteNoTrackNotification() {
|
||||
when(message.getContentRaw()).thenReturn(INVITE_LINK);
|
||||
AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class);
|
||||
when(message.delete()).thenReturn(auditableRestAction);
|
||||
when(messageService.deleteMessage(message)).thenReturn(auditableRestAction);
|
||||
when(inviteLinkFilterService.isCodeFiltered(eq(INVITE_CODE), any(ServerUser.class))).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.TRACK_USES)).thenReturn(false);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.FILTER_NOTIFICATIONS)).thenReturn(true);
|
||||
setupForNotification();
|
||||
setupBasicMessage();
|
||||
MessageReceivedListenerResult result = testUnit.execute(message);
|
||||
verify(metricService, times(1)).incrementCounter(any());
|
||||
Assert.assertEquals(MessageReceivedListenerResult.DELETED, result);
|
||||
verify(inviteLinkFilterService, times(0)).storeFilteredInviteLinkUsage(eq(INVITE_CODE), any(ServerUser.class));
|
||||
}
|
||||
@@ -142,13 +157,14 @@ public class InviteLinkFilterListenerTest {
|
||||
public void testExecutionWithOneNotAllowedInviteNoTrackNotificationNoPostTarget() {
|
||||
when(message.getContentRaw()).thenReturn(INVITE_LINK);
|
||||
AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class);
|
||||
when(message.delete()).thenReturn(auditableRestAction);
|
||||
when(messageService.deleteMessage(message)).thenReturn(auditableRestAction);
|
||||
when(inviteLinkFilterService.isCodeFiltered(eq(INVITE_CODE), any(ServerUser.class))).thenReturn(true);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.TRACK_USES)).thenReturn(false);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.INVITE_FILTER, SERVER_ID, InviteFilterMode.FILTER_NOTIFICATIONS)).thenReturn(true);
|
||||
when(postTargetService.postTargetDefinedInServer(InviteFilterPostTarget.INVITE_DELETE_LOG, SERVER_ID)).thenReturn(false);
|
||||
setupBasicMessage();
|
||||
MessageReceivedListenerResult result = testUnit.execute(message);
|
||||
verify(metricService, times(1)).incrementCounter(any());
|
||||
Assert.assertEquals(MessageReceivedListenerResult.DELETED, result);
|
||||
verify(inviteLinkFilterService, times(0)).storeFilteredInviteLinkUsage(eq(INVITE_CODE), any(ServerUser.class));
|
||||
verify(templateService, times(0)).renderEmbedTemplate(eq(INVITE_LINK_DELETED_NOTIFICATION_EMBED_TEMPLATE_KEY), any(InviteDeletedModel.class));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.moderation.listener.async;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.LoggingPostTarget;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
@@ -29,7 +29,7 @@ public class JoinLoggerTest {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private JoinLogger self;
|
||||
@@ -48,7 +48,7 @@ public class JoinLoggerTest {
|
||||
public void testExecute() {
|
||||
when(serverUser.getUserId()).thenReturn(USER_ID);
|
||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
||||
when(botService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
testUnit.execute(serverUser);
|
||||
verify(self, times(1)).sendJoinLog(serverUser, member);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class JoinMuteListenerTest {
|
||||
public void testNonMutedUserJoins() {
|
||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
||||
when(serverUser.getUserId()).thenReturn(USER_ID);
|
||||
when(userInServerManagementService.loadUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
||||
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
||||
when(muteManagementService.hasActiveMute(joiningUser)).thenReturn(false);
|
||||
testUnit.execute(serverUser);
|
||||
verify(muteService, times(0)).applyMuteRole(joiningUser);
|
||||
@@ -59,7 +59,7 @@ public class JoinMuteListenerTest {
|
||||
public void testMutedUserJoins() {
|
||||
when(serverUser.getServerId()).thenReturn(SERVER_ID);
|
||||
when(serverUser.getUserId()).thenReturn(USER_ID);
|
||||
when(userInServerManagementService.loadUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
||||
when(userInServerManagementService.loadOrCreateUser(SERVER_ID, USER_ID)).thenReturn(joiningUser);
|
||||
when(muteManagementService.hasActiveMute(joiningUser)).thenReturn(true);
|
||||
testUnit.execute(serverUser);
|
||||
verify(muteService, times(1)).applyMuteRole(joiningUser);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.moderation.listener.async;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.ServerUser;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.LoggingPostTarget;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
@@ -31,7 +31,7 @@ public class LeaveLoggerTest {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private LeaveLogger self;
|
||||
@@ -49,7 +49,7 @@ public class LeaveLoggerTest {
|
||||
public void testExecute() {
|
||||
when(leavingUser.getUserId()).thenReturn(USER_ID);
|
||||
when(leavingUser.getServerId()).thenReturn(SERVER_ID);
|
||||
when(botService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
when(memberService.getMemberInServerAsync(SERVER_ID, USER_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
testUnit.execute(leavingUser);
|
||||
verify(self, times(1)).executeJoinLogging(leavingUser, member);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ package dev.sheldan.abstracto.moderation.listener.async;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedAttachment;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedAuthor;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
@@ -40,7 +41,10 @@ public class MessageDeleteLogListenerTest {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private ChannelService channelService;
|
||||
|
||||
@Mock
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private ChannelManagementService channelManagementService;
|
||||
@@ -87,7 +91,7 @@ public class MessageDeleteLogListenerTest {
|
||||
when(deletedMessage.getAuthor()).thenReturn(cachedAuthor);
|
||||
when(cachedAuthor.getAuthorId()).thenReturn(AUTHOR_ID);
|
||||
when(deletedMessage.getServerId()).thenReturn(SERVER_ID);
|
||||
when(botService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
when(memberService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(member));
|
||||
testUnit.execute(deletedMessage);
|
||||
verify(self, times(1)).executeListener(deletedMessage, member);
|
||||
}
|
||||
@@ -99,7 +103,7 @@ public class MessageDeleteLogListenerTest {
|
||||
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
|
||||
when(member.getGuild()).thenReturn(guild);
|
||||
when(templateService.renderEmbedTemplate(eq(MessageDeleteLogListener.MESSAGE_DELETED_TEMPLATE), captor.capture())).thenReturn(messageToSend);
|
||||
when(botService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(textChannel);
|
||||
when(channelService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(textChannel);
|
||||
testUnit.executeListener(deletedMessage, member);
|
||||
verify(postTargetService, times(1)).sendEmbedInPostTarget(messageToSend, LoggingPostTarget.DELETE_LOG, SERVER_ID);
|
||||
MessageDeletedLog messageDeletedLog = captor.getValue();
|
||||
@@ -114,7 +118,7 @@ public class MessageDeleteLogListenerTest {
|
||||
String attachmentUrl = "url";
|
||||
when(deletedMessage.getServerId()).thenReturn(SERVER_ID);
|
||||
when(deletedMessage.getChannelId()).thenReturn(CHANNEL_ID);
|
||||
when(botService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(textChannel);
|
||||
when(channelService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(textChannel);
|
||||
CachedAttachment cachedAttachment = Mockito.mock(CachedAttachment.class);
|
||||
when(cachedAttachment.getProxyUrl()).thenReturn(attachmentUrl);
|
||||
List<CachedAttachment> attachmentList = Arrays.asList(cachedAttachment);
|
||||
@@ -138,7 +142,7 @@ public class MessageDeleteLogListenerTest {
|
||||
public void testExecuteListenerWithTwoAttachment() {
|
||||
when(deletedMessage.getServerId()).thenReturn(SERVER_ID);
|
||||
when(deletedMessage.getChannelId()).thenReturn(CHANNEL_ID);
|
||||
when(botService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(textChannel);
|
||||
when(channelService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(textChannel);
|
||||
String attachmentUrl = "url";
|
||||
String secondAttachmentUrl = "url2";
|
||||
CachedAttachment cachedAttachment = Mockito.mock(CachedAttachment.class);
|
||||
|
||||
@@ -2,7 +2,8 @@ package dev.sheldan.abstracto.moderation.listener.async;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedAuthor;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MemberService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.LoggingPostTarget;
|
||||
import dev.sheldan.abstracto.moderation.models.template.listener.MessageEditedLog;
|
||||
@@ -37,7 +38,10 @@ public class MessageEditedListenerTest {
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private ChannelService channelService;
|
||||
|
||||
@Mock
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private CachedMessage messageAfter;
|
||||
@@ -77,8 +81,8 @@ public class MessageEditedListenerTest {
|
||||
MessageToSend messageToSend = Mockito.mock(MessageToSend.class);
|
||||
ArgumentCaptor<MessageEditedLog> captor = ArgumentCaptor.forClass(MessageEditedLog.class);
|
||||
when(templateService.renderEmbedTemplate(eq(MessageEditedListener.MESSAGE_EDITED_TEMPLATE), captor.capture())).thenReturn(messageToSend);
|
||||
when(botService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(author));
|
||||
when(botService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(channel);
|
||||
when(memberService.getMemberInServerAsync(SERVER_ID, AUTHOR_ID)).thenReturn(CompletableFuture.completedFuture(author));
|
||||
when(channelService.getTextChannelFromServer(SERVER_ID, CHANNEL_ID)).thenReturn(channel);
|
||||
testUnit.execute(messageBefore, messageAfter);
|
||||
verify(postTargetService, times(1)).sendEmbedInPostTarget(messageToSend, LoggingPostTarget.EDIT_LOG, SERVER_ID);
|
||||
MessageEditedLog capturedValue = captor.getValue();
|
||||
|
||||
@@ -2,8 +2,8 @@ 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.GuildService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.ModerationMode;
|
||||
@@ -33,7 +33,7 @@ public class BanServiceBeanTest {
|
||||
private BanServiceBean testUnit;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private GuildService guildService;
|
||||
|
||||
@Mock
|
||||
private TemplateService templateService;
|
||||
@@ -99,7 +99,7 @@ public class BanServiceBeanTest {
|
||||
MessageToSend mockedMessage = Mockito.mock(MessageToSend.class);
|
||||
when(templateService.renderEmbedTemplate(BanServiceBean.BAN_ID_LOG_TEMPLATE, context)).thenReturn(mockedMessage);
|
||||
when(featureModeService.featureModeActive(ModerationFeatures.MODERATION, serverId, ModerationMode.BAN_LOG)).thenReturn(true);
|
||||
when(botService.getGuildByIdOptional(serverId)).thenReturn(Optional.of(mockedGuild));
|
||||
when(guildService.getGuildByIdOptional(serverId)).thenReturn(Optional.of(mockedGuild));
|
||||
testUnit.banUserViaId(serverId, userId, REASON, context);
|
||||
verify(mockedGuild, times(1)).ban(userId.toString(), 0, REASON);
|
||||
verify(postTargetService, times(1)).sendEmbedInPostTarget(mockedMessage, ModerationPostTarget.BAN_LOG, serverId);
|
||||
@@ -110,7 +110,7 @@ public class BanServiceBeanTest {
|
||||
Long userId = 8L;
|
||||
Long serverId = 5L;
|
||||
ServerContext context = Mockito.mock(ServerContext.class);
|
||||
when(botService.getGuildByIdOptional(serverId)).thenReturn(Optional.empty());
|
||||
when(guildService.getGuildByIdOptional(serverId)).thenReturn(Optional.empty());
|
||||
testUnit.banUserViaId(serverId, userId, REASON, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@ package dev.sheldan.abstracto.moderation.service;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.FeatureModeService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.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;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
@@ -11,6 +11,7 @@ import dev.sheldan.abstracto.core.service.*;
|
||||
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.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.MutingMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.MutingPostTarget;
|
||||
@@ -25,8 +26,10 @@ import dev.sheldan.abstracto.moderation.service.management.MuteRoleManagementSer
|
||||
import dev.sheldan.abstracto.scheduling.service.SchedulerService;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -69,7 +72,10 @@ public class MuteServiceBeanTest {
|
||||
private TemplateService templateService;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private GuildService guildService;
|
||||
|
||||
@Mock
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private MessageService messageService;
|
||||
@@ -221,8 +227,8 @@ public class MuteServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testMuteMember() {
|
||||
when(userInServerManagementService.loadUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
when(userInServerManagementService.loadUser(memberMuting)).thenReturn(userMuting);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberMuting)).thenReturn(userMuting);
|
||||
Instant unMuteDate = shorterMute();
|
||||
when(memberBeingMuted.getGuild()).thenReturn(guild);
|
||||
when(memberBeingMuted.getUser()).thenReturn(jdaUserBeingMuted);
|
||||
@@ -239,8 +245,8 @@ public class MuteServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testMuteMemberWithLog() {
|
||||
when(userInServerManagementService.loadUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
when(userInServerManagementService.loadUser(memberMuting)).thenReturn(userMuting);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberMuting)).thenReturn(userMuting);
|
||||
Instant unMuteDate = shorterMute();
|
||||
when(memberBeingMuted.getGuild()).thenReturn(guild);
|
||||
when(memberBeingMuted.getUser()).thenReturn(jdaUserBeingMuted);
|
||||
@@ -269,8 +275,8 @@ public class MuteServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testMuteMemberWithoutLog() {
|
||||
when(userInServerManagementService.loadUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
when(userInServerManagementService.loadUser(memberMuting)).thenReturn(userMuting);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberMuting)).thenReturn(userMuting);
|
||||
Instant unMuteDate = shorterMute();
|
||||
when(memberBeingMuted.getGuild()).thenReturn(guild);
|
||||
when(memberBeingMuted.getUser()).thenReturn(jdaUserBeingMuted);
|
||||
@@ -302,7 +308,7 @@ public class MuteServiceBeanTest {
|
||||
when(muteManagementService.hasActiveMute(userBeingMuted)).thenReturn(true);
|
||||
when(muteManagementService.getAMuteOf(userBeingMuted)).thenReturn(mute);
|
||||
when(mute.getMuteId()).thenReturn(new ServerSpecificId(SERVER_ID, MUTE_ID));
|
||||
when(botService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||
when(guildService.getGuildById(SERVER_ID)).thenReturn(guild);
|
||||
testUnit.unMuteUser(userBeingMuted);
|
||||
verifyNoUnMuteHappened();
|
||||
}
|
||||
@@ -315,8 +321,8 @@ public class MuteServiceBeanTest {
|
||||
when(mute.getServer()).thenReturn(server);
|
||||
when(muteManagementService.findMuteOptional(MUTE_ID, SERVER_ID)).thenReturn(Optional.of(mute));
|
||||
when(roleService.removeRoleFromUserFuture(userBeingMuted, aRole)).thenReturn(CompletableFuture.completedFuture(null));
|
||||
when(botService.getMemberInServerAsync(userBeingMuted)).thenReturn(CompletableFuture.completedFuture(memberBeingMuted));
|
||||
when(botService.getMemberInServerAsync(userMuting)).thenReturn(CompletableFuture.completedFuture(memberMuting));
|
||||
when(memberService.getMemberInServerAsync(userBeingMuted)).thenReturn(CompletableFuture.completedFuture(memberBeingMuted));
|
||||
when(memberService.getMemberInServerAsync(userMuting)).thenReturn(CompletableFuture.completedFuture(memberMuting));
|
||||
testUnit.endMute(MUTE_ID, SERVER_ID);
|
||||
verify(self, times(1)).sendUnmuteLog(eq(MUTE_ID), any(Guild.class), any(CompletableFuture.class), any(CompletableFuture.class));
|
||||
}
|
||||
@@ -374,7 +380,7 @@ public class MuteServiceBeanTest {
|
||||
public void testCompletelyUnMuteMember() {
|
||||
when(mute.getTriggerKey()).thenReturn(TRIGGER);
|
||||
when(muteManagementService.getAllMutesOf(userBeingMuted)).thenReturn(Arrays.asList(mute));
|
||||
when(userInServerManagementService.loadUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
when(userInServerManagementService.loadOrCreateUser(memberBeingMuted)).thenReturn(userBeingMuted);
|
||||
testUnit.completelyUnMuteMember(memberBeingMuted);
|
||||
verify(muteManagementService, times(1)).saveMute(any(Mute.class));
|
||||
verify(schedulerService, times(1)).stopTrigger(TRIGGER);
|
||||
@@ -407,8 +413,8 @@ public class MuteServiceBeanTest {
|
||||
when(mute.getServer()).thenReturn(server);
|
||||
setupUnMuteMocks(stillInGuild);
|
||||
when(roleService.removeRoleFromUserFuture(userBeingMuted, aRole)).thenReturn(CompletableFuture.completedFuture(null));
|
||||
when(botService.getMemberInServerAsync(userBeingMuted)).thenReturn(CompletableFuture.completedFuture(memberBeingMuted));
|
||||
when(botService.getMemberInServerAsync(userMuting)).thenReturn(CompletableFuture.completedFuture(memberMuting));
|
||||
when(memberService.getMemberInServerAsync(userBeingMuted)).thenReturn(CompletableFuture.completedFuture(memberBeingMuted));
|
||||
when(memberService.getMemberInServerAsync(userMuting)).thenReturn(CompletableFuture.completedFuture(memberMuting));
|
||||
testUnit.unMuteUser(userBeingMuted);
|
||||
|
||||
}
|
||||
@@ -418,8 +424,8 @@ public class MuteServiceBeanTest {
|
||||
when(muteManagementService.getAMuteOf(userBeingMuted)).thenReturn(mute);
|
||||
when(muteManagementService.hasActiveMute(userBeingMuted)).thenReturn(true);
|
||||
when(muteRoleManagementService.retrieveMuteRoleForServer(server)).thenReturn(muteRole);
|
||||
when(botService.getGuildById(server.getId())).thenReturn(guild);
|
||||
when(botService.isUserInGuild(guild, userBeingMuted)).thenReturn(stillInGuild);
|
||||
when(guildService.getGuildById(server.getId())).thenReturn(guild);
|
||||
when(memberService.isUserInGuild(guild, userBeingMuted)).thenReturn(stillInGuild);
|
||||
}
|
||||
|
||||
private void verifyDirectMute() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.moderation.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.metrics.service.MetricService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import dev.sheldan.abstracto.moderation.exception.NoMessageFoundException;
|
||||
import dev.sheldan.abstracto.moderation.models.template.commands.PurgeStatusUpdateModel;
|
||||
@@ -13,6 +15,7 @@ import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
@@ -32,12 +35,18 @@ public class PurgeServiceBeanTest {
|
||||
@InjectMocks
|
||||
private PurgeServiceBean testUnit;
|
||||
|
||||
@Mock
|
||||
private ChannelService channelService;
|
||||
|
||||
@Mock
|
||||
private MessageService messageService;
|
||||
|
||||
@Mock
|
||||
private TemplateService templateService;
|
||||
|
||||
@Mock
|
||||
private MetricService metricService;
|
||||
|
||||
@Mock
|
||||
private TextChannel textChannel;
|
||||
|
||||
@@ -66,9 +75,6 @@ public class PurgeServiceBeanTest {
|
||||
@Mock
|
||||
private MessageHistory history;
|
||||
|
||||
@Mock
|
||||
private MessageHistory.MessageRetrieveAction retrieveAction;
|
||||
|
||||
@Mock
|
||||
private MessageToSend firstStatusUpdateMessage;
|
||||
|
||||
@@ -90,8 +96,7 @@ public class PurgeServiceBeanTest {
|
||||
@Test
|
||||
public void testPurgeMessageViaStartMessage() {
|
||||
Integer amountToDelete = 50;
|
||||
when(textChannel.getHistoryBefore(START_MESSAGE_ID, amountToDelete)).thenReturn(retrieveAction);
|
||||
when(retrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(history));
|
||||
when(channelService.getHistoryOfChannel(textChannel, START_MESSAGE_ID, amountToDelete)).thenReturn(CompletableFuture.completedFuture(history));
|
||||
|
||||
setupOneMessageBatch(getDeletableMessageId(), getDeletableMessageId());
|
||||
|
||||
@@ -101,13 +106,13 @@ public class PurgeServiceBeanTest {
|
||||
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
|
||||
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
|
||||
verify(messageService, times(1)).updateStatusMessage(eq(textChannel), anyLong(), any());
|
||||
verify(metricService, times(1)).incrementCounter(any(), eq((long) amountToDelete));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPurgeMessageNotNoUser() {
|
||||
Integer amountToDelete = 50;
|
||||
when(textChannel.getHistoryBefore(START_MESSAGE_ID, amountToDelete)).thenReturn(retrieveAction);
|
||||
when(retrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(history));
|
||||
when(channelService.getHistoryOfChannel(textChannel, START_MESSAGE_ID, amountToDelete)).thenReturn(CompletableFuture.completedFuture(history));
|
||||
|
||||
when(firstMessage.getId()).thenReturn(getDeletableMessageId().toString());
|
||||
when(secondMessage.getId()).thenReturn(getDeletableMessageId().toString());
|
||||
@@ -119,13 +124,13 @@ public class PurgeServiceBeanTest {
|
||||
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
|
||||
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
|
||||
verify(messageService, times(1)).updateStatusMessage(eq(textChannel), anyLong(), any());
|
||||
verify(metricService, times(1)).incrementCounter(any(), eq((long) amountToDelete));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPurgeSingleMessage() {
|
||||
Integer amountToDelete = 50;
|
||||
when(textChannel.getHistoryBefore(START_MESSAGE_ID, amountToDelete)).thenReturn(retrieveAction);
|
||||
when(retrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(history));
|
||||
when(channelService.getHistoryOfChannel(textChannel, START_MESSAGE_ID, amountToDelete)).thenReturn(CompletableFuture.completedFuture(history));
|
||||
|
||||
when(firstMessage.getId()).thenReturn(getDeletableMessageId().toString());
|
||||
when(firstMessage.getAuthor()).thenReturn(messageAuthor);
|
||||
@@ -135,24 +140,23 @@ public class PurgeServiceBeanTest {
|
||||
when(history.getRetrievedHistory()).thenReturn(messagesToDelete);
|
||||
setupStatusMessageMocks();
|
||||
AuditableRestAction auditableRestAction = Mockito.mock(AuditableRestAction.class);
|
||||
when(firstMessage.delete()).thenReturn(auditableRestAction);
|
||||
when(messageService.deleteMessage(firstMessage)).thenReturn(auditableRestAction);
|
||||
mockQueueDoubleVoidConsumer(auditableRestAction);
|
||||
CompletableFuture<Void> futures = testUnit.purgeMessagesInChannel(amountToDelete, textChannel, START_MESSAGE_ID, purgedMember);
|
||||
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
|
||||
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
|
||||
verify(messageService, times(1)).updateStatusMessage(eq(textChannel), anyLong(), any());
|
||||
verify(metricService, times(1)).incrementCounter(any(), eq((long) amountToDelete));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPurgeMessagesInTwoIterationsSecondIterationsTooOld() {
|
||||
Integer amountToDelete = 150;
|
||||
Long latestDeletedMessageId = getDeletableMessageId();
|
||||
when(textChannel.getHistoryBefore(START_MESSAGE_ID, 100)).thenReturn(retrieveAction);
|
||||
when(retrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(history));
|
||||
MessageHistory.MessageRetrieveAction secondRetrieveAction = Mockito.mock(MessageHistory.MessageRetrieveAction.class);
|
||||
when(textChannel.getHistoryBefore(latestDeletedMessageId, 50)).thenReturn(secondRetrieveAction);
|
||||
when(channelService.getHistoryOfChannel(textChannel, START_MESSAGE_ID, amountToDelete - 50)).thenReturn(CompletableFuture.completedFuture(history));
|
||||
|
||||
MessageHistory secondHistory = Mockito.mock(MessageHistory.class);
|
||||
when(secondRetrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(secondHistory));
|
||||
when(channelService.getHistoryOfChannel(textChannel, latestDeletedMessageId, 50)).thenReturn(CompletableFuture.completedFuture(secondHistory));
|
||||
|
||||
when(secondMessage.getIdLong()).thenReturn(latestDeletedMessageId);
|
||||
when(thirdMessage.getId()).thenReturn(getNotDeletableMessageId().toString());
|
||||
@@ -168,6 +172,12 @@ public class PurgeServiceBeanTest {
|
||||
futures.whenComplete((aVoid, throwable) -> Assert.assertTrue(throwable.getCause() instanceof NoMessageFoundException));
|
||||
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
|
||||
verify(messageService, times(1)).updateStatusMessage(eq(textChannel), anyLong(), any());
|
||||
ArgumentCaptor<Long> deleted = ArgumentCaptor.forClass(Long.class);
|
||||
verify(metricService, times(2)).incrementCounter(any(), deleted.capture());
|
||||
List<Long> capturedValues = deleted.getAllValues();
|
||||
Assert.assertEquals(2, capturedValues.size());
|
||||
Assert.assertEquals(100, capturedValues.get(0).longValue());
|
||||
Assert.assertEquals(50, capturedValues.get(1).longValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -175,12 +185,9 @@ public class PurgeServiceBeanTest {
|
||||
public void testPurgeMessagesInTwoIterations() {
|
||||
Integer amountToDelete = 150;
|
||||
Long latestDeletedMessageId = getDeletableMessageId();
|
||||
when(textChannel.getHistoryBefore(START_MESSAGE_ID, 100)).thenReturn(retrieveAction);
|
||||
when(retrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(history));
|
||||
MessageHistory.MessageRetrieveAction secondRetrieveAction = Mockito.mock(MessageHistory.MessageRetrieveAction.class);
|
||||
when(textChannel.getHistoryBefore(latestDeletedMessageId, 50)).thenReturn(secondRetrieveAction);
|
||||
when(channelService.getHistoryOfChannel(textChannel, START_MESSAGE_ID, amountToDelete - 50)).thenReturn(CompletableFuture.completedFuture(history));
|
||||
MessageHistory secondHistory = Mockito.mock(MessageHistory.class);
|
||||
when(secondRetrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(secondHistory));
|
||||
when(channelService.getHistoryOfChannel(textChannel, latestDeletedMessageId, 50)).thenReturn(CompletableFuture.completedFuture(secondHistory));
|
||||
|
||||
when(secondMessage.getIdLong()).thenReturn(latestDeletedMessageId);
|
||||
|
||||
@@ -191,7 +198,7 @@ public class PurgeServiceBeanTest {
|
||||
RestAction secondDeleteMessagesAction = Mockito.mock(RestAction.class);
|
||||
List<Message> secondMessagesToDelete = Arrays.asList(thirdMessage, fourthMessage);
|
||||
when(secondHistory.getRetrievedHistory()).thenReturn(secondMessagesToDelete);
|
||||
when(textChannel.deleteMessages(secondMessagesToDelete)).thenReturn(secondDeleteMessagesAction);
|
||||
when(channelService.deleteMessagesInChannel(textChannel, secondMessagesToDelete)).thenReturn(secondDeleteMessagesAction);
|
||||
|
||||
|
||||
mockQueueDoubleVoidConsumer(secondDeleteMessagesAction);
|
||||
@@ -199,13 +206,18 @@ public class PurgeServiceBeanTest {
|
||||
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
|
||||
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
|
||||
verify(messageService, times(2)).updateStatusMessage(eq(textChannel), anyLong(), any());
|
||||
ArgumentCaptor<Long> deleted = ArgumentCaptor.forClass(Long.class);
|
||||
verify(metricService, times(2)).incrementCounter(any(), deleted.capture());
|
||||
List<Long> capturedValues = deleted.getAllValues();
|
||||
Assert.assertEquals(2, capturedValues.size());
|
||||
Assert.assertEquals(100, capturedValues.get(0).longValue());
|
||||
Assert.assertEquals(50, capturedValues.get(1).longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPurgeMessagesInOneIteration() {
|
||||
Integer amountToDelete = 50;
|
||||
when(textChannel.getHistoryBefore(START_MESSAGE_ID, amountToDelete)).thenReturn(retrieveAction);
|
||||
when(retrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(history));
|
||||
when(channelService.getHistoryOfChannel(textChannel, START_MESSAGE_ID, amountToDelete)).thenReturn(CompletableFuture.completedFuture(history));
|
||||
|
||||
setupOneMessageBatch(getDeletableMessageId(), getDeletableMessageId());
|
||||
|
||||
@@ -213,13 +225,13 @@ public class PurgeServiceBeanTest {
|
||||
futures.whenComplete((aVoid, throwable) -> Assert.assertNull(throwable));
|
||||
verify(deleteStatusAction, times(1)).queueAfter(5, TimeUnit.SECONDS);
|
||||
verify(messageService, times(1)).updateStatusMessage(eq(textChannel), anyLong(), any());
|
||||
verify(metricService, times(1)).incrementCounter(any(), eq((long) amountToDelete));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPurgeTooOldMessage() {
|
||||
Integer amountToDelete = 50;
|
||||
when(textChannel.getHistoryBefore(START_MESSAGE_ID, amountToDelete)).thenReturn(retrieveAction);
|
||||
when(retrieveAction.submit()).thenReturn(CompletableFuture.completedFuture(history));
|
||||
when(channelService.getHistoryOfChannel(textChannel, START_MESSAGE_ID, amountToDelete)).thenReturn(CompletableFuture.completedFuture(history));
|
||||
|
||||
when(firstMessage.getId()).thenReturn(getNotDeletableMessageId().toString());
|
||||
|
||||
@@ -240,7 +252,7 @@ public class PurgeServiceBeanTest {
|
||||
private void setupFirstMessageHistoryMocks() {
|
||||
List<Message> messagesToDelete = Arrays.asList(firstMessage, secondMessage);
|
||||
when(history.getRetrievedHistory()).thenReturn(messagesToDelete);
|
||||
when(textChannel.deleteMessages(messagesToDelete)).thenReturn(deleteMessagesAction);
|
||||
when(channelService.deleteMessagesInChannel(textChannel, messagesToDelete)).thenReturn(deleteMessagesAction);
|
||||
}
|
||||
|
||||
private void setupStatusMessageMocks() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.moderation.service;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
@@ -26,10 +26,7 @@ public class SlowModeServiceBeanTest {
|
||||
private SlowModeServiceBean testUnit;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
|
||||
@Mock
|
||||
private ChannelManager channelManager;
|
||||
private ChannelService channelService;
|
||||
|
||||
@Mock
|
||||
private ChannelManager returnedManager;
|
||||
@@ -42,12 +39,10 @@ public class SlowModeServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void setSlowModeInTextChannel() {
|
||||
when(channelManager.setSlowmode(anyInt())).thenReturn(returnedManager);
|
||||
when(channel.getGuild()).thenReturn(guild);
|
||||
when(channel.getManager()).thenReturn(channelManager);
|
||||
Duration duration = Duration.ofMinutes(5);
|
||||
testUnit.setSlowMode(channel, duration);
|
||||
verify(channelManager, times(1)).setSlowmode((int)duration.getSeconds());
|
||||
verify(channelService, times(1)).setSlowModeInChannel(channel,(int) duration.getSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,21 +50,17 @@ public class SlowModeServiceBeanTest {
|
||||
AServer server = MockUtils.getServer();
|
||||
AChannel aChannel = MockUtils.getTextChannel(server, 5L);
|
||||
Duration duration = Duration.ofMinutes(5);
|
||||
when(channelManager.setSlowmode(anyInt())).thenReturn(returnedManager);
|
||||
when(channel.getGuild()).thenReturn(guild);
|
||||
when(channel.getManager()).thenReturn(channelManager);
|
||||
when(botService.getTextChannelFromServerOptional(server.getId(), aChannel.getId())).thenReturn(Optional.of(channel));
|
||||
when(channelService.getTextChannelFromServerOptional(server.getId(), aChannel.getId())).thenReturn(Optional.of(channel));
|
||||
testUnit.setSlowMode(aChannel, duration);
|
||||
verify(channelManager, times(1)).setSlowmode((int)duration.getSeconds());
|
||||
verify(channelService, times(1)).setSlowModeInChannel(channel,(int) duration.getSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableSlowMode() {
|
||||
when(channelManager.setSlowmode(anyInt())).thenReturn(returnedManager);
|
||||
when(channel.getGuild()).thenReturn(guild);
|
||||
when(channel.getManager()).thenReturn(channelManager);
|
||||
testUnit.disableSlowMode(channel);
|
||||
verify(channelManager, times(1)).setSlowmode(0);
|
||||
verify(channelService, times(1)).setSlowModeInChannel(channel,0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -84,7 +75,7 @@ public class SlowModeServiceBeanTest {
|
||||
AServer server = MockUtils.getServer();
|
||||
AChannel aChannel = MockUtils.getTextChannel(server, 5L);
|
||||
Duration duration = Duration.ofMinutes(5);
|
||||
when(botService.getTextChannelFromServerOptional(server.getId(), aChannel.getId())).thenReturn(Optional.empty());
|
||||
when(channelService.getTextChannelFromServerOptional(server.getId(), aChannel.getId())).thenReturn(Optional.empty());
|
||||
testUnit.setSlowMode(aChannel, duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.*;
|
||||
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.WarnDecayMode;
|
||||
import dev.sheldan.abstracto.moderation.config.features.WarningDecayFeature;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.WarnDecayMode;
|
||||
import dev.sheldan.abstracto.moderation.config.features.mode.WarningMode;
|
||||
import dev.sheldan.abstracto.moderation.config.posttargets.WarningPostTarget;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
@@ -17,13 +18,15 @@ import dev.sheldan.abstracto.moderation.models.template.job.WarnDecayLogModel;
|
||||
import dev.sheldan.abstracto.moderation.service.management.WarnManagementService;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.core.test.command.CommandTestUtilities;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.time.Instant;
|
||||
@@ -32,7 +35,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static dev.sheldan.abstracto.moderation.service.WarnServiceBean.*;
|
||||
import static dev.sheldan.abstracto.moderation.service.WarnServiceBean.WARNINGS_COUNTER_KEY;
|
||||
import static dev.sheldan.abstracto.moderation.service.WarnServiceBean.WARN_LOG_TEMPLATE;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -52,7 +56,7 @@ public class WarnServiceBeanTest {
|
||||
private TemplateService templateService;
|
||||
|
||||
@Mock
|
||||
private BotService botService;
|
||||
private MemberService memberService;
|
||||
|
||||
@Mock
|
||||
private ConfigService configService;
|
||||
@@ -228,9 +232,9 @@ public class WarnServiceBeanTest {
|
||||
setupWarnings();
|
||||
when(configService.getLongValue(WarningDecayFeature.DECAY_DAYS_KEY, server.getId())).thenReturn(5L);
|
||||
List<Warning> warnings = Arrays.asList(firstWarning, secondWarning);
|
||||
when(botService.getMemberInServerAsync(warningUser)).thenReturn(CompletableFuture.completedFuture(warningMember));
|
||||
when(botService.getMemberInServerAsync(firstWarnedUser)).thenReturn(CompletableFuture.completedFuture(warnedMember));
|
||||
when(botService.getMemberInServerAsync(secondWarnedUser)).thenReturn(CompletableFuture.completedFuture(secondWarnedMember));
|
||||
when(memberService.getMemberInServerAsync(warningUser)).thenReturn(CompletableFuture.completedFuture(warningMember));
|
||||
when(memberService.getMemberInServerAsync(firstWarnedUser)).thenReturn(CompletableFuture.completedFuture(warnedMember));
|
||||
when(memberService.getMemberInServerAsync(secondWarnedUser)).thenReturn(CompletableFuture.completedFuture(secondWarnedMember));
|
||||
when(warnManagementService.getActiveWarningsInServerOlderThan(eq(server), any(Instant.class))).thenReturn(warnings);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@ import dev.sheldan.abstracto.moderation.repository.FilteredInviteLinkRepository;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Mute;
|
||||
import dev.sheldan.abstracto.moderation.repository.MuteRepository;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -105,7 +105,7 @@ public class MuteManagementServiceBeanTest {
|
||||
AServer server = MockUtils.getServer();
|
||||
AUserInAServer userInAServer = MockUtils.getUserObject(9L, server);
|
||||
Member member = Mockito.mock(Member.class);
|
||||
when(userInServerManagementService.loadUser(member)).thenReturn(userInAServer);
|
||||
when(userInServerManagementService.loadOrCreateUser(member)).thenReturn(userInAServer);
|
||||
Mute mute = Mute.builder().build();
|
||||
when(muteRepository.findTopByMutedUserAndMuteEndedFalse(userInAServer)).thenReturn(mute);
|
||||
Mute aMuteOf = testUnit.getAMuteOf(member);
|
||||
|
||||
@@ -2,9 +2,9 @@ package dev.sheldan.abstracto.moderation.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.models.database.MuteRole;
|
||||
import dev.sheldan.abstracto.moderation.repository.MuteRoleRepository;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -13,7 +13,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package dev.sheldan.abstracto.moderation.service.management;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.CounterService;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.models.database.UserNote;
|
||||
import dev.sheldan.abstracto.moderation.repository.UserNoteRepository;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -3,9 +3,9 @@ package dev.sheldan.abstracto.moderation.service.management;
|
||||
import dev.sheldan.abstracto.core.models.ServerSpecificId;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import dev.sheldan.abstracto.moderation.models.database.Warning;
|
||||
import dev.sheldan.abstracto.moderation.repository.WarnRepository;
|
||||
import dev.sheldan.abstracto.core.test.MockUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
Reference in New Issue
Block a user