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))