diff --git a/telegram_helpers.py b/telegram_helpers.py new file mode 100644 index 0000000..975e8ef --- /dev/null +++ b/telegram_helpers.py @@ -0,0 +1,10 @@ +def build_menu(buttons: [], + n_cols: int, + header_buttons: [] = None, + footer_buttons: [] = None): + menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] + if header_buttons: + menu.insert(0, [header_buttons]) + if footer_buttons: + menu.append([footer_buttons]) + return menu diff --git a/vvs.py b/vvs.py index 878516e..dbf65ff 100644 --- a/vvs.py +++ b/vvs.py @@ -3,6 +3,7 @@ import requests from telegram import InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton, InlineKeyboardMarkup from exceptions import MultipleStationsFoundError, NoArgError, ServerCommunicationError, StationNotFoundError +from telegram_helpers import build_menu sent_multiple_station_message_ids = dict() @@ -34,18 +35,6 @@ class Query: self.departure_count = int(arguments[argument_names.index(' times ') + 1]) -def build_menu(buttons, - n_cols, - header_buttons=None, - footer_buttons=None): - menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)] - if header_buttons: - menu.insert(0, [header_buttons]) - if footer_buttons: - menu.append([footer_buttons]) - return menu - - def reply_multiple_stations(message, message_text, queried_station, station_list): button_list = [] for station in station_list: