Browse Source

some cleanup; use command issuer's IRC nick as username if none is provided

tags/v0.1^2
Ben Kurtovic 13 years ago
parent
commit
7c8353530a
2 changed files with 15 additions and 16 deletions
  1. +7
    -8
      bot/commands/editcount.py
  2. +8
    -8
      bot/commands/rights.py

+ 7
- 8
bot/commands/editcount.py View File

@@ -17,23 +17,22 @@ class Command(BaseCommand):


def process(self, data): def process(self, data):
if not data.args: 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 = wiki.get_site()
site._maxlag = None site._maxlag = None
user = site.get_user(username)
user = site.get_user(name)


try: try:
count = user.editcount() count = user.editcount()
except wiki.UserNotFoundError: except wiki.UserNotFoundError:
msg = "the user \x0302{0}\x0301 does not exist." msg = "the user \x0302{0}\x0301 does not exist."
self.connection.reply(data, msg.format(username))
self.connection.reply(data, msg.format(name))
return return


safe = quote_plus(user.name())
url = "http://toolserver.org/~soxred93/pcount/index.php?name={0}&lang=en&wiki=wikipedia" 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})." 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)))

+ 8
- 8
bot/commands/rights.py View File

@@ -4,7 +4,7 @@ from classes import BaseCommand
import wiki import wiki


class Command(BaseCommand): class Command(BaseCommand):
"""Retrieve a list of rights for a given username."""
"""Retrieve a list of rights for a given name."""
name = "rights" name = "rights"


def check(self, data): def check(self, data):
@@ -15,19 +15,19 @@ class Command(BaseCommand):


def process(self, data): def process(self, data):
if not data.args: 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 = wiki.get_site()
site._maxlag = None site._maxlag = None
user = site.get_user(username)
user = site.get_user(name)
try: try:
rights = user.groups() rights = user.groups()
except wiki.UserNotFoundError: except wiki.UserNotFoundError:
msg = "the user \x0302{0}\x0301 does not exist." msg = "the user \x0302{0}\x0301 does not exist."
self.connection.reply(data, msg.format(username))
self.connection.reply(data, msg.format(name))
return return


try: try:
@@ -35,4 +35,4 @@ class Command(BaseCommand):
except ValueError: except ValueError:
pass pass
msg = "the rights for \x0302{0}\x0301 are {1}." 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)))

Loading…
Cancel
Save