[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:
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
if data.get("error") != 404:
if not data["list"]:
return await ctx.send(_("No Urban Dictionary entries were found."))
if await ctx.embed_requested():
# a list of embeds
embeds = []
@ -305,14 +306,14 @@ class General(commands.Cog):
else:
messages = []
for ud in data["list"]:
ud.set_default("example", "N/A")
ud.setdefault("example", "N/A")
description = _("{definition}\n\n**Example:** {example}").format(**ud)
if len(description) > 2048:
description = "{}...".format(description[:2045])
message = _(
"<{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)
messages.append(message)
@ -327,6 +328,5 @@ class General(commands.Cog):
)
else:
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