| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import telebot
- import re
- TOKEN = 'YOUR_TOKEN'
- bot = telebot.TeleBot(TOKEN)
- receiveReference = False
- reference = ''
- pattern = "((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*"
- @bot.message_handler(commands=['start'])
- def send_welcome(message):
- bot.reply_to(message, "Hello, I'm ready.")
- @bot.message_handler(commands=['help'])
- def send_help(message):
- bot.reply_to(message, "My commands are: /start, /help, /reference")
- @bot.message_handler(commands=['reference'])
- def send_question(message):
- global receiveReference
- receiveReference = True
- bot.reply_to(message, "tell me, what's your reference code?.")
- @bot.message_handler()
- def process_response(message):
- global receiveReference, reference
- if(len(reference) > 0):
- result = re.match(pattern, message.text)
- if(result):
- bot.delete_message(chat_id=message.chat.id, message_id=message.message_id)
- if(receiveReference):
- reference = message.text
- bot.reply_to(message, "OK, your reference is: %s, send me now any URL." % reference)
- receiveReference = False
- try:
- print('[INFO] Bot started...')
- bot.polling()
- except Exception as ex:
- print("Something goes wrong, exception: ", ex)
|