simmsb / calamity

A library for writing discord bots in haskell
https://hackage.haskell.org/package/calamity
MIT License
109 stars 11 forks source link

Sequencing of events? #55

Open MorrowM opened 1 year ago

MorrowM commented 1 year ago

This is more of a question than an issue, but is there a way to figure out which event occurred first between two events?

My use-case is that I have a bot that sends join and leave messages into a text channel whenever someone joins or leaves an associated voice channel. I have a handler which reacts to VoiceStateUpdateEvts and sends the appropriate message. The issue is that sometimes someone joins and immediately leaves a voice channel (or vice-versa). When that occurs it can sometimes happen that the leave event is handled before the join event which means the messages are sent out of order.

So my question is whether there's a way to recover such ordering information. From the Discord API I see there's some sort of sequence number but I'm not sure whether that's suitable for this.

simmsb commented 1 year ago

We could definitely add something to the event handler context to include the sequence number, though I really wouldn't be surprised if discord is sending the events out of order to begin with. The only point of parallelism in event handling is each event handling running in its own thread, internal library event handling is sequential until that point.