|
@@ -1,11 +1,12 @@
|
|
|
import telebot
|
|
import telebot
|
|
|
import re
|
|
import re
|
|
|
|
|
|
|
|
-TOKEN = 'YOUR_TOKEN'
|
|
|
|
|
|
|
+TOKEN = ''
|
|
|
bot = telebot.TeleBot(TOKEN)
|
|
bot = telebot.TeleBot(TOKEN)
|
|
|
receiveReference = False
|
|
receiveReference = False
|
|
|
reference = ''
|
|
reference = ''
|
|
|
-pattern = "((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*"
|
|
|
|
|
|
|
+pattern = "http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
|
|
|
|
|
+refPattern = "ref=.*\?"
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['start'])
|
|
@bot.message_handler(commands=['start'])
|
|
|
def send_welcome(message):
|
|
def send_welcome(message):
|
|
@@ -19,7 +20,7 @@ def send_help(message):
|
|
|
def send_question(message):
|
|
def send_question(message):
|
|
|
global receiveReference
|
|
global receiveReference
|
|
|
receiveReference = True
|
|
receiveReference = True
|
|
|
- bot.reply_to(message, "tell me, what's your reference code?.")
|
|
|
|
|
|
|
+ bot.reply_to(message, "Tell me, what's your reference code?.")
|
|
|
|
|
|
|
|
@bot.message_handler()
|
|
@bot.message_handler()
|
|
|
def process_response(message):
|
|
def process_response(message):
|
|
@@ -27,11 +28,25 @@ def process_response(message):
|
|
|
if(len(reference) > 0):
|
|
if(len(reference) > 0):
|
|
|
result = re.match(pattern, message.text)
|
|
result = re.match(pattern, message.text)
|
|
|
if(result):
|
|
if(result):
|
|
|
- bot.delete_message(chat_id=message.chat.id, message_id=message.message_id)
|
|
|
|
|
- if(receiveReference):
|
|
|
|
|
|
|
+ url = result.group()
|
|
|
|
|
+ print("[INFO] Found URL match on: %s" % url)
|
|
|
|
|
+ refResult = re.search(refPattern, url)
|
|
|
|
|
+ if(refResult):
|
|
|
|
|
+ ref = refResult.group()
|
|
|
|
|
+ print("[INFO] Found reference match on: %s" % ref)
|
|
|
|
|
+ newMessage = message.text.replace(ref, "ref=%s?" % reference)
|
|
|
|
|
+ bot.send_message(message.chat.id, newMessage)
|
|
|
|
|
+ bot.delete_message(chat_id=message.chat.id, message_id=message.message_id)
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("[INFO] No reference pattern matched")
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("[INFO] No URL pattern matched")
|
|
|
|
|
+ elif(receiveReference):
|
|
|
reference = message.text
|
|
reference = message.text
|
|
|
bot.reply_to(message, "OK, your reference is: %s, send me now any URL." % reference)
|
|
bot.reply_to(message, "OK, your reference is: %s, send me now any URL." % reference)
|
|
|
receiveReference = False
|
|
receiveReference = False
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("[INFO] Receive reference disabled, try /reference")
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
try:
|