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: 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: 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 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()