From e8be45de7e945e640216d4c1f230054937c475e8 Mon Sep 17 00:00:00 2001 From: X-Gorn Date: Mon, 10 Jun 2024 10:39:55 +0900 Subject: [PATCH] fix: thumbnail blocked --- .gitignore | 4 +++- Bot/config.py | 2 +- Bot/functions/dl_button.py | 2 +- Bot/functions/youtube_dl_button.py | 3 ++- Bot/plugins/echo.py | 2 +- Bot/plugins/settings.py | 10 ++++++++++ 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d03529d..87041fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ __pycache__ .venv .env -*.session \ No newline at end of file +*.session +*.session-journal +DOWNLOADS \ No newline at end of file diff --git a/Bot/config.py b/Bot/config.py index 0fb2bb3..3e9434a 100644 --- a/Bot/config.py +++ b/Bot/config.py @@ -17,7 +17,7 @@ class Config(object): BotCommand('broadcast', 'broadcast message') ] - DUMP_ID = int(os.environ.get("DUMP_ID")) + DUMP_ID = int(os.environ.get("DUMP_ID", 0)) BOT_TOKEN = os.environ.get("BOT_TOKEN", "") diff --git a/Bot/functions/dl_button.py b/Bot/functions/dl_button.py index 79359a8..8131805 100644 --- a/Bot/functions/dl_button.py +++ b/Bot/functions/dl_button.py @@ -129,7 +129,7 @@ async def ddl_call_back(bot: Client, update: CallbackQuery): if client.guess_mime_type(download_directory) in ffmpeg_supported_video_mimetypes: await run_cmd('ffmpeg -ss {} -i "{}" -vframes 1 "{}"'.format(random.randint(0, duration), download_directory, thumb_image_path)) # get the correct width, height, and duration for videos greater than 10MB - if os.path.exists(thumb_image_path) and not client.custom_thumbnail.get(update.from_user.id): + if os.path.exists(thumb_image_path): width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) diff --git a/Bot/functions/youtube_dl_button.py b/Bot/functions/youtube_dl_button.py index 3aae0c3..915587a 100644 --- a/Bot/functions/youtube_dl_button.py +++ b/Bot/functions/youtube_dl_button.py @@ -208,7 +208,7 @@ async def youtube_dl_call_back(bot: Client, update: CallbackQuery): if client.guess_mime_type(download_directory) in ffmpeg_supported_video_mimetypes: await run_cmd('ffmpeg -ss {} -i "{}" -vframes 1 "{}"'.format(random.randint(0, duration), download_directory, thumb_image_path)) # get the correct width, height, and duration for videos greater than 10MB - if os.path.exists(thumb_image_path) and not client.custom_thumbnail.get(update.from_user.id): + if os.path.exists(thumb_image_path): width = 0 height = 0 metadata = extractMetadata(createParser(thumb_image_path)) @@ -236,6 +236,7 @@ async def youtube_dl_call_back(bot: Client, update: CallbackQuery): thumb_image_path = None start_time = time.time() # try to upload file + client.logger.info(thumb_image_path) if tg_send_type == "audio": media = await bot.send_audio( chat_id=update.message.chat.id, diff --git a/Bot/plugins/echo.py b/Bot/plugins/echo.py index 937ceb1..b505f7f 100644 --- a/Bot/plugins/echo.py +++ b/Bot/plugins/echo.py @@ -244,7 +244,7 @@ async def echo_http(bot: Client, update: Message): if response_json["thumbnail"] is not None: thumbnail = response_json["thumbnail"] thumbnail_image = response_json["thumbnail"] - if not client.custom_thumbnail.get(update.from_user.id): + if thumbnail_image and not client.custom_thumbnail.get(update.from_user.id): thumb_image_path = client.config.DOWNLOAD_LOCATION + \ "/" + str(update.from_user.id) + ".webp" await download_coroutine( diff --git a/Bot/plugins/settings.py b/Bot/plugins/settings.py index 1b849d0..0b747c0 100644 --- a/Bot/plugins/settings.py +++ b/Bot/plugins/settings.py @@ -1,3 +1,4 @@ +import os from .. import client from pyrogram import Client, filters from pyrogram.types import Message @@ -55,6 +56,8 @@ async def custom_thumbnail(bot: Client, update: Message): return await update.reply( text='Reply to a photo or `/thumbnail https.....jpg`' ) + if os.path.isfile(client.custom_thumbnail[update.from_user.id]): + os.remove(client.custom_thumbnail[update.from_user.id]) thumbnail = None await update.reply(text='Custom thumbnail cleared.') client.custom_thumbnail[update.from_user.id] = thumbnail @@ -62,5 +65,12 @@ async def custom_thumbnail(bot: Client, update: Message): @Client.on_message(filters.private & filters.command('thumbnail') & filters.reply & filters.create(reply_to_photo_filter) & Filter.auth_users) async def custom_thumbnail_reply(bot: Client, update: Message): + if client.database: + user = await client.database.xurluploader.users.find_one({'id': update.from_user.id}) + if not user: + user = await client.database.xurluploader.users.insert_one({'id': update.from_user.id, 'banned': False}) + else: + if user.get('banned'): + return await update.reply('You are banned.') client.custom_thumbnail[update.from_user.id] = await update.reply_to_message.download(file_name=f'{client.config.DOWNLOAD_LOCATION}/{update.from_user.id}.jpg') await update.reply(text='Custom thumbnail updated.')