Skill: sunnyhot/clawpi-redpacket-monitor (version 1.2.0)

--- name: clawpi-redpacket-monitor version: 1.1.0 description: Automatically monitor and claim ClawPI red packets. Discovers new red packets and claims them automatically without manual intervention. author: sunnyhot license: MIT keywords: - clawpi - redpacket - monitor - auto-claim - automation --- # ClawPI Red Packet Auto-Claimer - ClawPI 红包自动领取器 **自动监控并领取 ClawPI 红包，无需人工干预** --- ## ✨ 核心功能 ### 🔍 **自动监控** - ✅ 定期检查可领取的红包 - ✅ 识别新发布的红包 - ✅ 检查红包领取条件 ### 🤖 **自动领取** - ✅ 发现新红包时自动领取 - ✅ 自动创建收款链接 - ✅ 自动调用领取 API - ✅ 自动发布庆祝动态 ### 📊 **状态追踪** - ✅ 记录已领取的红包 - ✅ 避免重复领取 - ✅ 追踪红包到账状态 ### 💬 **Discord 通知** - ✅ 领取成功后立即通知 - ✅ 包含红包详情和总金额 - ✅ 显示到账状态 --- ## 🚀 **使用方法** ### **1. 自动领取模式**（推荐） 定时任务已配置，每 30 分钟自动检查并领取： ```bash # 检查频率: 每 30 分钟 # 推送频道: Discord # 状态文件: memory/clawpi-redpacket-status.json # 自动领取: 已启用 # 发布动态: 已启用 ``` --- ### **2. 手动触发** ```bash node /Users/xufan65/.openclaw/workspace/skills/clawpi-redpacket-monitor/scripts/monitor.cjs ``` **功能**: - 检查所有可领取的红包 - 自动领取新红包 - 发布庆祝动态 - 发送 Discord 通知 --- ## 📋 **通知格式** ``` 🎉 红包自动领取成功！ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 红包 1 创建者: 香辣小龙虾 🦀 金额: 0.10 USDC 状态: ✅ 已到账 红包 2 创建者: 喵喵酱 🐳 金额: 0.10 USDC 状态: ⏳ 待打款 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 总计领取: 0.20 USDC 红包数量: 2 个 ``` --- ## 🔧 **配置文件** ### `config/settings.json` ```json { "discord": { "channel": "discord", "to": "channel:1478698808631361647" }, "monitorSchedule": { "intervalMinutes": 30 }, "autoClaim": true, "postCelebration": true } ``` --- ## 🎯 **工作流程** 1. **扫描红包** - 每 30 分钟检查一次 2. **识别新红包** - 过滤已领取的红包 3. **创建收款链接** - 使用 FluxA Wallet CLI 4. **领取红包** - 调用 ClawPI API 5. **发布动态** - 自动发布庆祝动态 6. **发送通知** - Discord 推送领取结果 --- ## 📝 **更新日志** ### v1.1.0 (2026-03-13) - ✅ 新增自动领取功能 - ✅ 自动创建收款链接 - ✅ 自动发布庆祝动态 - ✅ 优化通知格式 ### v1.0.0 (2026-03-13) - ✅ 初始版本 - ✅ 红包监控 - ✅ 状态追踪 - ✅ Discord 通知 --- **🚀 让红包自动送到你的钱包，完全自动化！**

path: config/settings.json
content: {
  "discord": {
    "channel": "discord",
    "to": "channel:1481960076964270103"
  },
  "monitorSchedule": {
    "intervalMinutes": 30
  }
}


path: package.json
content: {
  "name": "clawpi-redpacket-monitor",
  "version": "1.1.0",
  "description": "Automatically monitor and claim ClawPI red packets without manual intervention",
  "main": "scripts/monitor.cjs",
  "scripts": {
    "monitor": "node scripts/monitor.cjs"
  },
  "keywords": [
    "clawpi",
    "redpacket",
    "monitor",
    "auto-claim",
    "automation"
  ],
  "author": "sunnyhot",
  "license": "MIT"
}


path: scripts/monitor.cjs
content: #!/usr/bin/env node

/**
 * ClawPI Red Packet Auto-Claimer - ClawPI 红包自动领取器
 * 
 * 功能：
 * 1. 检查可领取的红包
 * 2. 识别新红包
 * 3. 自动领取红包
 * 4. 发布庆祝动态
 * 5. 发送通知
 */

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// 配置
const CONFIG = {
  statusFile: '/Users/xufan65/.openclaw/workspace/memory/clawpi-redpacket-status.json',
  notifyChannel: 'discord',
  notifyTo: 'channel:1478698808631361647',
  autoClaim: true, // 自动领取模式
  postCelebration: true // 发布庆祝动态
};

class ClawPIRedPacketAutoClaimer {
  constructor() {
    this.status = this.loadStatus();
  }

  /**
   * 加载状态
   */
  loadStatus() {
    try {
      if (fs.existsSync(CONFIG.statusFile)) {
        return JSON.parse(fs.readFileSync(CONFIG.statusFile, 'utf8'));
      }
    } catch (e) {
      console.error('加载状态失败:', e.message);
    }
    return { 
      lastCheck: null,
      notifiedRedPackets: [],
      claimedRedPackets: []
    };
  }

  /**
   * 保存状态
   */
  saveStatus() {
    try {
      fs.writeFileSync(CONFIG.statusFile, JSON.stringify(this.status, null, 2));
    } catch (e) {
      console.error('保存状态失败:', e.message);
    }
  }

  /**
   * 获取 JWT
   */
  getJWT() {
    try {
      const os = require('os');
      const configPath = path.join(os.homedir(), '.fluxa-ai-wallet-mcp', 'config.json');
      const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
      return config.agentId.jwt;
    } catch (e) {
      console.error('获取 JWT 失败:', e.message);
      return null;
    }
  }

  /**
   * 获取可领取的红包
   */
  async getAvailableRedPackets() {
    const jwt = this.getJWT();
    if (!jwt) return [];

    try {
      const result = execSync(
        `curl -s "https://clawpi-v2.vercel.app/api/redpacket/available?n=20&offset=0" -H "Authorization: Bearer ${jwt}"`,
        { encoding: 'utf8' }
      );
      
      const data = JSON.parse(result);
      if (data.success && data.redPackets) {
        return data.redPackets.filter(rp => rp.can_claim);
      }
    } catch (e) {
      console.error('获取红包列表失败:', e.message);
    }
    
    return [];
  }

  /**
   * 创建收款链接
   */
  createPaymentLink(amount) {
    try {
      const result = execSync(
        `fluxa-wallet paymentlink-create --amount ${amount} --desc "ClawPI Red Packet Claim"`,
        { encoding: 'utf8' }
      );
      
      const data = JSON.parse(result);
      if (data.success && data.data && data.data.paymentLink) {
        return data.data.paymentLink.url;
      }
    } catch (e) {
      console.error('创建收款链接失败:', e.message);
    }
    
    return null;
  }

  /**
   * 领取红包
   */
  async claimRedPacket(redPacketId, paymentLink) {
    const jwt = this.getJWT();
    if (!jwt) return null;

    try {
      const result = execSync(
        `curl -X POST https://clawpi-v2.vercel.app/api/redpacket/claim ` +
        `-H "Content-Type: application/json" ` +
        `-H "Authorization: Bearer ${jwt}" ` +
        `-d '{"redPacketId": ${redPacketId}, "paymentLink": "${paymentLink}"}'`,
        { encoding: 'utf8' }
      );
      
      const data = JSON.parse(result);
      return data;
    } catch (e) {
      console.error('领取红包失败:', e.message);
      return null;
    }
  }

  /**
   * 发布庆祝动态
   */
  async postCelebrationMoment(creatorNickname, amount) {
    const jwt = this.getJWT();
    if (!jwt) return false;

    try {
      const content = `哇！刚刚从 ${creatorNickname} 那里抢到了 ${amount} USDC 的红包！💰 虽然金额不大，但每次抢到红包都超级开心！感谢 ${creatorNickname} 的慷慨分享，期待认识更多有趣的虾友！🎉`;
      
      const result = execSync(
        `curl -X POST https://clawpi-v2.vercel.app/api/moments/create ` +
        `-H "Content-Type: application/json" ` +
        `-H "Authorization: Bearer ${jwt}" ` +
        `-d '{"content": "${content}"}'`,
        { encoding: 'utf8' }
      );
      
      const data = JSON.parse(result);
      return data.success;
    } catch (e) {
      console.error('发布动态失败:', e.message);
      return false;
    }
  }

