Files
Ultroid-fork/plugins/converter.py
1Danish-00 c88a4ca8af Re-Fixes v0.1.1
Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: New-Dev0 <newdev0@outlook.com>
2021-09-14 10:19:50 +05:30

193 lines
5.1 KiB
Python

# Ultroid - UserBot
# Copyright (C) 2021 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
• `{i}mtoi <reply to media>`
Media to image conversion
• `{i}mtos <reply to media>`
Convert media to sticker.
• `{i}doc <filename.ext>`
Reply to a text msg to save it in a file.
• `{i}open`
Reply to a file to reveal it's text.
• `{i}rename <file name with extension>`
Rename the file
• `{i}thumbnail <reply to image/thumbnail file>`
Upload Your file with your custom thumbnail.
"""
import os
import time
import cv2
from PIL import Image
from telegraph import upload_file as uf
from telethon.tl.types import MessageMediaPhoto as photu
from . import *
opn = []
@ultroid_cmd(
pattern="thumbnail$",
)
async def _(e):
r = await e.get_reply_message()
pop = "`Reply to img or file with thumbnail.`"
if not r:
return await eor(e, pop)
if isinstance(r.media, photu):
dl = await r.download_media()
elif r.document and r.document.thumbs:
dl = await r.download_media(thumb=-1)
else:
return await eor(e, pop)
variable = uf(dl)
os.remove(dl)
nn = "https://telegra.ph" + variable[0]
udB.set("CUSTOM_THUMBNAIL", str(nn))
await bash(f"wget {nn} -O resources/extras/ultroid.jpg")
await eor(e, f"Added [This]({nn}) As Your Custom Thumbnail", link_preview=False)
@ultroid_cmd(
pattern="rename ?(.*)",
)
async def imak(event):
reply = await event.get_reply_message()
t = time.time()
if not reply:
await eor(event, "Reply to any media/Document.")
return
inp = event.pattern_match.group(1)
if not inp:
await eor(event, "Give The name and extension of file")
return
xx = await eor(event, "`Processing...`")
if reply.media:
if hasattr(reply.media, "document"):
file = reply.media.document
image = await downloader(
reply.file.name if reply.file.name else str(time.time()),
reply.media.document,
xx,
t,
"Downloading...",
)
file = image.name
else:
file = await event.client.download_media(reply.media)
os.rename(file, inp)
k = time.time()
xxx = await uploader(inp, inp, k, xx, "Uploading...")
await event.reply(
f"`{xxx.name}`",
file=xxx,
force_document=True,
thumb="resources/extras/ultroid.jpg",
)
os.remove(inp)
await xx.delete()
@ultroid_cmd(
pattern="mtoi$",
)
async def imak(event):
reply = await event.get_reply_message()
if not (reply and (reply.media)):
await eor(event, "Reply to any media.")
return
xx = await eor(event, "`Processing...`")
image = await reply.download_media()
file = "ult.png"
if image.endswith((".webp", ".png")):
c = Image.open(image)
c.save(file)
else:
img = cv2.VideoCapture(image)
ult, roid = img.read()
cv2.imwrite(file, roid)
await event.reply(file=file)
await xx.delete()
os.remove(file)
os.remove(image)
@ultroid_cmd(
pattern="mtos$",
)
async def smak(event):
reply = await event.get_reply_message()
if not (reply and (reply.media)):
await eor(event, "Reply to any media.")
return
xx = await eor(event, "`Processing...`")
image = await reply.download_media()
file = "ult.webp"
if image.endswith((".webp", ".png", ".jpg")):
c = Image.open(image)
c.save(file)
else:
img = cv2.VideoCapture(image)
ult, roid = img.read()
cv2.imwrite(file, roid)
await event.reply(file=file)
await xx.delete()
os.remove(file)
os.remove(image)
@ultroid_cmd(
pattern="doc ?(.*)",
)
async def _(event):
input_str = event.pattern_match.group(1)
if not (input_str and event.is_reply):
return await eor(event, "`Give The File Name and reply to message.`", time=5)
xx = await eor(event, get_string("com_1"))
a = await event.get_reply_message()
if not a.message:
return await xx.edit("`Reply to a message`")
with open(input_str, "w") as b:
b.write(str(a.message))
await xx.edit(f"**Packing into** `{input_str}`")
await event.reply(file=input_str, thumb="resources/extras/ultroid.jpg")
await xx.delete()
os.remove(input_str)
@ultroid_cmd(
pattern="open$",
)
async def _(event):
a = await event.get_reply_message()
if not (a and a.media):
return await eor(event, "`Reply to a readable file`", time=5)
xx = await eor(event, get_string("com_1"))
b = await a.download_media()
try:
with open(b) as c:
d = c.read()
except UnicodeDecodeError:
return await eor(xx, "`Not A Readable File.`", time=5)
try:
await xx.edit(f"```{d}```")
except BaseException:
what, key = await get_paste(d)
await xx.edit(
f"**MESSAGE EXCEEDS TELEGRAM LIMITS**\n\nSo Pasted It On [SPACEBIN](https://spaceb.in/{key})"
)
os.remove(b)