From 09bfc441b0d75d32e9c5d635f333d0a5c79c6d87 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Wed, 4 Jul 2012 02:02:33 -0400 Subject: [PATCH] Some anti-hardcoding refactor work and other fixes. --- earwigbot/commands/_old.py | 38 -------------------------------------- earwigbot/commands/editcount.py | 5 +++-- earwigbot/commands/git.py | 17 +++++++++++------ earwigbot/commands/registration.py | 2 +- earwigbot/commands/replag.py | 10 ++++++++-- 5 files changed, 23 insertions(+), 49 deletions(-) diff --git a/earwigbot/commands/_old.py b/earwigbot/commands/_old.py index 3767fa9..8681b8b 100644 --- a/earwigbot/commands/_old.py +++ b/earwigbot/commands/_old.py @@ -128,44 +128,6 @@ def parse(command, line, line2, nick, chan, host, auth, notice, say, reply, s): return - if command == "sub" or command == "submissions": - try: - number = int(line2[4]) - except Exception: - reply("Please enter a number.", chan, nick) - return - do_url = False - try: - if "url" in line2[5:]: do_url = True - except Exception: - pass - url = "http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Pending_AfC_submissions&cmlimit=500&cmsort=timestamp" - query = urllib.urlopen(url) - data = query.read() - pages = re.findall("title="(.*?)"", data) - try: - pages.remove("Wikipedia:Articles for creation/Redirects") - except Exception: - pass - try: - pages.remove("Wikipedia:Files for upload") - except Exception: - pass - pages.reverse() - pages = pages[:number] - if not do_url: - s = string.join(pages, "]], [[") - s = "[[%s]]" % s - else: - s = string.join(pages, ">, ,_<", ">, <", s) - report = "\x02First %s pending AfC submissions:\x0F %s" % (number, s) - say(report, chan) - return - - if command == "trout": try: user = line2[4] diff --git a/earwigbot/commands/editcount.py b/earwigbot/commands/editcount.py index 60f225d..b25269f 100644 --- a/earwigbot/commands/editcount.py +++ b/earwigbot/commands/editcount.py @@ -47,6 +47,7 @@ class Command(BaseCommand): return safe = quote_plus(user.name) - url = "http://toolserver.org/~tparis/pcount/index.php?name={0}&lang=en&wiki=wikipedia" + url = "http://toolserver.org/~tparis/pcount/index.php?name={0}&lang={1}&wiki={2}" + fullurl = url.format(safe, site.lang, site.project) msg = "\x0302{0}\x0301 has {1} edits ({2})." - self.reply(data, msg.format(name, count, url.format(safe))) + self.reply(data, msg.format(name, count, fullurl)) diff --git a/earwigbot/commands/git.py b/earwigbot/commands/git.py index 8ee3f22..07c681a 100644 --- a/earwigbot/commands/git.py +++ b/earwigbot/commands/git.py @@ -30,10 +30,12 @@ class Command(BaseCommand): """Commands to interface with the bot's git repository; use '!git' for a sub-command list.""" name = "git" - repos = { - "core": "/home/earwig/git/earwigbot", - "plugins": "/home/earwig/git/earwigbot-plugins", - } + + def setup(self): + try: + self.repos = self.config.commands[self.name]["repos"] + except KeyError: + self.repos = None def process(self, data): self.data = data @@ -44,6 +46,9 @@ class Command(BaseCommand): if not data.args or data.args[0] == "help": self.do_help() return + if not self.repos: + self.reply(data, "no repos are specified in the config file.") + return command = data.args[0] try: @@ -55,7 +60,7 @@ class Command(BaseCommand): return if repo_name not in self.repos: repos = self.get_repos() - msg = "repository must be one of the following: {0}" + msg = "repository must be one of the following: {0}." self.reply(data, msg.format(repos)) return self.repo = git.Repo(self.repos[repo_name]) @@ -89,7 +94,7 @@ class Command(BaseCommand): try: return getattr(self.repo.remotes, remote_name) except AttributeError: - msg = "unknown remote: \x0302{0}\x0301".format(remote_name) + msg = "unknown remote: \x0302{0}\x0301.".format(remote_name) self.reply(self.data, msg) def get_time_since(self, date): diff --git a/earwigbot/commands/registration.py b/earwigbot/commands/registration.py index 88c4119..4c8b099 100644 --- a/earwigbot/commands/registration.py +++ b/earwigbot/commands/registration.py @@ -54,7 +54,7 @@ class Command(BaseCommand): elif user.gender == "female": gender = "She's" else: - gender = "They're" + gender = "They're" # Singluar they? msg = "\x0302{0}\x0301 registered on {1}. {2} {3} old." self.reply(data, msg.format(name, date, gender, age)) diff --git a/earwigbot/commands/replag.py b/earwigbot/commands/replag.py index ab81319..b8899bc 100644 --- a/earwigbot/commands/replag.py +++ b/earwigbot/commands/replag.py @@ -30,10 +30,16 @@ class Command(BaseCommand): """Return the replag for a specific database on the Toolserver.""" name = "replag" + def setup(self): + try: + self.key = self.config.commands[self.name]["default"] + except KeyError: + self.default = None + def process(self, data): args = {} if not data.args: - args["db"] = "enwiki_p" + args["db"] = self.default or self.bot.wiki.get_site().name + "_p" else: args["db"] = data.args[0] args["host"] = args["db"].replace("_", "-") + ".rrdb.toolserver.org" @@ -47,5 +53,5 @@ class Command(BaseCommand): replag = int(cursor.fetchall()[0][0]) conn.close() - msg = "Replag on \x0302{0}\x0301 is \x02{1}\x0F seconds." + msg = "replag on \x0302{0}\x0301 is \x02{1}\x0F seconds." self.reply(data, msg.format(args["db"], replag))