Skip to content

Commit

Permalink
✨新增marshoai-bangumi工具包
Browse files Browse the repository at this point in the history
  • Loading branch information
Asankilp committed Nov 24, 2024
1 parent 8221fa7 commit 25942a5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,5 @@ cython_debug/
bot.py
pdm.lock
praises.json
*.bak
*.bak
config/
29 changes: 29 additions & 0 deletions nonebot_plugin_marshoai/tools/marshoai-bangumi/__init__.py
Original file line number Diff line number Diff line change
@@ -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 ""
9 changes: 9 additions & 0 deletions nonebot_plugin_marshoai/tools/marshoai-bangumi/tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"type": "function",
"function": {
"name": "marshoai-bangumi__get_bangumi_news",
"description": "获取今天的新番(动漫)列表,在调用之前,你需要知道今天星期几。"
}
}
]
7 changes: 6 additions & 1 deletion nonebot_plugin_marshoai/tools/marshoai-basic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion nonebot_plugin_marshoai/tools/marshoai-basic/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "function",
"function": {
"name": "marshoai-basic__get_current_time",
"description": "获取现在的时间"
"description": "获取现在的日期,时间和星期"
}
}
]

0 comments on commit 25942a5

Please sign in to comment.