Revamp event system #11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The event system is outdated and doesn't work well with async/await, which modern bot libraries are using.
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 asubscribemethod 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.
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.