#!/usr/bin/env python3
"""发送 Discord 消息到 RobotDaily 频道."""

import requests
import os

def send_discord_message(channel_id: str, message: str) -> bool:
    """通过 Discord API 发送消息."""
    
    # 读取配置文件中的 Discord 令牌
    env_file = "/home/zhn/.openclaw/workspace/skills/robdaily/arxiv-digest/.env"
    
    if not os.path.exists(env_file):
        print(f"❌ 配置文件不存在：{env_file}")
        return False
    
    discord_token = None
    with open(env_file, 'r') as f:
        for line in f:
            if line.startswith('DISCORD_BOT_TOKEN='):
                discord_token = line.split('=', 1)[1].strip()
                break
    
    if not discord_token or discord_token == "your_bot_token_here":
        print("❌ 未配置 Discord 令牌，请编辑 .env 文件")
        return False
    
    url = f"https://discord.com/api/v10/channels/{channel_id}/messages"
    headers = {
        "Authorization": f"Bot {discord_token}",
        "Content-Type": "application/json",
    }
    
    data = {"content": message}
    
    try:
        response = requests.post(url, json=data, headers=headers, timeout=10)
        response.raise_for_status()
        print(f"✅ 消息已发送到 Discord 频道 {channel_id}")
        return True
    except requests.exceptions.RequestException as e:
        print(f"❌ Discord 消息发送失败：{e}")
        return False


if __name__ == "__main__":
    channel_id = "1481632217930141697"
    
    message = """📰 RobotDaily 2026-03-16

今日精选 7 篇论文：
• 具身智能：2 篇
• 表征学习：3 篇  
• 强化学习：2 篇

🔗 查看完整简报：
https://indigofloyd.space/ai-daily/2026-03-16/

祝有充实的一天！✨"""
    
    send_discord_message(channel_id, message)
