Limit titles in JokeCog to 256, pushes anything past that into description, closes #35

This commit is contained in:
Zeva Rose 2021-07-11 16:33:11 -06:00
parent ae1d32b485
commit 7ffbc3eba5

View file

@ -84,6 +84,21 @@ class JokeCog(commands.Cog):
else:
body += " " + word
desc = ""
title = result["title"]
if len(title) > 256:
new_title = ""
limit = False
for word in title.split(" "):
if len(new_title) + len(word) + 1 > 253 and not limit:
new_title += "..."
desc = "..."
limit = True
if not limit:
new_title += word + " "
else:
desc += word + " "
body_chunks.append(Field("", body, False))
fields = body_chunks
@ -94,8 +109,8 @@ class JokeCog(commands.Cog):
# ),
fields.append(Field("ID", result["id"]))
embed = build_embed(
title=result["title"],
description="",
title=title,
description=desc,
fields=fields,
url=f"https://reddit.com/r/jokes/comments/{result['id']}",
timestamp=datetime.fromtimestamp(result["created_utc"]),