Split long messages to prevent matrix event too large errors

This commit is contained in:
A git user 2023-09-03 17:40:51 +02:00
parent e0a992396e
commit ed4b34a788
No known key found for this signature in database
GPG Key ID: 7920D03B7AA7CD7B

View File

@ -117,11 +117,16 @@ class RSSBot(Plugin):
**attr.asdict(entry),
}
)
msgtype = MessageType.NOTICE if sub.send_notice else MessageType.TEXT
msgchunks = [message[i:i + 30000] for i in range(0, len(message), 30000)]
self.log.debug(f"Message length: {len(message)} Content length: {len(entry.content)} Chunks: {len(msgchunks)}")
try:
return await self.client.send_markdown(
sub.room_id, message, msgtype=msgtype, allow_html=True
)
for chunk in msgchunks:
returnval = await self.client.send_markdown(
sub.room_id, chunk, msgtype=msgtype, allow_html=True
)
return returnval
except Exception as e:
self.log.warning(f"Failed to send {entry.id} of {feed.id} to {sub.room_id}: {e}")