make karmawho work better

This commit is contained in:
David Schultz 2021-01-11 11:04:57 -06:00 committed by GitHub
parent cb43a6ae2b
commit b046c36052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,6 +14,11 @@ REGEX_PARENS = re.compile(r"\(([^)]+)\)(\+\+|--)")
@utils.export("channelset", utils.BoolSetting("karma-pattern", @utils.export("channelset", utils.BoolSetting("karma-pattern",
"Enable/disable parsing ++/-- karma format")) "Enable/disable parsing ++/-- karma format"))
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def listify(self, items):
if type(items) != list:
items = list(items)
return len(items) > 2 and ', '.join(items[:-1]) + ', and ' + items[-1] or len(items) > 1 and items[0] + ' and ' + items[1] or items and items[0] or ''
def _karma_str(self, karma): def _karma_str(self, karma):
karma_str = str(karma) karma_str = str(karma)
if karma < 0: if karma < 0:
@ -134,8 +139,12 @@ class Module(ModuleManager.BaseModule):
reverse=True) reverse=True)
parts = ["%s (%d)" % (n, v) for n, v in karma] parts = ["%s (%d)" % (n, v) for n, v in karma]
print(parts)
if len(parts) == 0:
event["stdout"].write("%s has no karma." % target)
return
event["stdout"].write("%s has karma from: %s" % event["stdout"].write("%s has karma from: %s" %
(target, ", ".join(parts))) (target, self.listify(parts)))
def _get_karma(self, server, target, own=False): def _get_karma(self, server, target, own=False):
settings = dict(server.get_all_user_settings("karma-%s" % target)) settings = dict(server.get_all_user_settings("karma-%s" % target))