Bladeren bron

Some anti-hardcoding refactor work and other fixes.

tags/v0.1^2
Ben Kurtovic 12 jaren geleden
bovenliggende
commit
09bfc441b0
5 gewijzigde bestanden met toevoegingen van 23 en 49 verwijderingen
  1. +0
    -38
      earwigbot/commands/_old.py
  2. +3
    -2
      earwigbot/commands/editcount.py
  3. +11
    -6
      earwigbot/commands/git.py
  4. +1
    -1
      earwigbot/commands/registration.py
  5. +8
    -2
      earwigbot/commands/replag.py

+ 0
- 38
earwigbot/commands/_old.py Bestand weergeven

@@ -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, ">, <http://en.wikipedia.org/wiki/")
s = "<http://en.wikipedia.org/wiki/%s>" % s
s = re.sub(" ", "_", s)
s = re.sub(">,_<", ">, <", s)
report = "\x02First %s pending AfC submissions:\x0F %s" % (number, s)
say(report, chan)
return


if command == "trout":
try:
user = line2[4]


+ 3
- 2
earwigbot/commands/editcount.py Bestand weergeven

@@ -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))

+ 11
- 6
earwigbot/commands/git.py Bestand weergeven

@@ -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):


+ 1
- 1
earwigbot/commands/registration.py Bestand weergeven

@@ -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))


+ 8
- 2
earwigbot/commands/replag.py Bestand weergeven

@@ -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))

Laden…
Annuleren
Opslaan