import telebot
import os
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import Updater, Filters, MessageHandler, CallbackContext
from pyzbar.pyzbar import decode
from os import listdir
from os.path import isfile, join
from io import BytesIO
from PIL import Image
#Код для пересылки по значениям
bot = telebot.TeleBot('********')
my_id = int('-*********') #chat AS
chat_id = int('-************') #chat BS
@bot.message_handler(commands=['start'])
def start(message):
print(message)
@bot.message_handler(regexp="AS", content_types=['text'])
def repeat_all_messages(message):
bot.forward_message(my_id, message.chat.id, message.id)
def decode_qr(update: Update, context: CallbackContext):
chat_id = update.message.chat_id
if update.message.photo:
id_img = update.message.photo[-1].file_id
else:
return
foto = context.bot.getFile(id_img)
new_file = context.bot.get_file(foto.file_id)
new_file.download('qrcode.png')
try:
result = decode(Image.open('qrcode.png'))
context.bot.sendMessage(chat_id=chat_id, text=result[0].data.decode("utf-8"))
os.remove("qrcode.png")
except Exception as e:
return
def main():
updater = Updater(TOKEN, request_kwargs={'read_timeout': 20, 'connect_timeout': 20}, use_context=True)
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.photo, decode_qr))
updater.start_polling()
updater.idle()
@bot.message_handler(regexp="BS", content_types=['text'])
def repeat_all_messages(message):
bot.forward_message(chat_id, message.chat.id, message.id)
bot.polling(none_stop=True)
Если не запустится, то def main перемести в BS