feat: 워크스페이스 이름충돌 감지 + 기본경로(VW_Proj) + 유령채널 자동정리

- workspace.py: find_by_name() 이름충돌, cleanup_orphans() 유령정리, 경로 자동생성
- config.py: WORKSPACE_BASE_DIR = VW_Proj
- discord_bot.py: /workspace set path 선택적, 이름충돌 안내, on_ready 유령정리
- VW_Proj 폴더 생성
This commit is contained in:
2026-03-06 21:19:42 +09:00
parent a9bdce90f4
commit b9e4a94e9a
3 changed files with 82 additions and 10 deletions

View File

@@ -7,6 +7,8 @@
import json
import logging
from pathlib import Path
import config
from dataclasses import dataclass, field, asdict
from typing import Optional
@@ -125,12 +127,21 @@ class WorkspaceManager:
encoding="utf-8",
)
def set_workspace(self, channel_id: int, name: str, path: str) -> Workspace:
"""채널에 워크스페이스 등록."""
def set_workspace(self, channel_id: int, name: str, path: str = "") -> Workspace:
"""채널에 워크스페이스 등록.
path가 비어있으면 WORKSPACE_BASE_DIR/{name} 으로 자동 생성.
"""
if not path:
path = str(Path(config.WORKSPACE_BASE_DIR) / name)
# 경로 디렉토리 자동 생성
Path(path).mkdir(parents=True, exist_ok=True)
ws = Workspace(name=name, path=path, channel_id=channel_id)
self.workspaces[channel_id] = ws
self._save()
logger.info(f"워크스페이스 설정: #{channel_id} {name} ({path})")
logger.info(f"워크스페이스 설정: #{channel_id} -> {name} ({path})")
return ws
def get_workspace(self, channel_id: int) -> Optional[Workspace]:
@@ -141,6 +152,30 @@ class WorkspaceManager:
"""이 채널이 워크스페이스로 등록되어 있는지."""
return channel_id in self.workspaces
def find_by_name(self, name: str) -> list[Workspace]:
"""이름으로 워크스페이스 검색 (채널 삭제 후 재생성 시 충돌 감지용)."""
return [
ws for ws in self.workspaces.values()
if ws.name.lower() == name.lower()
]
def cleanup_orphans(self, valid_channel_ids: set[int]) -> list[Workspace]:
"""존재하지 않는 채널의 워크스페이스 정리.
Returns: 제거된 워크스페이스 목록 (알림용)
"""
orphans = []
for ch_id, ws in list(self.workspaces.items()):
if ch_id not in valid_channel_ids:
orphans.append(ws)
del self.workspaces[ch_id]
logger.info(f"유령 워크스페이스 제거: {ws.name} (채널 {ch_id} 없음)")
if orphans:
self._save()
return orphans
def set_git(self, channel_id: int, url: str, token: str,
repo: str = "", branch: str = "main") -> bool:
"""워크스페이스에 Git 설정."""