feat: 채널 이름 변경 시 워크스페이스+폴더 자동 연동

- on_guild_channel_update 이벤트로 이름 변경 감지
- workspace.rename_workspace(): 이름+폴더 변경 (VW_Proj 하위에만)
- 변경 완료 시 채널에 알림 Embed 전송
This commit is contained in:
2026-03-06 21:52:10 +09:00
parent 63a12d9078
commit 3f69b6a47a
2 changed files with 64 additions and 0 deletions

View File

@@ -146,6 +146,37 @@ async def on_ready():
)
@bot.event
async def on_guild_channel_update(before, after):
"""채널 이름 변경 감지 -> 워크스페이스 자동 이름 변경."""
if before.name == after.name:
return
if not ws_manager.is_workspace_channel(after.id):
return
ws = ws_manager.get_workspace(after.id)
old_name = ws.name
new_name = after.name
success, new_path = ws_manager.rename_workspace(after.id, new_name)
if success:
embed = discord.Embed(
title="📝 워크스페이스 자동 업데이트",
description=(
f"채널 이름 변경 감지: `{old_name}` -> `{new_name}`\n\n"
f"워크스페이스 이름: **{new_name}**\n"
f"경로: `{new_path}`"
),
color=0x3498DB,
)
await after.send(embed=embed)
else:
logger.warning(f"채널 이름 변경 시 워크스페이스 업데이트 실패: {new_path}")
@bot.event
async def on_message(message: discord.Message):
"""메시지 수신 — 워크스페이스 채널이면 자동 응답."""

View File

@@ -251,6 +251,39 @@ class WorkspaceManager:
return True
return False
def rename_workspace(self, channel_id: int, new_name: str) -> tuple[bool, str]:
"""워크스페이스 이름 + 폴더 변경.
Returns: (성공 여부, 새 경로 또는 에러 메시지)
"""
ws = self.workspaces.get(channel_id)
if not ws:
return False, "워크스페이스 없음"
old_name = ws.name
old_path = Path(ws.path)
# 이름만 변경 (폴더는 기본경로일 때만 이동)
ws.name = new_name
# 기본경로(VW_Proj 아래)인 경우 폴더도 이동
base_dir = Path(config.WORKSPACE_BASE_DIR)
if old_path.parent == base_dir and old_path.exists():
new_path = base_dir / new_name
if not new_path.exists():
try:
old_path.rename(new_path)
ws.path = str(new_path)
logger.info(f"폴더 이동: {old_path} -> {new_path}")
except OSError as e:
logger.warning(f"폴더 이동 실패: {e}")
ws.path = str(old_path) # 폴더는 유지
self._save()
logger.info(f"워크스페이스 이름 변경: {old_name} -> {new_name}")
return True, ws.path
def list_all(self) -> list[Workspace]:
"""전체 워크스페이스 목록."""
return list(self.workspaces.values())