Unify start/stop slash commands by target

This commit is contained in:
2026-02-17 06:08:43 +09:00
parent 70020e3f71
commit 48c79c88c8
3 changed files with 196 additions and 38 deletions

View File

@@ -58,53 +58,59 @@ class SlackHandler:
if self._on_message_callback:
self._on_message_callback(text, channel_id)
@self.app.command("/start-claude")
def handle_start_claude(ack: Callable[..., None], body: dict) -> None:
@self.app.command("/start")
def handle_start(ack: Callable[..., None], body: dict) -> None:
ack()
user_id = body.get("user_id", "")
channel_id = body.get("channel_id", "")
target = self._parse_target(body.get("text", ""))
if not self._is_authorized(user_id, channel_id):
return
if self._on_command_callback:
self._on_command_callback("start", "claude", channel_id)
if target is None:
self.send_message(
channel_id,
(
":warning: 대상은 `claude` 또는 `codex`여야 합니다. "
"예: `/start codex`"
),
)
return
@self.app.command("/stop-claude")
def handle_stop_claude(ack: Callable[..., None], body: dict) -> None:
if self._on_command_callback:
self._on_command_callback("start", target, channel_id)
@self.app.command("/stop")
def handle_stop(ack: Callable[..., None], body: dict) -> None:
ack()
user_id = body.get("user_id", "")
channel_id = body.get("channel_id", "")
target = self._parse_target(body.get("text", ""))
if not self._is_authorized(user_id, channel_id):
return
if self._on_command_callback:
self._on_command_callback("stop", "claude", channel_id)
@self.app.command("/start-codex")
def handle_start_codex(ack: Callable[..., None], body: dict) -> None:
ack()
user_id = body.get("user_id", "")
channel_id = body.get("channel_id", "")
if not self._is_authorized(user_id, channel_id):
if target is None:
self.send_message(
channel_id,
(
":warning: 대상은 `claude` 또는 `codex`여야 합니다. "
"예: `/stop claude`"
),
)
return
if self._on_command_callback:
self._on_command_callback("start", "codex", channel_id)
self._on_command_callback("stop", target, channel_id)
@self.app.command("/stop-codex")
def handle_stop_codex(ack: Callable[..., None], body: dict) -> None:
ack()
user_id = body.get("user_id", "")
channel_id = body.get("channel_id", "")
if not self._is_authorized(user_id, channel_id):
return
if self._on_command_callback:
self._on_command_callback("stop", "codex", channel_id)
@staticmethod
def _parse_target(text: str) -> str | None:
"""슬래시 커맨드 인자에서 대상을 파싱한다."""
first_token = text.strip().split(maxsplit=1)[0].lower() if text.strip() else ""
if first_token in {"claude", "codex"}:
return first_token
return None
def on_message(self, callback: Callable[[str, str], None]) -> None:
"""메시지 수신 콜백을 등록한다."""