@bot.message_handler(commands=['игроки'])
def info(message):
global info_message
conn = sqlite3.connect('football_players.db')
cursor = conn.cursor()
cursor.execute("SELECT surname FROM players")
player_list = cursor.fetchall()
if not player_list:
bot.reply_to(message, 'Список игроков пуст')
return
markup_inline = types.InlineKeyboardMarkup()
for player in player_list:
item = types.InlineKeyboardButton(text=player[0], callback_data=player[0])
markup_inline.add(item)
info_message = bot.send_message(message.chat.id, 'Выберите игрока', reply_markup=markup_inline)
@bot.callback_query_handler(func = lambda call: True) #(Поправить надо что-то здесь)
def info_answer(call):
global info_message
conn = sqlite3.connect('football_players.db')
cursor = conn.cursor()
surname = call.data
cursor.execute('SELECT * FROM players WHERE surname=?', (surname,))
player = cursor.fetchone()
bot.send_photo(call.message.chat.id, player[11])
bot.send_message(call.message.chat.id,f'Фамилия:{player[1]}\nИмя: {player[2]}\nНомер: {player[3]}\nПозиция: {player[4]}\nГолы: {player[5]}\nМатчи: {player[6]}\nГолевые пасы: {player[7]}\nГ+П: {player[8]}\nЖелтые карточки: {player[9]}\nКрасные карточки: {player[10]}')
bot.delete_message(call.message.chat.id, info_message.message_id)
bot.answer_callback_query(call.id)
@bot.message_handler(commands=['матчи'])
def test(message):
global match_message
conn = sqlite3.connect('football_players.db')
cursor = conn.cursor()
cursor.execute("SELECT name, place FROM matches")
match_list = cursor.fetchall()
if not match_list:
bot.reply_to(message, 'Список матчей пуст')
return
markup_inline = types.InlineKeyboardMarkup()
for match in match_list:
item = types.InlineKeyboardButton(text = f'{match[0]} {match[1]}', callback_data=f'{match}')
markup_inline.add(item)
match_message = bot.send_message(message.chat.id, 'Выберите матч', reply_markup=markup_inline)
@bot.callback_query_handler(func = lambda call:True) #(И тут)
def match_answer(call):
conn = sqlite3.connect('football_players.db')
cursor = conn.cursor()
temp = list(map(str, call.data[2:-2].split("', '")))
cursor.execute("SELECT * FROM matches WHERE name=? AND place=?", (temp[0], temp[1]))
match = cursor.fetchone()
bot.reply_to(call.message, f"Соперник: {match[1]}\nСчет: {match[2]}\nРезультат: {match[3]}\nМесто проведения: {match[4]}")
bot.delete_message(call.message.chat.id, match_message.message_id)
bot.answer_callback_query(call.id)