Skip to content

v1.0.0-beta.next

Compare
Choose a tag to compare
@ShindouMihou ShindouMihou released this 28 Sep 14:02

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:
image

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.

image

Minor Changes

  1. Some behavioral changes have been done to NexusConsoleLoggingAdapter.
    • We now log to stderr instead of stdout for errors.
    • Exceptions are now handled through the logging adapter.
  2. Added more utilities to NexusMessage (Kotlin-only).
    • EmbedBuilder.toNexusMessage()
    • String.toNexusMessage()
  3. 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.
  4. Added support for superclasses in commands (e.g extending abstract classes).
  5. 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)
  6. A new reflection engine has replaced the previous, making things significantantly easier to add and also making things easier to maintain.
  7. 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 affect Nexus.synchronizer.synchronize() and Nexus.synchronizer.batchUpdate(server) as those methods uses bulkOverwrite which overwrites the entire commands altogether, allowing updates for those.
  8. You can now include additional ApplicationCommandBuilder to Nexus.synchronizer through Nexus.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.
  9. Added NexusCommandEvent.get(key) that returns an Object (or Any for Kotlin) as there are cases where our little type-casting doesn't really work, so we'd prefer doing it on our own.
  10. Fixed wiki links on documentations.
  11. 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.
  12. We now use Nexus.launcher to dispatch all events, so you can now use coroutines or related.