From 7c8353530a98e857061b5a143c94c2fdde040672 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 21 Aug 2011 21:21:50 -0400 Subject: [PATCH] some cleanup; use command issuer's IRC nick as username if none is provided --- bot/commands/editcount.py | 15 +++++++-------- bot/commands/rights.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/bot/commands/editcount.py b/bot/commands/editcount.py index 061c473..71e2492 100644 --- a/bot/commands/editcount.py +++ b/bot/commands/editcount.py @@ -17,23 +17,22 @@ class Command(BaseCommand): def process(self, data): if not data.args: - self.connection.reply(data, "who do you want me to look up?") - return + name = data.nick + else: + name = ' '.join(data.args) - username = ' '.join(data.args) site = wiki.get_site() site._maxlag = None - user = site.get_user(username) + user = site.get_user(name) try: count = user.editcount() except wiki.UserNotFoundError: msg = "the user \x0302{0}\x0301 does not exist." - self.connection.reply(data, msg.format(username)) + self.connection.reply(data, msg.format(name)) return + safe = quote_plus(user.name()) url = "http://toolserver.org/~soxred93/pcount/index.php?name={0}&lang=en&wiki=wikipedia" - url = url.format(quote_plus(user.name())) - msg = "\x0302{0}\x0301 has {1} edits ({2})." - self.connection.reply(data, msg.format(username, count, url)) + self.connection.reply(data, msg.format(name, count, url.format(safe))) diff --git a/bot/commands/rights.py b/bot/commands/rights.py index a38dfdf..db436a7 100644 --- a/bot/commands/rights.py +++ b/bot/commands/rights.py @@ -4,7 +4,7 @@ from classes import BaseCommand import wiki class Command(BaseCommand): - """Retrieve a list of rights for a given username.""" + """Retrieve a list of rights for a given name.""" name = "rights" def check(self, data): @@ -15,19 +15,19 @@ class Command(BaseCommand): def process(self, data): if not data.args: - self.connection.reply(data, "who do you want me to look up?") - return + name = data.nick + else: + name = ' '.join(data.args) - username = ' '.join(data.args) site = wiki.get_site() site._maxlag = None - user = site.get_user(username) - + user = site.get_user(name) + try: rights = user.groups() except wiki.UserNotFoundError: msg = "the user \x0302{0}\x0301 does not exist." - self.connection.reply(data, msg.format(username)) + self.connection.reply(data, msg.format(name)) return try: @@ -35,4 +35,4 @@ class Command(BaseCommand): except ValueError: pass msg = "the rights for \x0302{0}\x0301 are {1}." - self.connection.reply(data, msg.format(username, ', '.join(rights))) + self.connection.reply(data, msg.format(name, ', '.join(rights)))