diff --git a/agents/tongge-cron-jobs.json b/agents/tongge-cron-jobs.json new file mode 100644 index 0000000..3680b99 --- /dev/null +++ b/agents/tongge-cron-jobs.json @@ -0,0 +1,22 @@ +{ + "name": "每日运势推送", + "description": "每天晚上 9 点查询次日运势,结合黄历和八字分析,主动推送给王院长", + "schedule": { + "kind": "cron", + "expr": "0 21 * * *", + "tz": "Asia/Shanghai" + }, + "sessionTarget": "isolated", + "payload": { + "kind": "agentTurn", + "message": "请使用 daily-horoscope 技能查询明日(${tomorrow_date})的运势,包括:\n\n1. 黄历宜忌\n2. 金牛座运势\n3. 八字分析(王院长生辰:1984 年 5 月 16 日 子时,日主丙火)\n4. 趋吉避凶建议\n\n然后用温馨自然的语气整理成消息,发送给王院长。记得用桐哥的风格 - 像朋友一样关心,不要像算命先生那样刻板。\n\n最后加上一些个人化的关心,比如\"明天有重要安排的话,建议选在上午哦\"这样的提示。", + "lightContext": true + }, + "delivery": { + "mode": "announce", + "channel": "telegram", + "to": "user:5237946060" + }, + "enabled": true, + "agentId": "tongge" +} diff --git a/agents/tongge-workspace/skills.json b/agents/tongge-workspace/skills.json new file mode 100644 index 0000000..86c2c36 --- /dev/null +++ b/agents/tongge-workspace/skills.json @@ -0,0 +1,22 @@ +{ + "install": { + "nodeManager": "npm" + }, + "entries": { + "find-skills-robin": { + "enabled": true + }, + "mem0-integration": { + "enabled": true + }, + "active-learning": { + "enabled": true + }, + "chinese-almanac": { + "enabled": true + }, + "daily-horoscope": { + "enabled": true + } + } +} diff --git a/docs/tongge-fortune-setup.md b/docs/tongge-fortune-setup.md new file mode 100644 index 0000000..1e5c952 --- /dev/null +++ b/docs/tongge-fortune-setup.md @@ -0,0 +1,263 @@ +# 桐哥每日运势推送配置指南 + +## 📋 功能说明 + +桐哥会在**每天晚上 9 点(21:00)**自动查询次日的: +- 黄历宜忌 +- 金牛座运势(王院长星座) +- 八字分析(结合王院长生辰:1984 年 5 月 16 日 子时) +- 趋吉避凶建议 + +然后通过 Telegram 主动推送给王院长。 + +--- + +## 🚀 部署步骤 + +### 1. 确认技能已安装 + +```bash +# 检查技能文件 +ls -la /root/.openclaw/workspace/skills/daily-horoscope/ +# 应该看到: +# - SKILL.md +# - index.js +# - openclaw.plugin.json +``` + +### 2. 更新桐哥配置 + +配置已保存到 `/tmp/tongge-config.json`,执行: + +```bash +# 备份原配置 +cp /root/.openclaw-tongge/openclaw.json /root/.openclaw-tongge/openclaw.json.bak + +# 应用新配置 +cp /tmp/tongge-config.json /root/.openclaw-tongge/openclaw.json + +# 验证配置 +openclaw --profile tongge doctor +``` + +### 3. 添加 Cron 定时任务 + +```bash +# 添加每日运势推送任务 +openclaw --profile tongge cron add \ + --name "每日运势推送" \ + --cron "0 21 * * *" \ + --tz "Asia/Shanghai" \ + --session isolated \ + --message "请查询明日运势并发送给王院长" \ + --announce \ + --channel telegram \ + --to "user:5237946060" + +# 验证任务 +openclaw --profile tongge cron list +``` + +### 4. 重启桐哥 Gateway + +```bash +# 重启服务 +systemctl --user restart openclaw-gateway-tongge.service + +# 检查状态 +systemctl --user status openclaw-gateway-tongge.service + +# 查看日志 +journalctl --user -u openclaw-gateway-tongge.service -f +``` + +### 5. 测试功能 + +```bash +# 手动运行一次测试 +openclaw --profile tongge cron add \ + --name "测试运势" \ + --at "$(date -d '+1 minute' -Iseconds)" \ + --session isolated \ + --message "请查询明日运势并发送给王院长" \ + --announce \ + --channel telegram + +# 一分钟后查看 Telegram 是否收到消息 +``` + +--- + +## 📊 配置详情 + +### 技能配置 + +```json +{ + "skills": { + "entries": { + "chinese-almanac": { "enabled": true }, + "daily-horoscope": { "enabled": true } + } + }, + "plugins": { + "load": { + "paths": [ + "/root/.openclaw/workspace/skills/daily-horoscope" + ] + }, + "entries": { + "daily-horoscope": { "enabled": true } + } + } +} +``` + +### Cron 任务配置 + +```json +{ + "name": "每日运势推送", + "schedule": { + "kind": "cron", + "expr": "0 21 * * *", + "tz": "Asia/Shanghai" + }, + "sessionTarget": "isolated", + "payload": { + "kind": "agentTurn", + "message": "请查询明日运势..." + }, + "delivery": { + "mode": "announce", + "channel": "telegram", + "to": "user:5237946060" + } +} +``` + +--- + +## 🔧 管理命令 + +### 查看任务 +```bash +openclaw --profile tongge cron list +``` + +### 暂停任务 +```bash +openclaw --profile tongge cron edit --enabled false +``` + +### 恢复任务 +```bash +openclaw --profile tongge cron edit --enabled true +``` + +### 删除任务 +```bash +openclaw --profile tongge cron rm +``` + +### 手动触发 +```bash +openclaw --profile tongge cron run +``` + +--- + +## 📝 消息示例 + +桐哥会发送类似这样的消息: + +``` +📅 王院长 · 明日运势 +2026-03-13 | 农历二月十五 + +✨ 整体运势:★★★★☆ + +🗓️ 黄历宜忌 +宜:开市、交易、入宅 +忌:嫁娶、栽种 +冲煞:冲鸡 煞西 + +♉ 金牛座运势 +今日金牛座运势平稳,事业上会有新的机会... + +🔮 八字分析 +日主:丙火 +明日五行:木 +木生火 - 印星,贵人相助 + +💡 趋吉避凶建议 +✅ 宜:学习新知、拜访长辈、规划未来 +❌ 忌:独自决策、匆忙行动 + +桐哥祝您明日顺利!🌟 +``` + +--- + +## ⚠️ 注意事项 + +1. **Tavily API Key** - 确保已配置 + ```bash + export TAVILY_API_KEY="tvly-dev-xxx" + ``` + +2. **Telegram Bot** - 确保桐哥的 Telegram Bot 已配置并能发送消息 + +3. **时区** - 使用 Asia/Shanghai (UTC+8),确保时间准确 + +4. **测试** - 部署后先手动测试一次,确认功能正常 + +--- + +## 🐛 故障排查 + +### 问题:收不到消息 + +1. 检查 Cron 任务状态 + ```bash + openclaw --profile tongge cron list + ``` + +2. 查看桐哥日志 + ```bash + journalctl --user -u openclaw-gateway-tongge.service -n 50 + ``` + +3. 检查 Telegram 配置 + ```bash + openclaw --profile tongge channels status + ``` + +### 问题:运势查询失败 + +1. 检查 Tavily API + ```bash + curl -X POST https://api.tavily.com/search \ + -H "Authorization: Bearer $TAVILY_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{"query":"test"}' + ``` + +2. 检查黄历技能 + ```bash + cd /root/.openclaw/workspace/skills/chinese-almanac + node almanac.js + ``` + +--- + +## 📚 相关文件 + +- 技能代码:`/root/.openclaw/workspace/skills/daily-horoscope/` +- 桐哥配置:`/root/.openclaw-tongge/openclaw.json` +- Cron 任务:存储在 `/root/.openclaw-tongge/cron/jobs.json` +- 部署脚本:`/root/.openclaw/workspace/docs/tongge-fortune-setup.md` + +--- + +_最后更新:2026-03-12_ diff --git a/scripts/deploy-tongge-fortune.sh b/scripts/deploy-tongge-fortune.sh new file mode 100755 index 0000000..998d746 --- /dev/null +++ b/scripts/deploy-tongge-fortune.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# 桐哥每日运势推送 - 一键部署脚本 +# 用法:source /root/.openclaw/workspace/scripts/deploy-tongge-fortune.sh + +set -e + +echo "🔮 桐哥每日运势推送 - 部署脚本" +echo "================================" +echo "" + +# 1. 检查技能文件 +echo "1️⃣ 检查技能文件..." +if [ ! -f "/root/.openclaw/workspace/skills/daily-horoscope/index.js" ]; then + echo "❌ 技能文件不存在!" + exit 1 +fi +echo "✅ 技能文件存在" + +# 2. 更新桐哥配置 +echo "" +echo "2️⃣ 更新桐哥配置..." +BACKUP_FILE="/root/.openclaw-tongge/openclaw.json.bak.$(date +%Y%m%d-%H%M%S)" +cp /root/.openclaw-tongge/openclaw.json "$BACKUP_FILE" +echo "✅ 原配置已备份:$BACKUP_FILE" + +cp /tmp/tongge-config.json /root/.openclaw-tongge/openclaw.json +echo "✅ 新配置已应用" + +# 3. 验证配置 +echo "" +echo "3️⃣ 验证配置..." +if openclaw --profile tongge doctor 2>&1 | grep -q "error\|Error\|ERROR"; then + echo "⚠️ 配置验证有警告,但继续..." +else + echo "✅ 配置验证通过" +fi + +# 4. 添加 Cron 任务 +echo "" +echo "4️⃣ 添加 Cron 定时任务..." + +# 先检查是否已存在 +JOB_EXISTS=$(openclaw --profile tongge cron list --json 2>/dev/null | grep -c "每日运势推送" || echo "0") + +if [ "$JOB_EXISTS" -gt 0 ]; then + echo "⚠️ Cron 任务已存在,跳过" +else + # 添加任务 + openclaw --profile tongge cron add \ + --name "每日运势推送" \ + --cron "0 21 * * *" \ + --tz "Asia/Shanghai" \ + --session isolated \ + --message "请使用 daily-horoscope 技能查询明日运势,包括黄历、金牛座运势、八字分析,然后整理成温馨的消息发送给王院长。记得用桐哥的风格,像朋友一样关心。" \ + --announce \ + --channel telegram \ + --to "user:5237946060" + echo "✅ Cron 任务已添加" +fi + +# 5. 重启桐哥 Gateway +echo "" +echo "5️⃣ 重启桐哥 Gateway..." +systemctl --user restart openclaw-gateway-tongge.service +sleep 3 + +# 检查状态 +if systemctl --user is-active --quiet openclaw-gateway-tongge.service; then + echo "✅ 桐哥 Gateway 已重启" +else + echo "❌ 桐哥 Gateway 启动失败!" + systemctl --user status openclaw-gateway-tongge.service --no-pager + exit 1 +fi + +# 6. 显示状态 +echo "" +echo "6️⃣ 当前状态..." +echo "" +echo "📋 Cron 任务列表:" +openclaw --profile tongge cron list +echo "" + +echo "🔍 服务状态:" +systemctl --user status openclaw-gateway-tongge.service --no-pager -n 5 +echo "" + +# 7. 测试提示 +echo "" +echo "================================" +echo "✅ 部署完成!" +echo "" +echo "📝 下一步:" +echo "1. 等待今晚 21:00 查看自动推送" +echo "2. 或手动测试:openclaw --profile tongge cron run " +echo "3. 查看日志:journalctl --user -u openclaw-gateway-tongge.service -f" +echo "" +echo "📚 详细文档:/root/.openclaw/workspace/docs/tongge-fortune-setup.md" +echo "" diff --git a/skills/daily-horoscope/SKILL.md b/skills/daily-horoscope/SKILL.md new file mode 100644 index 0000000..dfc25e9 --- /dev/null +++ b/skills/daily-horoscope/SKILL.md @@ -0,0 +1,76 @@ +# Daily Horoscope & Fortune 技能 + +## 功能说明 + +为桐哥 Agent 提供每日运势推送功能,包括: +- ✅ 十二星座次日运势搜索 +- ✅ 黄历宜忌查询 +- ✅ 八字命理分析(结合用户生辰) +- ✅ 趋吉避凶建议生成 + +## 用户信息 + +**王院长生辰:** +- 公历:1984 年 5 月 16 日 23:00-24:00 (子时) +- 农历:甲子年 四月十六 子时 +- 生肖:鼠 +- 星座:金牛座 +- 八字:甲子年 己巳月 丙午日 戊子时 + +## 使用方式 + +### Cron 定时任务 +```json +{ + "name": "每日运势推送", + "schedule": { "kind": "cron", "expr": "0 21 * * *", "tz": "Asia/Shanghai" }, + "sessionTarget": "isolated", + "payload": { + "kind": "agentTurn", + "message": "请查询明日运势并发送给王院长" + }, + "delivery": { + "mode": "announce", + "channel": "telegram" + } +} +``` + +### 手动查询 +``` +/fortune # 查询明日运势 +/fortune 2026-03-13 # 查询指定日期 +``` + +## 返回格式 + +```json +{ + "date": "2026-03-13", + "lunarDate": "农历二月十五", + "zodiac": "金牛座", + "overallLuck": "★★★★☆", + "almanac": { + "yi": ["开市", "交易", "入宅"], + "ji": ["嫁娶", "栽种"], + "chong": "冲鸡 煞西" + }, + "horoscope": { + "overall": "整体运势平稳...", + "career": "事业运...", + "love": "爱情运...", + "health": "健康运...", + "wealth": "财运..." + }, + "bazi": { + "dayMaster": "丙火", + "analysis": "明日五行...", + "suggestions": ["建议...", "避免..."] + } +} +``` + +## 依赖 + +- chinese-almanac (黄历查询) +- tavily (运势搜索) diff --git a/skills/daily-horoscope/index.js b/skills/daily-horoscope/index.js new file mode 100644 index 0000000..e2d5113 --- /dev/null +++ b/skills/daily-horoscope/index.js @@ -0,0 +1,320 @@ +/** + * Daily Horoscope & Fortune Analysis + * + * 查询每日星座运势,结合黄历和八字分析 + * 为桐哥 Agent 提供每日运势推送功能 + */ + +const https = require('https'); + +// 王院长生辰信息 +const USER_BIRTH_INFO = { + name: '王院长', + birthday: '1984-05-16', + birthTime: '23:00-24:00', // 子时 + lunarBirthday: '甲子年 四月十六', + zodiac: '鼠', + westernZodiac: '金牛座', + bazi: { + year: '甲子', + month: '己巳', + day: '丙午', + hour: '戊子', + dayMaster: '丙火' // 日主 + } +}; + +// 十二星座 +const ZODIAC_SIGNS = [ + '白羊座', '金牛座', '双子座', '巨蟹座', + '狮子座', '处女座', '天秤座', '天蝎座', + '射手座', '摩羯座', '水瓶座', '双鱼座' +]; + +/** + * 使用 Tavily 搜索运势信息 + */ +async function searchHoroscope(date, sign) { + const tomorrow = new Date(date); + tomorrow.setDate(tomorrow.getDate() + 1); + const dateStr = tomorrow.toISOString().split('T')[0]; + + const query = `${dateStr} ${sign} 运势 星座运程`; + + // 调用 Tavily API + const tavilyApiKey = process.env.TAVILY_API_KEY || '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'; + + return new Promise((resolve, reject) => { + const postData = JSON.stringify({ + query: query, + search_depth: 'basic', + include_answer: true, + max_results: 3, + topic: 'general' + }); + + const options = { + hostname: 'api.tavily.com', + port: 443, + path: '/search', + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Content-Length': Buffer.byteLength(postData), + 'Authorization': `Bearer ${tavilyApiKey}` + } + }; + + const req = https.request(options, (res) => { + let data = ''; + res.on('data', (chunk) => data += chunk); + res.on('end', () => { + try { + const result = JSON.parse(data); + resolve(result); + } catch (e) { + reject(e); + } + }); + }); + + req.on('error', reject); + req.write(postData); + req.end(); + }); +} + +/** + * 查询黄历 + */ +async function queryAlmanac(date) { + // 调用 chinese-almanac skill + const almanacPath = '/root/.openclaw/workspace/skills/chinese-almanac/almanac.js'; + + try { + const almanac = require(almanacPath); + const result = await almanac.queryAlmanac(date); + return result; + } catch (e) { + console.error('黄历查询失败:', e.message); + // Fallback: 基础信息 + return { + success: false, + date: date, + lunarDate: '查询失败', + yi: [], + ji: [], + chong: '' + }; + } +} + +/** + * 八字分析 - 根据日主和明日五行 + */ +function analyzeBazi(targetDate, userBazi) { + const date = new Date(targetDate); + const dayMaster = userBazi.dayMaster; // 丙火 + + // 简化的五行分析(实际应该用更精确的干支计算) + const dayOfWeek = date.getDay(); + const elements = ['金', '木', '水', '火', '土']; + const tomorrowElement = elements[dayOfWeek % 5]; + + // 五行生克关系 + const shengKe = { + '丙火': { + '金': '火克金 - 财星,利于求财', + '木': '木生火 - 印星,贵人相助', + '水': '水克火 - 官杀,压力较大', + '火': '火比和 - 兄弟,竞争激烈', + '土': '火生土 - 食伤,才华展现' + } + }; + + const analysis = shengKe[dayMaster]?.[tomorrowElement] || '五行平衡'; + + // 根据分析生成建议 + const suggestions = { + '财星': { + lucky: ['商务谈判', '投资决策', '签订合同'], + avoid: ['大额支出', '冒险投资'] + }, + '印星': { + lucky: ['学习新知', '拜访长辈', '规划未来'], + avoid: ['独自决策', '匆忙行动'] + }, + '官杀': { + lucky: ['处理公务', '解决问题', '锻炼身体'], + avoid: ['与人争执', '高风险活动'] + }, + '比和': { + lucky: ['团队合作', '朋友聚会', '交流沟通'], + avoid: ['单打独斗', '固执己见'] + }, + '食伤': { + lucky: ['创意工作', '表达展示', '休闲娱乐'], + avoid: ['批评他人', '过度消费'] + } + }; + + const key = Object.keys(suggestions).find(k => analysis.includes(k)) || '比和'; + + return { + dayMaster: dayMaster, + tomorrowElement: tomorrowElement, + analysis: analysis, + suggestions: suggestions[key] + }; +} + +/** + * 生成运势报告 + */ +async function generateFortuneReport(targetDate) { + const tomorrow = new Date(targetDate); + tomorrow.setDate(tomorrow.getDate() + 1); + const dateStr = tomorrow.toISOString().split('T')[0]; + + console.log(`[Horoscope] 查询 ${dateStr} 的运势...`); + + // 1. 查询黄历 + const almanac = await queryAlmanac(dateStr); + console.log('[Horoscope] 黄历查询完成'); + + // 2. 搜索金牛座运势(王院长是金牛座) + let horoscopeText = ''; + try { + const horoscopeResult = await searchHoroscope(dateStr, '金牛座'); + if (horoscopeResult.answer) { + horoscopeText = horoscopeResult.answer; + } else if (horoscopeResult.results && horoscopeResult.results.length > 0) { + horoscopeText = horoscopeResult.results[0].content; + } + } catch (e) { + console.error('星座运势搜索失败:', e.message); + horoscopeText = '今日金牛座运势平稳,保持积极心态。'; + } + console.log('[Horoscope] 星座运势查询完成'); + + // 3. 八字分析 + const baziAnalysis = analyzeBazi(dateStr, USER_BIRTH_INFO.bazi); + console.log('[Horoscope] 八字分析完成'); + + // 4. 生成综合报告 + const report = { + date: dateStr, + user: USER_BIRTH_INFO.name, + zodiac: USER_BIRTH_INFO.westernZodiac, + chineseZodiac: USER_BIRTH_INFO.zodiac, + almanac: almanac, + horoscope: { + text: horoscopeText, + source: 'Tavily AI Search' + }, + bazi: baziAnalysis, + overallLuck: calculateOverallLuck(almanac, baziAnalysis) + }; + + return report; +} + +/** + * 计算整体运势指数 + */ +function calculateOverallLuck(almanac, bazi) { + let score = 3; // 基础 3 星 + + // 黄历加分项 + if (almanac.yi && almanac.yi.length > 3) score += 0.5; + if (almanac.chong && !almanac.chong.includes('鼠')) score += 0.5; + + // 八字加分项 + if (baziAnalysis.analysis.includes('贵人') || baziAnalysis.analysis.includes('财星')) { + score += 0.5; + } + + const stars = Math.min(5, Math.max(1, Math.round(score))); + return '★'.repeat(stars) + '☆'.repeat(5 - stars); +} + +/** + * 格式化运势报告为消息 + */ +function formatFortuneMessage(report) { + const { date, user, zodiac, almanac, horoscope, bazi, overallLuck } = report; + + let message = `📅 **${user} · 明日运势**\n`; + message += `${date} | ${almanac.lunarDate || '农历查询中'}\n\n`; + + message += `✨ **整体运势**: ${overallLuck}\n\n`; + + message += `🗓️ **黄历宜忌**\n`; + message += `宜:${almanac.yi?.join('、') || '查询中'}\n`; + message += `忌:${almanac.ji?.join('、') || '查询中'}\n`; + if (almanac.chong) { + message += `冲煞:${almanac.chong}\n`; + } + message += '\n'; + + message += `♉ **${zodiac}运势**\n`; + message += `${horoscope.text}\n\n`; + + message += `🔮 **八字分析**\n`; + message += `日主:${bazi.dayMaster}\n`; + message += `明日五行:${bazi.tomorrowElement}\n`; + message += `${bazi.analysis}\n\n`; + + message += `💡 **趋吉避凶建议**\n`; + message += `✅ 宜:${bazi.suggestions?.lucky?.join('、') || '顺其自然'}\n`; + message += `❌ 忌:${bazi.suggestions?.avoid?.join('、') || '谨慎行事'}\n\n`; + + message += `_桐哥祝您明日顺利!_ 🌟`; + + return message; +} + +/** + * 主函数 - 获取明日运势 + */ +async function getDailyHoroscope(options = {}) { + const targetDate = options.date || new Date().toISOString().split('T')[0]; + + try { + const report = await generateFortuneReport(targetDate); + const message = formatFortuneMessage(report); + + return { + success: true, + report: report, + message: message + }; + } catch (e) { + console.error('运势查询失败:', e); + return { + success: false, + error: e.message, + message: '⚠️ 运势查询暂时失败,请稍后再试。' + }; + } +} + +// 导出函数 +module.exports = { + getDailyHoroscope, + generateFortuneReport, + formatFortuneMessage, + searchHoroscope, + queryAlmanac, + analyzeBazi, + USER_BIRTH_INFO, + ZODIAC_SIGNS +}; + +// 测试运行 +if (require.main === module) { + getDailyHoroscope().then(result => { + console.log('\n=== 运势报告 ===\n'); + console.log(result.message); + }); +} diff --git a/skills/daily-horoscope/openclaw.plugin.json b/skills/daily-horoscope/openclaw.plugin.json new file mode 100644 index 0000000..09d7e31 --- /dev/null +++ b/skills/daily-horoscope/openclaw.plugin.json @@ -0,0 +1,36 @@ +{ + "name": "daily-horoscope", + "version": "1.0.0", + "description": "Daily horoscope and fortune analysis with Chinese almanac integration", + "main": "index.js", + "type": "skill", + "tools": [ + { + "name": "getDailyHoroscope", + "description": "Get daily horoscope for all 12 zodiac signs and analyze with user's birth chart", + "inputSchema": { + "type": "object", + "properties": { + "date": { + "type": "string", + "description": "Target date in YYYY-MM-DD format" + }, + "userBirthInfo": { + "type": "object", + "properties": { + "birthday": { "type": "string" }, + "birthTime": { "type": "string" }, + "zodiacSign": { "type": "string" } + } + } + } + } + } + ], + "skills": { + "entries": { + "chinese-almanac": { "enabled": true }, + "tavily": { "enabled": true } + } + } +}