refactor(link_filter): 优化链接过滤器中的链接标准化函数,修复关键词处理逻辑

This commit is contained in:
wood 2024-09-05 15:20:32 +08:00
parent ac1bcbc105
commit c1be5d9e0f
2 changed files with 3 additions and 1 deletions

View File

@ -67,7 +67,7 @@ async def process_message(event, client):
logger.info(f"Message should be filtered: {event.message.text}") logger.info(f"Message should be filtered: {event.message.text}")
if event.sender_id != ADMIN_ID: if event.sender_id != ADMIN_ID:
await event.delete() await event.delete()
notification = await event.respond("已撤回该消息。注:包含关键词或重复发送的非白名单链接会被自动撤回。") notification = await event.respond("已撤回该消息。注:已置顶项目分享链接, 二次分享链接, 都会被撤回.")
asyncio.create_task(delete_message_after_delay(client, event.chat_id, notification, 3 * 60)) asyncio.create_task(delete_message_after_delay(client, event.chat_id, notification, 3 * 60))
return return
if new_links: if new_links:

View File

@ -108,6 +108,7 @@ class LinkFilter:
new_non_whitelisted_links = [] new_non_whitelisted_links = []
for link in links: for link in links:
normalized_link = self.normalize_link(link) normalized_link = self.normalize_link(link)
normalized_link = normalized_link.lstrip('/') # 去除开头的双斜杠
if not self.is_whitelisted(normalized_link): if not self.is_whitelisted(normalized_link):
logger.debug(f"Link not whitelisted: {normalized_link}") logger.debug(f"Link not whitelisted: {normalized_link}")
if normalized_link not in self.keywords: if normalized_link not in self.keywords:
@ -121,6 +122,7 @@ class LinkFilter:
logger.info(f"New non-whitelisted links found: {new_non_whitelisted_links}") logger.info(f"New non-whitelisted links found: {new_non_whitelisted_links}")
return False, new_non_whitelisted_links return False, new_non_whitelisted_links
async def handle_keyword_command(self, event, command, args): async def handle_keyword_command(self, event, command, args):
if command == '/list': if command == '/list':
self.load_data_from_file() self.load_data_from_file()