更新Caller类,修复模块名称为空的情况并添加调试日志;修改run_shell_command描述并重命名

This commit is contained in:
远野千束(神羽) 2024-12-16 02:15:55 +08:00
parent b3c63f0ae4
commit dacb5aa854
2 changed files with 7 additions and 4 deletions

View File

@ -82,7 +82,7 @@ class Caller:
if module := inspect.getmodule(func): if module := inspect.getmodule(func):
module_name = module.__name__.split(".")[-1] module_name = module.__name__.split(".")[-1]
else: else:
module_name = "global" module_name = ""
self._name = f"{module_name}-{func.__name__}" self._name = f"{module_name}-{func.__name__}"
_caller_data[self._name] = self _caller_data[self._name] = self
@ -140,6 +140,7 @@ class Caller:
""" """
y, r = await self.pre_check() y, r = await self.pre_check()
if not y: if not y:
logger.debug(f"Function {self._name} pre_check failed: {r}")
return r return r
if self.func is None: if self.func is None:

View File

@ -95,9 +95,11 @@ async def run_python_code(code: str, b: Bot, e: MessageEvent) -> str:
return "运行成功: " + str(r) return "运行成功: " + str(r)
@on_function_call(description="运行shell命令,需要超级用户权限").params( @on_function_call(
command=String(description="shell命令内容") description="在设备上运行shell命令, Run command on this device"
).permission(SUPERUSER) ).params(command=String(description="shell命令内容")).permission(SUPERUSER).name(
"run_shell_command"
)
async def run_shell_command(command: str, b: Bot, e: MessageEvent) -> str: async def run_shell_command(command: str, b: Bot, e: MessageEvent) -> str:
"""运行shell命令""" """运行shell命令"""
try: try: