mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2024-11-26 23:05:04 +08:00
✨新增marshoai-bangumi工具包
This commit is contained in:
parent
8221fa7928
commit
25942a5e9a
3
.gitignore
vendored
3
.gitignore
vendored
@ -167,4 +167,5 @@ cython_debug/
|
|||||||
bot.py
|
bot.py
|
||||||
pdm.lock
|
pdm.lock
|
||||||
praises.json
|
praises.json
|
||||||
*.bak
|
*.bak
|
||||||
|
config/
|
29
nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py
Normal file
29
nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py
Normal file
@ -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 ""
|
@ -0,0 +1,9 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": "marshoai-bangumi__get_bangumi_news",
|
||||||
|
"description": "获取今天的新番(动漫)列表,在调用之前,你需要知道今天星期几。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
@ -10,6 +10,11 @@ async def get_current_env():
|
|||||||
|
|
||||||
async def get_current_time():
|
async def get_current_time():
|
||||||
current_time = datetime.now().strftime("%Y.%m.%d %H:%M:%S")
|
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:])
|
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
|
return time_prompt
|
@ -3,7 +3,7 @@
|
|||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "marshoai-basic__get_current_time",
|
"name": "marshoai-basic__get_current_time",
|
||||||
"description": "获取现在的时间。"
|
"description": "获取现在的日期,时间和星期。"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
Loading…
Reference in New Issue
Block a user