v3.0.0-alpha.16 | Improved localization, command introspection and RestResult
Overview
Improved localization support, added an API to inspect commands and improved RestAction
exception handling in Kotlin, among other features and changes.
Add localized reply functions to events (#177)
All interaction events, InteractionHook
and BaseCommandEvent
(incl CommandEvent
) now have several functions
to reply using the user locale, guild locale, or any locale.
By default, the localization bundles used are those registered in BLocalizationConfig#responseBundles
,
you can set a specific bundle, and set a localization prefix,
by setting localizationBundle
and localizationPrefix
on your event.
In interactions, the user and guild locales can be customized by implementing UserLocaleProvider
and GuildLocaleProvider
respectively.
In text commands, the locale can be customized by implementing TextCommandLocaleProvider
.
Use locale providers for AppLocalizationContext
/TextLocalizationContext
Using the same providers from the above feature, injected localization contexts will use their returned locales.
Previously it would always use Interaction#userLocale/guildLocale
or Guild#locale
,
it will now use UserLocaleProvider
/GuildLocaleProvider
and TextCommandLocaleProvider
.
This allows you to customize the locale without reimplementing your own localization.
Note: I recommend using the localized reply methods on the event itself.
Added API to introspect commands, parameters and options (#178)
You can now retrieve details, parameters and options of text and application commands.
Breaking changes
ComponentDescriptor
is no longer passed inComponentParameterResolver
ModalHandlerInfo
is no longer passed inModalParameterResolver
TextCommandVariation
andSlashCommandInfo
has moved to the API package- Parameters of
TextParameterResolver#getHelpContent
changed- Old:
(parameter: KParameter, event: BaseCommandEvent, isID: Boolean)
- New:
(option: TextCommandOption, event: BaseCommandEvent)
- Old:
Added annotated application command declaration filters (#185)
Old ways to restrict commands to a guild have been deprecated,
and replaced with an annotation set on each application command.
This enables having such filters be more visible, instead of being tucked away in two interfaces.
Deprecations
- Deprecated
CommandList
,SettingsProvider#getGuildCommands
andApplicationCommand#getGuildsForCommandId
Addition
- Added
@DeclarationFilter
andCommandDeclarationFilter
- Run on annotated application commands when pushed to a guild
Reworked getting framework messages (#181)
Breaking changes
- Renamed
DefaultMessagesSupplier
toDefaultMessagesFactory
- Has a default instance, can be overridden
- Added methods to get instances from
Interaction
andMessageReceivedEvent
- Uses
UserLocaleProvider
andTextCommandLocaleProvider
by default
- Uses
Deprecations
- Deprecated
DefaultMessages
getters in BContext
Additions
- Added getters in
LocalizableAction
(i.e., for text commands and interactions)
Added usability getters for text/application commands (#182)
You can now use getUsability
on TextCommandInfo
/ApplicationCommandInfo
,
this allows checking if a given command is visible and/or usable.
Also added support for any NSFW channels in text commands, previously it only supported text and news channels.
Improved text command patterns (commit)
Patterns of text command options can now specify pattern flags in Pattern.compile
;
Using embedded flag expressions is no longer necessary, but can still be used.
Unicode character classes (incl. unicode casing) are also now used on all patterns.
Improved text option resolvers (#184)
Deprecations
- Deprecated
TextParameterResolver#requiredGroups
Changes
- The pattern of resolvers is wrapped in a non-capturing group to prevent conflicts
- Improved detection of mentions
- Correctly reads either the full mention or the ID
Added a BotOwners
service (#183)
This service should now be used to check bot owners, it will take owner IDs from BConfig#predefinedOwnerIds
,
if not set, will retrieve owners from Discord.
Deprecations
- Deprecated
BConfig#ownerIds
- Renamed to
predefinedOwnerIds
, as these IDs do not always represent the real owners.
- Renamed to
- Deprecated
BConfig#addOwners
, renamed to BConfig#addPredefinedOwners - Deprecated
BConfig#isOwner
,BContext#isOwner
,BContext#ownerIds
Now using command IDs to differentiate top-level commands (#179)
This allows two commands with the same top-level name, in both the global and the guild scope.
Breaking changes
- Removed
ApplicationCommandMap
- Good riddance
ApplicationCommandsContext#findLive[Type]Command
->find[Type]Command
ApplicationCommandsContext#getLiveApplicationCommandsMap
->getApplicationCommands
ApplicationCommandsContext#getEffectiveApplicationCommandsMap
->getEffectiveApplicationCommands
Additions
- Added
ApplicationCommandsContext#getApplicationCommandById
- Finds by id, group, subcommand, and type
Replaced functional RestAction
handling from Result
to RestResult
(#180)
Now allows properly ignoring error responses from rest actions,
under the condition that the value never tries to get returned (i.e., you can still use onSuccess
).
See example here
Breaking changes
RestAction#awaitCatching
now returnsRestResult
Result
extensions moved toRestResult
- To have a
RestResult
, userunCatchingRest
- To have a
Changes
ignore
properly ignores error responsesgetOrThrow
still throws, usegetOrNull
oronSuccess
orThrow
throws if the exception has not been ignored
Additions
- Added
runCatchingRest
- Added
RestResult#recover
, creates a newRestResult
if the exception matches, with a new value or exception.
Breaking changes
Components
- Components that can be grouped implement
IGroupHolder
- Allows to not group groups
- Technically breaking, but you shouldn't see anything
Text commands
- Removed
Consumer
parameter fromBaseCommandEvent#sendWithEmbedFooterIcon
- It was unused anyway, as the
RestAction
is returned
- It was unused anyway, as the
Deprecations
Application commands
- Deprecated
BConfig#disableAutocompleteCache
- Moved to application configs
- Deprecated
BContext#invalidateAutocompleteCache
- Moved to
ApplicationCommandContext
- Moved to
Text commands
- Deprecated text command related properties in
BContext
, moved toTextCommandsContext
Misc
- Deprecated
BContext#getEffectiveLocale
andSettingsProvider#getLocale
- Prefer using locale getters such as
UserLocaleProvider
/GuildLocaleProvider
/TextCommandLocaleProvider
- Prefer using locale getters such as
Components
- Deprecated
EphemeralHandlerBuilder
/PersistentHandlerBuilder
andbindTo
overloads which configured those- This should not affect anyone as they are extra steps for no reason
- Deprecated type-safe
bindTo
andtimeout
extensions- Replaced with
bindWith
andtimeoutWith
- Should help with importing the functions
- Replaced with
- Deprecated
oneUse
- Renamed to
singleUse
- Renamed to
Changes
Dependencies
- JDA:
5.0.0-beta.24
->5.0.0
- jda-ktx:
0.11.0-beta.20
->0.12.0
- kotlinx.coroutines:
1.8.0
->1.8.1
- jackson-databind:
2.17.1
->2.17.2
- (JDA alignment) trove4j (changed artifact id from
trove4j
tocore
):3.0.3
->3.1.0
- kotlin-logging-jvm:
6.0.9
->7.0.0
Text commands
- Load and log on initialization
Misc
- Use timeout of
CoroutineEventManager
by default for each listener - Exceptions are sent to all bot owners
Additions
Built-in resolvers
- Added a
UserSnowflake
resolver for text/application commands, and components.
Text commands
- Added back text command support for enum resolver
- Added default provider for
DefaultEmbedSupplier
/DefaultEmbedFooterIconSupplier
- Added emoji for "Closed DMs"
- Used when an internal reply method cannot send a DM to a user
- Injecting a
TextSuggestionSupplier
will return the default text suggestion supplier if nothing else is available
Application commands
- Added
ApplicationCommandResolverData
- Allows you to inspect the command builder when getting a resolver
Components
- Added
bindWith
andtimeoutWith
extensions to allow unbound callable references- Allows
bindWith(MyClass::myFunction, arg1, arg2...)
, useful when you don't have the instance
- Allows
- Added metadata to top-level application commands
id
,version
and convenience methods, such as getting a command as a mention
Misc
- Added
KLogger#[Level]Null
- Logs and returns
null
- Logs and returns
- Added ban/bulk-ban extensions with Kotlin
Duration
- Added
BContext#getExceptionContext
- Allows getting the same message content as if it was sent automatically
Fixes
Application commands
- Always update global commands (in addition to the guild) when a command isn't found
Text commands
- Add missing spaces in built-in help command
- Fixed testing command patterns with quotes
Built-in dependency injection
- Filter out circular dependencies when getting interface service types
Don't hesitate to check out the changelogs and the wiki.
Full Changelog: v3.0.0-alpha.15...v3.0.0-alpha.16