diff --git a/src/main/java/pw/mihou/nexus/features/command/core/NexusCommandDispatcher.kt b/src/main/java/pw/mihou/nexus/features/command/core/NexusCommandDispatcher.kt index 8ad64744..ce6beccb 100755 --- a/src/main/java/pw/mihou/nexus/features/command/core/NexusCommandDispatcher.kt +++ b/src/main/java/pw/mihou/nexus/features/command/core/NexusCommandDispatcher.kt @@ -1,22 +1,18 @@ package pw.mihou.nexus.features.command.core import org.javacord.api.event.interaction.SlashCommandCreateEvent -import org.javacord.api.interaction.callback.InteractionOriginalResponseUpdater import org.javacord.api.util.logging.ExceptionLogger import pw.mihou.nexus.Nexus import pw.mihou.nexus.Nexus.globalAfterwares import pw.mihou.nexus.Nexus.globalMiddlewares import pw.mihou.nexus.Nexus.logger -import pw.mihou.nexus.core.threadpool.NexusThreadPool import pw.mihou.nexus.features.command.facade.NexusCommandEvent import pw.mihou.nexus.features.command.interceptors.core.NexusCommandInterceptorCore import pw.mihou.nexus.features.command.interceptors.core.NexusMiddlewareGateCore import pw.mihou.nexus.features.command.validation.OptionValidation import pw.mihou.nexus.features.command.validation.result.ValidationResult -import pw.mihou.nexus.features.messages.NexusMessage import java.time.Instant import java.util.concurrent.CompletableFuture -import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicBoolean object NexusCommandDispatcher { @@ -70,7 +66,11 @@ object NexusCommandDispatcher { val updater = updaterFuture.join() middlewareResponse.into(updater).update().exceptionally(ExceptionLogger.get()) } else { - middlewareResponse.into(nexusEvent.respondNow()).respond().exceptionally(ExceptionLogger.get()) + var responder = nexusEvent.respondNow() + if (middlewareResponse.ephemeral) { + responder = nexusEvent.respondNowAsEphemeral() + } + middlewareResponse.into(responder).respond().exceptionally(ExceptionLogger.get()) } } return diff --git a/src/main/java/pw/mihou/nexus/features/command/facade/NexusCommandEvent.java b/src/main/java/pw/mihou/nexus/features/command/facade/NexusCommandEvent.java index a9be65ae..2c9a6853 100755 --- a/src/main/java/pw/mihou/nexus/features/command/facade/NexusCommandEvent.java +++ b/src/main/java/pw/mihou/nexus/features/command/facade/NexusCommandEvent.java @@ -303,7 +303,11 @@ default void middlewares(List middlewares, Consumer success) { NexusMessage response = middlewareGate.response(); if (response != null) { - response.into(respondNow()).respond().exceptionally(ExceptionLogger.get()); + InteractionImmediateResponseBuilder responder = respondNow(); + if (response.getEphemeral()) { + responder = respondNowAsEphemeral(); + } + response.into(responder).respond().exceptionally(ExceptionLogger.get()); } } diff --git a/src/main/java/pw/mihou/nexus/features/messages/NexusMessage.kt b/src/main/java/pw/mihou/nexus/features/messages/NexusMessage.kt index 5936db18..f46d9e92 100644 --- a/src/main/java/pw/mihou/nexus/features/messages/NexusMessage.kt +++ b/src/main/java/pw/mihou/nexus/features/messages/NexusMessage.kt @@ -1,18 +1,40 @@ package pw.mihou.nexus.features.messages +import org.javacord.api.entity.message.embed.EmbedBuilder import org.javacord.api.interaction.callback.InteractionMessageBuilderBase +typealias NexusMessageBuilder = InteractionMessageBuilderBase<*>.() -> Unit + class NexusMessage internal constructor( val ephemeral: Boolean = false, - val builder: InteractionMessageBuilderBase<*>.() -> Unit = { } + val builder: NexusMessageBuilder = { } ) { companion object { - fun with(ephemeral: Boolean, builder: InteractionMessageBuilderBase<*>.() -> Unit): NexusMessage { + @JvmStatic + fun with(ephemeral: Boolean, builder: NexusMessageBuilder): NexusMessage { return NexusMessage(ephemeral, builder) } - fun with(builder: InteractionMessageBuilderBase<*>.() -> Unit): NexusMessage { + + @JvmStatic + fun with(builder: NexusMessageBuilder): NexusMessage { return with(false, builder) } + + @JvmStatic + @JvmOverloads + fun from(text: String, ephemeral: Boolean = false, builder: NexusMessageBuilder = {}): NexusMessage = + with(ephemeral) { + setContent(text) + builder(this) + } + + @JvmStatic + @JvmOverloads + fun from(ephemeral: Boolean = false, builder: NexusMessageBuilder = {}, vararg embeds: EmbedBuilder): NexusMessage = + with(ephemeral) { + addEmbeds(*embeds) + builder(this) + } } fun > into(instance: T): T { builder(instance)