From 6098130687ebe189b37e30ed8d7b23bd14075761 Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Sun, 6 Jul 2025 20:41:01 -0700 Subject: [PATCH] Remove outside double quotes from Bluesky responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add quote removal function to strip double quotes from AI responses before posting to prevent quoted text from appearing in posts. Only removes double quotes to preserve contractions and single quotes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- bsky.py | 10 ++++++---- bsky_utils.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/bsky.py b/bsky.py index 1afd51a..fa6e58f 100644 --- a/bsky.py +++ b/bsky.py @@ -588,20 +588,22 @@ Use the bluesky_reply tool to send a response less than 300 characters.""" # Send the reply(s) with language if len(reply_messages) == 1: # Single reply - use existing function - logger.info(f"Sending single reply: {reply_messages[0][:50]}... (lang: {reply_lang})") + cleaned_text = bsky_utils.remove_outside_quotes(reply_messages[0]) + logger.info(f"Sending single reply: {cleaned_text[:50]}... (lang: {reply_lang})") response = bsky_utils.reply_to_notification( client=atproto_client, notification=notification_data, - reply_text=reply_messages[0], + reply_text=cleaned_text, lang=reply_lang ) else: # Multiple replies - use new threaded function - logger.info(f"Sending threaded reply with {len(reply_messages)} messages (lang: {reply_lang})") + cleaned_messages = [bsky_utils.remove_outside_quotes(msg) for msg in reply_messages] + logger.info(f"Sending threaded reply with {len(cleaned_messages)} messages (lang: {reply_lang})") response = bsky_utils.reply_with_thread_to_notification( client=atproto_client, notification=notification_data, - reply_messages=reply_messages, + reply_messages=cleaned_messages, lang=reply_lang ) diff --git a/bsky_utils.py b/bsky_utils.py index f4ee80d..091e5e9 100644 --- a/bsky_utils.py +++ b/bsky_utils.py @@ -253,6 +253,31 @@ def default_login() -> Client: return init_client(username, password) +def remove_outside_quotes(text: str) -> str: + """ + Remove outside double quotes from response text. + + Only handles double quotes to avoid interfering with contractions: + - Double quotes: "text" → text + - Preserves single quotes and internal quotes + + Args: + text: The text to process + + Returns: + Text with outside double quotes removed + """ + if not text or len(text) < 2: + return text + + text = text.strip() + + # Only remove double quotes from start and end + if text.startswith('"') and text.endswith('"'): + return text[1:-1] + + return text + def reply_to_post(client: Client, text: str, reply_to_uri: str, reply_to_cid: str, root_uri: Optional[str] = None, root_cid: Optional[str] = None, lang: Optional[str] = None) -> Dict[str, Any]: """ Reply to a post on Bluesky with rich text support. -- 2.51.2