From a6d020b3f766c711481ba32d7fdfff5ead1917ff Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 3 Nov 2020 17:05:37 +0100 Subject: [PATCH] Fix embed name and value size --- extensions/tomuss.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/extensions/tomuss.py b/extensions/tomuss.py index 704dff8..e52ba7f 100644 --- a/extensions/tomuss.py +++ b/extensions/tomuss.py @@ -1,8 +1,8 @@ import re from datetime import datetime -from time import mktime, struct_time +from time import mktime -from discord import Embed, Forbidden +from discord import Embed, Forbidden, HTTPException from discord.ext import commands, tasks from discord.ext.commands import BadArgument from feedparser import parse @@ -87,16 +87,28 @@ class Tomuss(commands.Cog): if entries: embed = Embed(title="Tomuss update !") for e in entries: - embed.add_field(name=e.title, - value=e.summary.replace("
", "\n").replace("", "**").replace("", "**")) + if len(e.title) > 256: + title = e.title[:253] + "..." + else: + title = e.title + + summary = e.summary.replace("
", "\n").replace("", "**").replace("", "**") + if len(summary) > 1024: + summary = summary[:1021] + "..." + + embed.add_field(name=title, value=summary) try: await u.send(embed=embed) - - t.last = datetime.fromtimestamp(mktime(entries[-1].published_parsed)) - s.add(t) except Forbidden: s.delete(t) - s.commit() + s.commit() + continue + except HTTPException: + await u.send("Too much to send, I can't handle it sorry...") + finally: + t.last = datetime.fromtimestamp(mktime(entries[-1].published_parsed)) + s.add(t) + s.commit() s.close()