File size: 3,643 Bytes
78b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import time

import requests
from pyrogram.types import Message

from Hellbot.core import ENV
from Hellbot.functions.formatter import readable_time
from Hellbot.functions.images import get_wallpapers, make_logo

from . import Config, HelpMenu, db, hellbot, on_message


@on_message("logo", allow_stan=True)
async def makeLogo(_, message: Message):
    if len(message.command) < 2:
        return await hellbot.delete(message, "Provide a text to make a logo.")

    start_time = time.time()
    hell = await hellbot.edit(message, "Processing...")
    query = await hellbot.input(message)

    if message.reply_to_message and message.reply_to_message.photo:
        photo = await message.reply_to_message.download(Config.TEMP_DIR + "temp_bg.jpg")
        text = query
    else:
        if "--" in query:
            text, theme = query.split("--", 1)
            isRandom = False
        else:
            text, theme = query, ""
            isRandom = True

        access = await db.get_env(ENV.unsplash_api)
        if not access:
            return await hellbot.delete(
                hell, "Unsplash API not found. Either set it or reply to an image."
            )

        photo = await get_wallpapers(access, 1, theme.strip(), isRandom)
        if not photo:
            return await hellbot.delete(hell, "No wallpapers found.")

        binary = requests.get(photo[0]).content
        with open(Config.TEMP_DIR + "temp_bg.jpg", "wb") as f:
            f.write(binary)

    logo_path = await make_logo(Config.TEMP_DIR + "temp_bg.jpg", text.strip(), Config.FONT_PATH)
    time_taken = readable_time(int(time.time() - start_time))

    await message.reply_photo(
        logo_path,
        caption=f"**π–«π—ˆπ—€π—ˆ 𝖬𝖺𝖽𝖾 𝗂𝗇:** `{time_taken}`",
    )
    await hell.delete()
    os.remove(logo_path)


@on_message("setfont", allow_stan=True)
async def setFont(_, message: Message):
    if not message.reply_to_message or not message.reply_to_message.document:
        return await hellbot.delete(message, "Reply to a font file to save it.")

    hell = await hellbot.edit(message, "Processing...")
    font = await message.reply_to_message.download(Config.DWL_DIR)

    if not font.endswith(".ttf"):
        return await hellbot.delete(hell, "Invalid font file. Only .ttf is supported.")

    if not os.path.exists(font):
        return await hellbot.delete(hell, "Font not found.")

    Config.FONT_PATH = font
    await hellbot.delete(hell, "Font set successfully.")


@on_message("resetfont", allow_stan=True)
async def resetFont(_, message: Message):
    prev_font = Config.FONT_PATH
    if prev_font == "./Hellbot/resources/fonts/Montserrat.ttf":
        return await hellbot.delete(message, "Font is already set to default.")

    Config.FONT_PATH = "./Hellbot/resources/fonts/Montserrat.ttf"
    await hellbot.delete(message, "Font reset successfully.")
    os.remove(prev_font)


HelpMenu("logo").add(
    "logo",
    "<reply to image (optional)> <text>",
    "Make a logo with text. You can also reply to an image to use it as a background. You can also specify a theme by using `--` after the text.",
    "logo The HellBot --supra",
    "This command uses Unsplash API to get images.",
).add(
    "setfont",
    "<reply to font file>",
    "Set a font file to use for logo making. This is not permanent option.",
    "setfont",
    "Only .ttf files are supported.",
).add(
    "resetfont",
    None,
    "Reset the font file to default.",
    "resetfont",
).info(
    "Make Logos"
).done()