Open shizmob opened 8 years ago
I didn't realize pydle even had a flood control model until I saw this issue -- after implementing my own solution in an IRC bot framework I'm working on.
I wrote a solution here that you're welcome to adopt, though it probably needs some improvements to play nicer with asyncio and hasn't been extensively tested. That said, the basic concept is:
burst
units and refills at a rate of 1 unit every rate
seconds.collections.deque
of pending events and how much one event 'costs' (Usually the cost is 1 unit)Throttle.tick()
figures out how long it has been since the last tick, refills the bucket accordingly, and then pulls events from the queue (draining cost
units from the bucket each time)tick
) return a timedelta
of how long the caller should wait before ticking the queue again. This will be None if the queue is empty and the bucket is full.Updated link with a different, cleaner implementation:
https://github.com/dewiniaid/pydle-ircbot/blob/b85cb5bed4113099bab36be93a283a7daeb0088a/util.py#L34
Currently, pydle's flood model is very limited in its possibilites:
pydle.connection
module, and should be configurable per-client.pydle.connection.Connection._on_write
is messy.