mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 13:44:33 +00:00
[AB-333] providing some dates as separate instants instead of relying on the member attributes
truncating date to day when displaying the date for export emote stats fixing wrong message when confirming a command and adding missing exception handling
This commit is contained in:
@@ -271,13 +271,13 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
List<CompletableFuture<Message>> confirmationMessageFutures = channelService.sendMessageToSendToChannel(message, event.getChannel());
|
||||
FutureUtils.toSingleFutureGeneric(confirmationMessageFutures)
|
||||
.thenAccept(unused -> self.persistConfirmationCallbacks(model, confirmationMessageFutures.get(0).join()))
|
||||
.exceptionally(throwable -> self.failedCommandHandling(event, foundCommand, parsedParameters, commandContext, throwable));
|
||||
.exceptionally(throwable -> self.handleFailedCommand(foundCommand, commandContext, throwable));
|
||||
} else if(commandConfiguration.isAsync()) {
|
||||
log.info("Executing async command {} for server {} in channel {} based on message {} by user {}.",
|
||||
commandConfiguration.getName(), commandContext.getGuild().getId(), commandContext.getChannel().getId(), commandContext.getMessage().getId(), commandContext.getAuthor().getId());
|
||||
|
||||
self.executeAsyncCommand(foundCommand, commandContext)
|
||||
.exceptionally(throwable -> failedCommandHandling(event, foundCommand, parsedParameters, commandContext, throwable));
|
||||
.exceptionally(throwable -> handleFailedCommand(foundCommand, commandContext, throwable));
|
||||
} else {
|
||||
commandResult = self.executeCommand(foundCommand, commandContext);
|
||||
}
|
||||
@@ -287,32 +287,25 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
if(commandResult != null) {
|
||||
self.executePostCommandListener(foundCommand, commandContext, commandResult);
|
||||
}
|
||||
}).exceptionally(throwable -> failedCommandHandling(event, foundCommand, parsedParameters, commandContext, throwable));
|
||||
}).exceptionally(throwable -> handleFailedCommand(foundCommand, commandContext, throwable));
|
||||
|
||||
}
|
||||
|
||||
private Void failedCommandHandling(MessageReceivedEvent event, Command foundCommand, Parameters parsedParameters, CommandContext commandContext, Throwable throwable) {
|
||||
private Void handleFailedCommand(Command foundCommand, CommandContext commandContext, Throwable throwable) {
|
||||
log.error("Asynchronous command {} failed.", foundCommand.getConfiguration().getName(), throwable);
|
||||
UserInitiatedServerContext rebuildUserContext = buildUserInitiatedServerContext(commandContext);
|
||||
CommandContext rebuildContext = CommandContext.builder()
|
||||
.author(event.getMember())
|
||||
.guild(event.getGuild())
|
||||
.channel(event.getTextChannel())
|
||||
.message(event.getMessage())
|
||||
.jda(event.getJDA())
|
||||
.undoActions(commandContext.getUndoActions()) // TODO really do this? it would need to guarantee that its available and usable
|
||||
.userInitiatedContext(rebuildUserContext)
|
||||
.parameters(parsedParameters).build();
|
||||
CommandResult failedResult = CommandResult.fromError(throwable.getMessage(), throwable);
|
||||
self.executePostCommandListener(foundCommand, rebuildContext, failedResult);
|
||||
self.executePostCommandListener(foundCommand, commandContext, failedResult);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Transactional(isolation = Isolation.SERIALIZABLE)
|
||||
public CompletableFuture<Void> executeAsyncCommand(Command foundCommand, CommandContext commandContext) {
|
||||
return foundCommand.executeAsync(commandContext).thenAccept(result ->
|
||||
executePostCommandListener(foundCommand, commandContext, result)
|
||||
);
|
||||
executePostCommandListener(foundCommand, commandContext, result)
|
||||
).exceptionally(throwable -> {
|
||||
handleFailedCommand(foundCommand, commandContext, throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -391,10 +384,6 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
return buildUserInitiatedServerContext(event.getMember(), event.getTextChannel(), event.getGuild());
|
||||
}
|
||||
|
||||
private UserInitiatedServerContext buildUserInitiatedServerContext(CommandContext context) {
|
||||
return buildUserInitiatedServerContext(context.getAuthor(), context.getChannel(), context.getGuild());
|
||||
}
|
||||
|
||||
public CompletableFuture<Parameters> getParsedParameters(UnParsedCommandParameter unParsedCommandParameter, Command command, Message message){
|
||||
List<ParseResult> parsedParameters = new ArrayList<>();
|
||||
List<Parameter> parameters = command.getConfiguration().getParameters();
|
||||
|
||||
@@ -63,7 +63,12 @@ public class ConfirmationButtonClickedListener implements ButtonClickedListener
|
||||
log.info("Denying command {} in server {} from message {} in channel {} with event {}.",
|
||||
commandCtx.getCommandName(), commandCtx.getServerId(), commandCtx.getMessageId(),
|
||||
commandCtx.getChannelId(), model.getEvent().getInteraction().getId());
|
||||
cleanup(model, payload);
|
||||
cleanup(model, payload)
|
||||
.thenAccept(unused -> self.sendAbortNotification(model))
|
||||
.exceptionally(throwable -> {
|
||||
log.warn("Failed to clean up confirmation message {}.", model.getEvent().getMessageId());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return ButtonClickedListenerResult.ACKNOWLEDGED;
|
||||
}
|
||||
@@ -84,16 +89,11 @@ public class ConfirmationButtonClickedListener implements ButtonClickedListener
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup(ButtonClickedListenerModel model, CommandConfirmationPayload payload) {
|
||||
private CompletableFuture<Void> cleanup(ButtonClickedListenerModel model, CommandConfirmationPayload payload) {
|
||||
log.debug("Cleaning up component {} and {}.", payload.getOtherButtonComponentId(), model.getEvent().getComponentId());
|
||||
componentPayloadManagementService.deletePayloads(Arrays.asList(payload.getOtherButtonComponentId(), model.getEvent().getComponentId()));
|
||||
log.debug("Deleting confirmation message {}.", model.getEvent().getMessageId());
|
||||
messageService.deleteMessage(model.getEvent().getMessage())
|
||||
.thenAccept(unused -> self.sendAbortNotification(model))
|
||||
.exceptionally(throwable -> {
|
||||
log.warn("Failed to clean up confirmation message {}.", model.getEvent().getMessageId());
|
||||
return null;
|
||||
});
|
||||
return messageService.deleteMessage(model.getEvent().getMessage());
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> sendAbortNotification(ButtonClickedListenerModel model) {
|
||||
|
||||
Reference in New Issue
Block a user