[General] [p]urban: Handle no embeds (#2285)

This commit is contained in:
aikaterna 2018-11-14 14:21:11 -08:00 committed by Twentysix
parent d008a2559a
commit 9973b2e3b8

View File

@ -265,12 +265,13 @@ class General(commands.Cog):
except aiohttp.ClientError: except aiohttp.ClientError:
await ctx.send( await ctx.send(
_("No Urban dictionary entries were found, or there was an error in the process") _("No Urban Dictionary entries were found, or there was an error in the process.")
) )
return return
if data.get("error") != 404: if data.get("error") != 404:
if not data["list"]:
return await ctx.send(_("No Urban Dictionary entries were found."))
if await ctx.embed_requested(): if await ctx.embed_requested():
# a list of embeds # a list of embeds
embeds = [] embeds = []
@ -305,14 +306,14 @@ class General(commands.Cog):
else: else:
messages = [] messages = []
for ud in data["list"]: for ud in data["list"]:
ud.set_default("example", "N/A") ud.setdefault("example", "N/A")
description = _("{definition}\n\n**Example:** {example}").format(**ud) description = _("{definition}\n\n**Example:** {example}").format(**ud)
if len(description) > 2048: if len(description) > 2048:
description = "{}...".format(description[:2045]) description = "{}...".format(description[:2045])
message = _( message = _(
"<{permalink}>\n {word} by {author}\n\n{description}\n\n" "<{permalink}>\n {word} by {author}\n\n{description}\n\n"
"{thumbs_down} Down / {thumbs_up} Up, Powered by urban dictionary" "{thumbs_down} Down / {thumbs_up} Up, Powered by Urban Dictionary."
).format(word=ud.pop("word").capitalize(), description=description, **ud) ).format(word=ud.pop("word").capitalize(), description=description, **ud)
messages.append(message) messages.append(message)
@ -327,6 +328,5 @@ class General(commands.Cog):
) )
else: else:
await ctx.send( await ctx.send(
_("No Urban dictionary entries were found, or there was an error in the process.") _("No Urban Dictionary entries were found, or there was an error in the process.")
) )
return