diff --git a/bot.py b/bot.py index 94d76c2..f219600 100644 --- a/bot.py +++ b/bot.py @@ -6,7 +6,7 @@ import requests as r import youtube_dl from requests_toolbelt.downloadutils import stream - +import telegram from telegram import Update from telegram.ext import ( CallbackContext, @@ -19,6 +19,12 @@ from telegram.ext import ( URL_REGEX = r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)" +def start(update: Update, context: CallbackContext): + update.message.reply( + "This bot downloads the video from any link sent to it. @MisterBiggs for more help." + ) + + def url_search(update: Update, context: CallbackContext) -> None: msg = update.message.text.strip() print(msg) @@ -26,6 +32,9 @@ def url_search(update: Update, context: CallbackContext) -> None: ydl_opts = {} with youtube_dl.YoutubeDL(ydl_opts) as ydl: vid = ydl.extract_info(msg) + context.bot.send_chat_action( + chat_id=update.message.chat_id, action=telegram.ChatAction.UPLOAD_VIDEO + ) print(vid.keys()) b = io.BytesIO() resp = r.get(vid["url"], stream=True) @@ -39,6 +48,8 @@ def url_search(update: Update, context: CallbackContext) -> None: updater = Updater(os.environ["TELEGRAM"]) +updater.dispatcher.add_handler(CommandHandler("start", start)) +updater.dispatcher.add_handler(CommandHandler("help", start)) updater.dispatcher.add_handler(CommandHandler("dl", url_search)) updater.dispatcher.add_handler(MessageHandler(Filters.text, url_search))