Как сделать что бьі работали все три кнопки а не только bot.send_message(message.chat.id, useful_q)
вот так?
import telebot
import random
from telebot import types
from collections import deque
def get_first_element_in_the_queue(array: list) -> str:
first_element = array[0]
array.rotate(-1)
return first_element
f = open('/Users/marina/ukrwrite/ch.txt', 'r', encoding='UTF-8')
ch = f.read().split('\n')
f.close()
f = open('/Users/marina/ukrwrite/useful.txt', 'r', encoding='UTF-8')
useful = f.read().split('\n')
f.close()
f = open('/Users/marina/ukrwrite/ra.txt', 'r', encoding='UTF-8')
ra = f.read().split('\n')
f.close()
ch_q = deque(ch)
useful_q = deque(useful)
ra_q = deque(ra)
bot = telebot.TeleBot('611')
@bot.message_handler(commands=["start"])
def start(m, res=False):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1=types.KeyboardButton("челендж")
item2=types.KeyboardButton("корисне")
item3 = types.KeyboardButton("рекомендовані авторки")
markup.add(item1)
markup.add(item2)
markup.add(item3)
bot.send_message(m.chat.id, 'Привіт. ', reply_markup=markup)
handle_text(message=None, useful_q=useful_q)
@bot.message_handler(content_types=["text"])
def handle_text(message, useful_q):
if message.text.strip() == 'челендж':
ch_q == get_first_element_in_the_queue(ch_q)
bot.send_message(message.chat.id, ch_q)
elif message.text.strip() == 'корисне':
useful_q == get_first_element_in_the_queue(useful_q)
try:
useful_q == get_first_element_in_the_queue(useful_q)
bot.send_message(message.chat.id, useful_q)
except IndexError:
bot.send_message(message.chat.id, "Список закончился. Начинаю заново.")
useful_q = queue.Queue(maxsize=queue_size)
bot.send_message(message.chat.id, useful_q)
elif message.text.strip() == 'рекомендовані авторки':
ra_q == get_first_element_in_the_queue(ra_q)
bot.send_message(message.chat.id, ra_q)
bot.polling(none_stop=True, interval=0)
Источник: Stack Overflow на русском