Class ComponentManager.ComponentContext<E extends @NonNull ComponentInteractionEvent>

java.lang.Object
dev.sympho.bot_utils.component.ComponentManager.ComponentContext<E>
Type Parameters:
E - The event type.
All Implemented Interfaces:
AccessContext, AccessValidator, ChannelAccessContext
Direct Known Subclasses:
ButtonManager.ButtonContext, ModalManager.ModalContext
Enclosing class:
ComponentManager<E extends @NonNull ComponentInteractionEvent,C extends @NonNull ComponentManager.ComponentContext<E>,HF extends @NonNull ComponentManager.HandlerFunction<C>,H extends @NonNull ComponentManager.Handler<H,HF>,HE extends @NonNull ComponentManager.HandlerEntry<H>>

public static class ComponentManager.ComponentContext<E extends @NonNull ComponentInteractionEvent> extends Object implements ChannelAccessContext, AccessValidator
The execution context of a component being interacted with.
Since:
1.0
  • Constructor Details

    • ComponentContext

      protected ComponentContext(E event, AccessManager accessManager)
      Creates a new instance.
      Parameters:
      event - The triggering event.
      accessManager - The access manager to use.
  • Method Details

    • getEvent

      public E getEvent()
      Retrieves the triggering event.
      Returns:
      The event.
    • getClient

      public GatewayDiscordClient getClient()
      Description copied from interface: AccessContext
      Retrieves the backing client.
      Specified by:
      getClient in interface AccessContext
      Returns:
      The client.
    • getGuild

      public Mono<Guild> getGuild()
      Description copied from interface: AccessContext
      Retrieves the guild, if there is one.
      Specified by:
      getGuild in interface AccessContext
      Returns:
      The invoking guild.
    • getGuildId

      public @Nullable Snowflake getGuildId()
      Description copied from interface: AccessContext
      Retrieves the ID of the guild, if there is one.
      Specified by:
      getGuildId in interface AccessContext
      Returns:
      The guild's ID, or null if a private channel.
    • getUser

      public User getUser()
      Description copied from interface: AccessContext
      Retrieves the user.
      Specified by:
      getUser in interface AccessContext
      Returns:
      The user.
    • getMember

      public Mono<Member> getMember()
      Description copied from interface: AccessContext
      Retrieves the user as a guild member.
      Specified by:
      getMember in interface AccessContext
      Returns:
      The calling user as a guild member. May be empty if the context is a private channel.
    • getMember

      public Mono<Member> getMember(Snowflake guildId)
      Description copied from interface: AccessContext
      Retrieves the user as a guild member of the given guild.
      Specified by:
      getMember in interface AccessContext
      Parameters:
      guildId - The ID of the target guild.
      Returns:
      The user as a guild member of the given guild.
    • getChannel

      public Mono<MessageChannel> getChannel()
      Description copied from interface: ChannelAccessContext
      Retrieves the channel.
      Specified by:
      getChannel in interface ChannelAccessContext
      Returns:
      The channel.
    • getChannelId

      public Snowflake getChannelId()
      Description copied from interface: ChannelAccessContext
      Retrieves the ID of the channel.
      Specified by:
      getChannelId in interface ChannelAccessContext
      Returns:
      The channel's ID.
    • getMessage

      @Pure public @Nullable Message getMessage()
      Retrieves the message that the component is attached to.

      If the message is ephemeral, only the ID will be present.

      Returns:
      The message, or null if the message is ephemeral.
    • getMessageId

      @Pure public Snowflake getMessageId()
      Retrieves the ID of the message that the component is attached to.
      Returns:
      The message ID.
    • getInteraction

      @Pure public Interaction getInteraction()
      Retrieves the interaction associated with the event.
      Returns:
      The interaction.
    • hasAccess

      public Mono<Boolean> hasAccess(Group group)
      Description copied from interface: AccessValidator
      Determines whether the invoking user in the current execution context has access equivalent to the given group.

      Note that while the most straightforward implementation of this interface is to simply check if the caller belongs to the given group, implementations are allowed to add other conditions under which a user has equivalent permissions despite not belonging to the group (or conversely does not have permissions despite belonging to the group).

      Specified by:
      hasAccess in interface AccessValidator
      Parameters:
      group - The group required for access.
      Returns:
      Whether the caller has access equivalent to the given group under the current execution context.