mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-28 16:20:56 +08:00
✅ Repair self-test
This commit is contained in:
@@ -7,6 +7,7 @@ from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.utils import is_number
|
||||
|
||||
from .data_source import ShopManage
|
||||
|
||||
@@ -31,10 +32,10 @@ __plugin_meta__ = PluginMetadata(
|
||||
_matcher = on_alconna(
|
||||
Alconna(
|
||||
"插件商店",
|
||||
Subcommand("add", Args["plugin_id", int | str]),
|
||||
Subcommand("remove", Args["plugin_id", int | str]),
|
||||
Subcommand("add", Args["plugin_id", str]),
|
||||
Subcommand("remove", Args["plugin_id", str]),
|
||||
Subcommand("search", Args["plugin_name_or_author", str]),
|
||||
Subcommand("update", Args["plugin_id", int | str]),
|
||||
Subcommand("update", Args["plugin_id", str]),
|
||||
Subcommand("update_all"),
|
||||
),
|
||||
permission=SUPERUSER,
|
||||
@@ -90,12 +91,12 @@ async def _(session: EventSession):
|
||||
|
||||
|
||||
@_matcher.assign("add")
|
||||
async def _(session: EventSession, plugin_id: int | str):
|
||||
async def _(session: EventSession, plugin_id: str):
|
||||
try:
|
||||
if isinstance(plugin_id, str):
|
||||
await MessageUtils.build_message(f"正在添加插件 Module: {plugin_id}").send()
|
||||
else:
|
||||
if is_number(plugin_id):
|
||||
await MessageUtils.build_message(f"正在添加插件 Id: {plugin_id}").send()
|
||||
else:
|
||||
await MessageUtils.build_message(f"正在添加插件 Module: {plugin_id}").send()
|
||||
result = await ShopManage.add_plugin(plugin_id)
|
||||
except Exception as e:
|
||||
logger.error(f"添加插件 Id: {plugin_id}失败", "插件商店", session=session, e=e)
|
||||
@@ -107,7 +108,7 @@ async def _(session: EventSession, plugin_id: int | str):
|
||||
|
||||
|
||||
@_matcher.assign("remove")
|
||||
async def _(session: EventSession, plugin_id: int | str):
|
||||
async def _(session: EventSession, plugin_id: str):
|
||||
try:
|
||||
result = await ShopManage.remove_plugin(plugin_id)
|
||||
except Exception as e:
|
||||
@@ -138,12 +139,12 @@ async def _(session: EventSession, plugin_name_or_author: str):
|
||||
|
||||
|
||||
@_matcher.assign("update")
|
||||
async def _(session: EventSession, plugin_id: int | str):
|
||||
async def _(session: EventSession, plugin_id: str):
|
||||
try:
|
||||
if isinstance(plugin_id, str):
|
||||
await MessageUtils.build_message(f"正在更新插件 Module: {plugin_id}").send()
|
||||
else:
|
||||
if is_number(plugin_id):
|
||||
await MessageUtils.build_message(f"正在更新插件 Id: {plugin_id}").send()
|
||||
else:
|
||||
await MessageUtils.build_message(f"正在更新插件 Module: {plugin_id}").send()
|
||||
result = await ShopManage.update_plugin(plugin_id)
|
||||
except Exception as e:
|
||||
logger.error(f"更新插件 Id: {plugin_id}失败", "插件商店", session=session, e=e)
|
||||
|
||||
@@ -14,6 +14,7 @@ from zhenxun.utils.github_utils import GithubUtils
|
||||
from zhenxun.utils.github_utils.models import RepoAPI
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.utils.image_utils import BuildImage, ImageTemplate, RowStyle
|
||||
from zhenxun.utils.utils import is_number
|
||||
|
||||
from .config import BASE_PATH, DEFAULT_GITHUB_URL, EXTRA_GITHUB_URL
|
||||
|
||||
@@ -175,7 +176,7 @@ class ShopManage:
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def add_plugin(cls, plugin_id: int | str) -> str:
|
||||
async def add_plugin(cls, plugin_id: str) -> str:
|
||||
"""添加插件
|
||||
|
||||
参数:
|
||||
@@ -268,7 +269,7 @@ class ShopManage:
|
||||
raise Exception("插件下载失败")
|
||||
|
||||
@classmethod
|
||||
async def remove_plugin(cls, plugin_id: int | str) -> str:
|
||||
async def remove_plugin(cls, plugin_id: str) -> str:
|
||||
"""移除插件
|
||||
|
||||
参数:
|
||||
@@ -344,7 +345,7 @@ class ShopManage:
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def update_plugin(cls, plugin_id: int | str) -> str:
|
||||
async def update_plugin(cls, plugin_id: str) -> str:
|
||||
"""更新插件
|
||||
|
||||
参数:
|
||||
@@ -441,12 +442,13 @@ class ShopManage:
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def _resolve_plugin_key(cls, plugin_id: int | str) -> str:
|
||||
async def _resolve_plugin_key(cls, plugin_id: str) -> str:
|
||||
data: dict[str, StorePluginInfo] = await cls.get_data()
|
||||
if isinstance(plugin_id, int):
|
||||
if plugin_id < 0 or plugin_id >= len(data):
|
||||
if is_number(plugin_id):
|
||||
idx = int(plugin_id)
|
||||
if idx < 0 or idx >= len(data):
|
||||
raise ValueError("插件ID不存在...")
|
||||
return list(data.keys())[plugin_id]
|
||||
return list(data.keys())[idx]
|
||||
elif isinstance(plugin_id, str):
|
||||
if plugin_id not in [v.module for k, v in data.items()]:
|
||||
raise ValueError("插件Module不存在...")
|
||||
|
||||
@@ -228,3 +228,19 @@ def is_valid_date(date_text: str, separator: str = "-") -> bool:
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def is_number(text: str) -> bool:
|
||||
"""是否为数字
|
||||
|
||||
参数:
|
||||
text: 文本
|
||||
|
||||
返回:
|
||||
bool: 是否为数字
|
||||
"""
|
||||
try:
|
||||
float(text)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user