Revamp event system #11

Closed
opened 2025-11-30 11:48:52 +00:00 by kuschelyagi · 2 comments
Owner

The event system is outdated and doesn't work well with async/await, which modern bot libraries are using.

The event system is outdated and doesn't work well with async/await, which modern bot libraries are using.
kuschelyagi added this to the 2026.02 milestone 2025-11-30 11:48:52 +00:00
Author
Owner

Since I have a basic working discord module now I can flesh out the event handling system a bit.

I'm thinking there are two basic interfaces for event handling: add_event_listener(event, handler) which works like the equivalent named method in javascript, and a subscribe method that takes a table/object of (event => handler) methods. The first method is more simple wile the second allows a stateful object to be used to register for a bunch of events at once.

There will most likely be some sort of helper utility on the rust side to make implementing and using these interfaces easier. Maybe a "EventListener" struct which encapsulates the contained lua registry keys and the logic for dispatching events. I'm thinking a lot of the logic being developed in the discord module will be spun off into a helper library.

Since I have a basic working discord module now I can flesh out the event handling system a bit. I'm thinking there are two basic interfaces for event handling: `add_event_listener(event, handler)` which works like the equivalent named method in javascript, and a `subscribe` method that takes a table/object of (event => handler) methods. The first method is more simple wile the second allows a stateful object to be used to register for a bunch of events at once. There will most likely be some sort of helper utility on the rust side to make implementing and using these interfaces easier. Maybe a "EventListener" struct which encapsulates the contained lua registry keys and the logic for dispatching events. I'm thinking a lot of the logic being developed in the discord module will be spun off into a helper library.
Author
Owner

I successfully extracted the event handler implementation into a common library which is shared among all cores.

I also had the idea to have the event handler return a list of outgoing messages sent from the event callbacks. This more cleanly separates the lua-level event handling from the core-level chat integration than was possible in the 2017 edition, which iirc had to pass around a "MessageSender" object which wrapped those details.

I successfully extracted the event handler implementation into a common library which is shared among all cores. I also had the idea to have the event handler return a list of outgoing messages sent from the event callbacks. This more cleanly separates the lua-level event handling from the core-level chat integration than was possible in the 2017 edition, which iirc had to pass around a "MessageSender" object which wrapped those details.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
elsanctum/tenquestionmarks#11
No description provided.