add !addpoint and !rmpoint (explicit ++/-- karma)

This commit is contained in:
jesopo 2019-08-15 13:38:04 +01:00
parent bd5bc81d1c
commit 6332f80dc9

View file

@ -42,33 +42,22 @@ class Module(ModuleManager.BaseModule):
else: else:
user._last_negative_karma = time.time() user._last_negative_karma = time.time()
@utils.hook("command.regex")
@utils.kwarg("command", "karma")
@utils.kwarg("pattern", REGEX_KARMA)
def channel_message(self, event):
verbose = event["target"].get_setting("karma-verbose", False)
nickname_only = event["server"].get_setting("karma-nickname-only",
False)
positive = event["match"].group(2)[0] == "+"
if self._check_throttle(event["user"], positive): def _karma(self, server, sender, target, positive):
target = event["match"].group(1).strip().rstrip("".join(WORD_STOP)) if self._check_throttle(sender, positive):
if not target: nickname_only = server.get_setting("karma-nickname-only", False)
return
if event["server"].irc_lower(target) == event["user"].name: if server.irc_lower(target) == sender.name:
if verbose: return False, "You cannot change your own karma"
event["stderr"].write("You cannot change your own karma")
return
setting = "karma-%s" % target setting = "karma-%s" % target
setting_target = event["server"] setting_target = server
if nickname_only: if nickname_only:
user = event["server"].get_user(target) user = server.get_user(target, create=False)
if user == None:
return False, "No such user"
setting = "karma" setting = "karma"
setting_target = user setting_target = user
if not event["target"].has_user(user):
return
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
@ -79,12 +68,33 @@ class Module(ModuleManager.BaseModule):
setting_target.del_setting(setting) setting_target.del_setting(setting)
karma_str = self._karma_str(karma) karma_str = self._karma_str(karma)
self._set_throttle(sender, positive)
return True, "%s now has %s karma" % (target, karma_str)
else:
return False, "Try again in a couple of seconds"
@utils.hook("command.regex")
@utils.kwarg("command", "karma")
@utils.kwarg("pattern", REGEX_KARMA)
def channel_message(self, event):
verbose = event["target"].get_setting("karma-verbose", False)
positive = event["match"].group(2)[0] == "+"
target = event["match"].group(1).strip().rstrip("".join(WORD_STOP))
if target:
success, message = self._karma(event["server"], event["user"],
target, positive)
if verbose: if verbose:
event["stdout"].write( event["stdout" if success else "stderr"].write(message)
"%s now has %s karma" % (target, karma_str))
self._set_throttle(event["user"], positive) @utils.hook("received.command.addpoint")
elif verbose: @utils.hook("received.command.rmpoint")
event["stderr"].write("Try again in a couple of seconds") @utils.kwarg("min_args", 1)
@utils.kwarg("usage", "<target>")
def changepoint(self, event):
positive = event.name == "received.command.addpoint"
success, message = self._karma(event["server"], event["user"],
event["args"].strip(), positive)
event["stdout" if success else "stderr"].write(message)
@utils.hook("received.command.karma") @utils.hook("received.command.karma")
def karma(self, event): def karma(self, event):