mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-08 02:17:43 +00:00
[AB-xxx] changing some exception logging
fixing moderator member not re-used for reply command
This commit is contained in:
@@ -14,6 +14,7 @@ import dev.sheldan.abstracto.core.service.management.UserInServerManagementServi
|
|||||||
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
import dev.sheldan.abstracto.core.utils.ContextUtils;
|
||||||
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
import dev.sheldan.abstracto.core.templating.model.MessageToSend;
|
||||||
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
import dev.sheldan.abstracto.core.templating.service.TemplateService;
|
||||||
|
import dev.sheldan.abstracto.core.utils.FutureUtils;
|
||||||
import dev.sheldan.abstracto.logging.config.LoggingFeatureDefinition;
|
import dev.sheldan.abstracto.logging.config.LoggingFeatureDefinition;
|
||||||
import dev.sheldan.abstracto.logging.config.LoggingPostTarget;
|
import dev.sheldan.abstracto.logging.config.LoggingPostTarget;
|
||||||
import dev.sheldan.abstracto.logging.model.template.MessageDeletedAttachmentLog;
|
import dev.sheldan.abstracto.logging.model.template.MessageDeletedAttachmentLog;
|
||||||
@@ -81,11 +82,14 @@ public class MessageDeleteLogListener implements AsyncMessageDeletedListener {
|
|||||||
.member(authorMember)
|
.member(authorMember)
|
||||||
.build();
|
.build();
|
||||||
MessageToSend message = templateService.renderEmbedTemplate(MESSAGE_DELETED_TEMPLATE, logModel, messageFromCache.getServerId());
|
MessageToSend message = templateService.renderEmbedTemplate(MESSAGE_DELETED_TEMPLATE, logModel, messageFromCache.getServerId());
|
||||||
postTargetService.sendEmbedInPostTarget(message, LoggingPostTarget.DELETE_LOG, messageFromCache.getServerId());
|
FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(message, LoggingPostTarget.DELETE_LOG, messageFromCache.getServerId())).exceptionally(throwable -> {
|
||||||
|
log.error("Failed to send message deleted log.", throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
if(messageFromCache.getAttachments() != null){
|
if(messageFromCache.getAttachments() != null){
|
||||||
log.debug("Notifying about deletions of {} attachments.", messageFromCache.getAttachments().size());
|
log.debug("Notifying about deletions of {} attachments.", messageFromCache.getAttachments().size());
|
||||||
for (int i = 0; i < messageFromCache.getAttachments().size(); i++) {
|
for (int i = 0; i < messageFromCache.getAttachments().size(); i++) {
|
||||||
MessageDeletedAttachmentLog log = MessageDeletedAttachmentLog
|
MessageDeletedAttachmentLog attachmentLogModel = MessageDeletedAttachmentLog
|
||||||
.builder()
|
.builder()
|
||||||
.imageUrl(messageFromCache.getAttachments().get(i).getProxyUrl())
|
.imageUrl(messageFromCache.getAttachments().get(i).getProxyUrl())
|
||||||
.counter(i + 1)
|
.counter(i + 1)
|
||||||
@@ -93,8 +97,12 @@ public class MessageDeleteLogListener implements AsyncMessageDeletedListener {
|
|||||||
.channel(textChannel)
|
.channel(textChannel)
|
||||||
.member(authorMember)
|
.member(authorMember)
|
||||||
.build();
|
.build();
|
||||||
MessageToSend attachmentEmbed = templateService.renderEmbedTemplate(MESSAGE_DELETED_ATTACHMENT_TEMPLATE, log, messageFromCache.getServerId());
|
MessageToSend attachmentEmbed = templateService.renderEmbedTemplate(MESSAGE_DELETED_ATTACHMENT_TEMPLATE, attachmentLogModel, messageFromCache.getServerId());
|
||||||
postTargetService.sendEmbedInPostTarget(attachmentEmbed, LoggingPostTarget.DELETE_LOG, messageFromCache.getServerId());
|
FutureUtils.toSingleFutureGeneric(postTargetService.sendEmbedInPostTarget(attachmentEmbed, LoggingPostTarget.DELETE_LOG, messageFromCache.getServerId()))
|
||||||
|
.exceptionally(throwable -> {
|
||||||
|
log.error("Failed to send message deleted log.", throwable);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
future.completeExceptionally(exception);
|
future.completeExceptionally(exception);
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
}).exceptionally(throwable -> {
|
}).exceptionally(throwable -> {
|
||||||
log.error("Failed to load member {} for modmail in server {}.", userId, chosenServerId, throwable);
|
log.error("Failed to load member {} for modmail in server {}.", userId, chosenServerId, throwable);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -548,7 +548,6 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public CompletableFuture<Void> relayMessageToDm(Long modmailThreadId, String text, Message replyCommandMessage, boolean anonymous, MessageChannel feedBack, List<UndoActionInstance> undoActions, Member targetMember) {
|
public CompletableFuture<Void> relayMessageToDm(Long modmailThreadId, String text, Message replyCommandMessage, boolean anonymous, MessageChannel feedBack, List<UndoActionInstance> undoActions, Member targetMember) {
|
||||||
log.info("Relaying message {} to user {} in modmail thread {} on server {}.", replyCommandMessage.getId(), targetMember.getId(), modmailThreadId, targetMember.getGuild().getId());
|
log.info("Relaying message {} to user {} in modmail thread {} on server {}.", replyCommandMessage.getId(), targetMember.getId(), modmailThreadId, targetMember.getGuild().getId());
|
||||||
AUserInAServer moderator = userInServerManagementService.loadOrCreateUser(replyCommandMessage.getMember());
|
|
||||||
metricService.incrementCounter(MDOMAIL_THREAD_MESSAGE_SENT);
|
metricService.incrementCounter(MDOMAIL_THREAD_MESSAGE_SENT);
|
||||||
ModMailThread modMailThread = modMailThreadManagementService.getById(modmailThreadId);
|
ModMailThread modMailThread = modMailThreadManagementService.getById(modmailThreadId);
|
||||||
FullUserInServer fullThreadUser = FullUserInServer
|
FullUserInServer fullThreadUser = FullUserInServer
|
||||||
@@ -567,9 +566,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
log.debug("Message is sent anonymous.");
|
log.debug("Message is sent anonymous.");
|
||||||
modMailModeratorReplyModelBuilder.moderator(memberService.getBotInGuild(modMailThread.getServer()));
|
modMailModeratorReplyModelBuilder.moderator(memberService.getBotInGuild(modMailThread.getServer()));
|
||||||
} else {
|
} else {
|
||||||
// should be loaded, because we are currently processing a command caused by the message
|
modMailModeratorReplyModelBuilder.moderator(replyCommandMessage.getMember());
|
||||||
Member moderatorMember = memberService.getMemberInServer(moderator);
|
|
||||||
modMailModeratorReplyModelBuilder.moderator(moderatorMember);
|
|
||||||
}
|
}
|
||||||
ModMailModeratorReplyModel modMailUserReplyModel = modMailModeratorReplyModelBuilder.build();
|
ModMailModeratorReplyModel modMailUserReplyModel = modMailModeratorReplyModelBuilder.build();
|
||||||
MessageToSend messageToSend = templateService.renderEmbedTemplate(MODMAIL_STAFF_MESSAGE_TEMPLATE_KEY, modMailUserReplyModel, modMailThread.getServer().getId());
|
MessageToSend messageToSend = templateService.renderEmbedTemplate(MODMAIL_STAFF_MESSAGE_TEMPLATE_KEY, modMailUserReplyModel, modMailThread.getServer().getId());
|
||||||
@@ -581,7 +578,7 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
sameThreadMessageFuture = CompletableFuture.completedFuture(null);
|
sameThreadMessageFuture = CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
return CompletableFuture.allOf(future, sameThreadMessageFuture).thenAccept(avoid ->
|
return CompletableFuture.allOf(future, sameThreadMessageFuture).thenAccept(avoid ->
|
||||||
self.saveSendMessagesAndUpdateState(modmailThreadId, anonymous, moderator, future.join(), replyCommandMessage, sameThreadMessageFuture.join())
|
self.saveSendMessagesAndUpdateState(modmailThreadId, anonymous, future.join(), replyCommandMessage, sameThreadMessageFuture.join())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -815,11 +812,10 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
.builder()
|
.builder()
|
||||||
.closingMember(closingContext.getClosingMember())
|
.closingMember(closingContext.getClosingMember())
|
||||||
.note(closingContext.getNote())
|
.note(closingContext.getNote())
|
||||||
.silently(closingContext.getNotifyUser())
|
.silently(!closingContext.getNotifyUser())
|
||||||
.messageCount(modMailThread.getMessages().size())
|
.messageCount(modMailThread.getMessages().size())
|
||||||
.startDate(modMailThread.getCreated())
|
.startDate(modMailThread.getCreated())
|
||||||
.serverId(modMailThread.getServer().getId())
|
.serverId(modMailThread.getServer().getId())
|
||||||
.silently(!closingContext.getNotifyUser())
|
|
||||||
.userId(modMailThread.getUser().getUserReference().getId())
|
.userId(modMailThread.getUser().getUserReference().getId())
|
||||||
.build();
|
.build();
|
||||||
return userService.retrieveUserForId(modMailThread.getUser().getUserReference().getId()).thenApply(user -> {
|
return userService.retrieveUserForId(modMailThread.getUser().getUserReference().getId()).thenApply(user -> {
|
||||||
@@ -886,15 +882,15 @@ public class ModMailThreadServiceBean implements ModMailThreadService {
|
|||||||
* and updates the state of the {@link ModMailThread}.
|
* and updates the state of the {@link ModMailThread}.
|
||||||
* @param modMailThreadId The ID of the {@link ModMailThread} for which the messages were sent for
|
* @param modMailThreadId The ID of the {@link ModMailThread} for which the messages were sent for
|
||||||
* @param anonymous Whether or not the messages were send anonymous
|
* @param anonymous Whether or not the messages were send anonymous
|
||||||
* @param moderator The original {@link AUserInAServer} which authored the messages
|
|
||||||
* @param createdMessageInDM The {@link Message message} which was sent to the private channel with the {@link User user}
|
* @param createdMessageInDM The {@link Message message} which was sent to the private channel with the {@link User user}
|
||||||
* @param modMailThreadMessage The {@link Message message} which was sent in the channel representing the {@link ModMailThread thread}. Might be null.
|
* @param modMailThreadMessage The {@link Message message} which was sent in the channel representing the {@link ModMailThread thread}. Might be null.
|
||||||
* @param replyCommandMessage The {@link Message message} which contained the command used to reply to the user
|
* @param replyCommandMessage The {@link Message message} which contained the command used to reply to the user
|
||||||
* @throws ModMailThreadNotFoundException in case the {@link ModMailThread} is not found by the ID
|
* @throws ModMailThreadNotFoundException in case the {@link ModMailThread} is not found by the ID
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveSendMessagesAndUpdateState(Long modMailThreadId, Boolean anonymous, AUserInAServer moderator, Message createdMessageInDM, Message replyCommandMessage, Message modMailThreadMessage) {
|
public void saveSendMessagesAndUpdateState(Long modMailThreadId, Boolean anonymous, Message createdMessageInDM, Message replyCommandMessage, Message modMailThreadMessage) {
|
||||||
Optional<ModMailThread> modMailThreadOpt = modMailThreadManagementService.getByIdOptional(modMailThreadId);
|
Optional<ModMailThread> modMailThreadOpt = modMailThreadManagementService.getByIdOptional(modMailThreadId);
|
||||||
|
AUserInAServer moderator = userInServerManagementService.loadOrCreateUser(replyCommandMessage.getMember());
|
||||||
if(modMailThreadOpt.isPresent()) {
|
if(modMailThreadOpt.isPresent()) {
|
||||||
ModMailThread modMailThread = modMailThreadOpt.get();
|
ModMailThread modMailThread = modMailThreadOpt.get();
|
||||||
log.debug("Adding (anonymous: {}) message {} of moderator to modmail thread {} and setting state to {}.", anonymous, createdMessageInDM.getId(), modMailThreadId, ModMailThreadState.MOD_REPLIED);
|
log.debug("Adding (anonymous: {}) message {} of moderator to modmail thread {} and setting state to {}.", anonymous, createdMessageInDM.getId(), modMailThreadId, ModMailThreadState.MOD_REPLIED);
|
||||||
|
|||||||
@@ -50,27 +50,25 @@ public class AsyncPrivateMessageReceivedListenerBean extends ListenerAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cacheEntityService.buildCachedMessageFromMessage(event.getMessage()).thenAccept(cachedMessage ->
|
cacheEntityService.buildCachedMessageFromMessage(event.getMessage()).thenAccept(cachedMessage ->
|
||||||
privateMessageReceivedListeners.forEach(messageReceivedListener -> {
|
privateMessageReceivedListeners.forEach(messageReceivedListener -> CompletableFuture.runAsync(() ->
|
||||||
try {
|
self.executeIndividualPrivateMessageReceivedListener(cachedMessage, messageReceivedListener, event)
|
||||||
CompletableFuture.runAsync(() ->
|
, privateMessageReceivedExecutor)
|
||||||
self.executeIndividualPrivateMessageReceivedListener(cachedMessage, messageReceivedListener)
|
.exceptionally(throwable -> {
|
||||||
, privateMessageReceivedExecutor)
|
log.error("Async private message receiver listener {} failed.", messageReceivedListener, throwable);
|
||||||
.exceptionally(throwable -> {
|
return null;
|
||||||
log.error("Async private message receiver listener {} failed.", messageReceivedListener, throwable);
|
}))
|
||||||
return null;
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Private message received {} had exception when executing.", messageReceivedListener, e);
|
|
||||||
exceptionService.reportExceptionToPrivateMessageReceivedContext(e, event);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.SERIALIZABLE)
|
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.SERIALIZABLE)
|
||||||
public void executeIndividualPrivateMessageReceivedListener(CachedMessage cachedMessage, AsyncPrivateMessageReceivedListener messageReceivedListener) {
|
public void executeIndividualPrivateMessageReceivedListener(CachedMessage cachedMessage, AsyncPrivateMessageReceivedListener messageReceivedListener, PrivateMessageReceivedEvent event) {
|
||||||
log.debug("Executing private message listener {} for member {}.", messageReceivedListener.getClass().getName(), cachedMessage.getAuthor().getAuthorId());
|
try {
|
||||||
messageReceivedListener.execute(cachedMessage);
|
log.debug("Executing private message listener {} for member {}.", messageReceivedListener.getClass().getName(), cachedMessage.getAuthor().getAuthorId());
|
||||||
|
messageReceivedListener.execute(cachedMessage);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Private message received {} had exception when executing.", messageReceivedListener, e);
|
||||||
|
exceptionService.reportExceptionToPrivateMessageReceivedContext(e, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user