From e293d0546c4cd424258c7ce4ad19d992e75647eb Mon Sep 17 00:00:00 2001 From: crysis909 Date: Sat, 9 Jan 2016 00:15:51 +0100 Subject: [PATCH] New Command [!urban] Added Urban Dictionary --- red.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/red.py b/red.py index 621e59ace..6077779ee 100644 --- a/red.py +++ b/red.py @@ -42,6 +42,7 @@ help = """**Commands list:** !stoptwitchalert [stream] - Stop sending alerts about the specified stream in the channel (admin only) !roll [number] - Random number between 0 and [number] !gif [text] - GIF search +!urban [text] - Search definitions in the urban dictionary !customcommands - Custom commands' list !addcom [command] [text] - Add a custom command !editcom [command] [text] - Edit a custom command @@ -166,6 +167,8 @@ async def on_message(message): pass elif message.content.startswith('!gif'): await gif(message) + elif message.content.startswith('!urban'): + await urban(message) elif message.content.startswith('!uptime'): await uptime(message) elif message.content.startswith('!avatar'): @@ -697,6 +700,28 @@ async def image(message): # API's dead. else: await client.send_message(message.channel, "!image [text]") +async def urban(message): + msg = message.content.split() + if len(msg) > 1: + if len(msg[1]) > 1 and len([msg[1]]) < 20: + try: + msg.remove(msg[0]) + msg = "+".join(msg) + search = "http://api.urbandictionary.com/v0/define?term=" + msg + result = requests.get(search).json() + if result["list"] != []: + definition = result['list'][0]['definition'] + example = result['list'][0]['example'] + await client.send_message(message.channel, "Definition: " + definition + "\n\n" + "Beispiel: " + example ) + else: + await client.send_message(message.channel, "Your search terms gave no results.") + except: + await client.send_message(message.channel, "Error.") + else: + await client.send_message(message.channel, "Invalid search.") + else: + await client.send_message(message.channel, "!urban [text]") + async def gif(message): msg = message.content.split() if len(msg) > 1: