mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-06-23 22:16:53 +08:00
Merge branch 'main' into next
This commit is contained in:
@@ -137,7 +137,7 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
state["id"] = target
|
||||
state["name"] = name
|
||||
except (LookupError):
|
||||
url = "https://nonebot-bison.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
|
||||
url = "https://nonebot-bison.netlify.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
|
||||
title = "Bison所支持的平台UID"
|
||||
content = "查询相关平台的uid格式或获取方式"
|
||||
image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||
@@ -182,13 +182,17 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
if not platform_manager[state["platform"]].enable_tag:
|
||||
state["tags"] = []
|
||||
return
|
||||
state["_prompt"] = '请输入要订阅的tag,订阅所有tag输入"全部标签"'
|
||||
state["_prompt"] = '请输入要订阅/屏蔽的tag(不含#号)\n多个tag请使用空格隔开\n具体规则回复"详情"'
|
||||
|
||||
async def parser_tags(event: MessageEvent, state: T_State):
|
||||
if not isinstance(state["tags"], Message):
|
||||
return
|
||||
if str(event.get_message()).strip() == "取消": # 一般不会有叫 取消 的tag吧
|
||||
await add_sub.finish("已中止订阅")
|
||||
if str(event.get_message()).strip() == "详情":
|
||||
await add_sub.reject(
|
||||
'订阅tag直接输入tag内容\n订阅所有tag输入"全部标签"\n屏蔽tag请在tag名称前添加~号\n详见https://nonebot-bison.netlify.app/usage/#平台订阅标签-tag'
|
||||
)
|
||||
if str(event.get_message()).strip() == "全部标签":
|
||||
state["tags"] = []
|
||||
else:
|
||||
|
||||
@@ -110,6 +110,43 @@ class Platform(metaclass=RegistryABCMeta, base=True):
|
||||
def set_stored_data(self, target: Target, data: Any):
|
||||
self.store[target] = data
|
||||
|
||||
def tag_separator(self, stored_tags: list[Tag]) -> tuple[list[Tag], list[Tag]]:
|
||||
"""返回分离好的正反tag元组"""
|
||||
subscribed_tags = []
|
||||
banned_tags = []
|
||||
for tag in stored_tags:
|
||||
if tag.startswith("~"):
|
||||
banned_tags.append(tag.lstrip("~"))
|
||||
else:
|
||||
subscribed_tags.append(tag)
|
||||
return subscribed_tags, banned_tags
|
||||
|
||||
def is_banned_post(
|
||||
self,
|
||||
post_tags: Collection[Tag],
|
||||
subscribed_tags: list[Tag],
|
||||
banned_tags: list[Tag],
|
||||
) -> bool:
|
||||
"""只要存在任意屏蔽tag则返回真,此行为优先级最高。
|
||||
存在任意被订阅tag则返回假,此行为优先级次之。
|
||||
若被订阅tag为空,则返回假。
|
||||
"""
|
||||
# 存在任意需要屏蔽的tag则为真
|
||||
if banned_tags:
|
||||
for tag in post_tags or []:
|
||||
if tag in banned_tags:
|
||||
return True
|
||||
# 检测屏蔽tag后,再检测订阅tag
|
||||
# 存在任意需要订阅的tag则为假
|
||||
if subscribed_tags:
|
||||
ban_it = True
|
||||
for tag in post_tags or []:
|
||||
if tag in subscribed_tags:
|
||||
ban_it = False
|
||||
return ban_it
|
||||
else:
|
||||
return False
|
||||
|
||||
async def filter_user_custom(
|
||||
self, raw_post_list: list[RawPost], cats: list[Category], tags: list[Tag]
|
||||
) -> list[RawPost]:
|
||||
@@ -120,13 +157,9 @@ class Platform(metaclass=RegistryABCMeta, base=True):
|
||||
if cats and cat not in cats:
|
||||
continue
|
||||
if self.enable_tag and tags:
|
||||
flag = False
|
||||
post_tags = self.get_tags(raw_post)
|
||||
for tag in post_tags or []:
|
||||
if tag in tags:
|
||||
flag = True
|
||||
break
|
||||
if not flag:
|
||||
if self.is_banned_post(
|
||||
self.get_tags(raw_post), *self.tag_separator(tags)
|
||||
):
|
||||
continue
|
||||
res.append(raw_post)
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user