diff --git a/bot/commands/editcount.py b/bot/commands/editcount.py new file mode 100644 index 0000000..df136f7 --- /dev/null +++ b/bot/commands/editcount.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +from classes import BaseCommand +import wiki + +class Command(BaseCommand): + """Return a user's edit count.""" + name = "editcount" + + def check(self, data): + commands = ["ec", "editcount"] + if data.is_command and data.command in commands: + return True + return False + + def process(self, data): + if not data.args: + self.connection.reply(data, "who do you want me to look up?") + return + + username = ' '.join(data.args) + site = wiki.get_site() + site._maxlag = None + user = site.get_user(username) + + try: + count = user.editcount() + except wiki.UserNotFoundError: + msg = "the user \x0302{0}\x0301 does not exist." + self.connection.reply(data, msg.format(username)) + return + + msg = "\x0302{0}\x0301 has {1} edits." + self.connection.reply(data, msg.format(username, count)) diff --git a/bot/wiki/page.py b/bot/wiki/page.py index 62cba0d..41a789b 100644 --- a/bot/wiki/page.py +++ b/bot/wiki/page.py @@ -514,4 +514,4 @@ class Page(object): def add_section(self, text, title, minor=False, bot=True): """ """ - pass \ No newline at end of file + pass