From 276bb5fc834fc941473bc94c31f096685f7587c9 Mon Sep 17 00:00:00 2001 From: Xiaolan Bot Date: Sun, 22 Feb 2026 02:54:56 +0800 Subject: [PATCH] fix: restore get_subs_list_keyboard helper --- SubMind.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/SubMind.py b/SubMind.py index ff15a9c..06adcae 100644 --- a/SubMind.py +++ b/SubMind.py @@ -263,6 +263,27 @@ def _parse_category_id_from_callback(data: str) -> int | None: return int(payload) if payload.isdigit() else None +async def get_subs_list_keyboard(user_id: int, category_filter: str = None) -> InlineKeyboardMarkup: + with get_db_connection() as conn: + cursor = conn.cursor() + query, params = "SELECT id, name FROM subscriptions WHERE user_id = ? ", [user_id] + if category_filter: + query += "AND category = ? " + params.append(category_filter) + query += "ORDER BY next_due ASC" + cursor.execute(query, tuple(params)) + subs = cursor.fetchall() + if not subs: + return None + buttons = [InlineKeyboardButton(name, callback_data=f'view_{sub_id}') for sub_id, name in subs] + keyboard = [buttons[i:i + 2] for i in range(0, len(buttons), 2)] + if category_filter: + keyboard.append([InlineKeyboardButton("« 返回分类列表", callback_data='list_categories')]) + else: + keyboard.append([InlineKeyboardButton("🗂️ 按分类浏览", callback_data='list_categories')]) + return InlineKeyboardMarkup(keyboard) + + def _clear_action_state(context: CallbackContext, keys: list[str]): for key in keys: context.user_data.pop(key, None)