refactor: eliminate redundant truncation in email_ingest and fix em dash
- Replace em dash with hyphen in thread_ingest.py user message (feedback_no_emdash.md) - Remove duplicate truncation logic in email_ingest.py (lines 12-17 and _truncate_for_embed method) - Consolidate truncation responsibility to ping.py's _safe_field_value as single source of truth - This prevents email_ingest's marker from being re-truncated by ping.py's defensive catch-all
This commit is contained in:
parent
f8a853a80c
commit
240279f95b
2 changed files with 2 additions and 18 deletions
|
|
@ -9,13 +9,6 @@ from chorus_bot.ping import build_ping_embed
|
|||
|
||||
SEEN_UIDS_PATH = Path(os.environ.get("CHORUS_SEEN_UIDS_PATH", "seen_uids.json"))
|
||||
|
||||
# Discord embed field values cap at 1024 chars. Truncate the raw_content we pass
|
||||
# into the embed with headroom below that cap for build_ping_embed's own
|
||||
# truncation marker (see ping.py). This is intentionally lossy for very long
|
||||
# emails -- acceptable for MVP; the full body still lives in the source mailbox.
|
||||
_RAW_CONTENT_MAX = 1000
|
||||
_TRUNCATION_MARKER = "\n\n[...truncated for Discord embed limit...]"
|
||||
|
||||
# modality -> (imap host attr, imap user attr, imap password attr) on Config
|
||||
MAILBOXES = {
|
||||
"bh_email": ("bh_email_imap_host", "bh_email_imap_user", "bh_email_imap_password"),
|
||||
|
|
@ -80,7 +73,7 @@ class EmailIngestCog(commands.Cog):
|
|||
captured_at = parsedate_to_datetime(msg.get("Date"))
|
||||
body = self._extract_body(msg)
|
||||
snippet = body if len(body) <= 120 else body[:117] + "..."
|
||||
raw_content = self._truncate_for_embed(body)
|
||||
raw_content = body
|
||||
|
||||
embed = build_ping_embed(
|
||||
modality=modality, sender_id=sender, snippet=snippet,
|
||||
|
|
@ -95,15 +88,6 @@ class EmailIngestCog(commands.Cog):
|
|||
finally:
|
||||
conn.logout()
|
||||
|
||||
@staticmethod
|
||||
def _truncate_for_embed(body: str) -> str:
|
||||
"""Cap the raw_content passed into the embed at a safe length below
|
||||
Discord's 1024-char field limit. Lossy for very long emails but keeps
|
||||
ingestion from failing (and retrying forever) on oversized bodies."""
|
||||
if len(body) <= _RAW_CONTENT_MAX:
|
||||
return body
|
||||
return body[:_RAW_CONTENT_MAX] + _TRUNCATION_MARKER
|
||||
|
||||
@staticmethod
|
||||
def _extract_body(msg) -> str:
|
||||
if msg.is_multipart():
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class ThreadIngestCog(commands.Cog):
|
|||
sender_id=parsed["sender_id"],
|
||||
)
|
||||
await thread.send(
|
||||
"Logged in Chorus — open the app to fill in details and track this one."
|
||||
"Logged in Chorus - open the app to fill in details and track this one."
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue