diff options
| author | 2018-08-31 10:50:37 +0100 | |
|---|---|---|
| committer | 2018-08-31 10:50:37 +0100 | |
| commit | abed9cf4ea71dcbad2dd2c049683b8d14b942e09 (patch) | |
| tree | 3e40caf63fa7e1500469f4ad9a0c45c51808aad4 /modules/urbandictionary.py | |
| parent | Fix a copy paste fail in IRCLineHandler that caused PARTs to be handled as QUITs (diff) | |
| signature | ||
Reformat
Diffstat (limited to 'modules/urbandictionary.py')
| -rw-r--r-- | modules/urbandictionary.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/modules/urbandictionary.py b/modules/urbandictionary.py index d2bcc441..657df127 100644 --- a/modules/urbandictionary.py +++ b/modules/urbandictionary.py @@ -4,12 +4,13 @@ import Utils URL_URBANDICTIONARY = "http://api.urbandictionary.com/v0/define" REGEX_DEFNUMBER = re.compile("-n(\d+) \S+") + class Module(object): def __init__(self, bot): bot.events.on("received").on("command").on("urbandictionary", "ud" - ).hook(self.ud, min_args=1, - help="Get the definition of a provided term", - usage="<term>") + ).hook(self.ud, min_args=1, + help="Get the definition of a provided term", + usage="<term>") def ud(self, event): term = event["args"] @@ -19,14 +20,17 @@ class Module(object): number = int(match.group(1)) term = term.split(" ", 1)[1] page = Utils.get_url(URL_URBANDICTIONARY, get_params={"term": term}, - json=True) + json=True) if page: if len(page["list"]): - if number > 0 and len(page["list"]) > number-1: - definition = page["list"][number-1] + if number > 0 and len(page["list"]) > number - 1: + definition = page["list"][number - 1] event["stdout"].write("%s: %s" % (definition["word"], - definition["definition"].replace("\n", " ").replace( - "\r", "").replace(" ", " "))) + definition[ + "definition"].replace( + "\n", " ").replace( + "\r", "").replace( + " ", " "))) else: event["stderr"].write("Definition number does not exist") else: |
