Как заставить бота выдать заранее сгенерированную комбинацию символов?
Пользователь заходит в меню бота, выбирает язык, категорию и переходит по ссылке, которая "зашита" в Inline-кнопке (пример кода - ниже):
import telebot
from telebot import types
import config
bot=telebot.TeleBot(config.token)
@bot.message_handler(commands=['start'])
def start(message):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1=types.KeyboardButton("EN")
item2=types.KeyboardButton("RU")
item3=types.KeyboardButton("DE")
item4=types.KeyboardButton("UA")
markup.add(item1,item2,item3,item4)
text="Welcome to the TC-Market"
bot.send_message(message.chat.id,text.format(message.from_user),reply_markup=markup)
@bot.message_handler(content_types=['text'])
def EN(message):
if (message.text=="EN"):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1_1=types.KeyboardButton("Choose Categories")
item1_2=types.KeyboardButton("FAQ")
item1_3=types.KeyboardButton("About")
item1_4=types.KeyboardButton("Payment Instructions")
item1_5=types.KeyboardButton("Back")
markup.add(item1_1,item1_2,item1_3,item1_4,item1_5)
text="EN"
bot.send_message(message.chat.id,text,reply_markup=markup)
elif(message.text=="Choose Categories"):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1_1_1=types.KeyboardButton("Science")
item1_1_2=types.KeyboardButton("Arts")
item1_1_3=types.KeyboardButton("Technology")
item1_1_4=types.KeyboardButton("Personalities")
item1_1_5=types.KeyboardButton("History")
item1_1_6=types.KeyboardButton("Back")
markup.add(item1_1_1,item1_1_2,item1_1_3,item1_1_4,item1_1_5,item1_1_6)
text="Please choose category"
bot.send_message(message.chat.id,text,reply_markup=markup)
elif (message.text=="Science") or (message.text=="Arts") or (message.text=="Technology") or (message.text=="Personalities") or (message.text=="History"):
Categories(message)
elif(message.text=="FAQ"):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True,one_time_keyboard=True)
item1_2_1=types.KeyboardButton("Back")
markup.add(item1_2_1)
fe=open("Texts\FAQ.txt","r")
text=fe.read()
bot.send_message(message.chat.id,text[:1696],parse_mode="MarkdownV2",reply_markup=markup)
elif(message.text=="About"):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True,one_time_keyboard=True)
item1_3_1=types.KeyboardButton("Back")
markup.add(item1_3_1)
se=open("Texts\About.txt","r")
text=se.read()
bot.send_message(message.chat.id,text[:1227],parse_mode="MarkdownV2",reply_markup=markup)
elif(message.text=="Payment Instructions"):
markup=types.InlineKeyboardMarkup()
item1_4_1=types.InlineKeyboardButton("Binance(Deposit)",'https://www.binance.com/en/support/faq/85a1c394ac1d489fb0bfac0ef2fceafd')
item1_4_2=types.InlineKeyboardButton("Binance(Transaction)",'https://www.binance.com/en/support/faq/115003670492')
item1_4_3=types.InlineKeyboardButton("BlockChain(Deposit)",'https://support.blockchain.com/hc/en-us/sections/4416668301716-Send-and-Receive-Crypto')
item1_4_4=types.InlineKeyboardButton("BlockChain(Transaction)",'https://support.blockchain.com/hc/en-us/sections/4517566823060-Deposits-and-Withdrawals')
item1_4_5=types.InlineKeyboardButton("TrustWallet(Deposit)",'https://community.trustwallet.com/t/how-to-buy-crypto-with-trust-wallet/507')
item1_4_6=types.InlineKeyboardButton("TrustWallet(Transfer)",'https://community.trustwallet.com/t/sending-cryptocurrencies/65')
markup.add(item1_4_1,item1_4_2,item1_4_3,item1_4_4,item1_4_5,item1_4_6)
text="Choose your Wallet"
bot.send_message(message.chat.id,text,reply_markup=markup)
elif(message.text=="Back"):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1_1=types.KeyboardButton("Choose Categories")
item1_2=types.KeyboardButton("FAQ")
item1_3=types.KeyboardButton("About")
item1_4=types.KeyboardButton("Payment Instructions")
item1_5=types.KeyboardButton("Back")
text="You returned to the menu"
bot.send_message(message.chat.id,text,reply_markup=markup)
else:
RU(message)
..........................................................................................................
def Categories(message):
if(message.text=="Science"):
markup=types.InlineKeyboardMarkup()
item1=types.InlineKeyboardButton("1","vk.com")
item2=types.InlineKeyboardButton("2","yandex.ru")
item3=types.InlineKeyboardButton("3","binance.com")
item4=types.InlineKeyboardButton("4","google.com")
item5=types.InlineKeyboardButton("5","blockkchain.com")
markup.add(item1,item2,item3,item4,item5)
bot.send_message(message.chat.id,text="Welcome",reply_markup=markup)
b=open("Files\Photos\Block.jpg",'rb')
bot.send_photo(message.chat.id,b,caption="[Blockchain](blockchain.info)",parse_mode="MarkdownV2")
c=open("Files\Photos\Opera.jpg",'rb')
bot.send_photo(message.chat.id,c,caption="Opera")
elif(message.text=="Arts"):
markup=types.InlineKeyboardMarkup()
item1=types.InlineKeyboardButton("1",)
item2=types.InlineKeyboardButton("2",)
item3=types.InlineKeyboardButton("3",)
item4=types.InlineKeyboardButton("4",)
item5=types.InlineKeyboardButton("5",)
markup.add(item1,item2,item3,item4,item5)
bot.send_message(message.chat.id,"Welcome",reply_markup=markup)
b=open("Files\Photos\Block.jpg",'rb')
bot.send_photo(message.chat.id,b,reply_markup=markup,caption="[Blockchain](blockchain.info)",parse_mode="MarkdownV2")
elif(message.text=="Technology"):
markup=types.InlineKeyboardMarkup()
item1=types.InlineKeyboardButton("1",)
item2=types.InlineKeyboardButton("2",)
item3=types.InlineKeyboardButton("3",)
item4=types.InlineKeyboardButton("4",)
item5=types.InlineKeyboardButton("5",)
markup.add(item1,item2,item3,item4,item5)
bot.send_message(message.chat.id,"Welcome",reply_markup=markup)
elif(message.text=="Personalities"):
markup=types.InlineKeyboardMarkup()
item1=types.InlineKeyboardButton("1",)
item2=types.InlineKeyboardButton("2",)
item3=types.InlineKeyboardButton("3",)
item4=types.InlineKeyboardButton("4",)
item5=types.InlineKeyboardButton("5",)
markup.add(item1,item2,item3,item4,item5)
bot.send_message(message.chat.id,"Welcome",reply_markup=markup)
x=open("BOT\Files\Photos",'rb')
bot.send_photo(message.chat.id,x)
elif(message.text=="History"):
markup=types.InlineKeyboardMarkup()
item1=types.InlineKeyboardButton("1",)
item2=types.InlineKeyboardButton("2",)
item3=types.InlineKeyboardButton("3",)
item4=types.InlineKeyboardButton("4",)
item5=types.InlineKeyboardButton("5",)
markup.add(item1,item2,item3,item4,item5)
bot.send_message(message.chat.id,"Welcome",reply_markup=markup)
elif(message.text=="Back"):
markup=types.ReplyKeyboardMarkup(resize_keyboard=True)
item1_1=types.KeyboardButton("Choose Categories")
item1_2=types.KeyboardButton("FAQ")
item1_3=types.KeyboardButton("About")
item1_4=types.KeyboardButton("Payment Instructions")
item1_5=types.KeyboardButton("Back")
markup.add(item1_1,item1_2,item1_3,item1_4,item1_5)
text="You returned to the menu"
bot.send_message(message.chat.id,text,reply_markup=markup)
@bot.message_handler(content_types=['photo'])
def receive_photos_from_user(message):
try:
file_info=bot.get_file(message.photo[len(message.photo)-1].file_id)
downloaded_file=bot.download_file(file_info.file_path)
src='Photos'+file_info.file_path.replace('photos/','')
with open(src,'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message,"Thanks for the screenshot")
except Exception as e:
bot.reply_to(message,e)
Вопрос состоит из следующих пунктов:
- Как увидеть, был ли переход по какой-либо из ссылок?
- Как сделать так, чтобы получения изображения бот присылал заранее сгенерированный для файла набор символов (пароль от файла)?