fix: task embed 편집, metadata 중복 제거, closed- 채널 복원
This commit is contained in:
37
bot.py
37
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": "📋",
|
||||
|
||||
Reference in New Issue
Block a user