import logging import re from telegram import Update, ForceReply, Bot from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext, ConversationHandler, Handler # Enable logging logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO ) logger = logging.getLogger(__name__) regexpattern = re.compile("(http(s)?:\/\/)?(www.)?(m.)?youtube.*.\/watch\?(v=)?") regexpattern2 = re.compile("(http(s)?:\/\/)?(www.)?(m.)?youtu\.be\/(watch\?v=)?") def echo(update: Update, context: CallbackContext) -> None: # print("#############################################") # print(str(update)) # print(str(CallbackContext)) # print("#############################################") #update.message.reply_text("Found youtube",quote=False) #if(("https://" in update.message.text) or ("http://" in update.message.text)): # if(("youtu.be" in update.message.text) or ("youtube.com" in update.message.text)): # if("watch?v=" in update.message.text): # update.message.delete(); if((regexpattern.match(update.message.text)!=None)or(regexpattern2.match(update.message.text)!=None)): update.message.delete() def updated_message_handler(update: Update, context: CallbackContext) -> None: # print("#############################################") # print(str(update)) # print(str(CallbackContext)) # print("#############################################") #update.message.reply_text("Found youtube",quote=False) #if(("https://" in update.edited_message.text) or ("http://" in update.edited_message.text)): # if(("youtu.be" in update.edited_message.text) or ("youtube." in update.edited_message.text)): # if("watch?v=" in update.edited_message.text): # update.edited_message.delete(); if((regexpattern.match(update.edited_message.text)!=None)or(regexpattern2.match(update.edited_message.text)!=None)): update.edited_message.delete() def ignore_errors(update: Update, context: CallbackContext) -> None: pass #(http(s)?:\/\/)?(www.)?youtube.*.\/watch\?v= #(http(s)?:\/\/)?(www.)?youtu\.be\/watch\?v= def main() -> None: updater = Updater("Bot-Key-lol-Allahu-akbaru") dispatcher = updater.dispatcher dispatcher.add_handler(MessageHandler(Filters.update.message, echo)) dispatcher.add_handler(MessageHandler(Filters.update.edited_message, updated_message_handler)) dispatcher.add_error_handler(ignore_errors) # Start the Bot updater.start_polling() updater.idle() if __name__ == '__main__': main()