diff --git a/.gitignore b/.gitignore index 38fe047..a308d61 100644 --- a/.gitignore +++ b/.gitignore @@ -167,4 +167,5 @@ cython_debug/ bot.py pdm.lock praises.json -*.bak \ No newline at end of file +*.bak +config/ \ No newline at end of file diff --git a/nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py b/nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py new file mode 100644 index 0000000..1952c3d --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py @@ -0,0 +1,29 @@ +import httpx +import traceback +async def fetch_calendar(): + url = 'https://api.bgm.tv/calendar' + headers = { + 'User-Agent': 'LiteyukiStudio/nonebot-plugin-marshoai (https://github.com/LiteyukiStudio/nonebot-plugin-marshoai)' + } + async with httpx.AsyncClient() as client: + response = await client.get(url, headers=headers) + #print(response.text) + return response.json() + +async def get_bangumi_news(): + result = await fetch_calendar() + info = "" + try: + for i in result: + weekday = i["weekday"]["cn"] + #print(weekday) + info += f"{weekday}:" + items = i["items"] + for item in items: + name = item["name_cn"] + info += f"《{name}》" + info += "\n" + return info + except Exception as e: + traceback.print_exc() + return "" \ No newline at end of file diff --git a/nonebot_plugin_marshoai/tools/marshoai-bangumi/tools.json b/nonebot_plugin_marshoai/tools/marshoai-bangumi/tools.json new file mode 100644 index 0000000..c2c0b93 --- /dev/null +++ b/nonebot_plugin_marshoai/tools/marshoai-bangumi/tools.json @@ -0,0 +1,9 @@ +[ + { + "type": "function", + "function": { + "name": "marshoai-bangumi__get_bangumi_news", + "description": "获取今天的新番(动漫)列表,在调用之前,你需要知道今天星期几。" + } + } +] \ No newline at end of file diff --git a/nonebot_plugin_marshoai/tools/marshoai-basic/__init__.py b/nonebot_plugin_marshoai/tools/marshoai-basic/__init__.py index bbf1af9..0a08bed 100644 --- a/nonebot_plugin_marshoai/tools/marshoai-basic/__init__.py +++ b/nonebot_plugin_marshoai/tools/marshoai-basic/__init__.py @@ -10,6 +10,11 @@ async def get_current_env(): async def get_current_time(): current_time = datetime.now().strftime("%Y.%m.%d %H:%M:%S") + current_weekday = datetime.now().weekday() + + weekdays = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] + current_weekday_name = weekdays[current_weekday] + current_lunar_date = (DateTime.now().to_lunar().date_hanzify()[5:]) - time_prompt = f"现在的时间是{current_time},农历{current_lunar_date}。" + time_prompt = f"现在的时间是{current_time},{current_weekday_name},农历{current_lunar_date}。" return time_prompt \ No newline at end of file diff --git a/nonebot_plugin_marshoai/tools/marshoai-basic/tools.json b/nonebot_plugin_marshoai/tools/marshoai-basic/tools.json index 08a0254..eda028e 100644 --- a/nonebot_plugin_marshoai/tools/marshoai-basic/tools.json +++ b/nonebot_plugin_marshoai/tools/marshoai-basic/tools.json @@ -3,7 +3,7 @@ "type": "function", "function": { "name": "marshoai-basic__get_current_time", - "description": "获取现在的时间。" + "description": "获取现在的日期,时间和星期。" } } ] \ No newline at end of file