mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
开播提醒推送的图片改为使用直播间封面 (#249)
* ✨ 为bilibili直播添加下播提醒,添加直播分区信息 🚸 开播提醒推送的图片改为使用直播间封面 * ♻️ 使用Enum * 🐛 修复bilibili发送视频动态时不推送视频标题的问题 * 🎨 调整LiveAction的注释和jaccard函数代码位置 * 🚨 修改RawPost类型定义,优化bililive类型显示
This commit is contained in:
@@ -32,7 +32,7 @@ async def test_video_forward(bilibili, bing_dy_list):
|
||||
post = await bilibili.parse(bing_dy_list[1])
|
||||
assert (
|
||||
post.text
|
||||
== "答案揭晓:宿舍!来看看投票结果\nhttps://t.bilibili.com/568093580488553786\n--------------\n#可露希尔的秘密档案# \n11:来宿舍休息一下吧 \n档案来源:lambda:\\罗德岛内务\\秘密档案 \n发布时间:9/12 1:00 P.M. \n档案类型:可见 \n档案描述:今天请了病假在宿舍休息。很舒适。 \n提供者:赫默"
|
||||
== "答案揭晓:宿舍!来看看投票结果\nhttps://t.bilibili.com/568093580488553786\n--------------\n#可露希尔的秘密档案# \n11:来宿舍休息一下吧 \n档案来源:lambda:\\罗德岛内务\\秘密档案 \n发布时间:9/12 1:00 P.M. \n档案类型:可见 \n档案描述:今天请了病假在宿舍休息。很舒适。 \n提供者:赫默\n=================\n《可露希尔的秘密档案》11话:来宿舍休息一下吧"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ def bili_live(app: App):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_only_status_user_subinfo(app: App):
|
||||
def dummy_only_open_user_subinfo(app: App):
|
||||
from nonebot_bison.types import User, UserSubInfo
|
||||
|
||||
user = User(123, "group")
|
||||
@@ -24,9 +24,7 @@ def dummy_only_status_user_subinfo(app: App):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_only_status_change(
|
||||
bili_live, dummy_only_status_user_subinfo
|
||||
):
|
||||
async def test_fetch_bililive_only_live_open(bili_live, dummy_only_open_user_subinfo):
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
|
||||
bili_live_router = respx.get(
|
||||
@@ -38,28 +36,34 @@ async def test_fetch_bililive_only_status_change(
|
||||
bilibili_main_page_router.mock(return_value=Response(200))
|
||||
|
||||
target = "13164144"
|
||||
res = await bili_live.fetch_new_post(target, [dummy_only_status_user_subinfo])
|
||||
res = await bili_live.fetch_new_post(target, [dummy_only_open_user_subinfo])
|
||||
assert bili_live_router.call_count == 1
|
||||
assert len(res) == 0
|
||||
# 直播状态更新
|
||||
# 直播状态更新-上播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 1
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res2 = await bili_live.fetch_new_post(target, [dummy_only_status_user_subinfo])
|
||||
res2 = await bili_live.fetch_new_post(target, [dummy_only_open_user_subinfo])
|
||||
post = res2[0][1][0]
|
||||
assert post.target_type == "Bilibili直播"
|
||||
assert post.text == "【Zc】从0挑战到15肉鸽!目前10难度"
|
||||
assert post.text == "[开播] 【Zc】从0挑战到15肉鸽!目前10难度"
|
||||
assert post.url == "https://live.bilibili.com/3044248"
|
||||
assert post.target_name == "魔法Zc目录"
|
||||
assert post.target_name == "魔法Zc目录 其他单机"
|
||||
assert post.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
"https://i0.hdslb.com/bfs/live/new_room_cover/fd357f0f3cbbb48e9acfbcda616b946c2454c56c.jpg"
|
||||
]
|
||||
assert post.compress == True
|
||||
# 标题变更
|
||||
mock_bili_live_status["data"][target]["title"] = "【Zc】从0挑战到15肉鸽!目前11难度"
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res3 = await bili_live.fetch_new_post(target, [dummy_only_status_user_subinfo])
|
||||
res3 = await bili_live.fetch_new_post(target, [dummy_only_open_user_subinfo])
|
||||
assert bili_live_router.call_count == 3
|
||||
assert len(res3[0][1]) == 0
|
||||
# 直播状态更新-下播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 0
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res4 = await bili_live.fetch_new_post(target, [dummy_only_open_user_subinfo])
|
||||
assert bili_live_router.call_count == 4
|
||||
assert len(res4[0][1]) == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -95,7 +99,7 @@ async def test_fetch_bililive_only_title_change(
|
||||
res0 = await bili_live.fetch_new_post(target, [dummy_only_title_user_subinfo])
|
||||
assert bili_live_router.call_count == 2
|
||||
assert len(res0) == 0
|
||||
# 直播状态更新
|
||||
# 直播状态更新-上播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 1
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res2 = await bili_live.fetch_new_post(target, [dummy_only_title_user_subinfo])
|
||||
@@ -107,9 +111,74 @@ async def test_fetch_bililive_only_title_change(
|
||||
res3 = await bili_live.fetch_new_post(target, [dummy_only_title_user_subinfo])
|
||||
post = res3[0][1][0]
|
||||
assert post.target_type == "Bilibili直播"
|
||||
assert post.text == "【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post.text == "[标题更新] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post.url == "https://live.bilibili.com/3044248"
|
||||
assert post.target_name == "魔法Zc目录"
|
||||
assert post.target_name == "魔法Zc目录 其他单机"
|
||||
assert post.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
assert post.compress == True
|
||||
# 直播状态更新-下播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 0
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res4 = await bili_live.fetch_new_post(target, [dummy_only_title_user_subinfo])
|
||||
assert bili_live_router.call_count == 5
|
||||
assert len(res4[0][1]) == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_only_close_user_subinfo(app: App):
|
||||
from nonebot_bison.types import User, UserSubInfo
|
||||
|
||||
user = User(123, "group")
|
||||
return UserSubInfo(user=user, categories=[3], tags=[])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_fetch_bililive_only_close(bili_live, dummy_only_close_user_subinfo):
|
||||
mock_bili_live_status = get_json("bili_live_status.json")
|
||||
target = "13164144"
|
||||
|
||||
bili_live_router = respx.get(
|
||||
"https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids?uids[]=13164144"
|
||||
)
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
|
||||
bilibili_main_page_router = respx.get("https://www.bilibili.com/")
|
||||
bilibili_main_page_router.mock(return_value=Response(200))
|
||||
|
||||
res = await bili_live.fetch_new_post(target, [dummy_only_close_user_subinfo])
|
||||
assert bili_live_router.call_count == 1
|
||||
assert len(res) == 0
|
||||
# 未开播前标题变更
|
||||
mock_bili_live_status["data"][target]["title"] = "【Zc】从0挑战到15肉鸽!目前11难度"
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res0 = await bili_live.fetch_new_post(target, [dummy_only_close_user_subinfo])
|
||||
assert bili_live_router.call_count == 2
|
||||
assert len(res0) == 0
|
||||
# 直播状态更新-上播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 1
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res2 = await bili_live.fetch_new_post(target, [dummy_only_close_user_subinfo])
|
||||
assert bili_live_router.call_count == 3
|
||||
assert len(res2[0][1]) == 0
|
||||
# 标题变更
|
||||
mock_bili_live_status["data"][target]["title"] = "【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res3 = await bili_live.fetch_new_post(target, [dummy_only_close_user_subinfo])
|
||||
assert bili_live_router.call_count == 4
|
||||
assert len(res3[0][1]) == 0
|
||||
# 直播状态更新-下播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 0
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res4 = await bili_live.fetch_new_post(target, [dummy_only_close_user_subinfo])
|
||||
assert bili_live_router.call_count == 5
|
||||
post = res4[0][1][0]
|
||||
assert post.target_type == "Bilibili直播"
|
||||
assert post.text == "[下播] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post.url == "https://live.bilibili.com/3044248"
|
||||
assert post.target_name == "魔法Zc目录 其他单机"
|
||||
assert post.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
@@ -121,7 +190,7 @@ def dummy_bililive_user_subinfo(app: App):
|
||||
from nonebot_bison.types import User, UserSubInfo
|
||||
|
||||
user = User(123, "group")
|
||||
return UserSubInfo(user=user, categories=[1, 2], tags=[])
|
||||
return UserSubInfo(user=user, categories=[1, 2, 3], tags=[])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -147,17 +216,17 @@ async def test_fetch_bililive_combo(bili_live, dummy_bililive_user_subinfo):
|
||||
res0 = await bili_live.fetch_new_post(target, [dummy_bililive_user_subinfo])
|
||||
assert bili_live_router.call_count == 2
|
||||
assert len(res0) == 0
|
||||
# 直播状态更新
|
||||
# 直播状态更新-上播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 1
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res2 = await bili_live.fetch_new_post(target, [dummy_bililive_user_subinfo])
|
||||
post2 = res2[0][1][0]
|
||||
assert post2.target_type == "Bilibili直播"
|
||||
assert post2.text == "【Zc】从0挑战到15肉鸽!目前11难度"
|
||||
assert post2.text == "[开播] 【Zc】从0挑战到15肉鸽!目前11难度"
|
||||
assert post2.url == "https://live.bilibili.com/3044248"
|
||||
assert post2.target_name == "魔法Zc目录"
|
||||
assert post2.target_name == "魔法Zc目录 其他单机"
|
||||
assert post2.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
"https://i0.hdslb.com/bfs/live/new_room_cover/fd357f0f3cbbb48e9acfbcda616b946c2454c56c.jpg"
|
||||
]
|
||||
assert post2.compress == True
|
||||
# 标题变更
|
||||
@@ -166,10 +235,23 @@ async def test_fetch_bililive_combo(bili_live, dummy_bililive_user_subinfo):
|
||||
res3 = await bili_live.fetch_new_post(target, [dummy_bililive_user_subinfo])
|
||||
post3 = res3[0][1][0]
|
||||
assert post3.target_type == "Bilibili直播"
|
||||
assert post3.text == "【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post3.text == "[标题更新] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post3.url == "https://live.bilibili.com/3044248"
|
||||
assert post3.target_name == "魔法Zc目录"
|
||||
assert post3.target_name == "魔法Zc目录 其他单机"
|
||||
assert post3.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
assert post3.compress == True
|
||||
# 直播状态更新-下播
|
||||
mock_bili_live_status["data"][target]["live_status"] = 0
|
||||
bili_live_router.mock(return_value=Response(200, json=mock_bili_live_status))
|
||||
res4 = await bili_live.fetch_new_post(target, [dummy_bililive_user_subinfo])
|
||||
post4 = res4[0][1][0]
|
||||
assert post4.target_type == "Bilibili直播"
|
||||
assert post4.text == "[下播] 【Zc】从0挑战到15肉鸽!目前12难度"
|
||||
assert post4.url == "https://live.bilibili.com/3044248"
|
||||
assert post4.target_name == "魔法Zc目录 其他单机"
|
||||
assert post4.pics == [
|
||||
"https://i0.hdslb.com/bfs/live-key-frame/keyframe10170435000003044248mwowx0.jpg"
|
||||
]
|
||||
assert post4.compress == True
|
||||
|
||||
Reference in New Issue
Block a user