mirror of https://github.com/Mai-with-u/MaiBot.git
ruff
parent
9b96054c3c
commit
c0b511273e
|
|
@ -114,6 +114,7 @@ def get_tool_instance(tool_name: str) -> Optional[BaseTool]:
|
||||||
return None
|
return None
|
||||||
return tool_class()
|
return tool_class()
|
||||||
|
|
||||||
|
|
||||||
def run_lua_code(lua_code: str):
|
def run_lua_code(lua_code: str):
|
||||||
"""兼容Lua代码运行(小工具)
|
"""兼容Lua代码运行(小工具)
|
||||||
|
|
||||||
|
|
@ -124,6 +125,7 @@ def run_lua_code(lua_code: str):
|
||||||
_LuaTable: Lua运行时的全局变量
|
_LuaTable: Lua运行时的全局变量
|
||||||
"""
|
"""
|
||||||
from lupa import LuaRuntime
|
from lupa import LuaRuntime
|
||||||
|
|
||||||
lua = LuaRuntime(unpack_returned_tuples=True)
|
lua = LuaRuntime(unpack_returned_tuples=True)
|
||||||
lua.execute(lua_code)
|
lua.execute(lua_code)
|
||||||
return lua.globals()
|
return lua.globals()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from src.do_tool.tool_can_use.base_tool import BaseTool,run_lua_code
|
from src.do_tool.tool_can_use.base_tool import BaseTool, run_lua_code
|
||||||
from src.common.logger import get_module_logger
|
from src.common.logger import get_module_logger
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
|
@ -41,7 +41,7 @@ class CompareNumbersTool(BaseTool):
|
||||||
"""
|
"""
|
||||||
CompareNumbers = run_lua_code(lua_code).CompareNumbers
|
CompareNumbers = run_lua_code(lua_code).CompareNumbers
|
||||||
result = CompareNumbers(num1, num2)
|
result = CompareNumbers(num1, num2)
|
||||||
|
|
||||||
return {"name": self.name, "content": result}
|
return {"name": self.name, "content": result}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"比较数字失败: {str(e)}")
|
logger.error(f"比较数字失败: {str(e)}")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from src.do_tool.tool_can_use.base_tool import BaseTool,run_lua_code
|
from src.do_tool.tool_can_use.base_tool import BaseTool, run_lua_code
|
||||||
from src.common.logger import get_module_logger
|
from src.common.logger import get_module_logger
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue