mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-02-07 18:36:09 +08:00
modified: nonebot_plugin_marshoai/models.py
new file: nonebot_plugin_marshoai/tools/marshoai-megakits/a.py nonebot_plugin_marshoai/tools/marshoai-megakits/__init__.py nonebot_plugin_marshoai/tools/marshoai-megakits/tools.json
This commit is contained in:
parent
edd907fe83
commit
5d1cdecfc0
@ -1,9 +1,12 @@
|
||||
from nonebot_plugin_alconna.uniseg.adapters import module
|
||||
|
||||
from .util import *
|
||||
from .config import config
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
# import importlib.util
|
||||
import traceback
|
||||
@ -74,6 +77,11 @@ class MarshoTools:
|
||||
|
||||
for package_name in os.listdir(tools_dir):
|
||||
package_path = os.path.join(tools_dir, package_name)
|
||||
|
||||
logger.info(f"尝试加载工具包 {package_name}")
|
||||
|
||||
sys.path.append(package_path)
|
||||
|
||||
if os.path.isdir(package_path) and os.path.exists(
|
||||
os.path.join(package_path, "__init__.py")
|
||||
):
|
||||
@ -84,13 +92,14 @@ class MarshoTools:
|
||||
data = json.load(json_file)
|
||||
for i in data:
|
||||
self.tools_list.append(i)
|
||||
# 导入包
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
package_name, os.path.join(package_path, "__init__.py")
|
||||
)
|
||||
package = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(package)
|
||||
self.imported_packages[package_name] = package
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = module
|
||||
spec.loader.exec_module(sys.modules[spec.name])
|
||||
|
||||
logger.success(f"成功加载工具包 {package_name}")
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"解码 JSON {json_path} 时发生错误: {e}")
|
||||
|
5
nonebot_plugin_marshoai/tools/marshoai-megakits/a.py
Normal file
5
nonebot_plugin_marshoai/tools/marshoai-megakits/a.py
Normal file
@ -0,0 +1,5 @@
|
||||
from nonebot import logger
|
||||
|
||||
|
||||
def b () :
|
||||
logger.success("测试成功")
|
Loading…
x
Reference in New Issue
Block a user