chorus/bot/chorus_bot/cogs/thread_ingest.py
pyr0ball 240279f95b 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
2026-07-13 15:08:35 -07:00

41 lines
1.4 KiB
Python

import discord
from discord.ext import commands
from chorus_bot.ping import parse_ping_embed
class ThreadIngestCog(commands.Cog):
"""Opening a thread on an #inbox ping is what creates the real triage row."""
def __init__(self, bot: commands.Bot, config, backend_client):
self.bot = bot
self.config = config
self.backend_client = backend_client
@commands.Cog.listener()
async def on_thread_create(self, thread: discord.Thread):
if thread.parent_id != self.config.inbox_channel_id:
return
try:
parent_message = await thread.parent.fetch_message(thread.id)
except discord.NotFound:
# Standalone thread not started from a message -- nothing to ingest.
return
if not parent_message.embeds:
return
parsed = parse_ping_embed(parent_message.embeds[0])
await self.backend_client.create_item(
modality=parsed["modality"],
raw_content=parsed["raw_content"],
captured_at=parsed["captured_at"],
discord_message_id=str(thread.id),
sender_id=parsed["sender_id"],
)
await thread.send(
"Logged in Chorus - open the app to fill in details and track this one."
)
async def setup(bot: commands.Bot, config, backend_client):
await bot.add_cog(ThreadIngestCog(bot, config, backend_client))