Bläddra i källkod

Added bot file that get refence and remove URL messages

Okynos 6 år sedan
förälder
incheckning
80620f1eac
1 ändrade filer med 41 tillägg och 0 borttagningar
  1. 41 0
      bot.py

+ 41 - 0
bot.py

@@ -0,0 +1,41 @@
+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)