mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-03 02:30:01 +08:00
🎨 代码优化
This commit is contained in:
@@ -57,9 +57,10 @@ async def _(session: EventSession):
|
||||
try:
|
||||
result = await ShopManage.get_plugins_info()
|
||||
logger.info("查看插件列表", "插件商店", session=session)
|
||||
await MessageUtils.build_message(result).finish()
|
||||
await MessageUtils.build_message(result).send()
|
||||
except Exception as e:
|
||||
logger.error(f"查看插件列表失败 e: {e}", "插件商店", session=session, e=e)
|
||||
await MessageUtils.build_message("获取插件列表失败...").send()
|
||||
|
||||
|
||||
@_matcher.assign("add")
|
||||
|
||||
@@ -4,12 +4,10 @@ BASE_PATH = Path() / "zhenxun"
|
||||
BASE_PATH.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
CONFIG_URL = (
|
||||
"https://cdn.jsdelivr.net/gh/HibiKier/zhenxun_bot_plugins/plugins.json"
|
||||
)
|
||||
CONFIG_URL = "https://cdn.jsdelivr.net/gh/zhenxun-org/zhenxun_bot_plugins/plugins.json"
|
||||
"""插件信息文件"""
|
||||
|
||||
DOWNLOAD_URL = (
|
||||
"https://api.github.com/repos/HibiKier/zhenxun_bot_plugins/contents/{}?ref=main"
|
||||
"https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/contents/{}?ref=main"
|
||||
)
|
||||
"""插件下载地址"""
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import nonebot
|
||||
import ujson as json
|
||||
@@ -87,16 +87,29 @@ async def download_file(url: str):
|
||||
|
||||
def install_requirement(plugin_path: Path):
|
||||
requirement_path = plugin_path / "requirement.txt"
|
||||
|
||||
|
||||
if not requirement_path.exists():
|
||||
logger.debug(f"No requirement.txt found for plugin: {plugin_path.name}", "插件管理")
|
||||
logger.debug(
|
||||
f"No requirement.txt found for plugin: {plugin_path.name}", "插件管理"
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
try:
|
||||
result = subprocess.run(["pip", "install", "-r", str(requirement_path)], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
logger.debug(f"Successfully installed dependencies for plugin: {plugin_path.name}. Output:\n{result.stdout}", "插件管理")
|
||||
result = subprocess.run(
|
||||
["pip", "install", "-r", str(requirement_path)],
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
logger.debug(
|
||||
f"Successfully installed dependencies for plugin: {plugin_path.name}. Output:\n{result.stdout}",
|
||||
"插件管理",
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error(f"Failed to install dependencies for plugin: {plugin_path.name}. Error:\n{e.stderr}")
|
||||
logger.error(
|
||||
f"Failed to install dependencies for plugin: {plugin_path.name}. Error:\n{e.stderr}"
|
||||
)
|
||||
|
||||
|
||||
class ShopManage:
|
||||
@@ -187,11 +200,11 @@ class ShopManage:
|
||||
return "插件下载地址构建失败..."
|
||||
logger.debug(f"尝试下载插件 URL: {url_path}", "插件管理")
|
||||
await download_file(DOWNLOAD_URL.format(url_path))
|
||||
|
||||
|
||||
# 安装依赖
|
||||
plugin_path = BASE_PATH / "/".join(module_path_split)
|
||||
install_requirement(plugin_path)
|
||||
|
||||
|
||||
return f"插件 {plugin_key} 安装成功!"
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user