krisppurg / dimscord

A Discord Bot & REST Library for Nim.
https://krisppurg.github.io/dimscord/
MIT License
222 stars 22 forks source link

Make `DispatchEvent` be enum based #111

Closed ire4ever1190 closed 10 months ago

ire4ever1190 commented 1 year ago

Now dispatches events based on an enum instead of strings. This doesn't affect the users on_dispatch which still gets the raw event string.

Will rebase #110 on this so that it can use the enums instead of strings for specifying what event to listen for.

Conversion done via a script so shouldn't have missed anything

krisppurg commented 1 year ago

Since this a follow up to the waitforevent PR, what if the user wants to wait for an unknown event that isn’t in the enum? e.g. for instance imagine if the user wants to await for event “AUTO_MODERATION_CREATE” (ik its in the enum but say if it wasn’t implemented yet) the user would have to pass Unknown to the waitforevent proc and the user would not receive the event they wanted to wait for as there could be another unknown event that would be classified as Unknown as well.

ire4ever1190 commented 1 year ago

More of a precursor since this should be merged before the other PR.

For unknown events it could work, basically the dispatcher needs to call checkIfAwaiting to let the wait table know of a new event and run any handlers. Since we don't really know the data of an unknown event (Since its not implemented) then we could instead pass an object like

type
  UnknownEventData = ref object of DimscordObject
    eventName: string # e.g. AUTO_MODERATION_CREATE
    data: JsonNode

and then the handler could just check the eventName and then run any needed checks on top.

But if the user is relaying on unknown events then they should really raise an issue to have the event actually implemented. Should unknown events even be supported for awaiting? Since if they are implemented later then it will break users code

ire4ever1190 commented 1 year ago

I did not mean to close whoops

krisppurg commented 11 months ago

But if the user is relaying on unknown events then they should really raise an issue to have the event actually implemented. Should unknown events even be supported for awaiting? Since if they are implemented later then it will break users code

I believe so. But I think a good idea would be a raw json waitforevent so it would wait for any event and it would be JsonNode.

ire4ever1190 commented 10 months ago

Was annoying to merge this with master and then rebase #110 so will just close this and have these changes in that PR