mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2026-01-13 21:04:24 +08:00
@@ -65,7 +65,7 @@ def check_poll_for_chinese(message: Message) -> bool:
|
||||
|
||||
def check_caption_for_chinese(message: Message) -> bool:
|
||||
"""检查媒体消息的 caption 是否包含中文"""
|
||||
if hasattr(message, 'caption') and message.caption:
|
||||
if hasattr(message, "caption") and message.caption:
|
||||
return contains_non_ascii(message.caption)
|
||||
return False
|
||||
|
||||
@@ -73,25 +73,33 @@ def check_caption_for_chinese(message: Message) -> bool:
|
||||
def check_link_preview_for_chinese(message: Message) -> bool:
|
||||
"""检查消息链接预览是否包含中文"""
|
||||
# 检查 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
|
||||
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
|
||||
|
||||
# 检查 web_page(链接预览的详细信息)
|
||||
if hasattr(message, 'web_page') and message.web_page:
|
||||
if hasattr(message, "web_page") and 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
|
||||
# 检查描述
|
||||
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
|
||||
# 检查站点名称
|
||||
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
|
||||
# 检查 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 False
|
||||
@@ -100,9 +108,9 @@ def check_link_preview_for_chinese(message: Message) -> bool:
|
||||
def message_has_url(message: Message) -> bool:
|
||||
"""检查消息是否包含 URL"""
|
||||
# 检查 entities 中是否有 URL 类型
|
||||
if hasattr(message, 'entities') and message.entities:
|
||||
if hasattr(message, "entities") and message.entities:
|
||||
for entity in message.entities:
|
||||
if entity.type in ('url', 'text_link'):
|
||||
if entity.type in ("url", "text_link"):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -540,7 +548,8 @@ if settings.openai_api_key:
|
||||
|
||||
# 处理包含中文的投票
|
||||
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 is_chinese_ban_time()
|
||||
and check_poll_for_chinese(msg)
|
||||
@@ -560,13 +569,29 @@ if settings.openai_api_key:
|
||||
bot.register_message_handler(
|
||||
check_and_delete_chinese_caption,
|
||||
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,
|
||||
)
|
||||
bot.register_edited_message_handler(
|
||||
check_and_delete_chinese_caption,
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ def filter_message(message: Message, bot: TeleBot) -> bool:
|
||||
if message.text.startswith("/"):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
date_regex = re.compile(r"^(\d+)([dhm])$")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user