[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STABLE] Adds the remaining final touches to stable version. #17

Merged
merged 53 commits into from
Sep 28, 2023

Conversation

ShindouMihou
Copy link
Owner

Nexus 1.0 has been long overdue, and we need to make the final touches, which includes making sure everything is performant, stable, and complete, we need to simplify things a lot, such as:

  • Removing deprecated methods and fields, and non-standard things.
  • Debloating the dispatcher (especially since we have more complex handling), an example of this debloating is making additional things such as the option validations into native-class middleware (i.e. middleware injected by the dispatcher itself which allows it to utilize the handling of middleware from auto-defer, response handling).
  • Solving pain problems with the framework, such as the synchronizer overwriting other application command builders not managed by the framework (i.e. user and message context menus).
  • Focusing on stability and maintainability of the reflection engine, dispatcher, and other core parts (i.e. expressway).
  • Profiling the framework to identify potential fault lines at scale (i.e. memory bloat and unnecessary hotspots) that can happen in intensive areas such as the command manager, the dispatcher, the reflection engine, and other parts.
  • Focusing more on developer experience and maintainability by improving the experience of using the other existing tools such as the paginators and other stuff.
  • Revisiting the reflection engine completely to massively optimize for readability and whatever is possible, we need the engine to be agnostic, which means it should be able to pull and paste from object to object regardless of the class, this will help massively in the future functionalities (i.e. making user and message context menus first-class functions of Nexus).

Currently, this pull request includes multiple breaking changes and will involve massive changes, which need to be tested in-depth, therefore, it is separate from 1.0.0-beta to allow the branch to be updated in case of major required fixes.

Native interceptors are interceptors baked into the framework itself that are auto-prepended by the dispatcher, this helps us reduce a lot of duplicate handling especially for deferring, etc.
This feature doesn't support updating at the moment as the latest non-snapshot version of Javacord doesn't contain the update method, it's under the next release though.
This adds additional support for non-Nexus application commands to be bulk-overwritten, as the bulk overwrite methods tend to overwrite everything, which includes non-slash, this becomes a problem that needs some solution.
This commit adds a new reflection engine that is agnostic, allowing us to be able to use it for other future classes such as user and message context menus, etc. that are not just `NexusCommand`.

The new reflection engine is also written in Kotlin, but uses the same Java Reflection, enabling more readability and cleanliness.

This also adds a new `@Uuid` annotation that is used to figure out which field is the origin Uuid field of the reference class.
@ShindouMihou ShindouMihou marked this pull request as draft September 17, 2023 04:26
@ShindouMihou
Copy link
Owner Author

v1.0.0-next adds a massive simplfiication and breaking change to interceptors:

  1. We're removing NexusCommandInterceptor methods on the next possible version in favor Nexus.interceptors (e.g. Nexus.interceptors.middleware(name) { ev -> .. })
  2. We're removing NexusCommandInterceptorRepository altogether on the next possible version, this is because we now have a better reflection engine that can handle more tasks and operations, allowing us to collect the fields and add them directly. See the NexusCommonInterceptors.

@ShindouMihou
Copy link
Owner Author

After some little work, I've noticed that afterwares behavior was reversed in a older commit where they no longer execute even if the command was stopped by a middleware. It's the correct behavior, but we need some way to at least identify when it fails, and that is the onFailedDispatch override function in NexusAfterware interface.

By overidding the onFailedDispatch, you can listen to when a command failed to dispatch, usually because a middleware stopped the command from dispatching. You can see an example on the new NexusLogAfterware.

@ShindouMihou
Copy link
Owner Author

A key benefit we can get from failedDispatch event is that we can log additional data from the middleware, if they used the event.store(...), for example, the common ratelimiter of Nexus supports this and is used in the new common log afterware to produce logs such as this:
image

@ShindouMihou
Copy link
Owner Author

You can now get the middleware that blocked the execution on your afterware by getting the value of Nexus[NexusAfterware.BLOCKING_MIDDLEWARE_KEY] which is only available in afterwares.

image

@ShindouMihou
Copy link
Owner Author
ShindouMihou commented Sep 24, 2023

Nexus now natively supports user and message context menus. To get started, simply create a new class or object that inherits the NexusUserContextMenu or NexusMessageContextMenu abstract class and play with it like slash commands do:

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")
    }
}

To register them, simply use the Nexus.contextMenus method:

Nexus.contextMenus(TestUserContextMenu, TestMessageContextMenu)

We do not have support for afterwares and middlewares for context menus as we have no simpler middle between the two events. Additionally, to prevent something crazy, context menus are not included in the global.inheritance as it doesn't inherently support the same properties and functionalities as the slash commands.

@ShindouMihou
Copy link
Owner Author

It's almost time for Nexus 1.0, the following additional changes have been made:

  1. Fixed NexusMiddlewareEvent.interaction resulting in a NoClassDefError (related: https://youtrack.jetbrains.com/issue/KT-12466)
  2. Added support for inheritance with superclass fields.
  3. Added additional utilities for NexusMessage (Kotlin-only).
  4. Nexus will now use NexusConsoleLoggingAdapter by default whenever there is no SLF4J logger (to prevent important details from being hidden away).

And some more stability and maintainability changes. Note that this change will introduce quite a lot of breaking changes that will need a lot of work, but it is for the sake of keeping the API more consistent.

@ShindouMihou
Copy link
Owner Author

NexusConsoleLoggingAdapter now uses System.err (stderr) for error outputs, allowing for better logging with tools like Loki. Additionally, NexusConsoleLoggingAdapter can now handle throwing exceptions as long as there is no placeholders used (which in the modern Nexus, there shouldn't be any placeholders used now as we use Kotlin for this).

image

@ShindouMihou ShindouMihou marked this pull request as ready for review September 28, 2023 13:11
@ShindouMihou ShindouMihou merged commit 9f69cf5 into 1.0.0-beta Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant