From eb1b997fa6b514ca968c34285c58f8223b0855d0 Mon Sep 17 00:00:00 2001 From: WingsOfAltair Date: Thu, 21 Jan 2016 13:51:10 +0200 Subject: [PATCH] Added imdb command This command provides information about a certain movie using IMDB's API. Usage example: !imdb The dark knight --- red.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/red.py b/red.py index 72c5cf99c..14d3f8f1f 100644 --- a/red.py +++ b/red.py @@ -43,6 +43,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 +!imdb - Retrieves a movie's information from IMDB using its title !urban [text] - Search definitions in the urban dictionary !customcommands - Custom commands' list !addcom [command] [text] - Add a custom command @@ -200,6 +201,8 @@ async def on_message(message): pass elif message.content.startswith('!gif'): await gif(message) + elif message.content.startswith('!imdb'): + await imdb(message) elif message.content.startswith('!urban'): await urban(message) elif message.content.startswith('!uptime'): @@ -909,6 +912,29 @@ async def image(message): # API's dead. await client.send_message(message.channel, "!image [text]") """ +async def imdb(message): # Method added by BananaWaffles. + 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.myapifilms.com/imdb/title?format=json&title=" + msg + "&token=" + yourtokenhere + async with aiohttp.get(search) as r: + result = await r.json() + title = result['data']['movies'][0]['title'] + year = result['data']['movies'][0]['year'] + rating = result['data']['movies'][0]['rating'] + url = result['data']['movies'][0]['urlIMDB'] + msg = "Title: " + title + " | Released on: " + year + " | IMDB Rating: " + rating + ".\n" + url + await client.send_message(message.channel, msg) + except: + await client.send_message(message.channel, "Error.") + else: + await client.send_message(message.channel, "Invalid search.") + else: + await client.send_message(message.channel, "$imdb [text]") + async def urban(message): msg = message.content.split() if len(msg) > 1: @@ -1857,4 +1883,4 @@ if __name__ == '__main__': logger.error(e) loop.run_until_complete(client.logout()) finally: - loop.close() \ No newline at end of file + loop.close()