move define to be a slash command
This commit is contained in:
parent
3dc7663e41
commit
55015b1110
@ -56,6 +56,23 @@ class ActualUtils(commands.Cog):
|
||||
|
||||
await ctx.respond(r.json()["web_url"])
|
||||
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
name="define",
|
||||
description="Grabs the highest rated definition from urban dictionary",
|
||||
)
|
||||
@option(
|
||||
name="word",
|
||||
description="The word to define. Tries UD first then an actual dictionary",
|
||||
required=True,
|
||||
)
|
||||
async def define(self, ctx, word):
|
||||
|
||||
import define_word
|
||||
|
||||
embed = define_word.get_definition(word)
|
||||
await ctx.respond(embed=embed)
|
||||
|
||||
@commands.command(name="tts")
|
||||
async def tts(self, ctx: commands.Context):
|
||||
|
||||
|
@ -133,13 +133,6 @@ class Cheeky(commands.Cog):
|
||||
)
|
||||
)
|
||||
|
||||
@commands.command(name="define", aliases=["ud"])
|
||||
async def define(self, ctx: commands.Context):
|
||||
|
||||
import define_word
|
||||
|
||||
await ctx.send(embed=define_word.get_definition(ctx.message.content))
|
||||
|
||||
@commands.command(name="wallpaper")
|
||||
async def wallpaper(self, ctx: commands.Context):
|
||||
import wallpaper
|
||||
|
@ -4,19 +4,16 @@ import help_methods
|
||||
import discord
|
||||
|
||||
|
||||
def get_definition(content):
|
||||
def get_definition(word):
|
||||
"""
|
||||
get_definition(content)
|
||||
get_definition(word)
|
||||
|
||||
grabs a definition from urban dictionary
|
||||
Tries to return the highest voted definition from urbandictionary.
|
||||
If that fails, it reaches out to pearson for an actual defintion
|
||||
"""
|
||||
if len(content.split()) > 1:
|
||||
word = content.split()[1:]
|
||||
try:
|
||||
definition = requests.get(
|
||||
"https://api.urbandictionary.com/v0/define?term={}".format(
|
||||
"%20".join(word)
|
||||
)
|
||||
"https://api.urbandictionary.com/v0/define?term={}".format("%20".join(word))
|
||||
).json()["list"]
|
||||
# UD returns all the results in a json blob. Calculate which result has the highest upvotes to downvotes ratio
|
||||
# as this is the result that shows up at the top on urbandictionary.com
|
||||
|
Loading…
x
Reference in New Issue
Block a user