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)
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 class
Will be thrown if anything goes wrong while configuring jda-commands.static enum
The two available filter strategies -
Field Summary
Fields inherited from class com.github.kaktushose.jda.commands.extension.JDACBuilderData
baseClass, classFinders, context, controllerInstantiator, descriptor, errorMessageFactory, expirationStrategy, extensionData, extensionFilter, globalReplyConfig, guildScopeProvider, loadedExtensions, localizationFunction, log, middlewares, packages, permissionsProvider, typeAdapters, validators
-
Method Summary
Modifier and TypeMethodDescription@NotNull JDACBuilder
adapter
(@NotNull Class<?> type, @NotNull TypeAdapter<?> adapter) @NotNull JDACBuilder
classFinders
(@NotNull ClassFinder... classFinders) @NotNull JDACBuilder
descriptor
(@NotNull Descriptor descriptor) @NotNull JDACBuilder
errorMessageFactory
(@NotNull ErrorMessageFactory errorMessageFactory) @NotNull JDACBuilder
expirationStrategy
(@NotNull ExpirationStrategy expirationStrategy) @NotNull JDACBuilder
extensionData
(Extension.Data... data) RegistersExtension.Data
that will be passed to the respectiveExtension
s to configure them properly.@NotNull JDACBuilder
filterExtensions
(@NotNull JDACBuilder.FilterStrategy strategy, @NotNull String... classes) Specifies a way to filter found implementations ofExtension
if you have clashing or cycling dependencies for example.@NotNull JDACBuilder
globalReplyConfig
(@NotNull InteractionDefinition.ReplyConfig globalReplyConfig) @NotNull JDACBuilder
guildScopeProvider
(@NotNull GuildScopeProvider guildScopeProvider) instanceProvider
(InteractionControllerInstantiator instanceProvider) @NotNull JDACBuilder
localizationFunction
(@NotNull LocalizationFunction localizationFunction) @NotNull JDACBuilder
middleware
(@NotNull Priority priority, @NotNull Middleware middleware) @NotNull JDACBuilder
permissionsProvider
(@NotNull PermissionsProvider permissionsProvider) @NotNull JDACommands
start()
This method applies all found implementations ofExtension
, instantiates an instance ofJDACommands
and starts the framework.@NotNull JDACBuilder
validator
(@NotNull Class<? extends Annotation> annotation, @NotNull Validator validator) Methods inherited from class com.github.kaktushose.jda.commands.extension.JDACBuilderData
baseClass, classFinders, context, controllerInstantiator, descriptor, errorMessageFactory, expirationStrategy, globalReplyConfig, guildScopeProvider, localizationFunction, mergedClassFinder, middlewares, packages, permissionsProvider, 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
-
localizationFunction
@NotNull public @NotNull JDACBuilder localizationFunction(@NotNull @NotNull LocalizationFunction localizationFunction) - Parameters:
localizationFunction
- TheLocalizationFunction
to use
-
instanceProvider
- Parameters:
instanceProvider
- the implementation ofInteractionControllerInstantiator
to use
-
expirationStrategy
@NotNull public @NotNull JDACBuilder expirationStrategy(@NotNull @NotNull ExpirationStrategy expirationStrategy) - Parameters:
expirationStrategy
- TheExpirationStrategy
to be used
-
middleware
@NotNull public @NotNull JDACBuilder middleware(@NotNull @NotNull Priority priority, @NotNull @NotNull Middleware middleware) - Parameters:
priority
- ThePriority
with what theMiddleware
should be registeredmiddleware
- The to be registeredMiddleware
-
adapter
@NotNull public @NotNull JDACBuilder adapter(@NotNull @NotNull Class<?> type, @NotNull @NotNull TypeAdapter<?> adapter) - Parameters:
type
- The type that the givenTypeAdapter
can handleadapter
- TheTypeAdapter
to be registered
-
validator
@NotNull public @NotNull JDACBuilder validator(@NotNull @NotNull Class<? extends Annotation> annotation, @NotNull @NotNull Validator validator) -
permissionsProvider
@NotNull public @NotNull JDACBuilder permissionsProvider(@NotNull @NotNull PermissionsProvider permissionsProvider) - Parameters:
permissionsProvider
- ThePermissionsProvider
that should be used
-
errorMessageFactory
@NotNull public @NotNull JDACBuilder errorMessageFactory(@NotNull @NotNull ErrorMessageFactory errorMessageFactory) - Parameters:
errorMessageFactory
- TheErrorMessageFactory
that should be used
-
guildScopeProvider
@NotNull public @NotNull JDACBuilder guildScopeProvider(@NotNull @NotNull GuildScopeProvider guildScopeProvider) - Parameters:
guildScopeProvider
- TheGuildScopeProvider
that should be used
-
globalReplyConfig
@NotNull public @NotNull JDACBuilder globalReplyConfig(@NotNull @NotNull InteractionDefinition.ReplyConfig globalReplyConfig) - Parameters:
globalReplyConfig
- theInteractionDefinition.ReplyConfig
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
-
filterExtensions
@NotNull public @NotNull JDACBuilder filterExtensions(@NotNull @NotNull JDACBuilder.FilterStrategy strategy, @NotNull @NotNull String... classes) 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.
-