zhenxun_bot/basic_plugins/init_plugin_config/init_plugins_resources.py

26 lines
1.0 KiB
Python
Raw Normal View History

2022-12-04 16:46:33 +08:00
from utils.manager import resources_manager, plugin_data_manager
2021-11-23 21:44:59 +08:00
from utils.utils import get_matchers
from services.log import logger
from pathlib import Path
def init_plugins_resources():
"""
资源文件路径的移动
"""
2022-12-04 16:46:33 +08:00
for matcher in get_matchers(True):
if plugin_data := plugin_data_manager.get(matcher.plugin_name):
2021-11-23 21:44:59 +08:00
try:
2022-12-04 16:46:33 +08:00
_module = matcher.plugin.module
2021-11-23 21:44:59 +08:00
except AttributeError:
2022-02-19 18:20:19 +08:00
logger.warning(f"插件 {matcher.plugin_name} 加载失败...,资源控制未加载...")
2021-11-23 21:44:59 +08:00
else:
2022-12-04 16:46:33 +08:00
if resources := plugin_data.plugin_resources:
2021-11-23 21:44:59 +08:00
path = Path(_module.__getattribute__("__file__")).parent
for resource in resources.keys():
resources_manager.add_resource(
matcher.plugin_name, path / resource, resources[resource]
)
2021-11-23 21:44:59 +08:00
resources_manager.save()
resources_manager.start_move()