quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Discord bot extension for Quarkiverse (migration)

Open cottoncammy opened this issue 2 years ago • 9 comments

Description

Hi, I've written a Quarkus extension for developing Discord bots using the Discord4J library that I'd like to have migrated to Quarkiverse, if possible. You can find the extension here. I haven't used it in production so there could still be bugs. It's not on Maven Central but you can clone it if you want to test it out before deciding.

Configuration suggestion

No response

Additional context

No response

cottoncammy avatar Aug 10 '22 03:08 cottoncammy

/cc @aloubyansky, @gastaldi, @gsmet, @maxandersen

quarkus-bot[bot] avatar Aug 10 '22 03:08 quarkus-bot[bot]

That looks cool. Good job!

One question: can this extension also be used to create Discord API client apps using the Discord4j library (not a bot specifically, but code that allows compiling the library to native)?

Thinking if the repository should be named quarkus-discord4j and contain the modules you created or simply go with quarkus-discord-bot (I'm not very good with names, any suggestions?).

Another question: in Quarkus we prefer to expose reactive APIs using the SmallRye Mutiny API instead of the reactor libraries. Is this something that could be supported in this extension?

gastaldi avatar Aug 10 '22 04:08 gastaldi

Really nice project.

But yes Reactor usage would mean multiple event loops = inefficient and potential deadlocks.

Any way to avoid it?

maxandersen avatar Aug 10 '22 05:08 maxandersen

Another question: in Quarkus we prefer to expose reactive APIs using the SmallRye Mutiny API instead of the reactor libraries. Is this something that could be supported in this extension?

This is a very good point. It's only about preference, the usage of Mutiny also makes it a lot easier for users to use the rest of the Reactive Quarkus ecosystem, to say nothing of having a better runtime footprint if there is a single Reactive Streams implementation.

geoand avatar Aug 10 '22 05:08 geoand

Also small thing: if it wasn't created with the Quarkiverse template initially, probably a good idea to create the extension with the Quarkiverse template and copy the code there following the Quarkiverse conventions. That way everything will be set up properly, especially the workflows.

In any case, that's a good addition and Quarkiverse is the perfect home for it.

gsmet avatar Aug 10 '22 07:08 gsmet

Thanks all!

One question: can this extension also be used to create Discord API client apps using the Discord4j library (not a bot specifically, but code that allows compiling the library to native)?

It does contain some Graal substitutions for D4J that I could move out into a separate extension if desired.

As for Reactor, unfortunately D4J relies on it heavily so I'm not sure how to workaround it. Is there a way to configure the event loops that Reactor uses? Either way though, it would be bringing in and exposing an extra reactive streams implementation, unfortunately.

There are a few other Discord libs for Java that don't use Reactor, but I'm not familiar with them, and I started work on this project before I put much thought into it (I like Quarkus and D4J so I wanted to use them together).

Also small thing: if it wasn't created with the Quarkiverse template initially, probably a good idea to create the extension with the Quarkiverse template and copy the code there following the Quarkiverse conventions.

I hadn't and can do that in a bit. I'll update again once I'm done.

cottoncammy avatar Aug 10 '22 17:08 cottoncammy

Just recreated the repository using the Quarkiverse template. I'm currently relying on two environment variables (a Discord bot token and a Discord server ID) to test the deployment modules (I haven't learned Mockito yet) so the tests will fail without those defined somewhere.

cottoncammy avatar Aug 10 '22 23:08 cottoncammy

@gsmet Sorry for the ping, just wanted to check in and see if I needed to do anything else. I believe I found a way to configure Reactor Netty to reuse Quarkus's event loop group in this commit.

cottoncammy avatar Aug 24 '22 23:08 cottoncammy

One question: can this extension also be used to create Discord API client apps using the Discord4j library (not a bot specifically, but code that allows compiling the library to native)?

Thinking if the repository should be named quarkus-discord4j and contain the modules you created or simply go with quarkus-discord-bot (I'm not very good with names, any suggestions?).

@cameronprater any suggestions?

gastaldi avatar Sep 19 '22 13:09 gastaldi

@gastaldi The native substitutions in the extension mainly pertain to removing static analysis to SSLContext when GatewayDiscordClient#login is called (this is the WebSocket client which is a bot's connection to Discord, so not useful without a bot). There are a few other substitutions for removing Reactor Netty's usage of Micrometer.

I think quarkus-discord4j might be a better name than the current one, in case someone else in the future creates an extension for a different Discord library (I can't think of any better names), but I'm not sure that a separate extension for the native substitutions would be useful on their own.

cottoncammy avatar Sep 25 '22 08:09 cottoncammy