feat: session connect command + auto-registration + bridge/register protocol

This commit is contained in:
2026-03-07 14:15:53 +09:00
parent 887850d0c9
commit 98bb037c81
3 changed files with 136 additions and 1 deletions

26
bot.py
View File

@@ -140,12 +140,38 @@ class GravityBot(commands.Bot):
# Discover existing project channels
await self._discover_channels()
# Load conversation → project registrations from Extension
self._load_registrations()
# Open the gate
self._ready_event.set()
logger.info("Ready gate opened — event processing enabled")
# ─── Channel Management ──────────────────────────────────────────
def _load_registrations(self):
"""Read bridge/register/ to learn conversation → project mappings."""
register_dir = self.bridge.bridge_dir / "register"
if not register_dir.exists():
return
count = 0
for f in register_dir.glob("*.json"):
try:
data = json.loads(f.read_text(encoding="utf-8-sig"))
conv_id = data.get("conversation_id", "")
project = data.get("project_name", "")
if conv_id and project:
self.conv_to_project[conv_id] = project
count += 1
except (json.JSONDecodeError, OSError):
pass
if count:
logger.info(f"Loaded {count} conversation→project registrations")
# ─── Channel Management ──────────────────────────────────────────
async def _discover_channels(self):
"""Find existing project channels via Discord API (not cache)."""
all_channels = await self.guild.fetch_channels()