@bot.message_handler(content_types=['text'])
def distribution(message):
if message.text == 'Оценивать':
vote(message)
print(vote(message)[1])
elif message.text == 'Назад':
main_menu = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
main_1 = types.KeyboardButton('Мой профиль')
main_2 = types.KeyboardButton('Оценивать')
main_menu.add(main_1, main_2)
bot.send_message(message.chat.id, 'Главное меню', reply_markup=main_menu)
elif message.text == '1' or '2' or '3' or '4' or '5':
print(vote(message)[1])
print(message.text)
conn = sqlite3.connect('vote.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE chat_id == ?", (f'{vote(message)[1]}',))
res = cursor.fetchone()
rating = res[5] + int(message.text)
total_votes = res[6] + 1
cursor.execute(f"UPDATE users SET rating == ?, total_votes == ? WHERE chat_id == ?", (f'{rating}', f'{total_votes}', f'{vote(message)[1]}'))
conn.commit()
conn.close()
else:
bot.send_message(message.chat.id, 'Я не знаю такой команды')
def vote(message):
conn = sqlite3.connect('vote.db')
cursor = conn.cursor()
cursor.execute(f"SELECT id FROM users")
result1 = cursor.fetchall()
queue = (random.choice(result1)[0])
cursor.execute("SELECT * FROM users WHERE id == ?", (f'{queue}',))
result = cursor.fetchone()
chat_id = result[1]
name = result[2]
avatar = result[4]
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=5)
btn1 = types.KeyboardButton('1')
btn2 = types.KeyboardButton('2')
btn3 = types.KeyboardButton('3')
btn4 = types.KeyboardButton('4')
btn5 = types.KeyboardButton('5')
btn6 = types.KeyboardButton('Назад')
btn7 = types.KeyboardButton('Жалоба')
btn8 = types.KeyboardButton('Сообщение')
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8)
return [bot.send_photo(message.chat.id, avatar, caption=f'{chat_id}', reply_markup=markup), chat_id]