Class InteractionReplyManager

java.lang.Object
dev.sympho.bot_utils.event.reply.InteractionReplyManager
All Implemented Interfaces:
ReplyManager

public class InteractionReplyManager extends Object
Reply manager for interaction-based commands.
Since:
1.0
Version:
1.0
  • Field Details

    • replies

      protected final List<Reply> replies
      The sent replies.
    • sendLock

      protected final dev.sympho.reactor_utils.concurrent.ReactiveLock sendLock
      The lock for send ordering.
    • defaultPrivate

      protected final boolean defaultPrivate
      Whether replies are private by default.
    • acked

      protected boolean acked
      Whether the event has been acknowledged (first reply deferred or sent).
  • Constructor Details

    • InteractionReplyManager

      public InteractionReplyManager(String referenceTitle, Supplier<? extends Iterable<? extends EmbedCreateFields.Field>> referenceFields, DeferrableInteractionEvent event, boolean defaultPrivate, boolean requireReply)
      Creates a new message.
      Parameters:
      referenceTitle - The title of the reference message.
      referenceFields - Generator of the fields for the reference message.
      event - The backing interaction event.
      defaultPrivate - Whether replies are private by default.
      requireReply - Whether to require that a reply is made before detaching.
  • Method Details

    • doDefer

      protected Mono<Void> doDefer()
      Applies deferral to the initial response.
      Returns:
      A Mono that completes once deferral is complete.
    • send

      protected Mono<Reply> send(@org.checkerframework.checker.index.qual.NonNegative int index, ReplySpec spec)
      Sends a new reply.
      Parameters:
      index - The index of the created reply.
      spec - The reply specification.
      Returns:
      The created reply.
    • doDetach

      protected ReplyManager doDetach()
      Creates a new detached manager.
      Returns:
      The new manager.
    • detach

      public Mono<ReplyManager> detach()
      Description copied from interface: ReplyManager
      Obtains a detached copy of this manager, where the existing reply chain is the same, but new replies are sent independently.

      An initial reply must have already been sent before detaching (i.e. ReplyManager.get() should not throw an exception); otherwise the returned mono will finish with an error.

      The new manager may, in some cases, not use the same method to send replies (for example, it might use regular messages while the original manager uses interaction responses). This causes the side effect that, while existing replies are still accessible via ReplyManager.get(int), some functionality may be unavailable (for example, ephemeral interaction responses).

      However, managers returned by this method are required to use a sending method that does not expire, and so may be used in cases where the original reply manager might expire before processing finishes.

      Note that some events (like slash commands) require a response to be sent natively or else it is considered to have failed; a best-effort attempt is made to catch cases where detaching is attempted before a required response and throw an exception early for visibily, however not all cases can be caught as it might depend on actions outside of the manager's control (for example a component interaction might be responded to by editing the original message instead).

      Specified by:
      detach in interface ReplyManager
      Returns:
      A new detached manager. May result in an IllegalStateException if the manager detects that switching to a detached manager on the current state would cause an error or timeout later.
    • defer

      public Mono<Void> defer()
      Description copied from interface: ReplyManager
      Defers the initial response, signaling it to the user in some form. Whether it will be done privately or not is determined by the manager's default.

      If a deferral was already made or a reply was already sent, this method (and by extension the returned Mono) has no effect.

      Specified by:
      defer in interface ReplyManager
      Returns:
      A Mono that completes once deferral is complete.
    • add

      public Mono<Reply> add(ReplySpec spec)
      Description copied from interface: ReplyManager
      Sends a new reply.
      Specified by:
      add in interface ReplyManager
      Parameters:
      spec - The reply specification.
      Returns:
      The created reply.
    • get

      public Reply get(@org.checkerframework.checker.index.qual.NonNegative int index) throws IndexOutOfBoundsException
      Description copied from interface: ReplyManager
      Retrieves a reply.
      Specified by:
      get in interface ReplyManager
      Parameters:
      index - The reply index.
      Returns:
      The reply.
      Throws:
      IndexOutOfBoundsException - if there is no reply with that index.