mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-07 20:33:01 +08:00
初步完成屏蔽特定tag功能
This commit is contained in:
parent
07ab1b6fb3
commit
f486d0b983
@ -111,6 +111,30 @@ class Platform(metaclass=RegistryABCMeta, base=True):
|
|||||||
def set_stored_data(self, target: Target, data: Any):
|
def set_stored_data(self, target: Target, data: Any):
|
||||||
self.store[target] = data
|
self.store[target] = data
|
||||||
|
|
||||||
|
def tag_separator(self, stored_tags: list[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:
|
||||||
|
for tag in post_tags or []:
|
||||||
|
if banned_tags and tag in banned_tags:
|
||||||
|
return True
|
||||||
|
elif subscribed_tags and tag not in subscribed_tags:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
async def filter_user_custom(
|
async def filter_user_custom(
|
||||||
self, raw_post_list: list[RawPost], cats: list[Category], tags: list[Tag]
|
self, raw_post_list: list[RawPost], cats: list[Category], tags: list[Tag]
|
||||||
) -> list[RawPost]:
|
) -> list[RawPost]:
|
||||||
@ -121,13 +145,8 @@ class Platform(metaclass=RegistryABCMeta, base=True):
|
|||||||
if cats and cat not in cats:
|
if cats and cat not in cats:
|
||||||
continue
|
continue
|
||||||
if self.enable_tag and tags:
|
if self.enable_tag and tags:
|
||||||
flag = False
|
|
||||||
post_tags = self.get_tags(raw_post)
|
post_tags = self.get_tags(raw_post)
|
||||||
for tag in post_tags or []:
|
if self.is_banned_post(post_tags, **self.tag_separator(tags)):
|
||||||
if tag in tags:
|
|
||||||
flag = True
|
|
||||||
break
|
|
||||||
if not flag:
|
|
||||||
continue
|
continue
|
||||||
res.append(raw_post)
|
res.append(raw_post)
|
||||||
return res
|
return res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user