File size: 6,812 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import base64
import datetime
import math
import os
import time

from pyrogram.types import Message

from Hellbot.core import Limits
from Hellbot.functions.images import create_calendar
from . import Config, HelpMenu, Symbols, hellbot, on_message

math_cmds = ["sin", "cos", "tan", "square", "cube", "sqroot", "factorial", "power"]


@on_message("base64enc", allow_stan=True)
async def base64enc(_, message: Message):
    if len(message.command) < 2 and not message.reply_to_message:
        return await hellbot.delete(message, "Give me something to encode.")

    if len(message.command) >= 2:
        text = await hellbot.input(message)
    else:
        text = message.reply_to_message.text or message.reply_to_message.caption

    if not text:
        return await hellbot.delete(message, "Give me something to encode.")

    hell = await hellbot.edit(message, "Encoding...")

    encoded = base64.b64encode(text.encode()).decode()
    await hell.edit(f"**π–‘π–Ίπ—Œπ–Ύ64 π–€π—‡π–Όπ—ˆπ–½π–Ύπ–½:**\n\n`{encoded}`")


@on_message("base64dec", allow_stan=True)
async def base64dec(_, message: Message):
    if len(message.command) < 2 and not message.reply_to_message:
        return await hellbot.delete(message, "Give me something to decode.")

    if len(message.command) >= 2:
        text = await hellbot.input(message)
    else:
        text = message.reply_to_message.text or message.reply_to_message.caption

    if not text:
        return await hellbot.delete(message, "Give me something to decode.")

    hell = await hellbot.edit(message, "Decoding...")

    decoded = base64.b64decode(text.encode()).decode()
    await hell.edit(f"**π–‘π–Ίπ—Œπ–Ύ64 π–£π–Ύπ–Όπ—ˆπ–½π–Ύπ–½:**\n\n`{decoded}`")


@on_message(["calculate", "calc"], allow_stan=True)
async def calculator(_, message: Message):
    if len(message.command) < 2:
        return await hellbot.delete(message, "Give me something to calculate.")

    query = await hellbot.input(message)
    hell = await hellbot.edit(message, "Calculating...")
    try:
        result = eval(query)
    except Exception:
        result = "Invalid Expression"

    await hell.edit(
        f"**{Symbols.bullet} π–€π—‘π—‰π—‹π–Ύπ—Œπ—Œπ—‚π—ˆπ—‡:** `{query}`\n\n**{Symbols.bullet} π–±π–Ύπ—Œπ—Žπ—…π—,,:**\n`{result}`"
    )


@on_message("math", allow_stan=True)
async def maths(_, message: Message):
    if len(message.command) < 3:
        return await hellbot.delete(message, "Give me something to calculate.")

    cmd = message.command[1].lower()
    query = message.command[2].lower()

    if cmd not in math_cmds:
        return await hellbot.delete(
            message,
            f"**Unknown command!** \n\nAvailable Commands are: \n`{'`, `'.join(math_cmds)}`",
            20,
        )

    hell = await hellbot.edit(message, "Calculating...")

    if cmd == "sin":
        result = math.sin(int(query))
    elif cmd == "cos":
        result = math.cos(int(query))
    elif cmd == "tan":
        result = math.tan(int(query))
    elif cmd == "square":
        result = int(query) * int(query)
    elif cmd == "cube":
        result = int(query) * int(query) * int(query)
    elif cmd == "sqroot":
        result = math.sqrt(int(query))
    elif cmd == "factorial":
        result = math.factorial(int(query))
    elif cmd == "power":
        result = math.pow(int(query), 2)

    await hell.edit(
        f"**{Symbols.bullet} π–€π—‘π—‰π—‹π–Ύπ—Œπ—Œπ—‚π—ˆπ—‡:** `{cmd} {query}`\n\n**{Symbols.bullet} π–±π–Ύπ—Œπ—Žπ—…π—,,:**\n`{result}`"
    )


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

    hell = await hellbot.edit(message, "Unpacking...")
    filename = await message.reply_to_message.download(Config.TEMP_DIR)

    with open(filename, "rb") as f:
        data = f.read().decode()

    try:
        await hell.edit(
            data[: Limits.MessageLength],
            disable_web_page_preview=True,
        )
    except Exception as e:
        await hellbot.error(hell, f"`{e}`")

    os.remove(filename)


@on_message("pack", allow_stan=True)
async def pack(_, message: Message):
    if not message.reply_to_message or not message.reply_to_message.text:
        return await hellbot.delete(message, "Reply to a text to pack.")

    filename = f"pack_{int(time.time())}.txt"
    if len(message.command) >= 2:
        filename = message.command[1]

    with open(filename, "w") as f:
        f.write(message.reply_to_message.text)

    await message.reply_document(
        filename,
        caption=f"**πŸ’« Packed into {filename}**",
    )

    os.remove(filename)


@on_message("calendar", allow_stan=True)
async def getcalendar(_, message: Message):
    if len(message.command) < 2:
        year = datetime.datetime.now().year
        month = datetime.datetime.now().month
    else:
        query = await hellbot.input(message)
        if "/" in query:
            month, year = query.split("/")
            month = int(month)
            year = int(year)
        else:
            return await hellbot.delete(
                message,
                "Invalid query!\n\nExample: `calendar 1/2021`",
            )

    hell = await hellbot.edit(message, "Generating calendar...")
    image = await create_calendar(year, month)

    await hell.reply_photo(image, caption=f"**πŸ“… Calendar for {month}/{year}**")
    await hell.delete()

    os.remove(image)


HelpMenu("tools").add(
    "base64enc",
    "<reply> or <text>",
    "Encode the text to a base64 string.",
    "base64enc Hello, World!",
).add(
    "base64dec",
    "<reply> or <text>",
    "Decode the base64 string to text.",
    "base64dec SGVsbG8sIFdvcmxkIQ==",
).add(
    "calculate",
    "<expression>",
    "Calculate the expression.",
    "calculate 69*100",
    "You can also use 'calc' as an alias.",
).add(
    "math",
    "<expression>",
    "Perform some basic math operations.",
    "math sin 90",
    f"Available Commands are: \n`{'`, `'.join(math_cmds)}`",
).add(
    "unpack",
    "<reply to a file>",
    "Unpack the file and send the text content.",
    "unpack",
).add(
    "pack",
    "<reply to a text> <filename (optional)>",
    "Pack the text into a file.",
    "pack script.js",
).add(
    "calendar",
    "<month/year (optional)>",
    "Generate a calendar image.",
    "calendar 1/2024",
    "If no query is given, current month's calendar will be generated.",
).info(
    "Basic Tools"
).done()