From dc88316742969c8098e04544ee30349d454246b4 Mon Sep 17 00:00:00 2001 From: Benny Date: Sun, 28 May 2023 12:52:36 +0200 Subject: [PATCH] fix pagination --- searchgram/bot.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/searchgram/bot.py b/searchgram/bot.py index 3526ff4..4a7d5cf 100644 --- a/searchgram/bot.py +++ b/searchgram/bot.py @@ -190,8 +190,23 @@ def send_method_callback(client: "Client", callback_query: types.CallbackQuery): raise ValueError("Invalid direction") # find original user query + # /private hello + # -t=private -u=123 hello + # -t=private hello + # hello user_query = message.reply_to_message.text - new_text, new_markup = parse_and_search(user_query, new_page) + + parts = user_query.split(maxsplit=2) + if user_query.startswith("/"): + user_filter = f"-u={parts[1]}" if len(parts) > 2 else "" + keyword = parts[2] if len(parts) > 2 else parts[1] + refined_text = f"-t={parts[0][1:].upper()} {user_filter} {keyword}" + elif len(parts) == 1: + refined_text = parts[0] + else: + refined_text = user_query + client.send_chat_action(message.chat.id, enums.ChatAction.TYPING) + new_text, new_markup = parse_and_search(refined_text, new_page) message.edit_text(new_text, reply_markup=new_markup)