Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
converter.py197 linesDownload Raw Back to plugins
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7 8from . import get_help9 10__doc__ = get_help("help_converter")11 12import os13import time14 15from . import LOGS16 17try:18    import cv219except ImportError:20    cv2 = None21 22try:23    from PIL import Image24except ImportError:25    LOGS.info(f"{__file__}: PIL  not Installed.")26    Image = None27 28from . import upload_file as uf29 30from . import (31    ULTConfig,32    bash,33    con,34    downloader,35    get_paste,36    get_string,37    udB,38    ultroid_cmd,39    uploader,40)41 42opn = []43 44 45@ultroid_cmd(46    pattern="thumbnail$",47)48async def _(e):49    r = await e.get_reply_message()50    if r.photo:51        dl = await r.download_media()52    elif r.document and r.document.thumbs:53        dl = await r.download_media(thumb=-1)54    else:55        return await e.eor("`Reply to Photo or media with thumb...`")56    nn = uf(dl)57    os.remove(dl)58    udB.set_key("CUSTOM_THUMBNAIL", str(nn))59    await bash(f"wget {nn} -O resources/extras/ultroid.jpg")60    await e.eor(get_string("cvt_6").format(nn), link_preview=False)61 62 63@ultroid_cmd(64    pattern="rename( (.*)|$)",65)66async def imak(event):67    reply = await event.get_reply_message()68    t = time.time()69    if not reply:70        return await event.eor(get_string("cvt_1"))71    inp = event.pattern_match.group(1).strip()72    if not inp:73        return await event.eor(get_string("cvt_2"))74    xx = await event.eor(get_string("com_1"))75    if reply.media:76        if hasattr(reply.media, "document"):77            file = reply.media.document78            image = await downloader(79                reply.file.name or str(time.time()),80                reply.media.document,81                xx,82                t,83                get_string("com_5"),84            )85 86            file = image.name87        else:88            file = await event.client.download_media(reply.media)89    if os.path.exists(inp):90        os.remove(inp)91    await bash(f'mv """{file}""" """{inp}"""')92    if not os.path.exists(inp) or os.path.exists(inp) and not os.path.getsize(inp):93        os.rename(file, inp)94    k = time.time()95    n_file, _ = await event.client.fast_uploader(96        inp, show_progress=True, event=event, message="Uploading...", to_delete=True97    )98    await event.reply(99        f"`{n_file.name}`",100        file=n_file,101        force_document=True,102        thumb=ULTConfig.thumb,103    )104    os.remove(inp)105    await xx.delete()106 107 108conv_keys = {109    "img": "png",110    "sticker": "webp",111    "webp": "webp",112    "image": "png",113    "webm": "webm",114    "gif": "gif",115    "json": "json",116    "tgs": "tgs",117}118 119 120@ultroid_cmd(121    pattern="convert( (.*)|$)",122)123async def uconverter(event):124    xx = await event.eor(get_string("com_1"))125    a = await event.get_reply_message()126    if a is None:127        return await event.eor("`Reply to Photo or media with thumb...`")128    input_ = event.pattern_match.group(1).strip()129    b = await a.download_media("resources/downloads/")130    if not b and (a.document and a.document.thumbs):131        b = await a.download_media(thumb=-1)132    if not b:133        return await xx.edit(get_string("cvt_3"))134    try:135        convert = conv_keys[input_]136    except KeyError:137        return await xx.edit(get_string("sts_3").format("gif/img/sticker/webm"))138    file = await con.convert(b, outname="ultroid", convert_to=convert)139    print(file)140 141    if file:142        await event.client.send_file(143            event.chat_id, file, reply_to=event.reply_to_msg_id or event.id144        )145        os.remove(file)146    else:147        await xx.edit("`Failed to convert`")148        return149    await xx.delete()150 151@ultroid_cmd(152    pattern="doc( (.*)|$)",153)154async def _(event):155    input_str = event.pattern_match.group(1).strip()156    if not (input_str and event.is_reply):157        return await event.eor(get_string("cvt_1"), time=5)158    xx = await event.eor(get_string("com_1"))159    a = await event.get_reply_message()160    if not a.message:161        return await xx.edit(get_string("ex_1"))162    with open(input_str, "w") as b:163        b.write(str(a.message))164    await xx.edit(f"**Packing into** `{input_str}`")165    await event.reply(file=input_str, thumb=ULTConfig.thumb)166    await xx.delete()167    os.remove(input_str)168 169 170@ultroid_cmd(171    pattern="open( (.*)|$)",172)173async def _(event):174    a = await event.get_reply_message()175    b = event.pattern_match.group(1).strip()176    if not ((a and a.media) or (b and os.path.exists(b))):177        return await event.eor(get_string("cvt_7"), time=5)178    xx = await event.eor(get_string("com_1"))179    rem = None180    if not b:181        b = await a.download_media()182        rem = True183    try:184        with open(b) as c:185            d = c.read()186    except UnicodeDecodeError:187        return await xx.eor(get_string("cvt_8"), time=5)188    try:189        await xx.edit(f"```{d}```")190    except BaseException:191        what, data = await get_paste(d)192        await xx.edit(193            f"**MESSAGE EXCEEDS TELEGRAM LIMITS**\n\nSo Pasted It On [SPACEBIN]({data['link']})"194        )195    if rem:196        os.remove(b)197