def gen_markup(): markup = InlineKeyboardMarkup() markup.row_width = 1 length, home_team, guest_team, id = mysql_matches.mysql_select_home_teams(get_date()), mysql_matches.mysql_get_teams('home_team', get_date()), \ mysql_matches.mysql_get_teams('guest_team', get_date()), mysql_matches.mysql_get_teams('match_id', get_date()) for i in range(length): markup.add( InlineKeyboardButton(home_team[i] + ' — ' + guest_team[i], callback_data='cb_match{}'.format(id[i]))) return markup
def gen_bet(i, home_team_bet, guest_team_bet, draw_team_bet): markup = InlineKeyboardMarkup() markup.row_width = 2 home_team, guest_team, id = mysql_matches.mysql_get_teams('home_team', get_date()), \ mysql_matches.mysql_get_teams('guest_team', get_date()), mysql_matches.mysql_get_teams('match_id', get_date()) markup.add( InlineKeyboardButton(home_team[i] + ' ({})'.format(home_team_bet), callback_data='cb_home_team_{}'.format(id[i])), InlineKeyboardButton(guest_team[i] + ' ({})'.format(guest_team_bet), callback_data='cb_guest_team_{}'.format(id[i])), InlineKeyboardButton('Ничья' + ' ({})'.format(draw_team_bet), callback_data='cb_draw_{}'.format(id[i]))) return markup
def handle_matches(message): if mysql_matches.mysql_select_home_teams(get_date()) == 0: bot.send_message(message.chat.id, "⚠️Упс, нет матчей") else: bot.send_message(message.chat.id, "⚽️Сегодняшние матчи:", reply_markup=gen_markup())
def next_step_bet(message): try: if message.text.isdigit() and int(message.text) <= mysql_clients.mysql_get_tokens(message.from_user.id)\ and int(message.text) > 0: if mysql_clients.mysql_user_tokens_minus_bet( message.from_user.id, message.text) == True: main_id = mysql_bets.mysql_get_main_id(message.from_user.id, get_date()) mysql_bets.mysql_update_bets(main_id[-1], message.text) bot.send_message(message.chat.id, "✅ Ставка успешно обработана!") else: bot.send_message( message.chat.id, "⛔️Упс, что-то пошло не так!. \n\nПопробуйте еще раз /matches") except: bot.send_message( message.chat.id, "⛔️Упс, что-то пошло не так!. \n\nПопробуйте еще раз /matches")
def handle_text(message): try: arguments = parsing.find_arguments(message.text, last_is_string=True) cost = parsing.get_cost(arguments[0]) date = parsing.get_date(arguments[1]) description = parsing.get_description(arguments[2]) database.add(message.chat.id, cost, date, description) bot.send_message(message.chat.id, quotes.ADD_OK) except exceptions.WrongNumberOfArgumentsException as exception: bot.send_message(message.chat.id, exception.value) except exceptions.InvalidArgumentFormatException as exception: bot.send_message(message.chat.id, exception.value) except OSError as exception: logging.critical(exception) bot.send_message(message.chat.id, quotes.BACKEND_ERROR) raise except Exception as exception: logging.error(exception) bot.send_message(message.chat.id, quotes.UNEXPECTED_ERROR) raise
def handle_text(message): try: arguments = parsing.find_arguments(message.text) date = parsing.get_date(arguments[0]) database.clear_before_date(message.chat.id, date) bot.send_message(message.chat.id, quotes.CLEAR_OK) except exceptions.WrongNumberOfArgumentsException as exception: bot.send_message(message.chat.id, exception.value) except exceptions.InvalidArgumentFormatException as exception: bot.send_message(message.chat.id, exception.value) logging.critical(exception) bot.send_message(message.chat.id, quotes.BACKEND_ERROR) raise except OSError as exception: logging.critical(exception) bot.send_message(message.chat.id, quotes.BACKEND_ERROR) raise except Exception as exception: logging.error(exception) bot.send_message(message.chat.id, quotes.UNEXPECTED_ERROR) raise
def callback_query(call): length, home_team, guest_team, id, tokens = mysql_matches.mysql_select_home_teams(get_date()),\ mysql_matches.mysql_get_teams('home_team', get_date()), \ mysql_matches.mysql_get_teams('guest_team', get_date()),\ mysql_matches.mysql_get_teams('match_id', get_date()),\ mysql_clients.mysql_get_tokens(call.from_user.id), msg = "💰 У вас {} tokens. \n\nСколько tokens вы хотите поставить?".format( tokens) for i in range(length): home_bet_tokens, guest_bet_tokens, draw_bet_tokens = mysql_bets.mysql_get_tokens(id[i], 1, get_date()),\ mysql_bets.mysql_get_tokens(id[i], 2, get_date()),\ mysql_bets.mysql_get_tokens(id[i], 3, get_date()) home_team_bet, guest_team_bet, draw_team_bet = home_coef(home_bet_tokens, guest_bet_tokens), \ guest_coef(home_bet_tokens, guest_bet_tokens), \ draw_coef(home_bet_tokens, guest_bet_tokens) if call.data == 'cb_match{}'.format( id[i]) and mysql_matches.mysql_get_status(id[i], get_date()) == 1: txt = '📊 Коэффициенты: \t\n{home_team} ({home_bet})\t\nНичья ({draw})\t\n{guest_team} ({guest_bet})\n'.format( home_team=home_team[i], home_bet=home_team_bet, draw=draw_team_bet, guest_team=guest_team[i], guest_bet=guest_team_bet) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=txt, reply_markup=gen_bet(i, home_team_bet, guest_team_bet, draw_team_bet)) if call.data == 'cb_home_team_{}'.format( id[i]) and mysql_matches.mysql_get_status(id[i], get_date()) == 1: msg_edit = bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.message_id, text=msg) mysql_bets.mysql_insert_bets(call.from_user.id, id[i], 1, home_team_bet, -1, 1, 1, get_date()) bot.register_next_step_handler(msg_edit, next_step_bet) if call.data == 'cb_guest_team_{}'.format( id[i]) and mysql_matches.mysql_get_status(id[i], get_date()) == 1: msg_edit = bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.message_id, text=msg) mysql_bets.mysql_insert_bets(call.from_user.id, id[i], 2, guest_team_bet, -1, 1, 1, get_date()) bot.register_next_step_handler(msg_edit, next_step_bet) if call.data == 'cb_draw_{}'.format( id[i]) and mysql_matches.mysql_get_status(id[i], get_date()) == 1: msg_edit = bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.message_id, text=msg) mysql_bets.mysql_insert_bets(call.from_user.id, id[i], 3, draw_team_bet, -1, 1, 1, get_date()) bot.register_next_step_handler(msg_edit, next_step_bet)