Interface EventContext

All Superinterfaces:
AccessContext, AccessValidator
All Known Subinterfaces:
ApplicationCommandEventContext, ButtonEventContext, ChannelEventContext, ComponentEventContext, DeferrableInteractionEventContext, InteractionEventContext, MessageBasedContext, MessageCreateEventContext, MessageEventContext, MessageIncludedContext, ModalEventContext, RepliableContext, SlashCommandEventContext
All Known Implementing Classes:
AbstractChannelEventContext, AbstractEventContext, AbstractRepliableContext

public interface EventContext extends AccessContext, AccessValidator
The context of an user-triggered event received from Discord.
Since:
1.0
Version:
1.0
Implementation Requirements:
A context must be effectively constant; that is, an implementation of this interface must always return the same value on methods that return a direct value (such as AccessContext.user() or AccessContext.guildId()). Methods that fetch remote resources (i.e. that return a Mono) may return different objects over time (as the remote object is modified), but must always reference the same entity.
  • Method Details

    • event

      Event event()
      Retrieves the triggering event.
      Returns:
      The event.
    • client

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

      @Pure AccessValidator validator()
      The access validator used in this context.
      Returns:
      The validator.
    • hasAccess

      default Mono<Boolean> hasAccess(GuildGroup 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.
      See Also:
      API Note:
      This is a convenience shortcut for using the context validator. It is equivalent to validator().hasAccess(group).
    • validate

      default Mono<Void> validate(GuildGroup group)
      Description copied from interface: AccessValidator
      Determines whether the invoking user in the current execution context has access equivalent to the given group.
      Specified by:
      validate in interface AccessValidator
      Parameters:
      group - The group required for access.
      Returns:
      A Mono that completes empty if the caller has access equivalent to the given group under the current execution context, or otherwise issues an error of type AccessException.
      See Also:
      API Note:
      This is a convenience shortcut for using the context validator. It is equivalent to validator().validate(group).
    • belongs

      @SideEffectFree default Mono<Boolean> belongs(User user, GuildGroup group)
      Determines whether the given user belongs to the given group in the context of this event.
      Parameters:
      user - The user to check for.
      group - The group to check for.
      Returns:
      A Mono that emits true if the given user belongs to the given group under this event context, or false otherwise.
      API Note:
      This is a convenience method equivalent to group.belongs(user, this).
    • belongs

      @SideEffectFree default Mono<Boolean> belongs(Snowflake user, GuildGroup group)
      Determines whether the given user belongs to the given group in the context of this event.
      Parameters:
      user - The ID of the user to check for.
      group - The group to check for.
      Returns:
      A Mono that emits true if the given user belongs to the given group under this event context, or false otherwise.
      API Note:
      This is a convenience method equivalent to fetching the user then invoking group.belongs(user, this).