fix: lint

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
yihong0618
2026-01-06 20:00:35 +08:00
parent c643b0dec0
commit 1f0c37c3ab
2 changed files with 51 additions and 24 deletions

View File

@@ -65,7 +65,7 @@ def check_poll_for_chinese(message: Message) -> bool:
def check_caption_for_chinese(message: Message) -> bool: def check_caption_for_chinese(message: Message) -> bool:
"""检查媒体消息的 caption 是否包含中文""" """检查媒体消息的 caption 是否包含中文"""
if hasattr(message, 'caption') and message.caption: if hasattr(message, "caption") and message.caption:
return contains_non_ascii(message.caption) return contains_non_ascii(message.caption)
return False return False
@@ -73,25 +73,33 @@ def check_caption_for_chinese(message: Message) -> bool:
def check_link_preview_for_chinese(message: Message) -> bool: def check_link_preview_for_chinese(message: Message) -> bool:
"""检查消息链接预览是否包含中文""" """检查消息链接预览是否包含中文"""
# 检查 link_preview_options如果存在 # 检查 link_preview_options如果存在
if hasattr(message, 'link_preview_options') and message.link_preview_options: if hasattr(message, "link_preview_options") and message.link_preview_options:
lpo = message.link_preview_options lpo = message.link_preview_options
if hasattr(lpo, 'url') and lpo.url and contains_non_ascii(lpo.url): if hasattr(lpo, "url") and lpo.url and contains_non_ascii(lpo.url):
return True return True
# 检查 web_page链接预览的详细信息 # 检查 web_page链接预览的详细信息
if hasattr(message, 'web_page') and message.web_page: if hasattr(message, "web_page") and message.web_page:
wp = message.web_page wp = message.web_page
# 检查标题 # 检查标题
if hasattr(wp, 'title') and wp.title and contains_non_ascii(wp.title): if hasattr(wp, "title") and wp.title and contains_non_ascii(wp.title):
return True return True
# 检查描述 # 检查描述
if hasattr(wp, 'description') and wp.description and contains_non_ascii(wp.description): if (
hasattr(wp, "description")
and wp.description
and contains_non_ascii(wp.description)
):
return True return True
# 检查站点名称 # 检查站点名称
if hasattr(wp, 'site_name') and wp.site_name and contains_non_ascii(wp.site_name): if (
hasattr(wp, "site_name")
and wp.site_name
and contains_non_ascii(wp.site_name)
):
return True return True
# 检查 URL # 检查 URL
if hasattr(wp, 'url') and wp.url and contains_non_ascii(wp.url): if hasattr(wp, "url") and wp.url and contains_non_ascii(wp.url):
return True return True
return False return False
@@ -100,9 +108,9 @@ def check_link_preview_for_chinese(message: Message) -> bool:
def message_has_url(message: Message) -> bool: def message_has_url(message: Message) -> bool:
"""检查消息是否包含 URL""" """检查消息是否包含 URL"""
# 检查 entities 中是否有 URL 类型 # 检查 entities 中是否有 URL 类型
if hasattr(message, 'entities') and message.entities: if hasattr(message, "entities") and message.entities:
for entity in message.entities: for entity in message.entities:
if entity.type in ('url', 'text_link'): if entity.type in ("url", "text_link"):
return True return True
return False return False
@@ -540,7 +548,8 @@ if settings.openai_api_key:
# 处理包含中文的投票 # 处理包含中文的投票
poll_filter = lambda msg: ( poll_filter = lambda msg: (
hasattr(msg, 'poll') and msg.poll is not None hasattr(msg, "poll")
and msg.poll is not None
and msg.chat.id == TIGONG_CHAT_ID and msg.chat.id == TIGONG_CHAT_ID
and is_chinese_ban_time() and is_chinese_ban_time()
and check_poll_for_chinese(msg) and check_poll_for_chinese(msg)
@@ -560,13 +569,29 @@ if settings.openai_api_key:
bot.register_message_handler( bot.register_message_handler(
check_and_delete_chinese_caption, check_and_delete_chinese_caption,
func=caption_filter, func=caption_filter,
content_types=['photo', 'video', 'document', 'audio', 'voice', 'video_note', 'animation'], content_types=[
"photo",
"video",
"document",
"audio",
"voice",
"video_note",
"animation",
],
pass_bot=True, pass_bot=True,
) )
bot.register_edited_message_handler( bot.register_edited_message_handler(
check_and_delete_chinese_caption, check_and_delete_chinese_caption,
func=caption_filter, func=caption_filter,
content_types=['photo', 'video', 'document', 'audio', 'voice', 'video_note', 'animation'], content_types=[
"photo",
"video",
"document",
"audio",
"voice",
"video_note",
"animation",
],
pass_bot=True, pass_bot=True,
) )

View File

@@ -40,6 +40,8 @@ def filter_message(message: Message, bot: TeleBot) -> bool:
if message.text.startswith("/"): if message.text.startswith("/"):
return False return False
return True return True
date_regex = re.compile(r"^(\d+)([dhm])$") date_regex = re.compile(r"^(\d+)([dhm])$")