Class CommandBuilder<H extends Handlers>
- Type Parameters:
H- The handler type.
- Since:
- 1.0
- Version:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String>The command aliases.protected booleanWhether the command can be invoked directly.static final booleanDefault forwithCallable(boolean).static final ReplyManager.EphemeralTypeDefault forsetEphemeralReply(EphemeralType)(ReplyManager.EphemeralType.NONE).static final GroupDefault forrequireGroup(Group)(Groups.EVERYONE).static final booleanDefault forsetInheritSettings(boolean).static final booleanDefault forsetInvokeParent(boolean).static final booleanDefault forsetNsfw(boolean).static final booleanDefault forsetPrivateReply(boolean).static final booleanDefault forsetRequireParentGroups(boolean).static final Command.ScopeDefault forwithScope(Scope)(Command.Scope.GLOBAL).static final booleanDefault forsetSkipGroupCheckOnInteraction(boolean).protected @MonotonicNonNull @MatchesRegex("(?Us)^.{1,100}+$") StringThe command description.protected @MonotonicNonNull @MatchesRegex("(?U)^[ -_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") StringThe display name.protected ReplyManager.EphemeralTypeThe type of ephemeral response to use, if any.protected @MonotonicNonNull HThe handlers to process invocations with.protected booleanWhether to inherit settings from parent.protected booleanWhether to execute the parent.protected @MonotonicNonNull @MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") StringThe command name.protected booleanWhether the command can only be run in NSFW channels.The command parameters.protected InvocationThe command parent.protected booleanWhether the command response should only be seen by the caller.protected GroupThe group that a user must have access for.protected booleanWhether to also require the parent command's groups.protected Command.ScopeThe command scope.protected booleanWhether group access checking should be skipped. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new builder with default values.CommandBuilder(CommandBuilder<? extends H> base) Constructs a new builder that is a copy of the given builder. -
Method Summary
Modifier and TypeMethodDescriptionaddAliases(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String... aliases) Adds aliases to the command.addParameter(Parameter<?> parameter) Adds a parameter to the command.build()Builds the configured command.static <H extends Handlers>
CommandBuilder<H>Constructs a new builder that is initialized to make a copy of the given command.static CommandBuilder<InteractionHandlers>Creates a builder for an interaction command.static CommandBuilder<MessageHandlers>message()Creates a builder for a message-only command.Removes all aliases from the command.Removes all parameters from the command.requireGroup(@Nullable Group group) Sets the group that a user must have access for.setEphemeralReply(@Nullable ReplyManager.EphemeralType ephemeralReply) Sets the type of ephemeral response to use, if any.setInheritSettings(boolean inheritSettings) Sets whether the command should inherit settings from the parent command.setInvokeParent(boolean invokeParent) Sets whether the command should also invoke the parent's handler.setNsfw(boolean nsfw) Sets whether the command can only be run in channels marked as NSFW.setPrivateReply(boolean privateReply) Sets whether the command response should be sent privately to the caller.setRequireParentGroups(boolean require) Sets whether the command also require its parent command's groups.setSkipGroupCheckOnInteraction(boolean skip) Sets whether group access checking should be skipped.static CommandBuilder<SlashHandlers>slash()Creates a builder for a slash-only command.static CommandBuilder<TextHandlers>text()Creates a builder for a text (message and slash) command.withAliases(@Nullable Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String> aliases) Sets the aliases that a user should support.withCallable(boolean callable) Sets whether the command can be invoked directly.withDescription(@MatchesRegex("(?Us)^.{1,100}+$") String description) Sets the description of the command.withDisplayName(@MatchesRegex("(?U)^[ -_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) Sets the display name of the command.withHandlers(H handlers) Sets the handlers of the command.withName(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) Sets the name of the command.withParameters(@Nullable List<Parameter<?>> parameters) Sets the parameters that a user should provide.withParent(@Nullable Invocation parent) Sets the parent command.withScope(@Nullable Command.Scope scope) Sets the command scope.
-
Field Details
-
DEFAULT_SCOPE
Default forwithScope(Scope)(Command.Scope.GLOBAL). -
DEFAULT_CALLABLE
public static final boolean DEFAULT_CALLABLEDefault forwithCallable(boolean).- See Also:
-
DEFAULT_GROUP
Default forrequireGroup(Group)(Groups.EVERYONE). -
DEFAULT_SKIP
public static final boolean DEFAULT_SKIPDefault forsetSkipGroupCheckOnInteraction(boolean).- See Also:
-
DEFAULT_REQUIRE_PARENT_GROUPS
public static final boolean DEFAULT_REQUIRE_PARENT_GROUPSDefault forsetRequireParentGroups(boolean).- See Also:
-
DEFAULT_NSFW
public static final boolean DEFAULT_NSFWDefault forsetNsfw(boolean).- See Also:
-
DEFAULT_PRIVATE
public static final boolean DEFAULT_PRIVATEDefault forsetPrivateReply(boolean).- See Also:
-
DEFAULT_EPHEMERAL
Default forsetEphemeralReply(EphemeralType)(ReplyManager.EphemeralType.NONE). -
DEFAULT_INHERIT
public static final boolean DEFAULT_INHERITDefault forsetInheritSettings(boolean).- See Also:
-
DEFAULT_INVOKE_PARENT
public static final boolean DEFAULT_INVOKE_PARENTDefault forsetInvokeParent(boolean).- See Also:
-
scope
The command scope. -
callable
protected boolean callableWhether the command can be invoked directly. -
parent
The command parent. -
name
protected @MonotonicNonNull @MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String nameThe command name. -
aliases
protected Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String> aliasesThe command aliases. -
displayName
protected @MonotonicNonNull @MatchesRegex("(?U)^[ -_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String displayNameThe display name. -
description
The command description. -
parameters
The command parameters. -
requiredGroup
The group that a user must have access for. -
skipGroupCheckOnInteraction
protected boolean skipGroupCheckOnInteractionWhether group access checking should be skipped. -
requireParentGroups
protected boolean requireParentGroupsWhether to also require the parent command's groups. -
nsfw
protected boolean nsfwWhether the command can only be run in NSFW channels. -
privateReply
protected boolean privateReplyWhether the command response should only be seen by the caller. -
ephemeralReply
The type of ephemeral response to use, if any. -
inheritSettings
protected boolean inheritSettingsWhether to inherit settings from parent. -
invokeParent
protected boolean invokeParentWhether to execute the parent. -
handlers
The handlers to process invocations with.
-
-
Constructor Details
-
CommandBuilder
Constructs a new builder with default values. -
CommandBuilder
Constructs a new builder that is a copy of the given builder.- Parameters:
base- The builder to copy.
-
-
Method Details
-
from
@SideEffectFree public static <H extends Handlers> CommandBuilder<H> from(Command<H> base) throws IllegalArgumentException Constructs a new builder that is initialized to make a copy of the given command.- Type Parameters:
H- The handler type.- Parameters:
base- The command to copy.- Returns:
- The initialized builder.
- Throws:
IllegalArgumentException- if the given command has invalid values.
-
message
Creates a builder for a message-only command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-
slash
Creates a builder for a slash-only command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-
text
Creates a builder for a text (message and slash) command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-
interaction
Creates a builder for an interaction command.- Returns:
- The builder.
- API Note:
- Use to force the type argument when it cannot be inferred.
-
withScope
Sets the command scope.The default value is
DEFAULT_SCOPE.- Parameters:
scope- The command scope. Ifnull, restores the default value.- Returns:
- This builder.
- See Also:
-
withCallable
Sets whether the command can be invoked directly.The default value is true.
- Parameters:
callable- Whether a user can invoke the command directly.- Returns:
- This builder.
- See Also:
-
withParent
Sets the parent command.The default value is an empty invocation (no parent).
- Parameters:
parent- The invocation of the parent command. Ifnull, restores the default value.- Returns:
- This builder.
- See Also:
-
withName
@Deterministic public CommandBuilder<H> withName(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) Sets the name of the command.The default value is
null, e.g. no value. It must be specified before callingbuild()(so this method must be called at least once).- Parameters:
name- The command name.- Returns:
- This builder.
- See Also:
-
withAliases
@Deterministic public CommandBuilder<H> withAliases(@Nullable Set<@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String> aliases) throws IllegalArgumentException Sets the aliases that a user should support.The default value is an empty set (no aliases).
- Parameters:
aliases- The command aliases. Ifnull, restores the default value.- Returns:
- This builder.
- Throws:
IllegalArgumentException- if one of the aliases is not valid.- See Also:
-
addAliases
@Deterministic public CommandBuilder<H> addAliases(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String... aliases) throws IllegalArgumentException Adds aliases to the command.- Parameters:
aliases- The aliases to add.- Returns:
- This builder.
- Throws:
IllegalArgumentException- if any of the aliases is not valid. None will be added.- See Also:
-
noAliases
Removes all aliases from the command.- Returns:
- This builder.
- See Also:
-
withDisplayName
@Deterministic public CommandBuilder<H> withDisplayName(@MatchesRegex("(?U)^[ -_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) Sets the display name of the command.The default value is
null, e.g. no value. It must be specified before callingbuild()(so this method must be called at least once).- Parameters:
name- The command display name.- Returns:
- This builder.
- See Also:
-
withDescription
@Deterministic public CommandBuilder<H> withDescription(@MatchesRegex("(?Us)^.{1,100}+$") String description) Sets the description of the command.The default value is
null, e.g. no value. It must be specified before callingbuild()(so this method must be called at least once).- Parameters:
description- The command description.- Returns:
- This builder.
- See Also:
-
withParameters
Sets the parameters that a user should provide.The default value is an empty list (no parameters).
- Parameters:
parameters- The command parameters. Ifnull, restores the default value.- Returns:
- This builder.
- See Also:
-
addParameter
Adds a parameter to the command.- Parameters:
parameter- The parameter to add.- Returns:
- This builder.
- See Also:
-
noParameters
Removes all parameters from the command.- Returns:
- This builder.
- See Also:
-
requireGroup
Sets the group that a user must have access for.The default value is
DEFAULT_GROUP.- Parameters:
group- The required group. Ifnull, restores the default value.- Returns:
- This builder.
- See Also:
-
setSkipGroupCheckOnInteraction
Sets whether group access checking should be skipped.The default value is true, as application commands should generally avoid clashing with user-set permissions unless necessary.
- Parameters:
skip- Whether group access checking should be skipped.- Returns:
- This builder.
- See Also:
-
setRequireParentGroups
Sets whether the command also require its parent command's groups.The default value is true.
- Parameters:
require- Whether to require the parent's groups.- Returns:
- This builder.
- See Also:
-
setNsfw
Sets whether the command can only be run in channels marked as NSFW.The default value is false.
- Parameters:
nsfw- Whether the command is NSFW.- Returns:
- This builder.
- See Also:
-
setPrivateReply
Sets whether the command response should be sent privately to the caller.The default value is false.
- Parameters:
privateReply- Whether the response should be sent privately.- Returns:
- This builder.
- See Also:
-
setEphemeralReply
@Deterministic public CommandBuilder<H> setEphemeralReply(@Nullable ReplyManager.EphemeralType ephemeralReply) Sets the type of ephemeral response to use, if any.The default value is
DEFAULT_EPHEMERAL.- Parameters:
ephemeralReply- The type of ephemeral response to use, if any. Ifnull, restores the default value.- Returns:
- This builder.
- See Also:
-
setInheritSettings
Sets whether the command should inherit settings from the parent command.The default value is false.
- Parameters:
inheritSettings- Whether the command inherits the parent command's settings.- Returns:
- This builder.
- See Also:
-
setInvokeParent
Sets whether the command should also invoke the parent's handler.The default value is false.
- Parameters:
invokeParent- Whether the command should invoke the parent's handler.- Returns:
- This builder.
- See Also:
-
withHandlers
Sets the handlers of the command.The default value is
null, e.g. no value. It must be specified before callingbuild()(so this method must be called at least once).- Parameters:
handlers- The handlers.- Returns:
- This builder.
- See Also:
-
build
@SideEffectFree public Command<H> build(CommandBuilder<H extends Handlers> this) throws IllegalStateException Builds the configured command.- Returns:
- The built command.
- Throws:
IllegalStateException- if the current configuration is invalid.
-