throttle negative and positive karma independently of each other
closes #117
This commit is contained in:
parent
1478b3bb32
commit
8c58d33fa3
1 changed files with 19 additions and 5 deletions
|
@ -25,7 +25,22 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
@utils.hook("new.user")
|
@utils.hook("new.user")
|
||||||
def new_user(self, event):
|
def new_user(self, event):
|
||||||
event["user"].last_karma = None
|
event["user"]._last_positive_karma = None
|
||||||
|
event["user"]._last_negative_karma = None
|
||||||
|
|
||||||
|
def _check_throttle(self, user, positive):
|
||||||
|
timestamp = None
|
||||||
|
if positive:
|
||||||
|
timestamp = user._last_positive_karma
|
||||||
|
else:
|
||||||
|
timestamp = user._last_negative_karma
|
||||||
|
return timestamp == None or (time.time()-timestamp
|
||||||
|
) >= KARMA_DELAY_SECONDS
|
||||||
|
def _set_throttle(self, user, positive):
|
||||||
|
if positive:
|
||||||
|
user._last_positive_karma = time.time()
|
||||||
|
else:
|
||||||
|
user._last_negative_karma = time.time()
|
||||||
|
|
||||||
@utils.hook("command.regex")
|
@utils.hook("command.regex")
|
||||||
@utils.kwarg("command", "karma")
|
@utils.kwarg("command", "karma")
|
||||||
|
@ -34,9 +49,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
verbose = event["target"].get_setting("karma-verbose", False)
|
verbose = event["target"].get_setting("karma-verbose", False)
|
||||||
nickname_only = event["server"].get_setting("karma-nickname-only",
|
nickname_only = event["server"].get_setting("karma-nickname-only",
|
||||||
False)
|
False)
|
||||||
|
positive = event["match"].group(2)[0] == "+"
|
||||||
|
|
||||||
if not event["user"].last_karma or (time.time()-event["user"
|
if self._check_throttle(event["user"], positive):
|
||||||
].last_karma) >= KARMA_DELAY_SECONDS:
|
|
||||||
target = event["match"].group(1).strip().rstrip("".join(WORD_STOP))
|
target = event["match"].group(1).strip().rstrip("".join(WORD_STOP))
|
||||||
if not target:
|
if not target:
|
||||||
return
|
return
|
||||||
|
@ -55,7 +70,6 @@ class Module(ModuleManager.BaseModule):
|
||||||
if not event["target"].has_user(user):
|
if not event["target"].has_user(user):
|
||||||
return
|
return
|
||||||
|
|
||||||
positive = event["match"].group(2)[0] == "+"
|
|
||||||
karma = setting_target.get_setting(setting, 0)
|
karma = setting_target.get_setting(setting, 0)
|
||||||
karma += 1 if positive else -1
|
karma += 1 if positive else -1
|
||||||
|
|
||||||
|
@ -68,7 +82,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if verbose:
|
if verbose:
|
||||||
event["stdout"].write(
|
event["stdout"].write(
|
||||||
"%s now has %s karma" % (target, karma_str))
|
"%s now has %s karma" % (target, karma_str))
|
||||||
event["user"].last_karma = time.time()
|
self._set_throttle(event["user"], positive)
|
||||||
elif verbose:
|
elif verbose:
|
||||||
event["stderr"].write("Try again in a couple of seconds")
|
event["stderr"].write("Try again in a couple of seconds")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue