mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-28 08:38:52 +00:00
[AB-138] improving logging at various places fixing various issues regarding async commands and exception handling, fixing role role calculation being done twice
This commit is contained in:
@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.serverinfo.ServerInfoModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -21,6 +22,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ServerInfo extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
@@ -30,6 +32,7 @@ public class ServerInfo extends AbstractConditionableCommand {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
ServerInfoModel model = (ServerInfoModel) ContextConverter.fromCommandContext(commandContext, ServerInfoModel.class);
|
||||
model.setGuild(commandContext.getGuild());
|
||||
log.info("Displaying serverinfo for server {}", commandContext.getGuild().getId());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel("serverinfo_response", model, commandContext.getChannel()))
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.ShowAvatarModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -22,6 +23,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ShowAvatar extends AbstractConditionableCommand {
|
||||
|
||||
public static final String SHOW_AVATAR_RESPONSE_TEMPLATE = "showAvatar_response";
|
||||
@@ -34,6 +36,8 @@ public class ShowAvatar extends AbstractConditionableCommand {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Member memberToShow = parameters.size() == 1 ? (Member) parameters.get(0) : commandContext.getUserInitiatedContext().getMember();
|
||||
ShowAvatarModel model = (ShowAvatarModel) ContextConverter.fromCommandContext(commandContext, ShowAvatarModel.class);
|
||||
log.info("Showing avatar for member {} towards user {} in channel {} in server {}.",
|
||||
memberToShow.getId(), commandContext.getAuthor().getId(), commandContext.getChannel().getId(), commandContext.getGuild().getId());
|
||||
model.setMemberInfo(memberToShow);
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(SHOW_AVATAR_RESPONSE_TEMPLATE, model, commandContext.getChannel()))
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
|
||||
@@ -14,6 +14,7 @@ import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.UserInfoModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class UserInfo extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
@@ -42,6 +44,7 @@ public class UserInfo extends AbstractConditionableCommand {
|
||||
Member memberToShow = parameters.size() == 1 ? (Member) parameters.get(0) : commandContext.getAuthor();
|
||||
UserInfoModel model = (UserInfoModel) ContextConverter.slimFromCommandContext(commandContext, UserInfoModel.class);
|
||||
if(!memberToShow.hasTimeJoined()) {
|
||||
log.info("Force reloading member {} in guild {} for user info.", memberToShow.getId(), memberToShow.getGuild().getId());
|
||||
return botService.forceReloadMember(memberToShow).thenCompose(member -> {
|
||||
model.setMemberInfo(member);
|
||||
return self.sendResponse(commandContext, model)
|
||||
|
||||
@@ -14,6 +14,7 @@ import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.database.Reminder;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.ReminderModel;
|
||||
import dev.sheldan.abstracto.utility.service.ReminderService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -23,6 +24,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Remind extends AbstractConditionableCommand {
|
||||
|
||||
public static final String REMINDER_EMBED_KEY = "remind_response";
|
||||
@@ -45,6 +47,8 @@ public class Remind extends AbstractConditionableCommand {
|
||||
Reminder createdReminder = remindService.createReminderInForUser(aUserInAServer, text, remindTime, commandContext.getMessage());
|
||||
remindModel.setReminder(createdReminder);
|
||||
|
||||
log.info("Notifying user {} about reminder being scheduled.", commandContext.getAuthor().getId());
|
||||
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(REMINDER_EMBED_KEY, remindModel, commandContext.getChannel()))
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@@ -8,12 +8,14 @@ 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.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.database.Reminder;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.RemindersModel;
|
||||
import dev.sheldan.abstracto.utility.service.management.ReminderManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -21,6 +23,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Reminders extends AbstractConditionableCommand {
|
||||
|
||||
public static final String REMINDERS_RESPONSE_TEMPLATE = "reminders_response";
|
||||
@@ -33,9 +36,11 @@ public class Reminders extends AbstractConditionableCommand {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
List<Reminder> activeReminders = reminderManagementService.getActiveRemindersForUser(commandContext.getUserInitiatedContext().getAUserInAServer());
|
||||
AUserInAServer aUserInAServer = commandContext.getUserInitiatedContext().getAUserInAServer();
|
||||
List<Reminder> activeReminders = reminderManagementService.getActiveRemindersForUser(aUserInAServer);
|
||||
RemindersModel model = (RemindersModel) ContextConverter.fromCommandContext(commandContext, RemindersModel.class);
|
||||
model.setReminders(activeReminders);
|
||||
log.info("Showing {} reminders for user {} in server {}.", activeReminders.size(), commandContext.getAuthor().getId(), commandContext.getGuild().getId());
|
||||
return FutureUtils.toSingleFutureGeneric(channelService.sendEmbedTemplateInChannel(REMINDERS_RESPONSE_TEMPLATE, model, commandContext.getChannel()))
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -21,6 +22,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Accept extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
@@ -32,6 +34,7 @@ public class Accept extends AbstractConditionableCommand {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Long suggestionId = (Long) parameters.get(0);
|
||||
String text = parameters.size() == 2 ? (String) parameters.get(1) : "";
|
||||
log.trace("Using default reason for accept: {}.", parameters.size() != 2);
|
||||
SuggestionLog suggestionModel = (SuggestionLog) ContextConverter.fromCommandContext(commandContext, SuggestionLog.class);
|
||||
return suggestionService.acceptSuggestion(suggestionId, text, suggestionModel)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
|
||||
@@ -12,6 +12,7 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
import dev.sheldan.abstracto.utility.service.SuggestionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -21,6 +22,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Reject extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
@@ -32,6 +34,7 @@ public class Reject extends AbstractConditionableCommand {
|
||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
||||
Long suggestionId = (Long) parameters.get(0);
|
||||
String text = parameters.size() == 2 ? (String) parameters.get(1) : "";
|
||||
log.trace("Using default reason for accept: {}.", parameters.size() != 2);
|
||||
SuggestionLog suggestionModel = (SuggestionLog) ContextConverter.fromCommandContext(commandContext, SuggestionLog.class);
|
||||
return suggestionService.rejectSuggestion(suggestionId, text, suggestionModel)
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ReminderJob extends QuartzJobBean {
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
||||
try {
|
||||
log.info("executing reminder job for reminder {}", reminderId);
|
||||
log.info("Executing reminder job for reminder {}", reminderId);
|
||||
reminderService.executeReminder(reminderId);
|
||||
} catch (Exception e) {
|
||||
log.error("Reminder job failed to execute.", e);
|
||||
|
||||
@@ -39,14 +39,17 @@ public class MessageEmbedListener implements MessageReceivedListener {
|
||||
String messageRaw = message.getContentRaw();
|
||||
List<MessageEmbedLink> links = messageEmbedService.getLinksInMessage(messageRaw);
|
||||
if(!links.isEmpty()) {
|
||||
log.trace("We found {} links to embed in message {} in channel {} in guild {}.", links.size(), message.getId(), message.getChannel().getId(), message.getGuild().getId());
|
||||
Long userEmbeddingUserInServerId = userInServerManagementService.loadUser(message.getMember()).getUserInServerId();
|
||||
for (MessageEmbedLink messageEmbedLink : links) {
|
||||
if(!messageEmbedLink.getServerId().equals(message.getGuild().getIdLong())) {
|
||||
log.info("Link for message {} was from a foreign server {}. Do not embed.", messageEmbedLink.getMessageId(), messageEmbedLink.getServerId());
|
||||
continue;
|
||||
}
|
||||
messageRaw = messageRaw.replace(messageEmbedLink.getWholeUrl(), "");
|
||||
Consumer<CachedMessage> cachedMessageConsumer = cachedMessage ->self.loadUserAndEmbed(message, userEmbeddingUserInServerId, cachedMessage);
|
||||
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId()).thenAccept(cachedMessageConsumer)
|
||||
messageCache.getMessageFromCache(messageEmbedLink.getServerId(), messageEmbedLink.getChannelId(), messageEmbedLink.getMessageId())
|
||||
.thenAccept(cachedMessageConsumer)
|
||||
.exceptionally(throwable -> {
|
||||
log.error("Error when embedding link for message {}", message.getId(), throwable);
|
||||
return null;
|
||||
@@ -60,6 +63,8 @@ public class MessageEmbedListener implements MessageReceivedListener {
|
||||
|
||||
@Transactional
|
||||
public void loadUserAndEmbed(Message message, Long cause, CachedMessage cachedMessage) {
|
||||
log.info("Embedding link to message {} in channel {} in server {} to channel {} and server {}.",
|
||||
cachedMessage.getMessageId(), cachedMessage.getChannelId(), cachedMessage.getServerId(), message.getChannel().getId(), message.getGuild().getId());
|
||||
messageEmbedService.embedLink(cachedMessage, message.getTextChannel(), cause , message);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import dev.sheldan.abstracto.utility.config.features.UtilityFeature;
|
||||
import dev.sheldan.abstracto.utility.models.database.EmbeddedMessage;
|
||||
import dev.sheldan.abstracto.utility.service.management.MessageEmbedPostManagementService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -45,8 +44,6 @@ public class MessageEmbedRemovalReactionListener implements ReactedAddedListener
|
||||
Long guildId = message.getServerId();
|
||||
AEmote aEmote = emoteService.getEmoteOrDefaultEmote(REMOVAL_EMOTE, guildId);
|
||||
MessageReaction.ReactionEmote reactionEmote = event.getReactionEmote();
|
||||
Optional<Emote> emoteInGuild = botService.getEmote(guildId, aEmote);
|
||||
log.trace("Removing embed in message {} in channel {} in server {} because of a user reaction.", message.getMessageId(), message.getChannelId(), message.getServerId());
|
||||
if(emoteService.isReactionEmoteAEmote(reactionEmote, aEmote)) {
|
||||
Optional<EmbeddedMessage> embeddedMessageOptional = messageEmbedPostManagementService.findEmbeddedPostByMessageId(message.getMessageId());
|
||||
if(embeddedMessageOptional.isPresent()) {
|
||||
@@ -55,12 +52,18 @@ public class MessageEmbedRemovalReactionListener implements ReactedAddedListener
|
||||
if(embeddedMessage.getEmbeddedUser().getUserReference().getId().equals(userReacting.getId())
|
||||
|| embeddedMessage.getEmbeddingUser().getUserReference().getId().equals(userReacting.getId())
|
||||
) {
|
||||
log.info("Removing embed in message {} in channel {} in server {} because of a user reaction.", message.getMessageId(), message.getChannelId(), message.getServerId());
|
||||
messageService.deleteMessageInChannelInServer(message.getServerId(), message.getChannelId(), message.getMessageId()).thenAccept(aVoid ->{
|
||||
Optional<EmbeddedMessage> innerOptional = messageEmbedPostManagementService.findEmbeddedPostByMessageId(message.getMessageId());
|
||||
innerOptional.ifPresent(value -> messageEmbedPostManagementService.deleteEmbeddedMessage(value));
|
||||
});
|
||||
} else {
|
||||
log.trace("Somebody besides the original author and the user embedding added the removal reaction to the message {} in channel {} in server {}.",
|
||||
message.getMessageId(), message.getChannelId(), message.getServerId());
|
||||
}
|
||||
|
||||
} else {
|
||||
log.trace("Removal emote was placed on a message which was not recognized as an embedded message.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class StarboardListener implements ReactedAddedListener, ReactedRemovedLi
|
||||
AEmote aEmote = emoteService.getEmoteOrDefaultEmote(STAR_EMOTE, guildId);
|
||||
MessageReaction.ReactionEmote reactionEmote = addedReaction.getReactionEmote();
|
||||
if(emoteService.isReactionEmoteAEmote(reactionEmote, aEmote)) {
|
||||
log.trace("User {} in server {} reacted with star to put a message {} on starboard.", userAdding.getUserReference().getId(), userAdding.getServerReference().getId(), message.getMessageId());
|
||||
log.info("User {} in server {} reacted with star to put a message {} from channel {} on starboard.", userAdding.getUserReference().getId(), userAdding.getServerReference().getId(), message.getMessageId(), message.getChannelId());
|
||||
Optional<CachedReaction> reactionOptional = emoteService.getReactionFromMessageByEmote(message, aEmote);
|
||||
handleStarboardPostChange(message, reactionOptional.orElse(null), userAdding, true);
|
||||
}
|
||||
@@ -105,6 +105,7 @@ public class StarboardListener implements ReactedAddedListener, ReactedRemovedLi
|
||||
|
||||
private void updateStarboardPost(CachedMessage message, AUserInAServer userReacting, boolean adding, StarboardPost starboardPost, List<AUserInAServer> userExceptAuthor) {
|
||||
starboardPost.setIgnored(false);
|
||||
// TODO handle futures correctly
|
||||
starboardService.updateStarboardPost(starboardPost, message, userExceptAuthor);
|
||||
if(adding) {
|
||||
log.trace("Adding reactor {} from message {}", userReacting.getUserReference().getId(), message.getMessageId());
|
||||
@@ -130,7 +131,7 @@ public class StarboardListener implements ReactedAddedListener, ReactedRemovedLi
|
||||
AEmote aEmote = emoteService.getEmoteOrDefaultEmote(STAR_EMOTE, guildId);
|
||||
MessageReaction.ReactionEmote reactionEmote = removedReaction.getReactionEmote();
|
||||
if(emoteService.isReactionEmoteAEmote(reactionEmote, aEmote)) {
|
||||
log.trace("User {} in server {} removed star reaction from message {} on starboard.",
|
||||
log.info("User {} in server {} removed star reaction from message {} on starboard.",
|
||||
userRemoving.getUserReference().getId(), userRemoving.getServerReference().getId(), message.getMessageId());
|
||||
Optional<CachedReaction> reactionOptional = emoteService.getReactionFromMessageByEmote(message, aEmote);
|
||||
handleStarboardPostChange(message, reactionOptional.orElse(null), userRemoving, false);
|
||||
@@ -158,6 +159,8 @@ public class StarboardListener implements ReactedAddedListener, ReactedRemovedLi
|
||||
Optional<StarboardPost> starboardPostOptional = starboardPostManagementService.findByMessageId(message.getMessageId());
|
||||
|
||||
starboardPostOptional.ifPresent(starboardPost -> {
|
||||
log.info("Reactions on message {} in channel {} in server {} were cleared. Completely deleting the starboard post {}.",
|
||||
message.getMessageId(), message.getChannelId(), message.getServerId(), starboardPost.getId());
|
||||
starboardPostReactorManagementService.removeReactors(starboardPost);
|
||||
completelyRemoveStarboardPost(starboardPost);
|
||||
});
|
||||
|
||||
@@ -77,7 +77,7 @@ public class RemindServiceBean implements ReminderService {
|
||||
user.getUserReference().getId(), user.getServerReference().getId(), remindAt);
|
||||
|
||||
if(remindIn.getSeconds() < 60) {
|
||||
log.trace("Directly scheduling the reminder, because it was below the threshold.");
|
||||
log.info("Directly scheduling unremind for reminder {}, because it was below the threshold.", reminder.getId());
|
||||
instantReminderScheduler.schedule(() -> {
|
||||
try {
|
||||
self.executeReminder(reminder.getId());
|
||||
@@ -86,10 +86,10 @@ public class RemindServiceBean implements ReminderService {
|
||||
}
|
||||
}, remindIn.toNanos(), TimeUnit.NANOSECONDS);
|
||||
} else {
|
||||
log.trace("Starting scheduled job to execute reminder.");
|
||||
JobDataMap parameters = new JobDataMap();
|
||||
parameters.putAsString("reminderId", reminder.getId());
|
||||
String triggerKey = schedulerService.executeJobWithParametersOnce("reminderJob", "utility", parameters, Date.from(reminder.getTargetDate()));
|
||||
log.info("Starting scheduled job with trigger {} to execute reminder. {}", triggerKey, reminder.getId());
|
||||
reminder.setJobTriggerKey(triggerKey);
|
||||
reminderManagementService.saveReminder(reminder);
|
||||
}
|
||||
@@ -105,7 +105,8 @@ public class RemindServiceBean implements ReminderService {
|
||||
}
|
||||
AServer server = reminderToRemindFor.getServer();
|
||||
AChannel channel = reminderToRemindFor.getChannel();
|
||||
log.info("Executing reminder {}.", reminderId);
|
||||
log.info("Executing reminder {} in channel {} in server {} for user {}.",
|
||||
reminderId, channel.getId(), server.getId(), reminderToRemindFor.getRemindedUser().getUserReference().getId());
|
||||
Optional<Guild> guildToAnswerIn = botService.getGuildById(server.getId());
|
||||
if(guildToAnswerIn.isPresent()) {
|
||||
Optional<TextChannel> channelToAnswerIn = botService.getTextChannelFromServerOptional(server.getId(), channel.getId());
|
||||
@@ -133,9 +134,11 @@ public class RemindServiceBean implements ReminderService {
|
||||
|
||||
@Override
|
||||
public void unRemind(Long reminderId, AUserInAServer aUserInAServer) {
|
||||
log.info("Trying to end reminder {} for user {} in server {}.", reminderId, aUserInAServer.getUserReference().getId(),aUserInAServer.getServerReference().getId());
|
||||
Reminder reminder = reminderManagementService.getReminderByAndByUserNotReminded(aUserInAServer, reminderId).orElseThrow(() -> new ReminderNotFoundException(reminderId));
|
||||
reminder.setReminded(true);
|
||||
if(reminder.getJobTriggerKey() != null) {
|
||||
log.trace("Stopping scheduled trigger {} for reminder {}.", reminder.getJobTriggerKey(), reminderId);
|
||||
schedulerService.stopTrigger(reminder.getJobTriggerKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -90,9 +89,8 @@ public class StarboardServiceBean implements StarboardService {
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, StarboardPostTarget.STARBOARD, message.getServerId());
|
||||
Long starboardChannelId = starboard.getChannelReference().getId();
|
||||
Long starredUserId = starredUser.getUserInServerId();
|
||||
Long userReactingId = userReacting.getUserInServerId();
|
||||
CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid ->
|
||||
self.persistPost(message, userExceptAuthorIds, completableFutures, starboardChannelId, starredUserId, userReactingId)
|
||||
self.persistPost(message, userExceptAuthorIds, completableFutures, starboardChannelId, starredUserId)
|
||||
) .exceptionally(throwable -> {
|
||||
log.error("Failed to create starboard post for message {} in channel {} in server {}", message.getMessageId(), message.getChannelId(), message.getServerId(), throwable);
|
||||
return null;
|
||||
@@ -101,29 +99,25 @@ public class StarboardServiceBean implements StarboardService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void persistPost(CachedMessage message, List<Long> userExceptAuthorIds, List<CompletableFuture<Message>> completableFutures, Long starboardChannelId, Long starredUserId, Long userReactingId) {
|
||||
public void persistPost(CachedMessage message, List<Long> userExceptAuthorIds, List<CompletableFuture<Message>> completableFutures, Long starboardChannelId, Long starredUserId) {
|
||||
AUserInAServer innerStarredUser = userInServerManagementService.loadUserConditional(starredUserId).orElseThrow(() -> new UserInServerNotFoundException(starredUserId));
|
||||
try {
|
||||
AChannel starboardChannel = channelManagementService.loadChannel(starboardChannelId);
|
||||
Message message1 = completableFutures.get(0).get();
|
||||
AServerAChannelMessage aServerAChannelMessage = AServerAChannelMessage
|
||||
.builder()
|
||||
.messageId(message1.getIdLong())
|
||||
.channel(starboardChannel)
|
||||
.server(starboardChannel.getServer())
|
||||
.build();
|
||||
StarboardPost starboardPost = starboardPostManagementService.createStarboardPost(message, innerStarredUser, aServerAChannelMessage);
|
||||
if(userExceptAuthorIds.isEmpty()) {
|
||||
log.warn("There are no user ids except the author for the reactions in post {} in guild {} for message {} in channel {}.", starboardPost.getId(), message.getChannelId(), message.getMessageId(), message.getChannelId());
|
||||
}
|
||||
userExceptAuthorIds.forEach(aLong -> {
|
||||
AUserInAServer user = userInServerManagementService.loadUserConditional(aLong).orElseThrow(() -> new UserInServerNotFoundException(aLong));
|
||||
starboardPostReactorManagementService.addReactor(starboardPost, user);
|
||||
});
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("Failed to post messages.", e);
|
||||
Thread.currentThread().interrupt();
|
||||
AChannel starboardChannel = channelManagementService.loadChannel(starboardChannelId);
|
||||
Message message1 = completableFutures.get(0).join();
|
||||
AServerAChannelMessage aServerAChannelMessage = AServerAChannelMessage
|
||||
.builder()
|
||||
.messageId(message1.getIdLong())
|
||||
.channel(starboardChannel)
|
||||
.server(starboardChannel.getServer())
|
||||
.build();
|
||||
StarboardPost starboardPost = starboardPostManagementService.createStarboardPost(message, innerStarredUser, aServerAChannelMessage);
|
||||
log.info("Persisting starboard post in channel {} with message {} with {} reactors.", message1.getId(),starboardChannelId, userExceptAuthorIds.size());
|
||||
if(userExceptAuthorIds.isEmpty()) {
|
||||
log.warn("There are no user ids except the author for the reactions in post {} in guild {} for message {} in channel {}.", starboardPost.getId(), message.getChannelId(), message.getMessageId(), message.getChannelId());
|
||||
}
|
||||
userExceptAuthorIds.forEach(aLong -> {
|
||||
AUserInAServer user = userInServerManagementService.loadUserConditional(aLong).orElseThrow(() -> new UserInServerNotFoundException(aLong));
|
||||
starboardPostReactorManagementService.addReactor(starboardPost, user);
|
||||
});
|
||||
}
|
||||
|
||||
private StarboardPostModel buildStarboardPostModel(CachedMessage message, Integer starCount) {
|
||||
@@ -150,20 +144,14 @@ public class StarboardServiceBean implements StarboardService {
|
||||
|
||||
@Override
|
||||
public void updateStarboardPost(StarboardPost post, CachedMessage message, List<AUserInAServer> userExceptAuthor) {
|
||||
log.info("Updating starboard post {} in server {} with reactors {}.", post.getId(), post.getSourceChanel().getServer().getId(), userExceptAuthor.size());
|
||||
StarboardPostModel starboardPostModel = buildStarboardPostModel(message, userExceptAuthor.size());
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(STARBOARD_POST_TEMPLATE, starboardPostModel);
|
||||
List<CompletableFuture<Message>> futures = postTargetService.editOrCreatedInPostTarget(post.getStarboardMessageId(), messageToSend, StarboardPostTarget.STARBOARD, message.getServerId());
|
||||
Long starboardPostId = post.getId();
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
|
||||
try {
|
||||
Optional<StarboardPost> innerPost = starboardPostManagementService.findByStarboardPostId(starboardPostId);
|
||||
if(innerPost.isPresent()) {
|
||||
starboardPostManagementService.setStarboardPostMessageId(innerPost.get(), futures.get(0).get().getIdLong());
|
||||
}
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("Failed to post starboard post.", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
Optional<StarboardPost> innerPost = starboardPostManagementService.findByStarboardPostId(starboardPostId);
|
||||
innerPost.ifPresent(starboardPost -> starboardPostManagementService.setStarboardPostMessageId(starboardPost, futures.get(0).join().getIdLong()));
|
||||
}).exceptionally(throwable -> {
|
||||
log.error("Failed to update starboard post {}.", post.getId(), throwable);
|
||||
return null;
|
||||
@@ -173,6 +161,7 @@ public class StarboardServiceBean implements StarboardService {
|
||||
@Override
|
||||
public void deleteStarboardMessagePost(StarboardPost message) {
|
||||
AChannel starboardChannel = message.getStarboardChannel();
|
||||
log.info("Deleting starboard post {} in server {}", message.getId(), message.getSourceChanel().getServer().getId());
|
||||
botService.deleteMessage(starboardChannel.getServer().getId(), starboardChannel.getId(), message.getStarboardMessageId());
|
||||
}
|
||||
|
||||
|
||||
@@ -71,19 +71,23 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
suggestionLog.setText(text);
|
||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(SUGGESTION_LOG_TEMPLATE, suggestionLog);
|
||||
long guildId = member.getGuild().getIdLong();
|
||||
log.info("Creating suggestion with id {} in server {} from member {}.", newSuggestionId, member.getGuild().getId(), member.getId());
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, SuggestionPostTarget.SUGGESTION, guildId);
|
||||
return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenCompose(aVoid -> {
|
||||
Message message = completableFutures.get(0).join();
|
||||
log.trace("Posted message, adding reaction for suggestion {} to message {}.", newSuggestionId, message.getId());
|
||||
CompletableFuture<Void> firstReaction = messageService.addReactionToMessageWithFuture(SUGGESTION_YES_EMOTE, guildId, message);
|
||||
CompletableFuture<Void> secondReaction = messageService.addReactionToMessageWithFuture(SUGGESTION_NO_EMOTE, guildId, message);
|
||||
return CompletableFuture.allOf(firstReaction, secondReaction).thenAccept(aVoid1 ->
|
||||
self.persistSuggestionInDatabase(member, text, message, newSuggestionId)
|
||||
);
|
||||
return CompletableFuture.allOf(firstReaction, secondReaction).thenAccept(aVoid1 -> {
|
||||
log.trace("Reaction added to message {} for suggestion {}.", message.getId(), newSuggestionId);
|
||||
self.persistSuggestionInDatabase(member, text, message, newSuggestionId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void persistSuggestionInDatabase(Member member, String text, Message message, Long suggestionId) {
|
||||
log.info("Persisting suggestion {} for server {} in database.", suggestionId, member.getGuild().getId());
|
||||
suggestionManagementService.createSuggestion(member, text, message, suggestionId);
|
||||
}
|
||||
|
||||
@@ -91,6 +95,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
public CompletableFuture<Void> acceptSuggestion(Long suggestionId, String text, SuggestionLog suggestionLog) {
|
||||
Suggestion suggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new SuggestionNotFoundException(suggestionId));
|
||||
suggestionManagementService.setSuggestionState(suggestion, SuggestionState.ACCEPTED);
|
||||
log.info("Accepting suggestion {} in server {}.", suggestionId, suggestion.getServer().getId());
|
||||
return updateSuggestion(text, suggestionLog, suggestion);
|
||||
}
|
||||
|
||||
@@ -99,6 +104,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
Long channelId = suggestion.getChannel().getId();
|
||||
Long originalMessageId = suggestion.getMessageId();
|
||||
Long serverId = suggestion.getServer().getId();
|
||||
log.info("Updated posted suggestion {} in server {}.", suggestion.getId(), suggestion.getServer().getId());
|
||||
|
||||
suggestionLog.setOriginalChannelId(channelId);
|
||||
suggestionLog.setOriginalMessageId(originalMessageId);
|
||||
@@ -130,6 +136,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
public CompletableFuture<Void> updateSuggestionMessageText(String text, SuggestionLog suggestionLog, Message message) {
|
||||
Optional<MessageEmbed> embedOptional = message.getEmbeds().stream().filter(embed -> embed.getDescription() != null).findFirst();
|
||||
if(embedOptional.isPresent()) {
|
||||
log.info("Updating the text of the suggestion {} in server {}.", suggestionLog.getSuggestionId(), message.getGuild().getId());
|
||||
MessageEmbed suggestionEmbed = embedOptional.get();
|
||||
suggestionLog.setReason(text);
|
||||
suggestionLog.setText(suggestionEmbed.getDescription());
|
||||
@@ -143,9 +150,10 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> rejectSuggestion(Long suggestionId, String text, SuggestionLog log) {
|
||||
public CompletableFuture<Void> rejectSuggestion(Long suggestionId, String text, SuggestionLog suggestionLog) {
|
||||
Suggestion suggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new SuggestionNotFoundException(suggestionId));
|
||||
suggestionManagementService.setSuggestionState(suggestion, SuggestionState.REJECTED);
|
||||
return updateSuggestion(text, log, suggestion);
|
||||
log.info("Rejecting suggestion {} in server {}.", suggestionId, suggestion.getServer().getId());
|
||||
return updateSuggestion(text, suggestionLog, suggestion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ public class MessageEmbedPostManagementServiceBean implements MessageEmbedPostMa
|
||||
.embeddingUser(embeddingUser)
|
||||
.build();
|
||||
|
||||
log.info("Saving embedded post: message {} by user {} in channel {} in server {} embedded message {} by user {} in channel {} in server {}.",
|
||||
messageContainingEmbed.getIdLong(), embeddingUser.getUserReference().getId(), embeddingChannel.getId(), embeddingUser.getServerReference().getId(),
|
||||
embeddedMessage.getMessageId(), embeddedMessage.getAuthorId(), embeddedMessage.getChannelId(), embeddedMessage.getServerId());
|
||||
|
||||
embeddedMessageRepository.save(messageEmbedPost);
|
||||
}
|
||||
|
||||
@@ -68,6 +72,7 @@ public class MessageEmbedPostManagementServiceBean implements MessageEmbedPostMa
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteEmbeddedMessage(EmbeddedMessage embeddedMessage) {
|
||||
log.info("Deleting embedded message {}.", embeddedMessage.getEmbeddingMessageId());
|
||||
embeddedMessageRepository.delete(embeddedMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.utility.models.database.Reminder;
|
||||
import dev.sheldan.abstracto.utility.repository.ReminderRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -12,6 +13,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ReminderManagementServiceBean implements ReminderManagementService {
|
||||
|
||||
@Autowired
|
||||
@@ -29,6 +31,8 @@ public class ReminderManagementServiceBean implements ReminderManagementService
|
||||
.targetDate(timeToBeRemindedAt)
|
||||
.messageId(messageId)
|
||||
.build();
|
||||
log.info("Creating reminder for user {} in server {} in message {} to be reminded at {}.",
|
||||
userToBeReminded.getAUserInAServer().getUserReference().getId(), userToBeReminded.getGuild().getId(), messageId, timeToBeRemindedAt);
|
||||
|
||||
reminderRepository.save(reminder);
|
||||
return reminder;
|
||||
@@ -42,6 +46,7 @@ public class ReminderManagementServiceBean implements ReminderManagementService
|
||||
@Override
|
||||
public void setReminded(Reminder reminder) {
|
||||
reminder.setReminded(true);
|
||||
log.info("Setting reminder {} to reminded.", reminder.getId());
|
||||
reminderRepository.save(reminder);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.utility.models.database.StarboardPost;
|
||||
import dev.sheldan.abstracto.utility.repository.StarboardPostRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -17,6 +18,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class StarboardPostManagementServiceBean implements StarboardPostManagementService {
|
||||
|
||||
@Autowired
|
||||
@@ -38,6 +40,10 @@ public class StarboardPostManagementServiceBean implements StarboardPostManageme
|
||||
.starboardChannel(starboardPost.getChannel())
|
||||
.starredDate(Instant.now())
|
||||
.build();
|
||||
log.info("Persisting starboard post for message {} in channel {} in server {} on starboard at message {} in channel {} and server {} of user {}.",
|
||||
starredMessage.getMessageId(), starredMessage.getChannelId(), starredMessage.getServerId(),
|
||||
starboardPost.getMessageId(), starboardPost.getChannel().getId(), starboardPost.getServer().getId(),
|
||||
starredUser.getUserReference().getId());
|
||||
repository.save(post);
|
||||
return post;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ import dev.sheldan.abstracto.utility.models.template.commands.starboard.StarStat
|
||||
import dev.sheldan.abstracto.utility.repository.StarStatsUserResult;
|
||||
import dev.sheldan.abstracto.utility.repository.StarboardPostReactionRepository;
|
||||
import dev.sheldan.abstracto.utility.repository.converter.StarStatsUserConverter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class StarboardPostReactorManagementServiceBean implements StarboardPostReactorManagementService {
|
||||
|
||||
@Autowired
|
||||
@@ -28,16 +30,19 @@ public class StarboardPostReactorManagementServiceBean implements StarboardPostR
|
||||
.starboardPost(post)
|
||||
.reactor(user)
|
||||
.build();
|
||||
log.info("Persisting the reactor {} for starboard post {} in server {}.", user.getUserReference().getId(), post.getId(), user.getServerReference().getId());
|
||||
repository.save(reactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeReactor(StarboardPost post, AUserInAServer user) {
|
||||
log.info("Removing reactor {} from post {} in server {}.", user.getUserReference().getId(), post.getId(), user.getServerReference().getId());
|
||||
repository.deleteByReactorAndStarboardPost(user, post);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeReactors(StarboardPost post) {
|
||||
log.info("Removing all {} reactors from starboard post {}", post.getReactions().size(), post.getId());
|
||||
repository.deleteByStarboardPost(post);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.utility.models.database.Suggestion;
|
||||
import dev.sheldan.abstracto.utility.models.SuggestionState;
|
||||
import dev.sheldan.abstracto.utility.repository.SuggestionRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -17,6 +18,7 @@ import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SuggestionManagementServiceBean implements SuggestionManagementService {
|
||||
|
||||
@Autowired
|
||||
@@ -51,6 +53,8 @@ public class SuggestionManagementServiceBean implements SuggestionManagementServ
|
||||
.channel(channel)
|
||||
.messageId(message.getIdLong())
|
||||
.build();
|
||||
log.info("Persisting suggestion {} at message {} in channel {} on server {} from user {}.",
|
||||
suggestionId, message.getId(), channelId, message.getGuild().getId(), suggester.getUserReference().getId());
|
||||
suggestionRepository.save(suggestion);
|
||||
return suggestion;
|
||||
}
|
||||
@@ -64,6 +68,7 @@ public class SuggestionManagementServiceBean implements SuggestionManagementServ
|
||||
@Override
|
||||
public void setSuggestionState(Suggestion suggestion, SuggestionState newState) {
|
||||
suggestion.setState(newState);
|
||||
log.info("Setting suggestion {} to state {}.", suggestion.getId(), newState);
|
||||
suggestionRepository.save(suggestion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ import dev.sheldan.abstracto.core.service.FeatureValidatorService;
|
||||
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||
import dev.sheldan.abstracto.utility.StarboardFeatureValidator;
|
||||
import dev.sheldan.abstracto.utility.service.StarboardServiceBean;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class StarboardFeatureValidatorService implements StarboardFeatureValidator {
|
||||
|
||||
@Autowired
|
||||
@@ -22,6 +24,7 @@ public class StarboardFeatureValidatorService implements StarboardFeatureValidat
|
||||
@Override
|
||||
public void featureIsSetup(FeatureConfig featureConfig, AServer server, FeatureValidationResult validationResult) {
|
||||
int levelAmount = defaultConfigManagementService.getDefaultConfig(StarboardServiceBean.STAR_LEVELS_CONFIG_KEY).getLongValue().intValue();
|
||||
log.info("Validating starboard feature for server {}.", server.getId());
|
||||
for(int i = 1; i <= levelAmount; i++) {
|
||||
featureValidatorService.checkSystemConfig("starLvl" + i, server, validationResult);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ 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.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -60,6 +61,7 @@ public class UserInfoTest {
|
||||
CommandContext noParameters = CommandTestUtilities.getNoParameters();
|
||||
when(noParameters.getAuthor().hasTimeJoined()).thenReturn(false);
|
||||
Member loadedAuthor = Mockito.mock(Member.class);
|
||||
when(noParameters.getAuthor().getGuild()).thenReturn(Mockito.mock(Guild.class));
|
||||
when(botService.forceReloadMember(noParameters.getAuthor())).thenReturn(CompletableFuture.completedFuture(loadedAuthor));
|
||||
when(self.sendResponse(eq(noParameters), modelArgumentCaptor.capture())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
CompletableFuture<CommandResult> result = testUnit.executeAsync(noParameters);
|
||||
@@ -86,6 +88,7 @@ public class UserInfoTest {
|
||||
when(member.hasTimeJoined()).thenReturn(false);
|
||||
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(member));
|
||||
Member loadedAuthor = Mockito.mock(Member.class);
|
||||
when(member.getGuild()).thenReturn(Mockito.mock(Guild.class));
|
||||
when(botService.forceReloadMember(member)).thenReturn(CompletableFuture.completedFuture(loadedAuthor));
|
||||
when(self.sendResponse(eq(parameters), modelArgumentCaptor.capture())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
CompletableFuture<CommandResult> result = testUnit.executeAsync(parameters);
|
||||
|
||||
@@ -65,6 +65,7 @@ public class MessageEmbedListenerTest {
|
||||
public void setup(){
|
||||
when(guild.getIdLong()).thenReturn(ORIGIN_GUILD_ID);
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(message.getChannel()).thenReturn(textChannel);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -103,7 +103,6 @@ public class MessageEmbedRemovalReactionListenerTest {
|
||||
AEmote reactedEmote = AEmote.builder().build();
|
||||
when(emoteService.getEmoteOrDefaultEmote(MessageEmbedRemovalReactionListener.REMOVAL_EMOTE, serverId)).thenReturn(reactedEmote);
|
||||
when(messageReaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
when(botService.getEmote(serverId, reactedEmote)).thenReturn(Optional.of(emote));
|
||||
when(emoteService.isReactionEmoteAEmote(reactionEmote, reactedEmote)).thenReturn(true);
|
||||
EmbeddedMessage message = EmbeddedMessage
|
||||
.builder()
|
||||
@@ -134,7 +133,6 @@ public class MessageEmbedRemovalReactionListenerTest {
|
||||
AEmote reactedEmote = AEmote.builder().build();
|
||||
when(emoteService.getEmoteOrDefaultEmote(MessageEmbedRemovalReactionListener.REMOVAL_EMOTE, serverId)).thenReturn(reactedEmote);
|
||||
when(messageReaction.getReactionEmote()).thenReturn(reactionEmote);
|
||||
when(botService.getEmote(serverId, reactedEmote)).thenReturn(Optional.of(emote));
|
||||
when(emoteService.isReactionEmoteAEmote(reactionEmote, reactedEmote)).thenReturn(wasCorrectEmote);
|
||||
testUnit.executeReactionAdded(cachedMessage, messageReaction, userInAServer);
|
||||
verify(messageService, times(0)).deleteMessageInChannelInServer(serverId, channelId, messageId);
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.utility.service;
|
||||
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
@@ -145,7 +146,11 @@ public class RemindServiceBeanTest {
|
||||
AServer server = MockUtils.getServer();
|
||||
AChannel aChannel = MockUtils.getTextChannel(server, 4L);
|
||||
Long reminderId = 5L;
|
||||
Reminder remindedReminder = Reminder.builder().reminded(false).server(server).channel(aChannel).id(reminderId).build();
|
||||
AUserInAServer remindedUser = Mockito.mock(AUserInAServer.class);
|
||||
AUser user = Mockito.mock(AUser.class);
|
||||
when(user.getId()).thenReturn(6L);
|
||||
when(remindedUser.getUserReference()).thenReturn(user);
|
||||
Reminder remindedReminder = Reminder.builder().reminded(false).server(server).remindedUser(remindedUser).channel(aChannel).id(reminderId).build();
|
||||
when(reminderManagementService.loadReminder(reminderId)).thenReturn(Optional.of(remindedReminder));
|
||||
Guild guildMock = Mockito.mock(Guild.class);
|
||||
when(botService.getGuildById(server.getId())).thenReturn(Optional.of(guildMock));
|
||||
@@ -157,8 +162,14 @@ public class RemindServiceBeanTest {
|
||||
@Test
|
||||
public void testExecuteReminderFromNotFoundGuild() {
|
||||
AServer server = MockUtils.getServer();
|
||||
AChannel aChannel = Mockito.mock(AChannel.class);
|
||||
when(aChannel.getId()).thenReturn(9L);
|
||||
Long reminderId = 5L;
|
||||
Reminder remindedReminder = Reminder.builder().reminded(false).server(server).id(reminderId).build();
|
||||
AUserInAServer remindedUser = Mockito.mock(AUserInAServer.class);
|
||||
AUser user = Mockito.mock(AUser.class);
|
||||
when(user.getId()).thenReturn(6L);
|
||||
when(remindedUser.getUserReference()).thenReturn(user);
|
||||
Reminder remindedReminder = Reminder.builder().reminded(false).server(server).channel(aChannel).remindedUser(remindedUser).id(reminderId).build();
|
||||
when(reminderManagementService.loadReminder(reminderId)).thenReturn(Optional.of(remindedReminder));
|
||||
when(botService.getGuildById(server.getId())).thenReturn(Optional.empty());
|
||||
testUnit.executeReminder(reminderId);
|
||||
|
||||
@@ -131,7 +131,7 @@ public class StarboardServiceBeanTest {
|
||||
when(configService.getLongValue("starLvl2", server.getId())).thenReturn(2L);
|
||||
when(emoteService.getUsableEmoteOrDefault(server.getId(), "star2")).thenReturn("b");
|
||||
testUnit.createStarboardPost(message, userExceptAuthor, userReacting, starredUser);
|
||||
verify(self, times(1)).persistPost(eq(message), anyList(), eq(futures), eq(channelId), eq(starredUser.getUserInServerId()), eq(userReacting.getUserInServerId()));
|
||||
verify(self, times(1)).persistPost(eq(message), anyList(), eq(futures), eq(channelId), eq(starredUser.getUserInServerId()));
|
||||
List<StarboardPostModel> starboardPostModels = starboardPostModelArgumentCaptor.getAllValues();
|
||||
Assert.assertEquals(1, starboardPostModels.size());
|
||||
StarboardPostModel usedModel = starboardPostModels.get(0);
|
||||
@@ -162,7 +162,7 @@ public class StarboardServiceBeanTest {
|
||||
AUserInAServer secondStarrerUserObj = MockUtils.getUserObject(secondStarrerUserId, server);
|
||||
when(userInServerManagementService.loadUserConditional(secondStarrerUserId)).thenReturn(Optional.of(secondStarrerUserObj));
|
||||
when(userInServerManagementService.loadUserConditional(userReacting.getUserInServerId())).thenReturn(Optional.of(userReacting));
|
||||
testUnit.persistPost(message, userExceptAuthorIds, futures, channelId, starredUser.getUserInServerId(), userReacting.getUserInServerId());
|
||||
testUnit.persistPost(message, userExceptAuthorIds, futures, channelId, starredUser.getUserInServerId());
|
||||
verify(starboardPostReactorManagementService, times(2)).addReactor(eq(post), userInAServerArgumentCaptor.capture());
|
||||
List<AUserInAServer> addedReactors = userInAServerArgumentCaptor.getAllValues();
|
||||
Assert.assertEquals(secondStarrerUserId, addedReactors.get(0).getUserInServerId());
|
||||
@@ -178,6 +178,8 @@ public class StarboardServiceBeanTest {
|
||||
Long oldPostId = 36L;
|
||||
AUserInAServer starredUser = MockUtils.getUserObject(5L, server);
|
||||
Long channelId = 10L;
|
||||
AChannel sourceChannel = Mockito.mock(AChannel.class);
|
||||
when(sourceChannel.getServer()).thenReturn(server);
|
||||
CachedMessage message = CachedMessage
|
||||
.builder()
|
||||
.authorId(starredUser.getUserReference().getId())
|
||||
@@ -185,7 +187,7 @@ public class StarboardServiceBeanTest {
|
||||
.channelId(channelId)
|
||||
.build();
|
||||
Long starboardPostId = 47L;
|
||||
StarboardPost post = StarboardPost.builder().postMessageId(postMessageId).starboardMessageId(oldPostId).id(starboardPostId).build();
|
||||
StarboardPost post = StarboardPost.builder().postMessageId(postMessageId).starboardMessageId(oldPostId).sourceChanel(sourceChannel).id(starboardPostId).build();
|
||||
MessageToSend postMessage = MessageToSend.builder().build();
|
||||
when(templateService.renderEmbedTemplate(eq(StarboardServiceBean.STARBOARD_POST_TEMPLATE), starboardPostModelArgumentCaptor.capture())).thenReturn(postMessage);
|
||||
when(postTargetService.editOrCreatedInPostTarget(oldPostId, postMessage, StarboardPostTarget.STARBOARD, server.getId())).thenReturn(Arrays.asList(CompletableFuture.completedFuture(sendPost)));
|
||||
@@ -207,6 +209,7 @@ public class StarboardServiceBeanTest {
|
||||
StarboardPost post = StarboardPost
|
||||
.builder()
|
||||
.starboardChannel(channel)
|
||||
.sourceChanel(channel)
|
||||
.starboardMessageId(messageId)
|
||||
.build();
|
||||
testUnit.deleteStarboardMessagePost(post);
|
||||
@@ -275,6 +278,6 @@ public class StarboardServiceBeanTest {
|
||||
Long secondStarrerUserId = 2L;
|
||||
List<Long> userExceptAuthorIds = Arrays.asList(secondStarrerUserId, userReacting.getUserReference().getId());
|
||||
List<CompletableFuture<Message>> futures = Arrays.asList(CompletableFuture.completedFuture(sendPost));
|
||||
testUnit.persistPost(message, userExceptAuthorIds, futures, channelId, starredUser.getUserInServerId(), userReacting.getUserInServerId());
|
||||
testUnit.persistPost(message, userExceptAuthorIds, futures, channelId, starredUser.getUserInServerId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,8 @@ public class SuggestionServiceBeanTest {
|
||||
@Test
|
||||
public void testCreateSuggestion() {
|
||||
Member member = Mockito.mock(Member.class);
|
||||
when(member.getGuild()).thenReturn(guild);
|
||||
when(guild.getId()).thenReturn("5");
|
||||
String text = "text";
|
||||
Message message = Mockito.mock(Message.class);
|
||||
Long suggestionId = 3L;
|
||||
@@ -172,6 +174,8 @@ public class SuggestionServiceBeanTest {
|
||||
MessageEmbed embed = Mockito.mock(MessageEmbed.class);
|
||||
when(embed.getDescription()).thenReturn("description");
|
||||
Message suggestionMessage = Mockito.mock(Message.class);
|
||||
when(suggestionMessage.getGuild()).thenReturn(guild);
|
||||
when(guild.getId()).thenReturn("8");
|
||||
when(suggestionMessage.getEmbeds()).thenReturn(Arrays.asList(embed));
|
||||
MessageToSend updatedMessage = MessageToSend.builder().build();
|
||||
when(templateService.renderEmbedTemplate(eq(SuggestionServiceBean.SUGGESTION_LOG_TEMPLATE), any(SuggestionLog.class))).thenReturn(updatedMessage);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StarboardPostReactorManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveReactors() {
|
||||
StarboardPost post = StarboardPost.builder().build();
|
||||
StarboardPost post = StarboardPost.builder().reactions(new ArrayList<>()).build();
|
||||
testUnit.removeReactors(post);
|
||||
verify(repository, times(1)).deleteByStarboardPost(post);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.test.MockUtils;
|
||||
import dev.sheldan.abstracto.utility.models.SuggestionState;
|
||||
import dev.sheldan.abstracto.utility.models.database.Suggestion;
|
||||
import dev.sheldan.abstracto.utility.repository.SuggestionRepository;
|
||||
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.MessageChannel;
|
||||
@@ -48,12 +49,15 @@ public class SuggestionManagementServiceBeanTest {
|
||||
AServer server = MockUtils.getServer();
|
||||
AUserInAServer userInAServer = MockUtils.getUserObject(5L, server);
|
||||
String text = "text";
|
||||
Guild guild = Mockito.mock(Guild.class);
|
||||
Message message = Mockito.mock(Message.class);
|
||||
MessageChannel messageChannel = Mockito.mock(MessageChannel.class);
|
||||
when(messageChannel.getIdLong()).thenReturn(CHANNEL_ID);
|
||||
when(message.getChannel()).thenReturn(messageChannel);
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getId()).thenReturn("8");
|
||||
long suggestionId = 1L;
|
||||
Suggestion createdSuggestion = testUnit.createSuggestion(userInAServer, text,message, suggestionId);
|
||||
Suggestion createdSuggestion = testUnit.createSuggestion(userInAServer, text, message, suggestionId);
|
||||
verify(suggestionRepository, times(1)).save(createdSuggestion);
|
||||
Assert.assertEquals(SuggestionState.NEW, createdSuggestion.getState());
|
||||
Assert.assertEquals(userInAServer.getUserInServerId(), createdSuggestion.getSuggester().getUserInServerId());
|
||||
@@ -66,10 +70,13 @@ public class SuggestionManagementServiceBeanTest {
|
||||
AServer server = MockUtils.getServer();
|
||||
AUserInAServer userInAServer = MockUtils.getUserObject(5L, server);
|
||||
String text = "text";
|
||||
Guild guild = Mockito.mock(Guild.class);
|
||||
Message message = Mockito.mock(Message.class);
|
||||
MessageChannel messageChannel = Mockito.mock(MessageChannel.class);
|
||||
when(messageChannel.getIdLong()).thenReturn(CHANNEL_ID);
|
||||
when(message.getChannel()).thenReturn(messageChannel);
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getId()).thenReturn("5");
|
||||
when(userInServerManagementService.loadUser(member)).thenReturn(userInAServer);
|
||||
long suggestionId = 1L;
|
||||
Suggestion createdSuggestion = testUnit.createSuggestion(member, text, message, suggestionId);
|
||||
|
||||
Reference in New Issue
Block a user