fix(bot): Hub WS auto-approve Discord 알림 누락 + !auto 이중발송 dedup

This commit is contained in:
Variet Worker
2026-03-17 10:37:55 +09:00
parent edd4943e2e
commit 96e9b8adce

26
bot.py
View File

@@ -189,6 +189,7 @@ class GravityBot(commands.Bot):
self.auto_approve_projects: set[str] = set() # projects with auto-approve enabled
self._processed_message_ids: deque[int] = deque(maxlen=200) # dedup for Gateway event replay
self._approval_messages: dict[str, int] = {} # FIX #4: request_id → discord message_id (for auto_resolved lookup)
self._last_auto_toggle: dict[str, float] = {} # project → timestamp (dedup for !auto embed)
self.gateway = None # Set by main.py in gateway mode
self.hub = None # Set by main.py in gateway mode (WSHub instance)
@@ -921,6 +922,14 @@ class GravityBot(commands.Bot):
# Special command: !auto — toggle auto-approve
if actual_text == "!auto":
# Dedup: skip if toggled within 5s for same project (Gateway event replay)
now = time.time()
last = self._last_auto_toggle.get(project, 0)
if now - last < 5.0:
logger.info(f"[AUTO] Dedup: skipping duplicate !auto for {project} ({now-last:.1f}s ago)")
return
self._last_auto_toggle[project] = now
# Toggle per-project auto-approve
if project in self.auto_approve_projects:
self.auto_approve_projects.discard(project)
@@ -1043,6 +1052,8 @@ class GravityBot(commands.Bot):
async def _auto_approve_via_hub(self, request: ApprovalRequest):
"""Auto-approve a pending request via Hub."""
self._sent_approval_ids.add(request.request_id)
if self.hub:
await self.hub.send_response_to_pending_owner(request.request_id, {
"type": "response",
@@ -1060,7 +1071,20 @@ class GravityBot(commands.Bot):
step_type=request.step_type,
project_name=request.project_name,
))
logger.info(f"[HUB-AUTO] Auto-approved: {request.request_id[:12]}")
# Send compact auto-approved embed to Discord (was missing — caused silent approvals)
channel = await self._get_channel(request.project_name)
if channel:
try:
embed = discord.Embed(
title="🤖 자동 승인됨",
description=f"```\n{request.command[:500]}\n```",
color=discord.Color.green(),
)
embed.set_footer(text=f"auto-approve | {request.request_id[:12]}")
await channel.send(embed=embed)
except Exception as e:
logger.error(f"[HUB-AUTO] Discord send failed: {e}")
logger.info(f"[HUB-AUTO] Auto-approved: {request.request_id[:12]} project={request.project_name}")
async def _hub_on_chat(self, project: str, data: dict):
"""Handle chat snapshot from Hub (Extension->Hub->Bot->Discord)."""