From b046c36052540e554e4f8947ed3a533466a697bc Mon Sep 17 00:00:00 2001 From: David Schultz Date: Mon, 11 Jan 2021 11:04:57 -0600 Subject: [PATCH] make karmawho work better --- modules/karma.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/karma.py b/modules/karma.py index bf21b3b5..b5df23f3 100644 --- a/modules/karma.py +++ b/modules/karma.py @@ -14,6 +14,11 @@ REGEX_PARENS = re.compile(r"\(([^)]+)\)(\+\+|--)") @utils.export("channelset", utils.BoolSetting("karma-pattern", "Enable/disable parsing ++/-- karma format")) 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): karma_str = str(karma) if karma < 0: @@ -134,8 +139,12 @@ class Module(ModuleManager.BaseModule): reverse=True) 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" % - (target, ", ".join(parts))) + (target, self.listify(parts))) def _get_karma(self, server, target, own=False): settings = dict(server.get_all_user_settings("karma-%s" % target))