2022-10-15 20:50:02 +08:00
|
|
|
|
|
2021-11-23 21:44:59 +08:00
|
|
|
|
from ruamel.yaml import YAML
|
2022-12-04 16:46:33 +08:00
|
|
|
|
from utils.manager import plugins_manager, plugin_data_manager
|
2021-11-23 21:44:59 +08:00
|
|
|
|
from utils.utils import get_matchers
|
2022-10-15 20:50:02 +08:00
|
|
|
|
from services.log import logger
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
import ujson as json
|
|
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_yaml = YAML(typ="safe")
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-21 20:43:41 +08:00
|
|
|
|
def init_plugins_data():
|
2021-11-23 21:44:59 +08:00
|
|
|
|
"""
|
|
|
|
|
|
初始化插件数据信息
|
|
|
|
|
|
"""
|
2022-11-21 20:43:41 +08:00
|
|
|
|
for matcher in get_matchers(True):
|
2022-07-31 17:30:29 +08:00
|
|
|
|
_plugin = matcher.plugin
|
2022-09-08 20:13:26 +08:00
|
|
|
|
if not _plugin:
|
|
|
|
|
|
continue
|
2021-11-23 21:44:59 +08:00
|
|
|
|
try:
|
|
|
|
|
|
_module = _plugin.module
|
|
|
|
|
|
except AttributeError:
|
2022-11-21 20:43:41 +08:00
|
|
|
|
if matcher.plugin_name not in plugins_manager.keys():
|
2021-11-23 21:44:59 +08:00
|
|
|
|
plugins_manager.add_plugin_data(
|
2022-02-19 18:20:19 +08:00
|
|
|
|
matcher.plugin_name, matcher.plugin_name, error=True
|
2021-11-23 21:44:59 +08:00
|
|
|
|
)
|
|
|
|
|
|
else:
|
2022-11-21 20:43:41 +08:00
|
|
|
|
plugins_manager[matcher.plugin_name].error = True
|
2021-11-23 21:44:59 +08:00
|
|
|
|
else:
|
2022-12-04 16:46:33 +08:00
|
|
|
|
if plugin_data := plugin_data_manager.get(matcher.plugin_name):
|
|
|
|
|
|
try:
|
2022-12-10 19:59:16 +08:00
|
|
|
|
plugin_version = plugin_data.plugin_status.version
|
2022-12-04 16:46:33 +08:00
|
|
|
|
plugin_name = plugin_data.name
|
2022-12-10 19:59:16 +08:00
|
|
|
|
plugin_author = plugin_data.plugin_status.author
|
2022-12-04 16:46:33 +08:00
|
|
|
|
if matcher.plugin_name in plugins_manager.keys():
|
|
|
|
|
|
plugins_manager[matcher.plugin_name].error = False
|
|
|
|
|
|
if matcher.plugin_name not in plugins_manager.keys():
|
|
|
|
|
|
plugins_manager.add_plugin_data(
|
|
|
|
|
|
matcher.plugin_name,
|
|
|
|
|
|
plugin_name=plugin_name,
|
|
|
|
|
|
author=plugin_author,
|
|
|
|
|
|
version=plugin_version,
|
|
|
|
|
|
)
|
|
|
|
|
|
elif isinstance(plugin_version, str) or plugins_manager[matcher.plugin_name].version is None or (
|
|
|
|
|
|
plugin_version is not None
|
|
|
|
|
|
and plugin_version > float(plugins_manager[matcher.plugin_name].version)
|
|
|
|
|
|
):
|
|
|
|
|
|
plugins_manager[matcher.plugin_name].plugin_name = plugin_name
|
|
|
|
|
|
plugins_manager[matcher.plugin_name].author = plugin_author
|
|
|
|
|
|
plugins_manager[matcher.plugin_name].version = plugin_version
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"插件数据 {matcher.plugin_name} 加载发生错误 {type(e)}:{e}")
|
2021-11-23 21:44:59 +08:00
|
|
|
|
plugins_manager.save()
|