From a76208e4e6e1a553fba2b0d33741a46a34730577 Mon Sep 17 00:00:00 2001 From: CD Date: Sat, 7 Mar 2026 11:24:04 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20task=20embed=20=ED=8E=B8=EC=A7=91,=20met?= =?UTF-8?q?adata=20=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0,=20closed-=20?= =?UTF-8?q?=EC=B1=84=EB=84=90=20=EB=B3=B5=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 0e812f5..43dbd31 100644 --- a/bot.py +++ b/bot.py @@ -186,6 +186,8 @@ class GravityBot(commands.Bot): self._channel_locks: dict[str, asyncio.Lock] = {} # Bridge protocol for bidirectional communication self.bridge = BridgeProtocol() + # Cache: conversation_id -> last metadata summary (skip unchanged) + self._last_meta_summary: dict[str, str] = {} # Category for session channels self.session_category: discord.CategoryChannel | None = None # Guild reference @@ -270,6 +272,16 @@ class GravityBot(commands.Bot): if ch.topic and conversation_id in ch.topic: self.session_channels[conversation_id] = ch self.session_names[conversation_id] = project_name + # Rename back from closed- if needed + expected_name = f"{Config.CHANNEL_PREFIX}-{project_name}" + if ch.name != expected_name.lower(): + try: + await ch.edit(name=expected_name) + logger.info(f"Renamed channel {ch.name} -> {expected_name}") + except discord.errors.Forbidden: + pass + # Recover last task embed message ID + await self._recover_task_message(ch, conversation_id) logger.info(f"Reconnected to existing channel #{ch.name}") return ch @@ -301,6 +313,24 @@ class GravityBot(commands.Bot): logger.error(f"No permission to create channel: {channel_name}") return None + async def _recover_task_message( + self, channel: discord.TextChannel, conversation_id: str + ): + """Find the last task embed in channel history to reuse for editing.""" + if conversation_id in self.session_status_messages: + return # Already have it + + try: + async for msg in channel.history(limit=20): + if msg.author == self.user and msg.embeds: + embed = msg.embeds[0] + if embed.title and "Task 진행 현황" in embed.title: + self.session_status_messages[conversation_id] = msg.id + logger.info(f"Recovered task embed msg {msg.id} for {conversation_id[:8]}") + return + except (discord.Forbidden, discord.HTTPException): + pass + async def _process_events(self): """Main event processing loop.""" await self.wait_until_ready() @@ -407,11 +437,16 @@ class GravityBot(commands.Bot): summary = meta.get("summary", "") artifact_type = meta.get("artifactType", "") - updated_at = meta.get("updatedAt", "") if not summary: return + # Dedup: skip if summary unchanged since last notification + cache_key = f"{event.conversation_id}:{event.file_name}" + if self._last_meta_summary.get(cache_key) == summary: + return + self._last_meta_summary[cache_key] = summary + # Map artifact types to emoji type_emoji = { "ARTIFACT_TYPE_TASK": "📋",