use of net.robinfriedli.aiode.entities.CommandHistory in project aiode by robinfriedli.
the class CommandExecutionInterceptor method postCommand.
/**
* Finalize and persist the {@link CommandHistory} entry for this command execution.
*
* @param command the executed command
* @param completedSuccessfully whether the command completed sucessfully
* @param failedManually whether the command failed because {@link Command#isFailed()} returned true
* @param errorMessage the error message if an exception was thrown
* @param unexpectedException whether an unexpected exception was thrown, this excludes {@link UserException}
* @param aborted whether command execution was aborted
*/
private void postCommand(Command command, boolean completedSuccessfully, boolean failedManually, String errorMessage, boolean unexpectedException, boolean aborted) {
CommandContext context = command.getContext();
context.interruptMonitoring();
HistoryPool.execute(() -> {
CommandHistory history = context.getCommandHistory();
if (history != null) {
history.setDurationMs(System.currentTimeMillis() - history.getStartMillis());
history.setCompletedSuccessfully(completedSuccessfully);
history.setFailedManually(failedManually);
history.setUnexpectedException(unexpectedException);
history.setErrorMessage(errorMessage);
history.setAborted(aborted);
StaticSessionProvider.consumeSession(session -> session.persist(history));
} else {
logger.warn("Command " + command + " has no history");
}
});
}
use of net.robinfriedli.aiode.entities.CommandHistory in project aiode by robinfriedli.
the class HistoryInterceptor method performChained.
@Override
public void performChained(Command command) {
CommandContext context = command.getContext();
CommandHistory history = new CommandHistory();
long currentTimeMillis = System.currentTimeMillis();
history.setStartMillis(currentTimeMillis);
history.setTimestamp(LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis), ZoneId.systemDefault()));
history.setCommandContextId(command.getContext().getId());
history.setCommandIdentifier(command.getIdentifier());
history.setWidget(command instanceof AbstractWidgetAction);
history.setCommandBody(command instanceof AbstractCommand ? ((AbstractCommand) command).getCommandInput() : command.getCommandBody());
history.setInput(command instanceof AbstractCommand ? context.getMessage().getContentDisplay() : command.getCommandBody());
history.setGuild(context.getGuild().getName());
history.setGuildId(context.getGuild().getId());
history.setUser(context.getUser().getName());
history.setUserId(context.getUser().getId());
context.setCommandHistory(history);
}
Aggregations