38 lines
1.1 KiB
Python
Executable File
38 lines
1.1 KiB
Python
Executable File
import requests
|
|
import help_methods
|
|
|
|
import discord
|
|
|
|
|
|
def get_definition(content):
|
|
"""
|
|
get_definition(content)
|
|
|
|
grabs a definition from urban dictionary
|
|
"""
|
|
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']
|
|
site = 'Urban Dictionary'
|
|
|
|
except IndexError:
|
|
try:
|
|
# Try another dictionary
|
|
definition = requests.get(
|
|
"http://api.pearson.com/v2/dictionaries/ldoce5/entries?headword={}".format('%20'.join(word))
|
|
).json()['results'][0]['senses'][0]['definition'][0]
|
|
|
|
site = 'Pearson'
|
|
except IndexError:
|
|
definition = 'No definition found'
|
|
|
|
embed = discord.Embed(description="%s:\n%s" % (' '.join(word), definition), color=0x428bca, type="rich")
|
|
embed.set_author(name="From %s" % site)
|
|
|
|
return embed
|
|
|
|
return help_methods.get_help_message('define')
|