mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-08-02 08:29:51 +00:00
✨ 添加内置工具插件,支持获取已加载插件列表和读取本地文件内容功能
This commit is contained in:
23
nonebot_plugin_marshoai/plugins/builtin_tools/file_io.py
Normal file
23
nonebot_plugin_marshoai/plugins/builtin_tools/file_io.py
Normal file
@ -0,0 +1,23 @@
|
||||
import aiofiles # type: ignore
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
from nonebot_plugin_marshoai.plugin import String, on_function_call
|
||||
|
||||
|
||||
@on_function_call(description="获取设备上本地文件内容").params(
|
||||
fp=String(description="文件路径")
|
||||
).permission(SUPERUSER)
|
||||
async def read_file(fp: str) -> str:
|
||||
"""获取设备上本地文件内容
|
||||
|
||||
Args:
|
||||
fp (str): 文件路径
|
||||
|
||||
Returns:
|
||||
str: 文件内容
|
||||
"""
|
||||
try:
|
||||
async with aiofiles.open(fp, "r", encoding="utf-8") as f:
|
||||
return await f.read()
|
||||
except Exception as e:
|
||||
return "读取出错: " + str(e)
|
Reference in New Issue
Block a user