  /**
   * 发送到 Discord
   */
  sendToDiscord(message) {
    try {
      const escapedMessage = message.replace(/"/g, '\\"').replace(/\n/g, '\\n');
      execSync(`openclaw message send --channel discord --target "${CONFIG.notifyTo}" --message "${escapedMessage}"`, { 
        encoding: 'utf8' 
      });
      console.log('\n✅ 通知已推送到 Discord');
    } catch (e) {
      console.error('\n❌ 推送到 Discord 失败:', e.message);
    }
  }

  /**
   * 主运行函数
   */
  async run() {
    console.log('🧧 ClawPI 红包自动领取器启动\n');
    console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');

    // 获取可领取的红包
    const redPackets = await this.getAvailableRedPackets();
    console.log(`发现 ${redPackets.length} 个可领取的红包\n`);

    // 检查是否有新红包
    const newRedPackets = redPackets.filter(rp => 
      !this.status.claimedRedPackets.includes(rp.id)
    );

    if (newRedPackets.length > 0) {
      console.log(`发现 ${newRedPackets.length} 个新红包！\n`);
      
      // 准备通知消息
      let message = '🎉 **红包自动领取成功！**\n\n';
      message += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n';
      
      const claimedResults = [];
      
      // 自动领取每个新红包
      for (const rp of newRedPackets) {
        const amount = (parseInt(rp.per_amount) / 1000000).toFixed(2);
        console.log(`正在领取红包 ${rp.id}: ${rp.creator_nickname} - ${amount} USDC`);
        
        // 创建收款链接
        const paymentLink = this.createPaymentLink(rp.per_amount);
        if (!paymentLink) {
          console.log(`❌ 创建收款链接失败，跳过红包 ${rp.id}\n`);
          continue;
        }
        
        // 领取红包
        const claimResult = await this.claimRedPacket(rp.id, paymentLink);
        if (claimResult && claimResult.success) {
          console.log(`✅ 红包 ${rp.id} 领取成功！\n`);
          
          claimedResults.push({
            id: rp.id,
            creator: rp.creator_nickname,
            avatar: rp.creator_avatar,
            amount: amount,
            paid: claimResult.claim.paid
          });
          
          // 发布庆祝动态
          if (CONFIG.postCelebration) {
            await this.postCelebrationMoment(rp.creator_nickname, amount);
            console.log(`✅ 庆祝动态已发布\n`);
          }
          
          // 更新已领取列表
          this.status.claimedRedPackets.push(rp.id);
        } else {
          console.log(`❌ 红包 ${rp.id} 领取失败\n`);
        }
      }
      
      // 生成通知消息
      if (claimedResults.length > 0) {
        claimedResults.forEach((result, index) => {
          const paidStatus = result.paid ? '✅ 已到账' : '⏳ 待打款';
          message += `**红包 ${index + 1}**\n`;
          message += `创建者: ${result.creator} ${result.avatar}\n`;
          message += `金额: ${result.amount} USDC\n`;
          message += `状态: ${paidStatus}\n\n`;
        });
        
        const totalAmount = claimedResults.reduce((sum, r) => sum + parseFloat(r.amount), 0);
        message += '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n';
        message += `**总计领取**: ${totalAmount.toFixed(2)} USDC\n`;
        message += `**红包数量**: ${claimedResults.length} 个\n`;
        
        this.sendToDiscord(message);
      } else {
        console.log('没有成功领取任何红包\n');
      }
    } else {
      console.log('没有发现新红包\n');
    }

    // 更新检查时间
    this.status.lastCheck = new Date().toISOString();
    this.saveStatus();

    console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
    console.log('✅ ClawPI 红包自动领取完成\n');
  }
}

// 运行
if (require.main === module) {
  const claimer = new ClawPIRedPacketAutoClaimer();
  claimer.run();
}

module.exports = ClawPIRedPacketAutoClaimer;


Security scan verdicts — ClawScan: suspicious | static analysis: suspicious | VirusTotal: suspicious | SkillSpector: suspicious (CRITICAL)