def players_page(bot: Bot, chat_id: int, page_num: int, mode: AnswerMode, message_info: dict = None): request_is_correct = True players_list: List[PlayerPage] = get_players_page(page_num, 5) custom_navigation_keyboard = [] if len(players_list) == 0: request_is_correct = False else: total = players_list[0].total custom_navigation_keyboard = five_buttons_pagination_menu( total, page_num, 'pr_pg', chat_id) if request_is_correct: custom_keyboard = [[ InlineKeyboardButton(text=pr.secondname_name + ' ' + ('✅' if pr.rosterstatus == 't' else '❌'), callback_data='pr_#' + str(pr.player_id)) ] for pr in players_list] custom_keyboard.append(custom_navigation_keyboard) if mode == AnswerMode.SEND_NEW: send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, False) elif mode == AnswerMode.EDIT: print(message_info) send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, True) else: bot.send_message(chat_id=chat_id, text="<b>There is no page with this number</b>", parse_mode='HTML')
def seasons_page(bot: Bot, chat_id: int, page_num: int, mode: AnswerMode, message_info: dict = None): request_is_correct = True seasons_list: List[SeasonPage] = get_seasons_page(page_num, 5) custom_navigation_keyboard = [] if len(seasons_list) == 0: request_is_correct = False else: total = seasons_list[0].total custom_navigation_keyboard = five_buttons_pagination_menu( total, page_num, 'sn_pg', chat_id) if request_is_correct: custom_keyboard = [[ InlineKeyboardButton(text=sn.season_name, callback_data='sn_#' + str(sn.season_id)) ] for sn in seasons_list] custom_keyboard.append(custom_navigation_keyboard) if mode == AnswerMode.SEND_NEW: send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, False) elif mode == AnswerMode.EDIT: print(message_info) send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, True) else: bot.send_message(chat_id=chat_id, text="<b>There is no page with this number</b>", parse_mode='HTML')
def season(bot: Bot, chat_id: int, season_id: int, message_info: dict): found_season = get_season_by_id(season_id) current_message_id = int(message_info['message_id']) custom_keyboard = [[InlineKeyboardButton(text="BACK", callback_data='b_')]] if found_season is None: text = "<b>There is no season with this index</b>" else: text = str(found_season) send_message_with_save(bot, int(current_message_id), int(chat_id), text, custom_keyboard, True)
def game(bot: Bot, chat_id: int, game_id: int, message_info: dict): found_game = get_game_by_id(game_id) current_message_id = int(message_info['message_id']) custom_keyboard = [[InlineKeyboardButton(text="BACK", callback_data='b_')]] if found_game is None: text = "<b>There is no game with such index</b>" else: text = str(found_game) send_message_with_save(bot, int(current_message_id), int(chat_id), text, custom_keyboard, True)
def team_in_season(bot: Bot, chat_id: int, team_id: int, season_id: int, message_info: dict): found_team = get_season_team(team_id, season_id) current_message_id = int(message_info['message_id']) custom_keyboard = [[InlineKeyboardButton(text="BACK", callback_data='b_')]] if found_team is None: text = "<b>There are problems with team and/or season indexes</b>" else: text = found_team.fake_str() send_message_with_save(bot, int(current_message_id), int(chat_id), text, custom_keyboard, True)
def go_to_origin(bot: Bot, update: Update): chat_id = update.message.chat.id message = get_last_message(chat_id) custom_keyboard = inline_keyboard_from_buttons_lists( message.buttons_names, message.buttons_callbacks) message_parts = str(message.text).split('\n') if len(message_parts) >= 2: if message_parts[2] == 'Go to team\'s page: /origin': team_name = str(message.text).split('</b>')[0][3:] team(bot, chat_id, get_team_by_name(team_name).team_id, message.__dict__) if message_parts[2] == 'Go to season\'s page: /origin': season_name = message_parts[0].split('\n')[0][3:-4] season(bot, chat_id, get_season_by_name(season_name).season_id, message.__dict__) else: send_message_with_save( bot, message.message_id, chat_id, '<b>There is no links to entities\' origin in previous message</b>', custom_keyboard, False, False)
def team_in_season_page(bot: Bot, chat_id: int, season_id: int, page_num: int, mode: AnswerMode, message_info: dict = None): request_is_correct = True teams_list: List[TeamsPage] = get_teams_in_seasons_page( season_id, page_num, 5) custom_navigation_keyboard = [] if len(teams_list) == 0: request_is_correct = False else: total = teams_list[0].total custom_navigation_keyboard = five_buttons_pagination_menu( total, page_num, 'tmsn_pg#' + str(season_id), chat_id) if request_is_correct: custom_keyboard = [[ InlineKeyboardButton( text=tm.team_name + " (" + tm.abbreviation + ")", callback_data='tmsn_#' + str(tm.team_id) + "#" + str(season_id)) ] for tm in teams_list] custom_keyboard.append(custom_navigation_keyboard) custom_keyboard.append( [InlineKeyboardButton(text="BACK", callback_data='b_')]) if mode == AnswerMode.SEND_NEW: send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, False) elif mode == AnswerMode.EDIT: print(message_info) send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, True) else: bot.send_message(chat_id=chat_id, text="<b>There is no page with this number</b>", parse_mode='HTML')
def games_with_player_page(bot: Bot, chat_id: int, player_id: int, page_num: int, mode: AnswerMode, message_info: dict = None): request_is_correct = True games_list: List[GamePage] = get_games_with_player_page( player_id, page_num, 5) custom_navigation_keyboard = [] if len(games_list) == 0: request_is_correct = False else: total = games_list[0].total custom_navigation_keyboard = five_buttons_pagination_menu( total, page_num, 'gmpl_pg#' + str(player_id), chat_id) if request_is_correct: custom_keyboard = [[ InlineKeyboardButton(text=gm.home_abbreviation + " vs " + gm.away_abbreviation + " on " + gm.game_date, callback_data='gm_#' + str(gm.game_id)) ] for gm in games_list] custom_keyboard.append(custom_navigation_keyboard) custom_keyboard.append( [InlineKeyboardButton(text="BACK", callback_data='b_')]) if mode == AnswerMode.SEND_NEW: send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, False) elif mode == AnswerMode.EDIT: print(message_info) send_message_with_save(bot, message_info['message_id'], chat_id, invisible_character(), custom_keyboard, True) else: bot.send_message(chat_id=chat_id, text="<b>There is no page with this number</b>", parse_mode='HTML')
def popup_statistics(bot: Bot, update: Update): chat_id = update.message.chat.id # users_message_id = update.message.message_id # bot.delete_message(chat_id, users_message_id) message = get_last_message(chat_id) custom_keyboard = inline_keyboard_from_buttons_lists( message.buttons_names, message.buttons_callbacks) new_text = "" message_parts = str(message.text).split('---') if len(message_parts) > 1: # part for seasons if message_parts[1].find('Show season statistics') != -1: season_name = message_parts[0].split('\n')[0][3:-4] season = get_season_by_name(season_name) new_text = message_parts[ 0] + '---\nRemove season statistics: /stat\n' + str( season.statistics) elif message_parts[1].find('Remove season statistics') != -1: new_text = message_parts[0] + '---\nShow season statistics: /stat\n' elif message_parts[1].find('Show team statistics') != -1: team_name = message_parts[0].split('</b>')[0][3:] team = get_team_by_name(team_name) new_text = message_parts[ 0] + '---\nRemove team statistics: /stat\n' + str( team.statistics) elif message_parts[1].find('Remove team statistics') != -1: new_text = message_parts[0] + '---\nShow team statistics: /stat\n' elif message_parts[1].find('Show game statistics') != -1: home_team = message_parts[0].split('\n')[0].split( '</b> vs <b>')[0].split('<b>')[1] away_team = message_parts[0].split('\n')[0].split( '</b> vs <b>')[1].split('</b>')[0] date = message_parts[0].split('\n')[2].split('</i>')[0].split( '<i>')[1] season_name = message_parts[0].split('\n')[2].split('<i>')[2][:-4] game = get_game_by_team_names_and_season_date( home_team, away_team, date, season_name) new_text = message_parts[ 0] + '---\nRemove game statistics: /stat\n' + str( game.statistics) elif message_parts[1].find('Remove game statistics') != -1: new_text = message_parts[0] + '---\nShow game statistics: /stat\n' elif message_parts[1].find('Show player\'s statistics: /stat') != -1: player_name = message_parts[0].split('\n')[0].split( '</b>')[0].split('<b>')[1] team_name = message_parts[0].split('\n')[2].split('</b>')[0].split( '<b>')[1].split(' (')[0] team = get_team_by_name(team_name) player = get_player_by_name_and_team_id(player_name, team.team_id) new_text = message_parts[ 0] + '---\nRemove player\'s statistics: /stat\n' + str( player.statistics) elif message_parts[1].find('Remove player\'s statistics: /stat') != -1: new_text = message_parts[ 0] + '---\nShow player\'s statistics: /stat\n' send_message_with_save(bot, message.message_id, chat_id, new_text, custom_keyboard, True, False) else: send_message_with_save( bot, message.message_id, chat_id, '<b>There is no statistics in previous message</b>', custom_keyboard, False, False)