mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +08:00
feat (issue#67):添加屏蔽特定tag的功能
This commit is contained in:
parent
945f00f531
commit
4177fd149a
@ -112,6 +112,7 @@ class Platform(metaclass=RegistryABCMeta, base=True):
|
||||
self.store[target] = data
|
||||
|
||||
def tag_separator(self, stored_tags: list[Tag]):
|
||||
"""返回分离好的正反tag元组"""
|
||||
subscribed_tags = []
|
||||
banned_tags = []
|
||||
for tag in stored_tags:
|
||||
|
2079
tests/platforms/static/bilibili_bing_list.json
vendored
2079
tests/platforms/static/bilibili_bing_list.json
vendored
File diff suppressed because one or more lines are too long
246
tests/platforms/static/bilibili_fake_dy_list.json
vendored
Normal file
246
tests/platforms/static/bilibili_fake_dy_list.json
vendored
Normal file
@ -0,0 +1,246 @@
|
||||
{
|
||||
"data": {
|
||||
"cards": [
|
||||
{
|
||||
"desc": {
|
||||
"type": 2
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 1
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 8
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "明日方舟"
|
||||
},
|
||||
{
|
||||
"topic_name": "风笛"
|
||||
},
|
||||
{
|
||||
"topic_name": "琴柳"
|
||||
},
|
||||
{
|
||||
"topic_name": "风暴瞭望"
|
||||
},
|
||||
{
|
||||
"topic_name": "轮换池"
|
||||
},
|
||||
{
|
||||
"topic_name": "打卡挑战"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 2
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 1
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "明日方舟"
|
||||
},
|
||||
{
|
||||
"topic_name": "饼学大厦"
|
||||
},
|
||||
{
|
||||
"topic_name": "可露希尔的秘密档案"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 1
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "罗德岛相簿"
|
||||
},
|
||||
{
|
||||
"topic_name": "可露希尔的秘密档案"
|
||||
},
|
||||
{
|
||||
"topic_name": "罗德岛闲逛部"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 8
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "明日方舟"
|
||||
},
|
||||
{
|
||||
"topic_name": "轮换学"
|
||||
},
|
||||
{
|
||||
"topic_name": "常驻标准寻访"
|
||||
},
|
||||
{
|
||||
"topic_name": "轮换池"
|
||||
},
|
||||
{
|
||||
"topic_name": "打卡挑战"
|
||||
},
|
||||
{
|
||||
"topic_name": "舟游"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 2
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "明日方舟"
|
||||
},
|
||||
{
|
||||
"topic_name": "饼学大厦"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 4
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 1
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "明日方舟"
|
||||
},
|
||||
{
|
||||
"topic_name": "饼学大厦"
|
||||
},
|
||||
{
|
||||
"topic_name": "罗德岛相簿"
|
||||
},
|
||||
{
|
||||
"topic_name": "可露希尔的秘密档案"
|
||||
},
|
||||
{
|
||||
"topic_name": "罗德岛闲逛部"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 1
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "明日方舟"
|
||||
},
|
||||
{
|
||||
"topic_name": "饼学大厦"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": {
|
||||
"type": 1
|
||||
},
|
||||
"display": {
|
||||
"topic_info": {
|
||||
"topic_details": [
|
||||
{
|
||||
"topic_name": "明日方舟"
|
||||
},
|
||||
{
|
||||
"topic_name": "饼学大厦"
|
||||
},
|
||||
{
|
||||
"topic_name": "罗德岛相簿"
|
||||
},
|
||||
{
|
||||
"topic_name": "可露希尔的秘密档案"
|
||||
},
|
||||
{
|
||||
"topic_name": "罗德岛闲逛部"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -69,3 +69,33 @@ async def test_parse_target(bilibili: "Bilibili"):
|
||||
await bilibili.parse_target(
|
||||
"https://www.bilibili.com/video/BV1qP4y1g738?spm_id_from=333.999.0.0"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def post_list():
|
||||
return get_json("bilibili_fake_dy_list.json")["data"]["cards"]
|
||||
|
||||
|
||||
# 测试新tag机制的平台推送情况
|
||||
@pytest.mark.asyncio
|
||||
async def test_filter_user_custom(bilibili, post_list):
|
||||
|
||||
only_banned_tags = ["~可露希尔的秘密档案"]
|
||||
res0 = await bilibili.filter_user_custom(post_list, [], only_banned_tags)
|
||||
assert len(res0) == 8
|
||||
|
||||
only_subscribed_tags = ["可露希尔的秘密档案"]
|
||||
res1 = await bilibili.filter_user_custom(post_list, [], only_subscribed_tags)
|
||||
assert len(res1) == 4
|
||||
|
||||
multi_subs_tags_1 = ["可露希尔的秘密档案", "罗德岛相簿"]
|
||||
res2 = await bilibili.filter_user_custom(post_list, [], multi_subs_tags_1)
|
||||
assert len(res2) == 4
|
||||
|
||||
multi_subs_tags_2 = ["罗德岛相簿", "风暴瞭望"]
|
||||
res3 = await bilibili.filter_user_custom(post_list, [], multi_subs_tags_2)
|
||||
assert len(res3) == 4
|
||||
|
||||
multi_subs_tags_3 = ["明日方舟", "~饼学大厦"]
|
||||
res4 = await bilibili.filter_user_custom(post_list, [], multi_subs_tags_3)
|
||||
assert len(res4) == 2
|
||||
|
@ -9,6 +9,7 @@ def test_cases():
|
||||
return get_json("tag_cases.json")
|
||||
|
||||
|
||||
# 测试正反tag的判断情况
|
||||
@pytest.mark.asyncio
|
||||
async def test_filter_user_custom_tag(app: App, test_cases):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
@ -17,3 +18,15 @@ async def test_filter_user_custom_tag(app: App, test_cases):
|
||||
for case in test_cases:
|
||||
res = bilibili.is_banned_post(**case["case"])
|
||||
assert res == case["result"]
|
||||
|
||||
|
||||
# 测试正反tag的分离情况
|
||||
@pytest.mark.asyncio
|
||||
async def test_tag_separator(app: App):
|
||||
from nonebot_bison.platform import platform_manager
|
||||
|
||||
bilibili = platform_manager["bilibili"]
|
||||
tags = ["~111", "222", "333", "~444", "555"]
|
||||
res = bilibili.tag_separator(tags)
|
||||
assert res[0] == ["222", "333", "555"]
|
||||
assert res[1] == ["111", "444"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user