Class JDACBuilder
This builder is used to build instances of JDACommands
.
Please note that values that can be set have a default implementation. These following implementations are based on reflections. If you want to avoid reflections, you have to provide your own implementations for:
descriptor(Descriptor)
classFinders(ClassFinder...)
instanceProvider(InteractionControllerInstantiator)
In addition to manually configuring this builder, you can also provide implementations of Extension
trough Javas service provider interface
, which are applied during JDACommands
creation.
Values manually defined by this builder will always override loaded and default ones, except for:
which will add to the default and loaded ones.
These implementations of Extension
can be additionally configured by adding the according implementation of Extension.Data
by calling extensionData(Extension.Data...)
. (if supported by the extension)
If any exception while configuration/start of JDA-Commands is thrown, the JDA instance if shutdown per default.
This can be configured by settings shutdownJDA(boolean)
.
Example
JDACommands jdaCommands = JDACommands.builder(jda, Main.class)
.middleware(Priority.NORMAL, new TestMiddleware())
.globalReplyConfig(new InteractionDefinition.ReplyConfig(false, false, true))
.classFinders(ClassFinder.reflective(Main.class), ClassFinders.explicit(ButtonInteraction.class))
.start();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The two available filter strategies -
Field Summary
Fields inherited from class com.github.kaktushose.jda.commands.extension.JDACBuilderData
baseClass, classFinders, context, controllerInstantiator, descriptor, embeds, errorMessageFactory, expirationStrategy, extensionData, extensionFilter, globalCommandConfig, globalReplyConfig, guildScopeProvider, loadedExtensions, localizeCommands, localizer, log, middlewares, packages, permissionsProvider, shutdownJDA, typeAdapters, validators
-
Method Summary
Modifier and TypeMethodDescriptionadapter
(Class<?> source, Class<?> target, TypeAdapter<?, ?> adapter) classFinders
(ClassFinder... classFinders) descriptor
(Descriptor descriptor) embeds
(Consumer<EmbedConfig> consumer) Configuration step for the Embed API of JDA-Commands.errorMessageFactory
(ErrorMessageFactory errorMessageFactory) expirationStrategy
(ExpirationStrategy expirationStrategy) extensionData
(Extension.Data... data) RegistersExtension.Data
that will be passed to the respectiveExtension
s to configure them properly.filterExtensions
(JDACBuilder.FilterStrategy strategy, String... classes) Specifies a way to filter found implementations ofExtension
if you have clashing or cycling dependencies for example.globalReplyConfig
(InteractionDefinition.ReplyConfig globalReplyConfig) guildScopeProvider
(GuildScopeProvider guildScopeProvider) instanceProvider
(InteractionControllerInstantiator instanceProvider) localizeCommands
(boolean localize) Whether JDA-Commands should use theI18n
feature to localize commands.middleware
(Priority priority, Middleware middleware) permissionsProvider
(PermissionsProvider permissionsProvider) shutdownJDA
(boolean shutdown) Whether the JDA instance should be shutdown if the configuration/start of JDA-Commands fails or ifJDACommands.shutdown()
is calledstart()
This method applies all found implementations ofExtension
, instantiates an instance ofJDACommands
and starts the framework.validator
(Class<? extends Annotation> annotation, Validator<?, ?> validator) Methods inherited from class com.github.kaktushose.jda.commands.extension.JDACBuilderData
baseClass, classFinders, context, controllerInstantiator, descriptor, embeds, errorMessageFactory, expirationStrategy, globalCommandConfig, globalReplyConfig, guildScopeProvider, i18n, localizeCommands, localizer, mergedClassFinder, middlewares, packages, permissionsProvider, shutdownJDA, typeAdapters, validators
-
Method Details
-
classFinders
- Parameters:
classFinders
- the to be usedClassFinder
s- API Note:
- This method overrides the underlying collection instead of adding to it.
If you want to add own
ClassFinder
s while keeping the default reflective implementation, you have to add it explicitly viaClassFinder.reflective(Class, String...)
too.
-
descriptor
- Parameters:
descriptor
- theDescriptor
to be used
-
embeds
Configuration step for the Embed API of JDA-Commands.
Use the given
EmbedConfig
to declare placeholders or data sources. -
localizer
- Parameters:
localizer
- TheLocalizer
to use
-
instanceProvider
- Parameters:
instanceProvider
- the implementation ofInteractionControllerInstantiator
to use
-
expirationStrategy
- Parameters:
expirationStrategy
- TheExpirationStrategy
to be used
-
middleware
- Parameters:
priority
- ThePriority
with what theMiddleware
should be registeredmiddleware
- The to be registeredMiddleware
-
adapter
- Parameters:
source
- The source type that the givenTypeAdapter
can handletarget
- The target type that the givenTypeAdapter
can handleadapter
- TheTypeAdapter
to be registered
-
validator
-
permissionsProvider
- Parameters:
permissionsProvider
- ThePermissionsProvider
that should be used
-
errorMessageFactory
- Parameters:
errorMessageFactory
- TheErrorMessageFactory
that should be used
-
guildScopeProvider
- Parameters:
guildScopeProvider
- TheGuildScopeProvider
that should be used
-
globalReplyConfig
- Parameters:
globalReplyConfig
- theInteractionDefinition.ReplyConfig
to be used as a global fallback option
-
globalCommandConfig
- Parameters:
config
- theCommandDefinition.CommandConfig
to be used as a global fallback option
-
extensionData
RegistersExtension.Data
that will be passed to the respectiveExtension
s to configure them properly.- Parameters:
data
- the instances ofExtension.Data
to be used
-
shutdownJDA
Whether the JDA instance should be shutdown if the configuration/start of JDA-Commands fails or ifJDACommands.shutdown()
is called- Parameters:
shutdown
- whether to shut down the JDA instance, default true
-
localizeCommands
Whether JDA-Commands should use theI18n
feature to localize commands.- Parameters:
localize
- whether to localize commands, default false- See Also:
-
filterExtensions
Specifies a way to filter found implementations ofExtension
if you have clashing or cycling dependencies for example.- Parameters:
strategy
- the filtering strategy to be used eitherJDACBuilder.FilterStrategy.INCLUDE
orJDACBuilder.FilterStrategy.EXCLUDE
classes
- the classes to be filtered- API Note:
- This method compares the
fully classified class name
of allExtension
implementations by usingString.startsWith(String)
, so it's possible to include/exclude a bunch of classes in the same package by just providing the package name.
-
start
This method applies all found implementations ofExtension
, instantiates an instance ofJDACommands
and starts the framework.
-