Extracted build_menu to separate file
This commit is contained in:
parent
fbb2c65fd0
commit
724415bcb4
2 changed files with 11 additions and 12 deletions
10
telegram_helpers.py
Normal file
10
telegram_helpers.py
Normal file
|
@ -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
|
13
vvs.py
13
vvs.py
|
@ -3,6 +3,7 @@ import requests
|
||||||
from telegram import InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton, InlineKeyboardMarkup
|
from telegram import InlineQueryResultArticle, InputTextMessageContent, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
|
|
||||||
from exceptions import MultipleStationsFoundError, NoArgError, ServerCommunicationError, StationNotFoundError
|
from exceptions import MultipleStationsFoundError, NoArgError, ServerCommunicationError, StationNotFoundError
|
||||||
|
from telegram_helpers import build_menu
|
||||||
|
|
||||||
sent_multiple_station_message_ids = dict()
|
sent_multiple_station_message_ids = dict()
|
||||||
|
|
||||||
|
@ -34,18 +35,6 @@ class Query:
|
||||||
self.departure_count = int(arguments[argument_names.index(' times ') + 1])
|
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):
|
def reply_multiple_stations(message, message_text, queried_station, station_list):
|
||||||
button_list = []
|
button_list = []
|
||||||
for station in station_list:
|
for station in station_list:
|
||||||
|
|
Loading…
Reference in a new issue