From 9f19440f9b82c906d6425cf3cabaea71a7e04ff1 Mon Sep 17 00:00:00 2001 From: JuliusFreudenberger Date: Fri, 18 Oct 2019 12:35:58 +0200 Subject: [PATCH] Message for selecting stations is now deleted after choice this makes the chat shorter if a first query matched many possible stations --- bot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 18a41f8..af6972a 100644 --- a/bot.py +++ b/bot.py @@ -14,6 +14,8 @@ dispatcher = updater.dispatcher logging.basicConfig(format='%(acstime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) +sent_multiple_station_message_ids = dict() + class Query: station_id = -1 @@ -61,7 +63,8 @@ def reply_multiple_stations(message, message_text, queried_station, station_list callback_data="/vvs " + message_text .replace(queried_station, station['stationId']))) reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=2)) - message.reply_text("Multiple stations found:", reply_markup=reply_markup) + sent_multiple_station_message_ids[message.chat_id] = message.reply_text("Multiple stations found:", + reply_markup=reply_markup).message_id def handle_multiple_stations_reply(update, context): @@ -69,6 +72,9 @@ def handle_multiple_stations_reply(update, context): departures = get_vvs_departures(query) for reply in departures: context.bot.send_message(update.effective_chat['id'], reply) + context.bot.delete_message(chat_id=update.effective_chat['id'], + message_id=sent_multiple_station_message_ids[update.effective_chat['id']]) + del sent_multiple_station_message_ids[update.effective_chat['id']] def search_station(query):