mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🎈 perf: 使用commit号下载插件
This commit is contained in:
parent
983248374d
commit
f9c736093d
@ -73,6 +73,68 @@ async def test_add_plugin_basic(
|
|||||||
assert (mock_base_path / "plugins" / "search_image" / "__init__.py").is_file()
|
assert (mock_base_path / "plugins" / "search_image" / "__init__.py").is_file()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("package_api", ["jsd", "gh"])
|
||||||
|
async def test_add_plugin_basic_commit_version(
|
||||||
|
package_api: str,
|
||||||
|
app: App,
|
||||||
|
mocker: MockerFixture,
|
||||||
|
mocked_api: MockRouter,
|
||||||
|
create_bot: Callable,
|
||||||
|
tmp_path: Path,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
测试添加基础插件
|
||||||
|
"""
|
||||||
|
from zhenxun.builtin_plugins.plugin_store import _matcher
|
||||||
|
|
||||||
|
init_mocked_api(mocked_api=mocked_api)
|
||||||
|
mock_base_path = mocker.patch(
|
||||||
|
"zhenxun.builtin_plugins.plugin_store.data_source.BASE_PATH",
|
||||||
|
new=tmp_path / "zhenxun",
|
||||||
|
)
|
||||||
|
|
||||||
|
if package_api != "jsd":
|
||||||
|
mocked_api["zhenxun_bot_plugins_metadata_commit"].respond(404)
|
||||||
|
if package_api != "gh":
|
||||||
|
mocked_api["zhenxun_bot_plugins_tree_commit"].respond(404)
|
||||||
|
|
||||||
|
plugin_id = 3
|
||||||
|
|
||||||
|
async with app.test_matcher(_matcher) as ctx:
|
||||||
|
bot = create_bot(ctx)
|
||||||
|
bot: Bot = cast(Bot, bot)
|
||||||
|
raw_message = f"添加插件 {plugin_id}"
|
||||||
|
event: GroupMessageEvent = _v11_group_message_event(
|
||||||
|
message=raw_message,
|
||||||
|
self_id=BotId.QQ_BOT,
|
||||||
|
user_id=UserId.SUPERUSER,
|
||||||
|
group_id=GroupId.GROUP_ID_LEVEL_5,
|
||||||
|
message_id=MessageId.MESSAGE_ID,
|
||||||
|
to_me=True,
|
||||||
|
)
|
||||||
|
ctx.receive_event(bot=bot, event=event)
|
||||||
|
ctx.should_call_send(
|
||||||
|
event=event,
|
||||||
|
message=Message(message=f"正在添加插件 Id: {plugin_id}"),
|
||||||
|
result=None,
|
||||||
|
bot=bot,
|
||||||
|
)
|
||||||
|
ctx.should_call_send(
|
||||||
|
event=event,
|
||||||
|
message=Message(message="插件 B站订阅 安装成功! 重启后生效"),
|
||||||
|
result=None,
|
||||||
|
bot=bot,
|
||||||
|
)
|
||||||
|
assert mocked_api["basic_plugins"].called
|
||||||
|
assert mocked_api["extra_plugins"].called
|
||||||
|
if package_api == "jsd":
|
||||||
|
assert mocked_api["zhenxun_bot_plugins_metadata_commit"].called
|
||||||
|
if package_api == "gh":
|
||||||
|
assert mocked_api["zhenxun_bot_plugins_tree_commit"].called
|
||||||
|
assert mocked_api["bilibili_sub_plugin_file_init"].called
|
||||||
|
assert (mock_base_path / "plugins" / "bilibili_sub" / "__init__.py").is_file()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("package_api", ["jsd", "gh"])
|
@pytest.mark.parametrize("package_api", ["jsd", "gh"])
|
||||||
async def test_add_plugin_basic_is_not_dir(
|
async def test_add_plugin_basic_is_not_dir(
|
||||||
package_api: str,
|
package_api: str,
|
||||||
@ -156,7 +218,7 @@ async def test_add_plugin_extra(
|
|||||||
if package_api != "gh":
|
if package_api != "gh":
|
||||||
mocked_api["zhenxun_github_sub_tree"].respond(404)
|
mocked_api["zhenxun_github_sub_tree"].respond(404)
|
||||||
|
|
||||||
plugin_id = 3
|
plugin_id = 4
|
||||||
|
|
||||||
async with app.test_matcher(_matcher) as ctx:
|
async with app.test_matcher(_matcher) as ctx:
|
||||||
bot = create_bot(ctx)
|
bot = create_bot(ctx)
|
||||||
|
|||||||
@ -64,6 +64,15 @@ async def test_plugin_store(
|
|||||||
[
|
[
|
||||||
"",
|
"",
|
||||||
3,
|
3,
|
||||||
|
"B站订阅",
|
||||||
|
"非常便利的B站订阅通知",
|
||||||
|
"HibiKier",
|
||||||
|
"0.3-b101fbc",
|
||||||
|
"普通插件",
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"",
|
||||||
|
4,
|
||||||
"github订阅",
|
"github订阅",
|
||||||
"订阅github用户或仓库",
|
"订阅github用户或仓库",
|
||||||
"xuanerwa",
|
"xuanerwa",
|
||||||
@ -72,7 +81,7 @@ async def test_plugin_store(
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
"",
|
"",
|
||||||
4,
|
5,
|
||||||
"Minecraft查服",
|
"Minecraft查服",
|
||||||
"Minecraft服务器状态查询,支持IPv6",
|
"Minecraft服务器状态查询,支持IPv6",
|
||||||
"molanp",
|
"molanp",
|
||||||
|
|||||||
@ -63,7 +63,7 @@ async def test_search_plugin_name(
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
"",
|
"",
|
||||||
3,
|
4,
|
||||||
"github订阅",
|
"github订阅",
|
||||||
"订阅github用户或仓库",
|
"订阅github用户或仓库",
|
||||||
"xuanerwa",
|
"xuanerwa",
|
||||||
@ -129,7 +129,7 @@ async def test_search_plugin_author(
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
"",
|
"",
|
||||||
3,
|
4,
|
||||||
"github订阅",
|
"github订阅",
|
||||||
"订阅github用户或仓库",
|
"订阅github用户或仓库",
|
||||||
"xuanerwa",
|
"xuanerwa",
|
||||||
|
|||||||
@ -17,6 +17,7 @@ def get_content_bytes(file: str) -> bytes:
|
|||||||
|
|
||||||
|
|
||||||
def init_mocked_api(mocked_api: MockRouter) -> None:
|
def init_mocked_api(mocked_api: MockRouter) -> None:
|
||||||
|
# metadata
|
||||||
mocked_api.get(
|
mocked_api.get(
|
||||||
"https://data.jsdelivr.com/v1/packages/gh/zhenxun-org/zhenxun_bot_plugins@main",
|
"https://data.jsdelivr.com/v1/packages/gh/zhenxun-org/zhenxun_bot_plugins@main",
|
||||||
name="zhenxun_bot_plugins_metadata",
|
name="zhenxun_bot_plugins_metadata",
|
||||||
@ -25,7 +26,12 @@ def init_mocked_api(mocked_api: MockRouter) -> None:
|
|||||||
"https://data.jsdelivr.com/v1/packages/gh/xuanerwa/zhenxun_github_sub@main",
|
"https://data.jsdelivr.com/v1/packages/gh/xuanerwa/zhenxun_github_sub@main",
|
||||||
name="zhenxun_github_sub_metadata",
|
name="zhenxun_github_sub_metadata",
|
||||||
).respond(json=get_response_json("zhenxun_github_sub_metadata.json"))
|
).respond(json=get_response_json("zhenxun_github_sub_metadata.json"))
|
||||||
|
mocked_api.get(
|
||||||
|
"https://data.jsdelivr.com/v1/packages/gh/zhenxun-org/zhenxun_bot_plugins@b101fbc",
|
||||||
|
name="zhenxun_bot_plugins_metadata_commit",
|
||||||
|
).respond(json=get_response_json("zhenxun_bot_plugins_metadata.json"))
|
||||||
|
|
||||||
|
# tree
|
||||||
mocked_api.get(
|
mocked_api.get(
|
||||||
"https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/trees/main?recursive=1",
|
"https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/trees/main?recursive=1",
|
||||||
name="zhenxun_bot_plugins_tree",
|
name="zhenxun_bot_plugins_tree",
|
||||||
@ -34,6 +40,10 @@ def init_mocked_api(mocked_api: MockRouter) -> None:
|
|||||||
"https://api.github.com/repos/xuanerwa/zhenxun_github_sub/git/trees/main?recursive=1",
|
"https://api.github.com/repos/xuanerwa/zhenxun_github_sub/git/trees/main?recursive=1",
|
||||||
name="zhenxun_github_sub_tree",
|
name="zhenxun_github_sub_tree",
|
||||||
).respond(json=get_response_json("zhenxun_github_sub_tree.json"))
|
).respond(json=get_response_json("zhenxun_github_sub_tree.json"))
|
||||||
|
mocked_api.get(
|
||||||
|
"https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/trees/b101fbc?recursive=1",
|
||||||
|
name="zhenxun_bot_plugins_tree_commit",
|
||||||
|
).respond(json=get_response_json("zhenxun_bot_plugins_tree.json"))
|
||||||
|
|
||||||
mocked_api.head(
|
mocked_api.head(
|
||||||
"https://raw.githubusercontent.com/",
|
"https://raw.githubusercontent.com/",
|
||||||
@ -70,3 +80,7 @@ def init_mocked_api(mocked_api: MockRouter) -> None:
|
|||||||
"https://raw.githubusercontent.com/xuanerwa/zhenxun_github_sub/main/github_sub/__init__.py",
|
"https://raw.githubusercontent.com/xuanerwa/zhenxun_github_sub/main/github_sub/__init__.py",
|
||||||
name="github_sub_plugin_file_init",
|
name="github_sub_plugin_file_init",
|
||||||
).respond(content=get_content_bytes("github_sub.py"))
|
).respond(content=get_content_bytes("github_sub.py"))
|
||||||
|
mocked_api.get(
|
||||||
|
"https://raw.githubusercontent.com/zhenxun-org/zhenxun_bot_plugins/b101fbc/plugins/bilibili_sub/__init__.py",
|
||||||
|
name="bilibili_sub_plugin_file_init",
|
||||||
|
).respond(content=get_content_bytes("bilibili_sub.py"))
|
||||||
|
|||||||
37
tests/content/plugin_store/bilibili_sub.py
Normal file
37
tests/content/plugin_store/bilibili_sub.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from nonebot.plugin import PluginMetadata
|
||||||
|
|
||||||
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
|
||||||
|
__plugin_meta__ = PluginMetadata(
|
||||||
|
name="B站订阅",
|
||||||
|
description="非常便利的B站订阅通知",
|
||||||
|
usage="""
|
||||||
|
usage:
|
||||||
|
B站直播,番剧,UP动态开播等提醒
|
||||||
|
主播订阅相当于 直播间订阅 + UP订阅
|
||||||
|
指令:
|
||||||
|
添加订阅 ['主播'/'UP'/'番剧'] [id/链接/番名]
|
||||||
|
删除订阅 ['主播'/'UP'/'id'] [id]
|
||||||
|
查看订阅
|
||||||
|
示例:
|
||||||
|
添加订阅主播 2345344 <-(直播房间id)
|
||||||
|
添加订阅UP 2355543 <-(个人主页id)
|
||||||
|
添加订阅番剧 史莱姆 <-(支持模糊搜索)
|
||||||
|
添加订阅番剧 125344 <-(番剧id)
|
||||||
|
删除订阅id 2324344 <-(任意id,通过查看订阅获取)
|
||||||
|
""".strip(),
|
||||||
|
extra=PluginExtraData(
|
||||||
|
author="HibiKier",
|
||||||
|
version="0.3-b101fbc",
|
||||||
|
superuser_help="""
|
||||||
|
登录b站获取cookie防止风控:
|
||||||
|
bil_check/检测b站
|
||||||
|
bil_login/登录b站
|
||||||
|
bil_logout/退出b站 uid
|
||||||
|
示例:
|
||||||
|
登录b站
|
||||||
|
检测b站
|
||||||
|
bil_logout 12345<-(退出登录的b站uid,通过检测b站获取)
|
||||||
|
""",
|
||||||
|
).dict(),
|
||||||
|
)
|
||||||
@ -28,5 +28,15 @@
|
|||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
"plugin_type": "NORMAL",
|
"plugin_type": "NORMAL",
|
||||||
"is_dir": false
|
"is_dir": false
|
||||||
|
},
|
||||||
|
"B站订阅": {
|
||||||
|
"module": "bilibili_sub",
|
||||||
|
"module_path": "plugins.bilibili_sub",
|
||||||
|
"description": "非常便利的B站订阅通知",
|
||||||
|
"usage": "B站直播,番剧,UP动态开播等提醒",
|
||||||
|
"author": "HibiKier",
|
||||||
|
"version": "0.3-b101fbc",
|
||||||
|
"plugin_type": "NORMAL",
|
||||||
|
"is_dir": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,18 @@
|
|||||||
"size": 1530
|
"size": 1530
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "directory",
|
||||||
|
"name": "bilibili_sub",
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"type": "file",
|
||||||
|
"name": "__init__.py",
|
||||||
|
"hash": "407DCgNFcZnuEK+d716j8EWrFQc4Nlxa35V3yemy3WQ=",
|
||||||
|
"size": 14293
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -134,22 +134,6 @@
|
|||||||
"sha": "236b6a8ce846884fb7dbb10aab58f95782844c27",
|
"sha": "236b6a8ce846884fb7dbb10aab58f95782844c27",
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/trees/236b6a8ce846884fb7dbb10aab58f95782844c27"
|
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/trees/236b6a8ce846884fb7dbb10aab58f95782844c27"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"path": "plugins/bilibili_sub/README.md",
|
|
||||||
"mode": "100644",
|
|
||||||
"type": "blob",
|
|
||||||
"sha": "b05b281b72dc1276e176411f7167f5c7c52d90bb",
|
|
||||||
"size": 853,
|
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/b05b281b72dc1276e176411f7167f5c7c52d90bb"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "plugins/bilibili_sub/Wbi.py",
|
|
||||||
"mode": "100644",
|
|
||||||
"type": "blob",
|
|
||||||
"sha": "7ee68e789125b110a5796eab05f1a3cf0b32e481",
|
|
||||||
"size": 2503,
|
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/7ee68e789125b110a5796eab05f1a3cf0b32e481"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "plugins/bilibili_sub/__init__.py",
|
"path": "plugins/bilibili_sub/__init__.py",
|
||||||
"mode": "100644",
|
"mode": "100644",
|
||||||
@ -158,38 +142,6 @@
|
|||||||
"size": 14302,
|
"size": 14302,
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/2eec6bd0c8208e4026b0fe1400838c161ac826c4"
|
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/2eec6bd0c8208e4026b0fe1400838c161ac826c4"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"path": "plugins/bilibili_sub/auth.py",
|
|
||||||
"mode": "100644",
|
|
||||||
"type": "blob",
|
|
||||||
"sha": "0bf48390942a71070d8a176414e8131820ad60b4",
|
|
||||||
"size": 2490,
|
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/0bf48390942a71070d8a176414e8131820ad60b4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "plugins/bilibili_sub/data_source.py",
|
|
||||||
"mode": "100644",
|
|
||||||
"type": "blob",
|
|
||||||
"sha": "2140347d5338f945829a3c7ecf2931d059a2cf33",
|
|
||||||
"size": 15101,
|
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/2140347d5338f945829a3c7ecf2931d059a2cf33"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "plugins/bilibili_sub/model.py",
|
|
||||||
"mode": "100644",
|
|
||||||
"type": "blob",
|
|
||||||
"sha": "3df5e9a4b180fa014daf5338a5de05f1f42fb514",
|
|
||||||
"size": 6855,
|
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/3df5e9a4b180fa014daf5338a5de05f1f42fb514"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "plugins/bilibili_sub/utils.py",
|
|
||||||
"mode": "100644",
|
|
||||||
"type": "blob",
|
|
||||||
"sha": "6852ac0b05eb9e716e2eef3d0dcc35dd30992d6f",
|
|
||||||
"size": 7695,
|
|
||||||
"url": "https://api.github.com/repos/zhenxun-org/zhenxun_bot_plugins/git/blobs/6852ac0b05eb9e716e2eef3d0dcc35dd30992d6f"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "plugins/black_word",
|
"path": "plugins/black_word",
|
||||||
"mode": "040000",
|
"mode": "040000",
|
||||||
|
|||||||
@ -195,6 +195,10 @@ class ShopManage:
|
|||||||
if plugin_info.github_url is None:
|
if plugin_info.github_url is None:
|
||||||
plugin_info.github_url = DEFAULT_GITHUB_URL
|
plugin_info.github_url = DEFAULT_GITHUB_URL
|
||||||
is_external = False
|
is_external = False
|
||||||
|
version_split = plugin_info.version.split("-")
|
||||||
|
if len(version_split) > 1:
|
||||||
|
github_url_split = plugin_info.github_url.split("/tree/")
|
||||||
|
plugin_info.github_url = f"{github_url_split[0]}/tree/{version_split[1]}"
|
||||||
logger.info(f"正在安装插件 {plugin_key}...")
|
logger.info(f"正在安装插件 {plugin_key}...")
|
||||||
await cls.install_plugin_with_repo(
|
await cls.install_plugin_with_repo(
|
||||||
plugin_info.github_url,
|
plugin_info.github_url,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user