-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add global and channel rate limits #1065
Changes from 1 commit
b49a32e
56d6b58
91cd3ac
f5a742a
5479ed4
f8edf1b
6e411d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,7 +158,9 @@ def clean_callable(func, config): | |
func.unblockable = getattr(func, 'unblockable', False) | ||
func.priority = getattr(func, 'priority', 'medium') | ||
func.thread = getattr(func, 'thread', True) | ||
func.rate = getattr(func, 'rate', 0) | ||
func.user_rate = getattr(func, 'user_rate', 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing |
||
func.channel_rate = getattr(func, 'channel_rate', 0) | ||
func.global_rate = getattr(func, 'global_rate', 0) | ||
|
||
if not hasattr(func, 'event'): | ||
func.event = ['PRIVMSG'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,8 +248,10 @@ def add_attribute(function): | |
return add_attribute | ||
|
||
|
||
def rate(value): | ||
"""Decorate a function to limit how often a single user may trigger it. | ||
def rate(user_rate, channel_rate=0, global_rate=0): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason not to also specify a default value for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No particular reason, other than that I don't know what a good default would be. If zero, that's the same as having no @Rate decorator at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would, however, allow using the decorator like I'd bet whoever owns the username "rate" on Github is going to get mighty tired of this thread. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't think of that; It was 3 in the morning, haha. Fixed now. |
||
"""Decorate a function to limit how often it can be triggered. Without | ||
arguments, the limit defaults to per-user. The global and channel parameters | ||
are self-explanatory. A value of zero means no limit. | ||
|
||
If a function is given a rate of 20, a single user may only use that | ||
function once every 20 seconds. This limit applies to each user | ||
|
@@ -260,7 +262,9 @@ def rate(value): | |
threading.Timer() instead of sched, or rate limiting will not work properly. | ||
""" | ||
def add_attribute(function): | ||
function.rate = value | ||
function.user_rate = user_rate | ||
function.channel_rate = channel_rate | ||
function.global_rate = global_rate | ||
return function | ||
return add_attribute | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timediff
is undefined, should bechantimediff