🔊 Feature: 优化插件加载日志 (#1716)

This commit is contained in:
Ju4tCode 2023-02-20 13:19:05 +08:00 committed by GitHub
parent 97723a0838
commit 728902bfcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,14 +148,21 @@ class PluginManager:
else:
raise RuntimeError(f"Plugin not found: {name}! Check your plugin name")
logger.opt(colors=True).success(
f'Succeeded to import "<y>{escape_tag(name)}</y>"'
)
if (plugin := getattr(module, "__plugin__", None)) is None:
if (
plugin := getattr(module, "__plugin__", None)
) is None or not isinstance(plugin, Plugin):
raise RuntimeError(
f"Module {module.__name__} is not loaded as a plugin! "
"Make sure not to import it before loading."
)
logger.opt(colors=True).success(
f'Succeeded to load plugin "<y>{escape_tag(plugin.name)}</y>"'
+ (
f' from "<m>{escape_tag(plugin.module_name)}</m>"'
if plugin.module_name != plugin.name
else ""
)
)
return plugin
except Exception as e:
logger.opt(colors=True, exception=e).error(