diff --git a/.claude/discord_notify.py b/.claude/discord_notify.py new file mode 100644 index 0000000..e35bbc7 --- /dev/null +++ b/.claude/discord_notify.py @@ -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) diff --git a/.claude/settings.json b/.claude/settings.json index 37d2ba9..18f02eb 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -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 + } + ] + } + ] + } } diff --git a/.gitignore b/.gitignore index ff1f188..afed35e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ __pycache__/ *.pyc *.pyo .DS_Store +.claude/settings.local.json diff --git a/app/monitor/notifier.py b/app/monitor/notifier.py index e89e655..a88d196 100644 --- a/app/monitor/notifier.py +++ b/app/monitor/notifier.py @@ -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},