Limit urban to nsfw channels
This commit is contained in:
parent
9be23219c5
commit
ff672d1f81
|
@ -154,32 +154,35 @@ class Links:
|
||||||
|
|
||||||
EXAMPLE: !urban a normal phrase
|
EXAMPLE: !urban a normal phrase
|
||||||
RESULT: Probably something lewd; this is urban dictionary we're talking about"""
|
RESULT: Probably something lewd; this is urban dictionary we're talking about"""
|
||||||
await ctx.message.channel.trigger_typing()
|
if utils.channel_is_nsfw(ctx.message.channel, self.bot.db):
|
||||||
|
await ctx.message.channel.trigger_typing()
|
||||||
|
|
||||||
url = "http://api.urbandictionary.com/v0/define"
|
url = "http://api.urbandictionary.com/v0/define"
|
||||||
params = {"term": msg}
|
params = {"term": msg}
|
||||||
try:
|
try:
|
||||||
data = await utils.request(url, payload=params)
|
data = await utils.request(url, payload=params)
|
||||||
if data is None:
|
if data is None:
|
||||||
|
await ctx.send("Sorry but I failed to connect to urban dictionary!")
|
||||||
|
return
|
||||||
|
|
||||||
|
# List is the list of definitions found, if it's empty then nothing was found
|
||||||
|
if len(data['list']) == 0:
|
||||||
|
await ctx.send("No result with that term!")
|
||||||
|
# If the list is not empty, use the first result and print it's defintion
|
||||||
|
else:
|
||||||
|
entries = [x['definition'] for x in data['list']]
|
||||||
|
try:
|
||||||
|
pages = utils.Pages(self.bot, message=ctx.message, entries=entries[:5], per_page=1)
|
||||||
|
await pages.paginate()
|
||||||
|
except utils.CannotPaginate as e:
|
||||||
|
await ctx.send(str(e))
|
||||||
|
# Urban dictionary has some long definitions, some might not be able to be sent
|
||||||
|
except discord.HTTPException:
|
||||||
|
await ctx.send('```\nError: Definition is too long for me to send```')
|
||||||
|
except KeyError:
|
||||||
await ctx.send("Sorry but I failed to connect to urban dictionary!")
|
await ctx.send("Sorry but I failed to connect to urban dictionary!")
|
||||||
return
|
else:
|
||||||
|
await ctx.send("This command is limited to nsfw channels")
|
||||||
# List is the list of definitions found, if it's empty then nothing was found
|
|
||||||
if len(data['list']) == 0:
|
|
||||||
await ctx.send("No result with that term!")
|
|
||||||
# If the list is not empty, use the first result and print it's defintion
|
|
||||||
else:
|
|
||||||
entries = [x['definition'] for x in data['list']]
|
|
||||||
try:
|
|
||||||
pages = utils.Pages(self.bot, message=ctx.message, entries=entries[:5], per_page=1)
|
|
||||||
await pages.paginate()
|
|
||||||
except utils.CannotPaginate as e:
|
|
||||||
await ctx.send(str(e))
|
|
||||||
# Urban dictionary has some long definitions, some might not be able to be sent
|
|
||||||
except discord.HTTPException:
|
|
||||||
await ctx.send('```\nError: Definition is too long for me to send```')
|
|
||||||
except KeyError:
|
|
||||||
await ctx.send("Sorry but I failed to connect to urban dictionary!")
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
Loading…
Reference in a new issue