Added imdb command

This command provides information about a certain movie using IMDB's API.
Usage example: !imdb The dark knight
This commit is contained in:
WingsOfAltair 2016-01-21 13:51:10 +02:00
parent 7be20e127b
commit eb1b997fa6

28
red.py
View File

@ -43,6 +43,7 @@ help = """**Commands list:**
!stoptwitchalert [stream] - Stop sending alerts about the specified stream in the channel (admin only) !stoptwitchalert [stream] - Stop sending alerts about the specified stream in the channel (admin only)
!roll [number] - Random number between 0 and [number] !roll [number] - Random number between 0 and [number]
!gif [text] - GIF search !gif [text] - GIF search
!imdb - Retrieves a movie's information from IMDB using its title
!urban [text] - Search definitions in the urban dictionary !urban [text] - Search definitions in the urban dictionary
!customcommands - Custom commands' list !customcommands - Custom commands' list
!addcom [command] [text] - Add a custom command !addcom [command] [text] - Add a custom command
@ -200,6 +201,8 @@ async def on_message(message):
pass pass
elif message.content.startswith('!gif'): elif message.content.startswith('!gif'):
await gif(message) await gif(message)
elif message.content.startswith('!imdb'):
await imdb(message)
elif message.content.startswith('!urban'): elif message.content.startswith('!urban'):
await urban(message) await urban(message)
elif message.content.startswith('!uptime'): elif message.content.startswith('!uptime'):
@ -909,6 +912,29 @@ async def image(message): # API's dead.
await client.send_message(message.channel, "!image [text]") 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): async def urban(message):
msg = message.content.split() msg = message.content.split()
if len(msg) > 1: if len(msg) > 1:
@ -1857,4 +1883,4 @@ if __name__ == '__main__':
logger.error(e) logger.error(e)
loop.run_until_complete(client.logout()) loop.run_until_complete(client.logout())
finally: finally:
loop.close() loop.close()