Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge branch 'The-MoonTg-project:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiTheModder authored Apr 20, 2024
2 parents a527c74 + 2de0e32 commit 5f5eea3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
9 changes: 6 additions & 3 deletions modules/removebg.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ async def rmbg(client: Client, message: Message):
allow_redirects=True,
stream=True,
)
os.remove(cool)
if os.path.exists(cool):
os.remove(cool)
output_file_name = r
contentType = output_file_name.headers.get("content-type")
if "image" in contentType:
Expand All @@ -126,7 +127,8 @@ async def rmbg(client: Client, message: Message):
await pablo.edit(
"<code>Removed image's Background in {} seconds, powered by </code> <b>@moonuserbot</b>".format(ms)
)
os.remove("BG_rem.png")
if os.path.exists("BG_rem.png"):
os.remove("BG_rem.png")
else:
await pablo.edit(
"ReMove.BG API returned Errors. Please report to @moonub_chat\n`{}".format(
Expand Down Expand Up @@ -159,7 +161,8 @@ async def rembg(client: Client, message: Message):
except Exception as e:
await message.reply_text(f"An error occurred: {format_exc(e)}")
finally:
os.remove(photo_data)
if os.path.exists(photo_data):
os.remove(photo_data)


modules_help["removebg"] = {
Expand Down
9 changes: 6 additions & 3 deletions modules/stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ async def kang(client: Client, message: types.Message):
return

resized = resize_image(path)
os.remove(path)
if os.path.exists(path):
os.remove(path)

await interact_with(await client.send_document("@stickers", resized, parse_mode=enums.ParseMode.MARKDOWN))
response = await interact_with(await client.send_message("@stickers", emoji, parse_mode=enums.ParseMode.MARKDOWN))
Expand All @@ -99,7 +100,8 @@ async def stick2png(client: Client, message: types.Message):
path = await message.reply_to_message.download()
with open(path, "rb") as f:
content = f.read()
os.remove(path)
if os.path.exists(path):
os.remove(path)

file_io = BytesIO(content)
file_io.name = "sticker.png"
Expand All @@ -120,7 +122,8 @@ async def resize_cmd(client: Client, message: types.Message):
path = await message.reply_to_message.download()
resized = resize_image(path)
resized.name = "image.png"
os.remove(path)
if os.path.exists(path):
os.remove(path)

await client.send_document(message.chat.id, resized, parse_mode=enums.ParseMode.MARKDOWN)
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion modules/upl.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ async def uplr(client: Client, message: Message):
except Exception as e:
await message.edit(format_exc(e), parse_mode=enums.ParseMode.HTML)
finally:
os.remove(link)
if os.path.exists(link):
os.remove(link)

modules_help["uplud"] = {
"upl": f"[filepath]/[reply to path]*",
Expand Down
55 changes: 37 additions & 18 deletions modules/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import requests
import time
import traceback
import urllib3
from pyrogram import Client, filters, enums
from pyrogram.types import Message
import requests
from utils.misc import modules_help, prefix
from utils.scripts import format_exc
from utils.scripts import format_exc, progress, edit_or_reply

from io import BytesIO
import requests

from utils.config import apiflash_key

Expand Down Expand Up @@ -53,8 +54,6 @@ async def short(_, message: Message):

await message.edit(r.data.decode().replace("https://", "<b>Shortened Url:</b>"), disable_web_page_preview=True, parse_mode=enums.ParseMode.HTML)



@Client.on_message(filters.command("urldl", prefix) & filters.me)
async def urldl(client: Client, message: Message):
if len(message.command) > 1:
Expand All @@ -72,21 +71,33 @@ async def urldl(client: Client, message: Message):
file_name = "downloads/" + link.split("/")[-1]

try:
resp = requests.get(link)
resp = requests.get(link, stream=True)
resp.raise_for_status()

# Get the total file size
total_size = int(resp.headers.get('content-length', 0))

with open(file_name, "wb") as f:
downloaded = 0
chunk_count = 0
update_frequency = 800
for chunk in resp.iter_content(chunk_size=8192):
f.write(chunk)

await message.edit("<b>Uploading...</b>", parse_mode=enums.ParseMode.HTML)
await client.send_document(message.chat.id, file_name, parse_mode=enums.ParseMode.HTML)
downloaded += len(chunk)
chunk_count += 1
progress_dl = (downloaded / total_size) * 100
if chunk_count % update_frequency == 0:
await message.edit_text(f"<b>Downloading...</b>\nProgress: {progress_dl:.2f}%")

ms_ = await message.edit("<b>Uploading...</b>", parse_mode=enums.ParseMode.HTML)
c_time = time.time()
await client.send_document(message.chat.id, file_name, progress=progress, progress_args=(ms_, c_time, '`Uploading...`'), parse_mode=enums.ParseMode.MARKDOWN)
await message.delete()
except Exception as e:
await message.edit(format_exc(e), parse_mode=enums.ParseMode.HTML)
await message.edit(f"<b>Error:</b> {traceback.format_exc(e)}", parse_mode=enums.ParseMode.HTML)
finally:
os.remove(file_name)

if os.path.exists(file_name):
os.remove(file_name)

@Client.on_message(filters.command("upload", prefix) & filters.me)
async def upload_cmd(_, message: Message):
Expand All @@ -96,20 +107,28 @@ async def upload_cmd(_, message: Message):
min_file_age = 31
max_file_age = 180

await message.edit("<b>Downloading...</b>", parse_mode=enums.ParseMode.HTML)
ms_ = await message.edit("`Downloading...`", parse_mode=enums.ParseMode.MARKDOWN)
c_time = time.time()

try:
file_name = await message.download()
file_name = await message.download(
progress=progress,
progress_args=(ms_, c_time, '`Downloading...`')
)
except ValueError:
try:
file_name = await message.reply_to_message.download()
file_name = await message.reply_to_message.download(
progress=progress,
progress_args=(ms_, c_time, '`Downloading...`')
)
except ValueError:
await message.edit("<b>File to upload not found</b>", parse_mode=enums.ParseMode.HTML)
return

if os.path.getsize(file_name) > max_size:
await message.edit(f"<b>Files longer than {max_size_mb}MB isn't supported</b>", parse_mode=enums.ParseMode.HTML)
os.remove(file_name)
if os.path.exists(file_name):
os.remove(file_name)
return

await message.edit("<b>Uploading...</b>", parse_mode=enums.ParseMode.HTML)
Expand All @@ -135,8 +154,8 @@ async def upload_cmd(_, message: Message):
else:
await message.edit(f"<b>API returned an error!\n" f"{response.text}\n Not allowed</b>", parse_mode=enums.ParseMode.HTML)
print(response.text)

os.remove(file_name)
if os.path.exists(file_name):
os.remove(file_name)



Expand Down
8 changes: 5 additions & 3 deletions modules/vt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pyrogram.types import Message

from utils.misc import modules_help, prefix
from utils.scripts import edit_or_reply, format_exc, time_formatter, humanbytes, edit_or_send_as_file, get_text, progress
from utils.scripts import edit_or_reply, format_exc, progress
from utils.config import vt_key as vak


Expand Down Expand Up @@ -48,7 +48,8 @@ async def scan_my_file(client, message):
except Exception as e:
return await ms_.edit(format_exc(e))
await ms_.edit(f"<b><u>Scanned {message.reply_to_message.document.file_name}</b></u>. <b>You Can Visit :</b> <a href=\"https://www.virustotal.com/gui/file/{md5}\">Here</a> <b>In 5-10 Min To See File Report</b>")
os.remove(downloaded_file_name)
if os.path.exists(downloaded_file_name):
os.remove(downloaded_file_name)

@Client.on_message(filters.command("vtl", prefix) & filters.me)
async def scan_my_large_file(client, message):
Expand Down Expand Up @@ -119,7 +120,8 @@ async def scan_my_large_file(client, message):
except Exception as e:
return await ms_.edit(format_exc(e))
await ms_.edit(f"<b><u>Scanned {message.reply_to_message.document.file_name}</b></u>. <b>You Can Visit :</b> <a href=\"https://www.virustotal.com/gui/file/{md5}\">Here</a> <b>In 5-10 Min To See File Report</b>")
os.remove(downloaded_file_name)
if os.path.exists(downloaded_file_name):
os.remove(downloaded_file_name)

modules_help["virustotal"] = {
"vt [reply to file]*": "Scan for viruses on Virus Total (for lower file size <32MB)",
Expand Down

0 comments on commit 5f5eea3

Please sign in to comment.