mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-10 18:33:29 +00:00
added message to user initiated context
fixed templates for ban and kick logging refactored kicking service fixed guild not found exception template added command validator to be used for unit testing commands added default values for command configuration changed some interfaces to message channel instead of text channel added separate executor service for un-mutes, which is shared updated spring boot version to 2.3.1 removed database connection string from properties added logback configuration changed some future logic in purge refactored error message for un mute, when there is no active mute refactored listener interface and removed usage of context utils added tests for moderation services
This commit is contained in:
@@ -40,7 +40,6 @@ public class Remind extends AbstractConditionableCommand {
|
||||
String text = (String) parameters.get(1);
|
||||
AUserInAServer aUserInAServer = commandContext.getUserInitiatedContext().getAUserInAServer();
|
||||
ReminderModel remindModel = (ReminderModel) ContextConverter.fromCommandContext(commandContext, ReminderModel.class);
|
||||
remindModel.setMessage(commandContext.getMessage());
|
||||
remindModel.setRemindText(text);
|
||||
Reminder createdReminder = remindService.createReminderInForUser(aUserInAServer, text, remindTime, commandContext.getMessage());
|
||||
remindModel.setReminder(createdReminder);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package dev.sheldan.abstracto.utility.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
@Configuration
|
||||
public class UtilitySpringConfig {
|
||||
|
||||
@Bean(name = "reminderScheduler")
|
||||
public ScheduledExecutorService getUnMuteExecutor() {
|
||||
return Executors.newScheduledThreadPool(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package dev.sheldan.abstracto.utility.listener.starboard;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.listener.MessageDeletedListener;
|
||||
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
|
||||
import dev.sheldan.abstracto.core.models.GuildChannelMember;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.database.StarboardPost;
|
||||
@@ -20,7 +22,7 @@ public class StarboardPostDeletedListener implements MessageDeletedListener {
|
||||
private StarboardPostManagementService starboardPostManagementService;
|
||||
|
||||
@Override
|
||||
public void execute(CachedMessage messageBefore) {
|
||||
public void execute(CachedMessage messageBefore, AServerAChannelAUser authorUser, GuildChannelMember authorMember) {
|
||||
Optional<StarboardPost> byStarboardPostId = starboardPostManagementService.findByStarboardPostId(messageBefore.getMessageId());
|
||||
if(byStarboardPostId.isPresent()) {
|
||||
StarboardPost post = byStarboardPostId.get();
|
||||
|
||||
@@ -23,6 +23,7 @@ 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;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -57,6 +58,10 @@ public class RemindServiceBean implements ReminderService {
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("reminderScheduler")
|
||||
private ScheduledExecutorService instantReminderScheduler;
|
||||
|
||||
@Override
|
||||
public Reminder createReminderInForUser(AUserInAServer user, String remindText, Duration remindIn, Message message) {
|
||||
AChannel channel = channelManagementService.loadChannel(message.getChannel().getIdLong()).orElseThrow(() -> new ChannelNotFoundException(message.getChannel().getIdLong(), message.getGuild().getIdLong()));
|
||||
@@ -74,9 +79,7 @@ public class RemindServiceBean implements ReminderService {
|
||||
|
||||
if(remindIn.getSeconds() < 60) {
|
||||
log.trace("Directly scheduling the reminder, because it was below the threshold.");
|
||||
// TODO make a bean out of this
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
scheduler.schedule(() -> {
|
||||
instantReminderScheduler.schedule(() -> {
|
||||
try {
|
||||
self.executeReminder(reminder.getId());
|
||||
} catch (Exception exception) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.utility.commands;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.serverinfo.ServerInfoModel;
|
||||
import org.junit.Test;
|
||||
@@ -30,4 +31,9 @@ public class ServerInfoTest {
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.ShowAvatarModel;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
@@ -55,4 +56,9 @@ public class ShowAvatarTest {
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.ShowEmoteLog;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
@@ -63,4 +64,9 @@ public class ShowEmoteTest {
|
||||
Assert.assertEquals(emote, usedLog.getEmote());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.utility.commands;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.starboard.StarStatsModel;
|
||||
import dev.sheldan.abstracto.utility.service.StarboardService;
|
||||
@@ -37,4 +38,9 @@ public class StarStatsTest {
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.UserInfoModel;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
@@ -91,4 +92,9 @@ public class UserInfoTest {
|
||||
Assert.assertEquals(loadedAuthor, usedModel.getMemberInfo());
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.ReminderModel;
|
||||
import dev.sheldan.abstracto.utility.service.ReminderService;
|
||||
@@ -67,4 +68,9 @@ public class RemindTest {
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.utility.commands.remind;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.database.Reminder;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.RemindersModel;
|
||||
@@ -51,4 +52,9 @@ public class RemindersTest {
|
||||
Assert.assertEquals(reminders.size(), usedModel.getReminders().size());
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.service.ReminderService;
|
||||
import org.junit.Test;
|
||||
@@ -43,4 +44,9 @@ public class UnRemindTest {
|
||||
verify(reminderService, times(1)).unRemind(reminderId, withParameters.getUserInitiatedContext().getAUserInAServer());
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
@@ -48,4 +49,9 @@ public class AcceptTest {
|
||||
verify(suggestionService, times(1)).acceptSuggestion(eq(suggestionId), eq(text), any(SuggestionLog.class));
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
@@ -48,4 +49,9 @@ public class RejectTest {
|
||||
verify(suggestionService, times(1)).rejectSuggestion(eq(suggestionId), eq(text), any(SuggestionLog.class));
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
|
||||
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
@@ -45,4 +46,9 @@ public class SuggestTest {
|
||||
CommandTestUtilities.checkSuccessfulCompletion(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommand() {
|
||||
CommandConfigValidator.validateCommandConfiguration(testUnit.getConfiguration());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.sheldan.abstracto.utility.listener.starboard;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
|
||||
import dev.sheldan.abstracto.core.models.GuildChannelMember;
|
||||
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
@@ -11,6 +13,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -34,7 +37,9 @@ public class StarboardPostDeletedListenerTest {
|
||||
.builder()
|
||||
.messageId(messageId)
|
||||
.build();
|
||||
testUnit.execute(cachedMessage);
|
||||
AServerAChannelAUser user = Mockito.mock(AServerAChannelAUser.class);
|
||||
GuildChannelMember member = Mockito.mock(GuildChannelMember.class);
|
||||
testUnit.execute(cachedMessage, user, member);
|
||||
verify( starboardPostManagementService, times(0)).setStarboardPostIgnored(messageId, true);
|
||||
}
|
||||
|
||||
@@ -50,7 +55,9 @@ public class StarboardPostDeletedListenerTest {
|
||||
.builder()
|
||||
.messageId(messageId)
|
||||
.build();
|
||||
testUnit.execute(cachedMessage);
|
||||
AServerAChannelAUser user = Mockito.mock(AServerAChannelAUser.class);
|
||||
GuildChannelMember member = Mockito.mock(GuildChannelMember.class);
|
||||
testUnit.execute(cachedMessage, user, member);
|
||||
verify( starboardPostManagementService, times(1)).setStarboardPostIgnored(messageId, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -69,6 +70,9 @@ public class RemindServiceBeanTest {
|
||||
@Mock
|
||||
private TextChannel channel;
|
||||
|
||||
@Mock
|
||||
private ScheduledExecutorService instantReminderScheduler;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
when(message.getIdLong()).thenReturn(5L);
|
||||
|
||||
Reference in New Issue
Block a user