Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
logo.py102 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"""8✘ Commands Available -9 10• `{i}logo <text>`11   Generate a logo of the given Text12   Or Reply To image , to write ur text on it.13   Or Reply To Font File, To write with that font.14 15"""16import glob17import os18import random19 20from telethon.tl.types import InputMessagesFilterPhotos21 22try:23    from PIL import Image24except ImportError:25    Image = None26from pyUltroid.fns.misc import unsplashsearch27from pyUltroid.fns.tools import LogoHelper28 29from . import OWNER_ID, OWNER_NAME, download_file, get_string, mediainfo, ultroid_cmd30 31 32@ultroid_cmd(pattern="logo( (.*)|$)")33async def logo_gen(event):34    xx = await event.eor(get_string("com_1"))35    name = event.pattern_match.group(1).strip()36    if not name:37        return await xx.eor("`Give a name too!`", time=5)38    bg_, font_ = None, None39    if event.reply_to_msg_id:40        temp = await event.get_reply_message()41        if temp.media:42            if hasattr(temp.media, "document") and (43                ("font" in temp.file.mime_type)44                or (".ttf" in temp.file.name)45                or (".otf" in temp.file.name)46            ):47                font_ = await temp.download_media("resources/fonts/")48            elif "pic" in mediainfo(temp.media):49                bg_ = await temp.download_media()50    if not bg_:51        SRCH = [52                "background",53                "neon",54                "anime",55                "art",56                "bridges",57                "streets",58                "computer",59                "cyberpunk",60                "nature",61                "abstract",62                "exoplanet",63                "magic",64                "3d render",65            ]66        res = await unsplashsearch(random.choice(SRCH), limit=1)67        bg_, _ = await download_file(res[0], "resources/downloads/logo.png")68        newimg = "resources/downloads/unsplash-temp.jpg"69        img_ = Image.open(bg_)70        img_.save(newimg)71        os.remove(bg_)72        bg_ = newimg73 74    if not font_:75        fpath_ = glob.glob("resources/fonts/*")76        font_ = random.choice(fpath_)77    if len(name) <= 8:78        strke = 1079    elif len(name) >= 9:80        strke = 581    else:82        strke = 2083    name = LogoHelper.make_logo(84        bg_,85        name,86        font_,87        fill="white",88        stroke_width=strke,89        stroke_fill="black",90    )91    await xx.edit("`Done!`")92    await event.client.send_file(93        event.chat_id,94        file=name,95        caption=f"Logo by [{OWNER_NAME}](tg://user?id={OWNER_ID})",96        force_document=True,97    )98    os.remove(name)99    await xx.delete()100    if os.path.exists(bg_):101        os.remove(bg_)102