mirror of
https://github.com/Zippland/Bubbles.git
synced 2026-01-19 09:41:17 +08:00
Remove weather and news functions
This commit is contained in:
@@ -2,96 +2,9 @@
|
||||
AI路由功能注册
|
||||
将需要通过AI路由的功能在这里注册
|
||||
"""
|
||||
import re
|
||||
import json
|
||||
import os
|
||||
from typing import Optional, Match
|
||||
from datetime import datetime
|
||||
|
||||
from .ai_router import ai_router
|
||||
from .context import MessageContext
|
||||
|
||||
# ======== 天气功能 ========
|
||||
@ai_router.register(
|
||||
name="weather_query",
|
||||
description="查询城市未来五天的简要天气预报",
|
||||
examples=["北京天气怎么样", "上海天气"],
|
||||
params_description="城市名称"
|
||||
)
|
||||
def ai_handle_weather(ctx: MessageContext, params: str) -> bool:
|
||||
"""AI路由的天气查询处理"""
|
||||
city_name = params.strip()
|
||||
if not city_name:
|
||||
ctx.send_text("🤔 请告诉我你想查询哪个城市的天气")
|
||||
return True
|
||||
|
||||
# 加载城市代码
|
||||
city_codes = {}
|
||||
city_code_path = os.path.join(os.path.dirname(__file__), '..', 'function', 'main_city.json')
|
||||
try:
|
||||
with open(city_code_path, 'r', encoding='utf-8') as f:
|
||||
city_codes = json.load(f)
|
||||
except Exception as e:
|
||||
if ctx.logger:
|
||||
ctx.logger.error(f"加载城市代码文件失败: {e}")
|
||||
ctx.send_text("⚠️ 抱歉,天气功能暂时不可用")
|
||||
return True
|
||||
|
||||
# 查找城市代码
|
||||
city_code = city_codes.get(city_name)
|
||||
if not city_code:
|
||||
# 尝试模糊匹配
|
||||
for name, code in city_codes.items():
|
||||
if city_name in name:
|
||||
city_code = code
|
||||
city_name = name
|
||||
break
|
||||
|
||||
if not city_code:
|
||||
ctx.send_text(f"😕 找不到城市 '{city_name}' 的天气信息")
|
||||
return True
|
||||
|
||||
# 获取天气信息
|
||||
try:
|
||||
from function.func_weather import Weather
|
||||
weather_info = Weather(city_code).get_weather(include_forecast=True)
|
||||
ctx.send_text(weather_info)
|
||||
return True
|
||||
except Exception as e:
|
||||
if ctx.logger:
|
||||
ctx.logger.error(f"获取天气信息失败: {e}")
|
||||
ctx.send_text(f"😥 获取 {city_name} 天气时遇到问题")
|
||||
return True
|
||||
|
||||
# ======== 新闻功能 ========
|
||||
@ai_router.register(
|
||||
name="news_query",
|
||||
description="获取今日新闻",
|
||||
examples=["看看今天的新闻", "今日要闻"],
|
||||
params_description="无需参数"
|
||||
)
|
||||
def ai_handle_news(ctx: MessageContext, params: str) -> bool:
|
||||
"""AI路由的新闻查询处理"""
|
||||
try:
|
||||
from function.func_news import News
|
||||
news_instance = News()
|
||||
is_today, news_content = news_instance.get_important_news()
|
||||
|
||||
if is_today:
|
||||
ctx.send_text(f"📰 今日要闻来啦:\n{news_content}")
|
||||
else:
|
||||
if news_content:
|
||||
ctx.send_text(f"ℹ️ 今日新闻暂未发布,为您找到最近的一条新闻:\n{news_content}")
|
||||
else:
|
||||
ctx.send_text("❌ 获取新闻失败,请稍后重试")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
if ctx.logger:
|
||||
ctx.logger.error(f"获取新闻失败: {e}")
|
||||
ctx.send_text("❌ 获取新闻时发生错误")
|
||||
return True
|
||||
|
||||
# ======== 提醒功能 ========
|
||||
@ai_router.register(
|
||||
name="reminder_set",
|
||||
@@ -214,4 +127,4 @@ def ai_handle_perplexity(ctx: MessageContext, params: str) -> bool:
|
||||
if ctx.logger:
|
||||
ctx.logger.error(f"默认AI处理失败: {e}")
|
||||
|
||||
return was_handled
|
||||
return was_handled
|
||||
|
||||
@@ -28,13 +28,13 @@ class AIRouter:
|
||||
装饰器:注册一个功能到AI路由器
|
||||
|
||||
@ai_router.register(
|
||||
name="weather_query",
|
||||
description="查询指定城市的天气预报",
|
||||
examples=["北京天气怎么样", "查一下上海的天气", "明天深圳会下雨吗"],
|
||||
params_description="城市名称"
|
||||
name="reminder_set",
|
||||
description="设置提醒",
|
||||
examples=["提醒我下午3点开会", "每天早上8点提醒我吃早饭"],
|
||||
params_description="提醒时间和内容"
|
||||
)
|
||||
def handle_weather(ctx: MessageContext, params: str) -> bool:
|
||||
# 实现天气查询逻辑
|
||||
def handle_reminder(ctx: MessageContext, params: str) -> bool:
|
||||
# 实现提醒设置逻辑
|
||||
pass
|
||||
"""
|
||||
def decorator(func: Callable) -> Callable:
|
||||
@@ -88,8 +88,8 @@ class AIRouter:
|
||||
}
|
||||
|
||||
#### 示例:
|
||||
- 用户输入"北京天气怎么样" -> {"action_type": "function", "function_name": "weather_query", "params": "北京"}
|
||||
- 用户输入"看看新闻" -> {"action_type": "function", "function_name": "news_query", "params": ""}
|
||||
- 用户输入"提醒我下午3点开会" -> {"action_type": "function", "function_name": "reminder_set", "params": "下午3点开会"}
|
||||
- 用户输入"查看我的提醒" -> {"action_type": "function", "function_name": "reminder_list", "params": ""}
|
||||
- 用户输入"你好" -> {"action_type": "chat"}
|
||||
- 用户输入"查一下Python教程" -> {"action_type": "function", "function_name": "perplexity_search", "params": "Python教程"}
|
||||
|
||||
@@ -249,4 +249,4 @@ class AIRouter:
|
||||
return False
|
||||
|
||||
# 创建全局AI路由器实例
|
||||
ai_router = AIRouter()
|
||||
ai_router = AIRouter()
|
||||
|
||||
Reference in New Issue
Block a user