Skip to content

v3.0.0-alpha.23 | Improved dynamic DI, simplified runtime filters, and general improvements

Choose a tag to compare

@freya022 freya022 released this 25 Jan 17:56
· 231 commits to 3.X since this release
378dc06

JDA version

Overview

Improved built-in DI capabilities, simplified runtime filters, and general usability improvements.

Replaced DynamicSupplier with user-defined service suppliers (#225, #226)

This aims to allow defining services earlier in the loading process, for example, when initializing the framework, or while discovering classes.

One use case is to define services when discovering an interface with a given annotation; a similar example in Spring would be JPA repositories (using @Repository on an interface that gets implemented automatically).

Breaking changes

  • Removed DynamicSupplier

Deprecations

  • Deprecated instance suppliers
    • InstanceSupplier
    • BServiceConfig#instanceSupplierMap
    • BServiceConfigBuilder#registerInstanceSupplier

Changes

  • Passed a ServiceContainer in ClassGraphProcessor methods
  • Annotations are no longer read from classes supplied by InstanceSuppliers
    • This shouldn't affect anyone as you would use a service factory instead

New features

  • Added ServiceSupplier
    • This lets you configure a service with a bit more depth
  • Added DefaultServiceContainer#putSuppliedService(ServiceSupplier)
    • You should be able to call this from a ClassGraphProcessor, for example, if you want to register proxied interfaces as services
  • Added BServiceConfigBuilder#registerServiceSupplier(...)

Removed append attributes from @UserPermission, @BotPermissions and @Test (#227)

You will now have to annotate the affected function directly, to clarify what affects a function, however, to reduce repetition, you can use them as meta-annotations, combine them and override them.

Breaking changes

  • Removed the append attribute
  • Removed the CLASS target
  • If findAllAnnotations encounters the target annotation, this will override meta-annotations (children annotations) if directOverrides is true
  • findAllAnnotations has no defined order anymore

Changes

  • Added the ANNOTATION_CLASS target

Slightly simplified filters (#228)

A rejection handler is no longer mandatory, however, you can keep using it if you wish, by calling it yourself.

Breaking changes

  • You no longer need to make rejection handlers
    • Instead of returning arbitrary data, you handle the rejection in the filter directly, and return a string for logging purposes
    • I recommend using a separate function/class to reduce maintenance
  • The global property of filters is now abstract
    • Clarifies which filter is global or command-specific

Breaking changes

Built-in dependency injection

  • Removed ServiceContainer#lazyService
    • This already existed as lazy

Changes

Dependencies

  • Kotlin: 2.0.0 -> 2.1.0
  • kotlinx-coroutines: 1.9.2 -> 1.10.1
  • (Optional) Spring boot: 3.2.12 -> 3.4.2
  • kotlinx-datetime: 0.5.0 -> 0.6.1
  • ClassGraph: 4.8.175 -> 4.8.179
  • Caffeine: 3.1.8 -> 3.2.0
  • slf4j-api: 2.0.13 -> 2.0.16
  • kotlin-logging: 7.0.0 -> 7.0.3
  • (Optional) HikariCP: 5.1.0 -> 6.2.1

App emojis

  • Throw exception if not enough slots are available

New features

App emojis

  • Added BAppEmojisConfig#deleteOnOutOfSlots
    • If there are not enough slots, it will delete the oldest application emojis that aren't required by the bot

Localization

  • Added LocalizationContext#fromLocaleProviders
    • This helps you create a localization context using the same locales as using the events would
    • This can be useful when replying in an interaction filter
  • Adding a / prefix to your template key will make the library ignore any set prefix
    • Example: /my.command.responses.ok will stay as my.command.responses.ok even if a prefix is set

Components

  • Added a few helpers to create IdentifiableComponent from JDA components
  • Added a few helpers to remove stored components using JDA components

Misc

  • Added a few utilities to convert from/to Kotlin/Java functions in ReflectionUtils

Bug fixes

Built-in dependency injection

  • Fixed using LazyService in Java constructors

App emojis

  • Fixed app emojis being enabled by default on Spring apps

Don't hesitate to check out the examples and the wiki.

Full Changelog: v3.0.0-alpha.22...v3.0.0-alpha.23