mirror of
				https://github.com/cdryzun/tg_bot_collections.git
				synced 2025-11-04 16:56:43 +08:00 
			
		
		
		
	fix: support search with space
Signed-off-by: Frost Ming <me@frostming.com>
This commit is contained in:
		@ -3,6 +3,7 @@ from __future__ import annotations
 | 
				
			|||||||
import logging
 | 
					import logging
 | 
				
			||||||
from datetime import datetime, timezone
 | 
					from datetime import datetime, timezone
 | 
				
			||||||
from functools import partial
 | 
					from functools import partial
 | 
				
			||||||
 | 
					import shlex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import telegramify_markdown
 | 
					import telegramify_markdown
 | 
				
			||||||
from telebot import TeleBot
 | 
					from telebot import TeleBot
 | 
				
			||||||
@ -96,7 +97,7 @@ def stats_command(message: Message, bot: TeleBot):
 | 
				
			|||||||
@non_llm_handler
 | 
					@non_llm_handler
 | 
				
			||||||
def search_command(message: Message, bot: TeleBot):
 | 
					def search_command(message: Message, bot: TeleBot):
 | 
				
			||||||
    """搜索群组消息(示例:/search 关键词 [N])"""
 | 
					    """搜索群组消息(示例:/search 关键词 [N])"""
 | 
				
			||||||
    text_parts = message.text.split(maxsplit=2)
 | 
					    text_parts = shlex.split(message.text)
 | 
				
			||||||
    if len(text_parts) < 2:
 | 
					    if len(text_parts) < 2:
 | 
				
			||||||
        bot.reply_to(message, "请提供要搜索的关键词。")
 | 
					        bot.reply_to(message, "请提供要搜索的关键词。")
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
@ -115,7 +116,7 @@ def search_command(message: Message, bot: TeleBot):
 | 
				
			|||||||
    items = []
 | 
					    items = []
 | 
				
			||||||
    for msg in messages:
 | 
					    for msg in messages:
 | 
				
			||||||
        link = f"https://t.me/c/{chat_id}/{msg.message_id}"
 | 
					        link = f"https://t.me/c/{chat_id}/{msg.message_id}"
 | 
				
			||||||
        items.append(f"{link}\n```\n{msg.content}\n```")
 | 
					        items.append(f"{link}\n```\n{msg.user_name}: {msg.content}\n```")
 | 
				
			||||||
    message_text = telegramify_markdown.markdownify("\n".join(items))
 | 
					    message_text = telegramify_markdown.markdownify("\n".join(items))
 | 
				
			||||||
    bot.reply_to(
 | 
					    bot.reply_to(
 | 
				
			||||||
        message,
 | 
					        message,
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user