Merged in define-finnaly (pull request #20)

added define module, fixes #3

Approved-by: Luke Robles <lukelrobles@gmail.com>
This commit is contained in:
Tyler Hodapp 2017-08-12 02:26:07 +00:00
commit 2744734786
2 changed files with 21 additions and 13 deletions

18
app/define_method.py Normal file
View File

@ -0,0 +1,18 @@
import requests
import help_methods
def get_definition(content):
if len(content.split()) > 1:
word = content.split()[1:]
try:
definition = requests.get(
"https://api.urbandictionary.com/v0/define?term={}".format('%20'.join(word))
).json()['list'][0]['definition']
except IndexError:
definition = 'No definition found'
return "`{}`\n```{}```".format(' '.join(word), definition)
else:
return help_methods.get_help_message('define')

View File

@ -2,7 +2,7 @@ import random
import sys
import requests
import os
import define_method
import help_methods
import discord
import docker
@ -134,17 +134,7 @@ async def on_message(message):
print('fuck u')
if message.content.startswith('!define'):
if len(message.content.split()) > 1:
word = message.content.split()[1:]
try:
definition = requests.get(
"https://api.urbandictionary.com/v0/define?term={}".format('%20'.join(word))
).json()['list'][0]['definition']
except IndexError:
definition = 'No definition found'
await client.send_message(message.channel, "`{}`\n```{}```".format(' '.join(word), definition))
else:
await client.send_message(message.channel, help_methods.get_help_message('define'))
await client.send_message(message.channel, define_method.get_definition(message.content))
if message.content.startswith('!help'):
await client.send_message(
@ -268,4 +258,4 @@ async def on_message(message):
await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines))
client.run(tokens[dragon_environment])
client.run(tokens[dragon_environment])