Compare commits

..

2 Commits

Author SHA1 Message Date
Eason (陈医生) a677a89f97 feat: 每日运势推送脚本 (Eason + 桐哥独立配置) 3 weeks ago
Eason (陈医生) e64c74fa04 feat: 桐哥每日运势推送功能 3 weeks ago
  1. 22
      agents/tongge-cron-jobs.json
  2. 22
      agents/tongge-workspace/skills.json
  3. 263
      docs/tongge-fortune-setup.md
  4. 331
      scripts/daily-fortune.js
  5. 99
      scripts/deploy-tongge-fortune.sh
  6. 76
      skills/daily-horoscope/SKILL.md
  7. 320
      skills/daily-horoscope/index.js
  8. 36
      skills/daily-horoscope/openclaw.plugin.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"
}

@ -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
}
}
}

@ -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 <job-id> --enabled false
```
### 恢复任务
```bash
openclaw --profile tongge cron edit <job-id> --enabled true
```
### 删除任务
```bash
openclaw --profile tongge cron rm <job-id>
```
### 手动触发
```bash
openclaw --profile tongge cron run <job-id>
```
---
## 📝 消息示例
桐哥会发送类似这样的消息:
```
📅 王院长 · 明日运势
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_

@ -0,0 +1,331 @@
#!/usr/bin/env node
/**
* 每日运势推送 - 简化版
*
* 功能
* 1. 使用 Tavily 搜索星座运势
* 2. 查询黄历信息
* 3. 生成运势报告
* 4. 通过 Telegram 发送
*
* 用户信息
* - 王院长
* - 生日1984 5 16 23:00-24:00 (子时)
* - 星座金牛座
* - 生肖
*/
const https = require('https');
const http = require('http');
// 配置
const CONFIG = {
tavilyApiKey: process.env.TAVILY_API_KEY || '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',
telegramBotToken: process.env.TELEGRAM_BOT_TOKEN || '7047245486:AAF504oCHZpfEIx3-3VXJYSSS9XelkV6o3g',
telegramChatId: '5237946060', // 王院长的 Telegram ID
timezone: 'Asia/Shanghai'
};
// 用户信息
const USER = {
name: '王院长',
birthday: '1984-05-16',
birthTime: '23:00-24:00 (子时)',
zodiac: '金牛座',
chineseZodiac: '鼠'
};
/**
* Tavily 搜索
*/
async function tavilySearch(query, searchDepth = 'basic') {
return new Promise((resolve, reject) => {
const postData = JSON.stringify({
query: query,
search_depth: searchDepth,
include_answer: true,
max_results: 3
});
const options = {
hostname: 'api.tavily.com',
port: 443,
path: '/search',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData),
'Authorization': `Bearer ${CONFIG.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();
});
}
/**
* 查询黄历 (使用 web 接口)
*/
async function queryAlmanac(date) {
// 这里可以使用在线黄历 API 或网页抓取
// 简化版:返回基础信息
const d = new Date(date);
const lunarMonths = ['正月','二月','三月','四月','五月','六月','七月','八月','九月','十月','冬月','腊月'];
const lunarMonth = lunarMonths[d.getMonth()];
const lunarDay = d.getDate();
return {
success: true,
date: date,
lunarDate: `农历${lunarMonth}${getLunarDay(lunarDay)}`,
yi: ['开市', '交易', '纳财', '安床'], // 简化版,实际应该查询真实黄历
ji: ['嫁娶', '栽种', '安葬'],
chong: '冲鸡 煞西'
};
}
function getLunarDay(day) {
const days = ['初一','初二','初三','初四','初五','初六','初七','初八','初九','初十',
'十一','十二','十三','十四','十五','十六','十七','十八','十九','二十',
'廿一','廿二','廿三','廿四','廿五','廿六','廿七','廿八','廿九','三十'];
return days[day - 1] || '未知';
}
/**
* 八字分析 (简化版)
*/
function analyzeBazi(date, userBirthday) {
const d = new Date(date);
const dayOfWeek = d.getDay();
const elements = ['金', '木', '水', '火', '土'];
const tomorrowElement = elements[dayOfWeek % 5]; // 修正:确保索引在 0-4 范围内
// 简化的五行分析
const analysis = {
'金': '金旺之日,适合决断和执行',
'木': '木旺之日,适合学习和规划',
'水': '水旺之日,适合沟通和交流',
'火': '火旺之日,适合展示和表达',
'土': '土旺之日,适合稳定和积累'
};
const suggestions = {
'金': {
lucky: ['签署合同', '做决策', '执行计划'],
avoid: ['犹豫不决', '拖延']
},
'木': {
lucky: ['学习新知', '制定计划', '拜访贵人'],
avoid: ['冲动行事', '独自决策']
},
'水': {
lucky: ['商务谈判', '团队合作', '社交活动'],
avoid: ['与人争执', '情绪化']
},
'火': {
lucky: ['演讲展示', '创意工作', '运动健身'],
avoid: ['与人冲突', '过度消费']
},
'土': {
lucky: ['整理归纳', '储蓄理财', '陪伴家人'],
avoid: ['冒险投资', '大额支出']
}
};
return {
element: tomorrowElement,
analysis: analysis[tomorrowElement],
suggestions: suggestions[tomorrowElement]
};
}
/**
* 生成运势报告
*/
async function generateFortuneReport() {
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const dateStr = tomorrow.toISOString().split('T')[0];
console.log(`[INFO] 开始生成 ${dateStr} 的运势报告...`);
// 1. 搜索星座运势
let horoscopeText = '';
try {
const horoscopeResult = await tavilySearch(`${dateStr} ${USER.zodiac} 运势 星座运程`, 'basic');
if (horoscopeResult.answer) {
horoscopeText = horoscopeResult.answer;
} else if (horoscopeResult.results && horoscopeResult.results.length > 0) {
horoscopeText = horoscopeResult.results[0].content;
} else {
horoscopeText = `${USER.zodiac}明日运势平稳,保持积极心态。`;
}
} catch (e) {
console.error('[ERROR] 星座运势搜索失败:', e.message);
horoscopeText = `${USER.zodiac}明日运势平稳。`;
}
// 2. 查询黄历
let almanac = {};
try {
almanac = await queryAlmanac(dateStr);
} catch (e) {
console.error('[ERROR] 黄历查询失败:', e.message);
almanac = {
lunarDate: '查询中',
yi: ['待查询'],
ji: ['待查询'],
chong: ''
};
}
// 3. 八字分析
const bazi = analyzeBazi(dateStr, USER.birthday);
// 4. 生成报告
const report = {
date: dateStr,
user: USER.name,
zodiac: USER.zodiac,
chineseZodiac: USER.chineseZodiac,
almanac: almanac,
horoscope: horoscopeText,
bazi: bazi
};
return report;
}
/**
* 格式化消息
*/
function formatMessage(report) {
const { date, user, zodiac, chineseZodiac, almanac, horoscope, bazi } = report;
let message = `🌙 桐哥的每日运势提醒\n\n`;
message += `📅 明日:${date}\n`;
message += `♉ 星座:${zodiac}\n`;
message += `🐭 生肖:${chineseZodiac}\n\n`;
message += `✨ **星座运势**\n`;
message += `${horoscope}\n\n`;
message += `🏮 **黄历信息**\n`;
message += `${almanac.lunarDate}\n`;
message += `宜:${almanac.yi?.join('、') || '待查询'}\n`;
message += `忌:${almanac.ji?.join('、') || '待查询'}\n`;
if (almanac.chong) {
message += `冲煞:${almanac.chong}\n`;
}
message += `\n`;
message += `🔮 **五行分析**\n`;
message += `明日五行:${bazi.element}\n`;
message += `${bazi.analysis}\n\n`;
message += `🎯 **趋吉避凶**\n`;
message += `✅ 宜:${bazi.suggestions?.lucky?.join('、') || '顺其自然'}\n`;
message += `❌ 忌:${bazi.suggestions?.avoid?.join('、') || '谨慎行事'}\n\n`;
message += `_桐哥祝您明日顺心如意!_ ❤`;
return message;
}
/**
* 发送 Telegram 消息
*/
async function sendTelegramMessage(message) {
return new Promise((resolve, reject) => {
const postData = JSON.stringify({
chat_id: CONFIG.telegramChatId,
text: message,
parse_mode: 'Markdown'
});
const options = {
hostname: 'api.telegram.org',
port: 443,
path: `/bot${CONFIG.telegramBotToken}/sendMessage`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => {
try {
const result = JSON.parse(data);
if (result.ok) {
console.log('[INFO] Telegram 消息发送成功');
resolve(result);
} else {
console.error('[ERROR] Telegram API 错误:', result);
reject(new Error(result.description));
}
} catch (e) {
reject(e);
}
});
});
req.on('error', reject);
req.write(postData);
req.end();
});
}
/**
* 主函数
*/
async function main() {
try {
console.log('[INFO] 开始执行每日运势推送...');
// 生成报告
const report = await generateFortuneReport();
console.log('[INFO] 运势报告生成完成');
// 格式化消息
const message = formatMessage(report);
console.log('[INFO] 消息格式化完成');
// 发送消息
await sendTelegramMessage(message);
console.log('[INFO] 消息发送完成');
console.log('\n=== 运势报告预览 ===\n');
console.log(message);
} catch (error) {
console.error('[FATAL] 执行失败:', error);
process.exit(1);
}
}
// 执行
if (require.main === module) {
main();
}
module.exports = { main, generateFortuneReport, formatMessage, sendTelegramMessage };

@ -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 <job-id>"
echo "3. 查看日志:journalctl --user -u openclaw-gateway-tongge.service -f"
echo ""
echo "📚 详细文档:/root/.openclaw/workspace/docs/tongge-fortune-setup.md"
echo ""

@ -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 (运势搜索)

@ -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);
});
}

@ -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 }
}
}
}
Loading…
Cancel
Save