diff --git a/telezab.py b/telezab.py index 55ce955..f353c23 100644 --- a/telezab.py +++ b/telezab.py @@ -547,6 +547,14 @@ def process_remove_region(message): with db_lock: conn = sqlite3.connect('telezab.db') cursor = conn.cursor() + # Проверка существования региона + query = 'SELECT COUNT(*) FROM regions WHERE region_id = ?' + cursor.execute(query, (region_id,)) + count = cursor.fetchone()[0] + if count == 0: + bot.send_message(chat_id, f"Регион с ID {region_id} не существует.") + return show_settings_menu(chat_id) + query = 'UPDATE regions SET active = FALSE WHERE region_id = ?' app.logger.debug(f"Executing query: {query} with region_id={region_id}") cursor.execute(query, (region_id,)) @@ -606,10 +614,12 @@ def handle_my_subscriptions(message): if not user_regions: bot.send_message(chat_id, "Вы не подписаны ни на один регион.") else: + user_regions.sort(key=lambda x: int(x[0])) # Сортировка по числовому значению region_id regions_list = format_regions_list(user_regions) bot.send_message(chat_id, f"Ваши активные подписки:\n{regions_list}") show_settings_menu(chat_id) + # Handle displaying all active regions def handle_active_regions(message): chat_id = message.chat.id