Python
5
Вклад в тег
import telebot
from telebot import types
import threading
import time
bot = telebot.TeleBot("token")
clicked = False
timeout = 10 # Секунд
def run_in_thread(func):
def wrapper(*args, **kwargs):
thread = threading.Thread(target=func, args=args, kwargs=kwargs)
thread.start()
return wrapper
@run_in_thread
def asynchronous():
global clicked
while True:
if clicked:
time.sleep(timeout)
clicked = False
@bot.message_handler(commands=["start"])
def start(message):
markup = types.InlineKeyboardMarkup()
hello_button = types.InlineKeyboardButton(text="Показать процессоры", callback_data="cpu")
markup.add(hello_button)
bot.send_message(message.chat.id, "Здравствуйте, %s!" % (f"[{message.from_user.first_name}](tg://user?id={message.from_user.id})"), parse_mode="markdown", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
global clicked
if clicked:
bot.answer_callback_query(call.id, "Попробуйте снова через 10 секунд!", show_alert=True)
return
if call.data == "cpu":
clicked = True
bot.send_message(call.from_user.id, "Процессоры..")
if __name__ == "__main__":
asynchronous()
bot.polling(none_stop=True, interval=0)
import telebot
import config
bot = telebot.TeleBot(
token=config.token
)
@bot.message_handler(content_types=["photo"])
def get_photo(message):
bot.send_photo(message.from_user.id, message.photo[0].file_id, message.caption)
if __name__ == "__main__":
bot.infinity_polling()
message.from_user.id
и айди фото message.photo[0].file_id)
message.caption