[2026-05-15] Discord Stop 훅 추가 및 notifier User-Agent 수정
- .claude/discord_notify.py: 세션 종료 시 git log/status를 Discord로 전송 - .claude/settings.json: Stop 훅 등록 - notifier.py: Cloudflare 차단 방지를 위해 User-Agent 헤더 추가 - .gitignore: settings.local.json 제외 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import subprocess, json, urllib.request, datetime, sys
|
||||
|
||||
WEBHOOK = "https://discord.com/api/webhooks/1504705352166543370/H3dhs_4LaxnaFj_mhUUi02qpk3JegE_Ji9C6rNpEqRNv_iW6aqvso8VyPw17048Nt0oF"
|
||||
|
||||
def run(cmd):
|
||||
return subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8', errors='replace').stdout.strip()
|
||||
|
||||
log = run(['git', 'log', '--oneline', '-5'])
|
||||
status = run(['git', 'status', '--short'])
|
||||
diff_stat = run(['git', 'diff', '--stat'])
|
||||
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||
|
||||
parts = [f"**[Claude Code 작업완료] {now}**"]
|
||||
|
||||
if log:
|
||||
parts.append(f"```\n{log}\n```")
|
||||
|
||||
if status or diff_stat:
|
||||
combined = '\n'.join(filter(None, [status, diff_stat]))
|
||||
parts.append(f"**미커밋 변경:**\n```\n{combined}\n```")
|
||||
|
||||
if len(parts) == 1:
|
||||
parts.append("_변경사항 없음_")
|
||||
|
||||
msg = '\n'.join(parts)
|
||||
if len(msg) > 1990:
|
||||
msg = msg[:1987] + '...'
|
||||
|
||||
data = json.dumps({'content': msg}).encode('utf-8')
|
||||
req = urllib.request.Request(WEBHOOK, data=data, headers={'Content-Type': 'application/json', 'User-Agent': 'DiscordBot (stockbot, 1.0)'}, method='POST')
|
||||
try:
|
||||
urllib.request.urlopen(req)
|
||||
except Exception as e:
|
||||
print(f"Discord notify failed: {e}", file=sys.stderr)
|
||||
+14
-1
@@ -1,4 +1,17 @@
|
||||
{
|
||||
"dangerouslySkipPermissions": true,
|
||||
"instructions": "코드만 출력, 설명은 주석으로. 수정은 변경된 함수/diff 단위만. 답변 마지막에 1줄 요약. 상세 설명은 요청 시에만. 수정 후 반드시 git commit/push."
|
||||
"instructions": "코드만 출력, 설명은 주석으로. 수정은 변경된 함수/diff 단위만. 답변 마지막에 1줄 요약. 상세 설명은 요청 시에만. 수정 후 반드시 git commit/push.",
|
||||
"hooks": {
|
||||
"Stop": [
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "python .claude/discord_notify.py",
|
||||
"timeout": 30
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,3 +8,4 @@ __pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
.DS_Store
|
||||
.claude/settings.local.json
|
||||
|
||||
@@ -18,7 +18,8 @@ async def send(message: str) -> None:
|
||||
logger.warning(f"[Discord 미설정] {message}")
|
||||
return
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
headers = {"User-Agent": "DiscordBot (stockbot, 1.0)"}
|
||||
async with aiohttp.ClientSession(headers=headers) as session:
|
||||
await session.post(
|
||||
WEBHOOK_URL,
|
||||
json={"content": message},
|
||||
|
||||
Reference in New Issue
Block a user