Class BaseUserContextMenu
java.lang.Object
com.dianxin.tori.api.commands.usercontext.BaseUserContextMenu
- All Implemented Interfaces:
IUserContextMenu
An abstract base class for statically configured User Context Menus.
This class relies on constructor parameters or a builder to define its metadata
and execution constraints (such as required permissions or channel restrictions)
instead of class-level annotations, ensuring optimized performance.
-
Constructor Summary
ConstructorsConstructorDescriptionBaseUserContextMenu(String title, net.dv8tion.jda.api.JDA jda, IBotMeta meta, boolean isDefer, boolean guildOnly, boolean ownerOnly, boolean privateChannelOnly, boolean directMessageOnly, List<net.dv8tion.jda.api.Permission> permissionsRequired, List<net.dv8tion.jda.api.Permission> selfPermissionsRequired, boolean isDebug) Constructs a statically configured BaseUserContextMenu with explicit parameters.BaseUserContextMenu(String title, net.dv8tion.jda.api.JDA jda, IBotMeta meta, LegacyCommandBuilder builder) Constructs a statically configured BaseUserContextMenu using aLegacyCommandBuilder. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidexecute(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent event) The core execution logic of the user context menu command.protected net.dv8tion.jda.api.JDAgetJda()Retrieves the JDA instance associated with this command.protected org.slf4j.LoggerRetrieves the logger instance for the current command.getTitle()Retrieves the title of the context menu as shown in the Discord client.final voidhandle(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent event, CommandReplyConfig replyConfig) Handles the lifecycle and validation of the user context menu execution.
-
Constructor Details
-
BaseUserContextMenu
public BaseUserContextMenu(String title, net.dv8tion.jda.api.JDA jda, IBotMeta meta, boolean isDefer, boolean guildOnly, boolean ownerOnly, boolean privateChannelOnly, boolean directMessageOnly, List<net.dv8tion.jda.api.Permission> permissionsRequired, List<net.dv8tion.jda.api.Permission> selfPermissionsRequired, boolean isDebug) Constructs a statically configured BaseUserContextMenu with explicit parameters.- Parameters:
title- The name or title of the context menu displayed in Discord.jda- TheJDAinstance running this command.meta- TheIBotMetacontaining the bot's metadata.isDefer- Whether the reply should be automatically deferred.guildOnly- Whether the command is restricted to guilds (servers).ownerOnly- Whether the command is restricted strictly to the bot owner.privateChannelOnly- Whether the command is restricted to private channels.directMessageOnly- Whether the command is restricted to direct messages.permissionsRequired- A list of permissions required by the user invoking the command.selfPermissionsRequired- A list of permissions required by the bot itself.isDebug- Whether to log debug information upon execution.
-
BaseUserContextMenu
public BaseUserContextMenu(String title, net.dv8tion.jda.api.JDA jda, IBotMeta meta, LegacyCommandBuilder builder) Constructs a statically configured BaseUserContextMenu using aLegacyCommandBuilder.- Parameters:
title- The name or title of the context menu displayed in Discord.jda- TheJDAinstance running this command.meta- TheIBotMetacontaining the bot's metadata.builder- The configuredLegacyCommandBuildercontaining execution constraints.
-
-
Method Details
-
getJda
protected net.dv8tion.jda.api.JDA getJda()Retrieves the JDA instance associated with this command.- Returns:
- The
JDAinstance.
-
getTitle
Retrieves the title of the context menu as shown in the Discord client.- Returns:
- The title string.
-
getLogger
protected org.slf4j.Logger getLogger()Retrieves the logger instance for the current command.- Returns:
- The
Loggerinstance.
-
handle
public final void handle(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent event, CommandReplyConfig replyConfig) Handles the lifecycle and validation of the user context menu execution. Validates all statically defined conditions before delegating toexecute(UserContextInteractionEvent).- Specified by:
handlein interfaceIUserContextMenu- Parameters:
event- TheUserContextInteractionEventtriggered by Discord.replyConfig- The configuration used for custom error or rejection messages.
-
execute
protected abstract void execute(net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent event) The core execution logic of the user context menu command. Developers must implement this method to define what the command actually does after passing all checks.- Parameters:
event- The validUserContextInteractionEventpassed through all pre-execution checks.
-