v1.0.0-beta.next
Nexus 1.0 is now ready for official release with the following latest changes and breaking changes from the 1.0.0-next.
Breaking Changes
NexusCommandInterceptor
Methods to add interceptors such as middlewares and afterwares in the NexusCommandInterceptor
interface has been removed completely in favor of Nexus.interceptors
, this is to keep the API more consistent across the board.
Migration:
- NexusCommandInterceptor.addMiddleware("key") { ... }
+ Nexus.interceptors.middleware("key") { ... }
- NexusCommandInterceptor.middleware { ... }
+ Nexus.interceptors.middleware { ... }
NexusCommandInterceptorRepository
We're removing this altogether because there is no point in bringing this when it simply just does the same thing as the newer style but under a define function.
Migration:
- object SomeRepository: NexusCommandInterceptorRepository {
- val SOME_MIDDLEWARE: String = "some.middleware"
- override fun define() {
- middleware(SOME_MIDDLEWARE) { ... }
- }
- }
+ object SomeRepository {
+ val SOME_MIDDLEWARE: String = Nexus.interceptors.middleware("some.middleware") { ... }
+ }
cooldown
in NexusCommand
We've removed cooldown
field as a native field in NexusCommand
, this is, in order to keep things more consistent, as we do not offer the Ratelimiter as a Nexus-Native middleware (like OptionValidation is).
Migration:
- val cooldown = Duration.ofSeconds(5)
+ @Share val cooldown = Duration.ofSeconds(5)
NexusCommonInterceptors
We recently changed NexusCommonInterceptors
from a interface to an singleton, so this may cause some import issues for some people. Don't worry, just reimport it!
NexusLoggingAdapter
We recently changed the internal methods of Nexus to pass exceptions in the parameters of Nexus.logger
without any placeholders (not that we even use placeholders now as we use Kotlin), so you may see exceptions being passed as a parameter even though there are no placeholders.
NexusCommand
We've removed older methods that have long been marked for deprecation, the following functions were moved:
- fun addSupportFor(vararg serverIds: Long): NexusCommand
- fun removeSupportFor(vararg serverIds: Long): NexusCommand
- fun getServerId(): Long
Migration:
val command = ...
command.associate(serverIds)
command.disassociate(serverIds)
# Same behavior as the old `NexusCommand#getServerId`
command.serverIds.first()
Major Changes
Context Menus
First-class support for context menus (user and message) in Nexus is now supported. This will make it so that we don't have to use some sketchy methods to prevent your context menus from being overridden, and this makes it easier to use Nexus with context menus.
object TestUserContextMenu: NexusUserContextMenu() {
val name = "test"
override fun onEvent(event: NexusContextMenuEvent<UserContextMenuCommandEvent, UserContextMenuInteraction>) {
event.respondNowEphemerallyWith("Hello")
}
}
object TestMessageContextMenu: NexusMessageContextMenu() {
val name = "test"
override fun onEvent(event: NexusContextMenuEvent<MessageContextMenuCommandEvent, MessageContextMenuInteraction>) {
event.respondNowEphemerallyWith("Hello")
}
}
Nexus.contextMenus(TestUserContextMenu, TestMessageContextMenu)
Failed Dispatch Afterwares
Afterwares can now listen to failed dispatch events which will significantly help with logging and analytical afterwares. Previously, afterwares weren't able to execute after a command failed to dispatch (e.g. a middleware rejecting dispatch), but now, we can listen to these events and even know which middleware caused the problem by using NexusCommandEvent.get(NexusAfterware.BLOCKING_MIDDLEWARE_KEY)
.
A prime example of this mechanism is the new NexusCommonInterceptors.LOG
middleware:
object SomeAfterware: NexusAfterware {
override fun onAfterCommandExecution(event: NexusCommandEvent) {}
override fun onFailedDispatch(event: NexusCommandEvent) {} // optional
}
log
common afterware
We now have our first common afterware, and it's the NexusCommonInterceptors.LOG
afterware which helps you log commands easily. This uses the Nexus.logger
to log.
Minor Changes
- Some behavioral changes have been done to
NexusConsoleLoggingAdapter
.- We now log to
stderr
instead ofstdout
for errors. - Exceptions are now handled through the logging adapter.
- We now log to
- Added more utilities to
NexusMessage
(Kotlin-only).EmbedBuilder.toNexusMessage()
String.toNexusMessage()
- Added support for inheritance parents with superclass fields, this will make it so parent inheritance can extend upon superclasses (e.g. abstract classes) and still copy the fields from there.
- Added support for superclasses in commands (e.g extending abstract classes).
- Nexus will now automatically use
NexusConsoleLoggingAdapter
when there is no SLF4J logger (as the default logger caused issues wherein exceptions would be ignored as there was no adapter to handle them a.k.a NOP) - A new reflection engine has replaced the previous, making things significantantly easier to add and also making things easier to maintain.
- Added some incomplete support for
nsfw
field for both context and slash commands.- Due to Javacord issues, we cannot update the application command's nsfw field using the
SlashCommandUpdater
because it's missing on the current stable version of Javacord. This does not affectNexus.synchronizer.synchronize()
andNexus.synchronizer.batchUpdate(server)
as those methods usesbulkOverwrite
which overwrites the entire commands altogether, allowing updates for those.
- Due to Javacord issues, we cannot update the application command's nsfw field using the
- You can now include additional
ApplicationCommandBuilder
toNexus.synchronizer
throughNexus.synchronize.include(server, commands)
. This is intended when you want to add your own little other stuff e.g. custom context menus that doesn't use Nexus. - Added
NexusCommandEvent.get(key)
that returns anObject
(orAny
for Kotlin) as there are cases where our little type-casting doesn't really work, so we'd prefer doing it on our own. - Fixed wiki links on documentations.
- A warning is now sent when you try to add
@Inherits
to an inheritance parent (as that isn't really supported),@Inherits
should only be on children. - We now use
Nexus.launcher
to dispatch all events, so you can now use coroutines or related.