Skip to content

Commit

Permalink
plugin: using sched in rate-limited callables no longer breaks
Browse files Browse the repository at this point in the history
This appears to have been fixed as part of the big rule-system rewrite
back in 7.1. The rule system now also considers the *start* time of the
callable's most recent run in the given context, if it hasn't finished
running since the last time it was started.

I also tested this with a very basic plugin:

    import sched
    import time

    from sopel import plugin

    s = sched.scheduler(time.time, time.sleep)

    @plugin.rate(60)
    @plugin.command('testrate')
    def rate_limited(bot, trigger):
        s.enter(30, 2, bot.say, argument=('hi',))
        s.run()

Despite trying to run `.testrate` three times in a few seconds, as a non
admin user, the bot only said "hi" once.
  • Loading branch information
dgw committed Sep 2, 2024
1 parent 148bb6c commit 69f8393
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions sopel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,10 +1193,6 @@ def rate(
@rate(10, 10, 2, message='Sorry {nick}, you hit the {rate_limit_type} rate limit!')
Rate-limited functions that use scheduled future commands should import
:class:`threading.Timer` instead of :mod:`sched`, or rate limiting will
not work properly.
.. versionchanged:: 8.0
Optional keyword argument ``message`` was added in Sopel 8.
Expand Down

0 comments on commit 69f8393

Please sign in to comment.