mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-11-28 18:56:44 +08:00
@ -366,7 +366,7 @@ if settings.openai_api_key:
|
|||||||
confirm_command, commands=["confirm"], pass_bot=True
|
confirm_command, commands=["confirm"], pass_bot=True
|
||||||
)
|
)
|
||||||
bot.register_message_handler(
|
bot.register_message_handler(
|
||||||
handle_message, func=partial(filter_message, bot=bot), pass_bot=True
|
handle_message, func=partial(filter_message, bot=bot, check_chinese=True), pass_bot=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# 启动提肛提醒定时任务
|
# 启动提肛提醒定时任务
|
||||||
|
|||||||
@ -18,15 +18,22 @@ def contains_non_ascii(text: str) -> bool:
|
|||||||
return not text.isascii()
|
return not text.isascii()
|
||||||
|
|
||||||
|
|
||||||
def filter_message(message: Message, bot: TeleBot) -> bool:
|
def filter_message(message: Message, bot: TeleBot, check_chinese: bool = False) -> bool:
|
||||||
"""过滤消息,排除非文本消息和命令消息"""
|
"""过滤消息,排除非文本消息和命令消息
|
||||||
|
|
||||||
|
Args:
|
||||||
|
message: 消息对象
|
||||||
|
bot: Bot 实例
|
||||||
|
check_chinese: 是否允许检查中文消息(即不过滤命令)
|
||||||
|
"""
|
||||||
if not message.text:
|
if not message.text:
|
||||||
return False
|
return False
|
||||||
if not message.from_user:
|
if not message.from_user:
|
||||||
return False
|
return False
|
||||||
if message.from_user.id == bot.get_me().id:
|
if message.from_user.id == bot.get_me().id:
|
||||||
return False
|
return False
|
||||||
if message.text.startswith("/"):
|
# 如果需要检查中文,则不过滤命令消息(让 handle_message 处理)
|
||||||
|
if not check_chinese and message.text.startswith("/"):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user