mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-08-01 22:59:53 +00:00
添加强制设置昵称配置项,移动测试插件到单独文件夹,稍微修改memory插件description(应该还是无法达到预期喵)
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
import random
|
||||
|
||||
from nonebot_plugin_marshoai.plugin import Integer, PluginMetadata, on_function_call
|
||||
|
||||
__marsho_meta__ = PluginMetadata(
|
||||
name="随机数生成器", author="MarshoAI", description="生成指定数量的随机数"
|
||||
)
|
||||
|
||||
|
||||
@on_function_call(description="生成随机数").params(
|
||||
count=Integer(description="随机数的数量")
|
||||
)
|
||||
async def generate_random_numbers(count: int) -> str:
|
||||
random_numbers = [random.randint(1, 100) for _ in range(count)]
|
||||
return f"生成的随机数为: {', '.join(map(str, random_numbers))}"
|
||||
|
||||
|
||||
# 该插件由MarshoAI自举编写
|
||||
|
||||
|
||||
@on_function_call(description="重载测试")
|
||||
def test_reload():
|
||||
return 1
|
@ -0,0 +1,108 @@
|
||||
import os
|
||||
import platform
|
||||
|
||||
import psutil
|
||||
from nonebot.adapters import Bot, Event
|
||||
|
||||
# from nonebot.adapters.onebot.v11 import MessageEvent
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
from nonebot_plugin_marshoai.plugin import (
|
||||
Integer,
|
||||
Parameter,
|
||||
PluginMetadata,
|
||||
String,
|
||||
on_function_call,
|
||||
)
|
||||
from nonebot_plugin_marshoai.plugin.func_call.caller import Caller
|
||||
|
||||
__marsho_meta__ = PluginMetadata(
|
||||
name="SnowyKami 测试插件",
|
||||
description="A test plugin for SnowyKami",
|
||||
usage="SnowyKami Test Plugin",
|
||||
)
|
||||
|
||||
|
||||
@on_function_call(description="使用姓名,年龄,性别进行算命").params(
|
||||
age=Integer(description="年龄"),
|
||||
name=String(description="姓名"),
|
||||
gender=String(enum=["男", "女"], description="性别"),
|
||||
)
|
||||
async def fortune_telling(age: int, name: str, gender: str) -> str:
|
||||
"""使用姓名,年龄,性别进行算命"""
|
||||
|
||||
# 进行一系列算命操作...
|
||||
|
||||
return f"{name},你的年龄是{age},你的性别很好"
|
||||
|
||||
|
||||
@on_function_call(description="获取一个地点未来一段时间的天气").params(
|
||||
location=String(description="地点名称,可以是城市名、地区名等"),
|
||||
days=Integer(description="天数", minimum=1, maximum=30),
|
||||
unit=String(enum=["摄氏度", "华氏度"], description="温度单位", default="摄氏度"),
|
||||
)
|
||||
async def get_weather(location: str, days: int, unit: str) -> str:
|
||||
"""获取一个地点未来一段时间的天气"""
|
||||
|
||||
# 进行一系列获取天气操作...
|
||||
|
||||
return f"{location}未来{days}天的天气很好,全都是晴天,温度是34"
|
||||
|
||||
|
||||
@on_function_call(description="获取设备物理地理位置")
|
||||
def get_location() -> str:
|
||||
"""获取设备物理地理位置"""
|
||||
|
||||
# 进行一系列获取地理位置操作...
|
||||
|
||||
return "日本 东京都 世田谷区"
|
||||
|
||||
|
||||
@on_function_call(description="获取聊天者个人信息及发送的消息和function call调用参数")
|
||||
async def get_user_info(e: Event, c: Caller) -> str:
|
||||
return (
|
||||
f"用户ID: {e.user_id} "
|
||||
"用户昵称: {e.sender.nickname} "
|
||||
"FC调用参数:{c._parameters} "
|
||||
"消息内容: {e.raw_message}"
|
||||
)
|
||||
|
||||
|
||||
@on_function_call(description="获取设备信息")
|
||||
def get_device_info() -> str:
|
||||
"""获取机器人所运行的设备信息"""
|
||||
|
||||
# 进行一系列获取设备信息操作...
|
||||
|
||||
data = {
|
||||
"cpu 性能": f"{psutil.cpu_percent()}% {psutil.cpu_freq().current:.2f}MHz {psutil.cpu_count()}线程 {psutil.cpu_count(logical=False)}物理核",
|
||||
"memory 内存": f"{psutil.virtual_memory().percent}% {psutil.virtual_memory().available / 1024 / 1024 / 1024:.2f}/{psutil.virtual_memory().total / 1024 / 1024 / 1024:.2f}GB",
|
||||
"swap 交换分区": f"{psutil.swap_memory().percent}% {psutil.swap_memory().used / 1024 / 1024 / 1024:.2f}/{psutil.swap_memory().total / 1024 / 1024 / 1024:.2f}GB",
|
||||
"cpu 信息": f"{psutil.cpu_stats()}",
|
||||
"system 系统": f"system: {platform.system()}, version: {platform.version()}, arch: {platform.architecture()}, machine: {platform.machine()}",
|
||||
}
|
||||
return str(data)
|
||||
|
||||
|
||||
@on_function_call(description="在设备上运行Python代码,需要超级用户权限").params(
|
||||
code=String(description="Python代码内容")
|
||||
).permission(SUPERUSER)
|
||||
async def run_python_code(code: str, b: Bot, e: Event) -> str:
|
||||
"""运行Python代码"""
|
||||
try:
|
||||
r = eval(code)
|
||||
except Exception as e:
|
||||
return "运行出错: " + str(e)
|
||||
return "运行成功: " + str(r)
|
||||
|
||||
|
||||
@on_function_call(
|
||||
description="在设备上运行shell命令, Run command on this device"
|
||||
).params(command=String(description="shell命令内容")).permission(SUPERUSER)
|
||||
async def run_shell_command(command: str, b: Bot, e: Event) -> str:
|
||||
"""运行shell命令"""
|
||||
try:
|
||||
r = os.popen(command).read()
|
||||
except Exception as e:
|
||||
return "运行出错: " + str(e)
|
||||
return "运行成功: " + str(r)
|
13
nonebot_plugin_marshoai/plugins_test/weather_demo.py
Normal file
13
nonebot_plugin_marshoai/plugins_test/weather_demo.py
Normal file
@ -0,0 +1,13 @@
|
||||
from nonebot_plugin_marshoai.plugin import PluginMetadata, String, on_function_call
|
||||
|
||||
metadata = PluginMetadata(
|
||||
name="天气查询", author="MarshoAI", description="一个简单的查询天气的插件"
|
||||
)
|
||||
|
||||
|
||||
@on_function_call(description="可以用于查询天气").params(
|
||||
location=String(description="地点")
|
||||
)
|
||||
async def weather(location: str) -> str:
|
||||
# 这里可以调用天气API查询天气,这里只是一个简单的示例
|
||||
return f"{location}的天气是晴天, 温度是25°C"
|
Reference in New Issue
Block a user