From 7ffbc3eba5c6da93687942d889f7333c6d131625 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sun, 11 Jul 2021 16:33:11 -0600 Subject: [PATCH] Limit titles in JokeCog to 256, pushes anything past that into description, closes #35 --- jarvis/cogs/jokes.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/jarvis/cogs/jokes.py b/jarvis/cogs/jokes.py index e448756..1c8c94e 100644 --- a/jarvis/cogs/jokes.py +++ b/jarvis/cogs/jokes.py @@ -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"]),