From 8d9b50d34b0cb0b29c040386faaaa37ccb61fd3b Mon Sep 17 00:00:00 2001 From: freamon Date: Thu, 16 May 2024 10:42:56 +0100 Subject: [PATCH] autotldr bot handling: add check for post.body is None --- app/activitypub/util.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 9aad4ea4..afd4b85e 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1361,14 +1361,15 @@ def create_post_reply(activity_log: ActivityPubLog, community: Community, in_rep post = Post.query.get(post_id) # special case: add comment from auto-tldr bot to post body if body is empty - if user.ap_id == 'autotldr@lemmings.world' and post.body.strip() == '': - if not '::: spoiler' in post_reply.body: - post.body = "🤖 I'm a bot that provides automatic summaries for articles:\n::: spoiler Click here to see the summary\n" + post_reply.body + '\n:::' - else: - post.body = post_reply.body - post.body_html = lemmy_markdown_to_html(post.body) + '\n\nGenerated using AI by: AutoTL;DR' - db.session.commit() - return None + if user.ap_id == 'autotldr@lemmings.world': + if not post.body or (post.body and post.body.strip() == ''): + if not '::: spoiler' in post_reply.body: + post.body = "🤖 I'm a bot that provides automatic summaries for articles:\n::: spoiler Click here to see the summary\n" + post_reply.body + '\n:::' + else: + post.body = post_reply.body + post.body_html = lemmy_markdown_to_html(post.body) + '\n\nGenerated using AI by: AutoTL;DR' + db.session.commit() + return None if post.comments_enabled: anchor = None