天气丰富一下

This commit is contained in:
liuwei
2026-01-26 08:56:10 +08:00
parent 9be7f227b3
commit 2e088e5d37

View File

@@ -560,36 +560,68 @@ class WeatherPlugin(MessagePluginInterface):
# --- 旧版兼容方法,用于普通查询 ---
async def _get_weather_text_response(self, city_name: str) -> str:
"""普通查询流程:查找 -> 获取 -> 拼接"""
# 1. 查 ID
city_info = await self._lookup_city_info(city_name)
if not city_info: return ""
cid = city_info['id']
# 2. 查天气
cid = city_info.get('id')
raw = await self._fetch_weather_by_id(cid)
if not raw: return ""
# 3. 拼接
geo_str = f"{city_info['country']}{city_info['adm1']}{city_info['adm2']}"
now = raw['now']
daily = raw['daily_forecast']
msg = (
f"{geo_str} 实时天气☁️\n"
f"{raw['updateTime'][11:16]}\n\n"
f"🌡️ {now['temp']}℃ (体感{now['feelsLike']})\n"
f"☁️ {now['text']}\n"
f"🌬️ {now['windDir']} {now['windScale']}\n"
f"💦 湿度{now['humidity']}%\n"
f"👀 能见度{now['vis']}km\n\n"
f"☁️ 未来预报:\n"
)
for day in daily[0:3]:
d = day['fxDate'][5:]
msg += f"{d} {day['textDay']}|{day['tempMin']}~{day['tempMax']}\n"
return msg
now = raw.get('now', {})
daily = raw.get('daily_forecast', [])
today = daily[0] if daily else {}
history = self.redis_manager.get_history(cid) if self.redis_manager else None
update_hm = str(raw.get('updateTime', ''))[11:16]
geo_str = f"{city_info.get('country','')}{city_info.get('adm1','')}{city_info.get('adm2','')}"
title = f"{geo_str} | {city_info.get('name','')}"
t_now = now.get('temp', '-')
feels = now.get('feelsLike', '-')
text_now = now.get('text', '')
wind_dir = now.get('windDir', '')
wind_scale = now.get('windScale', '')
humidity = now.get('humidity', '')
vis = now.get('vis', '')
t_min = str(today.get('tempMin', ''))
t_max = str(today.get('tempMax', ''))
text_day = today.get('textDay', '')
uv = str(today.get('uvIndex', ''))
precip = str(today.get('precip', ''))
pressure = str(today.get('pressure', ''))
sunrise = today.get('sunrise', '')
sunset = today.get('sunset', '')
alerts = self._check_alerts_and_history(today, history) if today else []
tips = self._generate_life_tips(today) if today else []
clothing = self._get_clothing_advice(int(t_min) if t_min.isdigit() else 0, int(t_max) if t_max.isdigit() else 0) if today else ""
lines = []
lines.append(f"📍 {title}")
lines.append(f"{update_hm}")
lines.append("")
lines.append(f"🌡️ {t_now}℃ (体感{feels}℃) | {text_now}")
lines.append(f"💧 湿度{humidity}% | 🌬️ {wind_dir} {wind_scale}级 | 👀 能见度{vis}km")
if today:
lines.append(f"🗓️ 今日 {text_day} | {t_min}~{t_max}")
lines.append(f"☀️ 日出{sunrise} | <20> 日落{sunset}")
lines.append(f"🔆 紫外线{uv} | 🌧️ 降水{precip}mm | ⏱️ 气压{pressure}hPa")
if alerts:
lines.append("")
lines.append("⚠️ 特别关注")
for a in alerts[:3]:
lines.append(f"- {a}")
if tips:
lines.append("")
lines.append("<EFBFBD> 温馨提示")
for t in tips[:3]:
lines.append(f"- {t}")
if clothing:
lines.append("")
lines.append(f"<EFBFBD> 穿衣:{clothing}")
if daily:
lines.append("")
lines.append("📈 未来3天")
for day in daily[0:3]:
d = str(day.get('fxDate',''))[5:]
lines.append(f"- {d} {day.get('textDay','')} | {day.get('tempMin','')}~{day.get('tempMax','')}")
lines.append("")
lines.append("回复 '取消订阅' 可退订每日早报")
return "\n".join(lines)
def _extract_city_name(self, content: str) -> str:
content = content.replace(" ", "")