diff options
| author | 2018-08-31 10:51:47 +0100 | |
|---|---|---|
| committer | 2018-08-31 10:51:47 +0100 | |
| commit | 90ce92dc39395444862edfc7946ef7a1195f2464 (patch) | |
| tree | 6832c146a15879df292d265083bfe5795cbdfa69 /modules/urbandictionary.py | |
| parent | Reformat (diff) | |
Revert "Reformat"
This reverts commit abed9cf
Diffstat (limited to 'modules/urbandictionary.py')
| -rw-r--r-- | modules/urbandictionary.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/modules/urbandictionary.py b/modules/urbandictionary.py index 657df127..d2bcc441 100644 --- a/modules/urbandictionary.py +++ b/modules/urbandictionary.py @@ -4,13 +4,12 @@ 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"] @@ -20,17 +19,14 @@ 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: |
