Package dev.sympho.bot_utils.access
Interface AccessContext
- All Known Subinterfaces:
ApplicationCommandEventContext,ButtonEventContext,ChannelAccessContext,ChannelEventContext,ComponentEventContext,DeferrableInteractionEventContext,EventContext,InteractionEventContext,MessageBasedContext,MessageCreateEventContext,MessageEventContext,MessageIncludedContext,ModalEventContext,RepliableContext,SlashCommandEventContext
- All Known Implementing Classes:
AbstractChannelEventContext,AbstractEventContext,AbstractRepliableContext
public interface AccessContext
Context around the access of a program function by a user.
- 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
user()orguildId()). 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 Summary
Modifier and TypeMethodDescriptiondefault AccessContextCreates a copy of this context with the guild replaced by the given guild.default AccessContextCreates a copy of this context with the user replaced by the given user.client()Retrieves the backing client.guild()Retrieves the guild, if there is one.guildId()Retrieves the ID of the guild, if there is one.default booleanDetermines if this context is a private channel.member()Retrieves the user as a guild member.Retrieves the user as a guild member of the given guild.static AccessContextCreates an access context for the given member, in the guild that the member is from.static AccessContextCreates an access context for the given user in the given guild.user()Retrieves the user.
-
Method Details
-
client
Retrieves the backing client.- Returns:
- The client.
-
user
Retrieves the user.- Returns:
- The user.
-
member
Retrieves the user as a guild member.- Returns:
- The calling user as a guild member. May be empty if the context is a private channel.
- Implementation Requirements:
- The default implementation delegates to
member(Snowflake). It may (and should) be overriden to use existing instances when possible to avoid API calls.
-
member
Retrieves the user as a guild member of the given guild.- Parameters:
guildId- The ID of the target guild.- Returns:
- The user as a guild member of the given guild.
- Implementation Note:
- The default implementation deletegates to
user().asMember(). It may (and should) be overriden to use existing instances when possible to avoid API calls.
-
guild
Retrieves the guild, if there is one.- Returns:
- The invoking guild.
-
guildId
Retrieves the ID of the guild, if there is one.- Returns:
- The guild's ID, or
nullif a private channel.
-
isPrivate
Determines if this context is a private channel.- Returns:
- Whether the context is a private channel.
-
asGuild
Creates a copy of this context with the guild replaced by the given guild.All associated values are also replaced accordingly.
- Parameters:
guild- The target guild. May benullto obtain a private-channel context.- Returns:
- The new context.
-
asUser
Creates a copy of this context with the user replaced by the given user.All associated values are also replaced accordingly.
- Parameters:
user- The target user.- Returns:
- The new context.
-
of
Creates an access context for the given member, in the guild that the member is from.- Parameters:
member- The member.- Returns:
- The access context.
-
of
Creates an access context for the given user in the given guild.- Parameters:
user- The user.guild- The guild, ornullfor a private channel.- Returns:
- The access context.
-