From 2e088e5d373ac8b1a98f542af41527f8177cb30c Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 26 Jan 2026 08:56:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=94=E4=B8=B0=E5=AF=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/weather/main.py | 84 ++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/plugins/weather/main.py b/plugins/weather/main.py index 2fcf9e9..048531c 100644 --- a/plugins/weather/main.py +++ b/plugins/weather/main.py @@ -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} | � 日落{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("� 温馨提示") + for t in tips[:3]: + lines.append(f"- {t}") + if clothing: + lines.append("") + lines.append(f"� 穿衣:{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(" ", "")