jaraco / irc

Full-featured Python IRC library for Python.
MIT License
392 stars 87 forks source link

Ratelimit notices #18

Closed jaraco closed 8 years ago

jaraco commented 8 years ago

Given certain situations, it's possible for someone to force a bot to exit if too many notices are buffered.

I'm sure I could rate limit in my code, but a forced rate limit in the lib might also be warranted.


jaraco commented 8 years ago

I've put together a draft implementation that would allow one to set a rate limit on a connection in 95d201adc509. One would simply call connection.set_rate_limit with a number (messages per second), and it would install a throttler on the send_raw method.

Let me know what you think, and if that interface would be suitable.


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

When trying to run it, hit a few snags - not sure if it's me. (not a python guy yet).

client.py - line 967 : should it be .count() not .Count() client.py - line 971 : self.start isn't a function (I think)

Finally, what I can't figure out is this traceback:

File "./libs/irc/bot.py", line 259, in start self._connect() File "./libs/irc/bot.py", line 115, in _connect _self.__connect_params) File "./libs/irc/client.py", line 1173, in connect self.connection.connect(_args, _kwargs) File "./libs/irc/functools.py", line 37, in wrapper return method(self, args, _kwargs) File "./libs/irc/client.py", line 494, in connect self.nick(self.nickname) File "./libs/irc/client.py", line 816, in nick self.send_raw("NICK " + newnick) File "./libs/irc/client.py", line 974, in call return self.func() TypeError: send_raw() takes exactly 2 arguments (1 given)


Original comment by: Jason Kendall

jaraco commented 8 years ago

Thanks for the help in troubleshooting and for the pull request. I've accepted the pull request and taken the opportunity to also add a couple of tests to exercise the Throttler class (something I would normally have done early).

I've released 8.2 with this feature. Please let me know if you encounter any other issues.


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

Fixed and released in 8.2


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

Thanks Jason. No way I would have thought of that method. Good learning for me as well.


Original comment by: Jason Kendall