de37f0642c
- .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>
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
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)
|