File size: 9,895 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
from pyrogram import filters
from pyrogram.enums import ParseMode
from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup

from Hellbot.functions.templates import command_template, help_template

from ..btnsG import gen_bot_help_buttons, gen_inline_help_buttons, start_button
from . import HELP_MSG, START_MSG, Config, Symbols, hellbot


async def check_auth_click(cb: CallbackQuery) -> bool:
    if cb.from_user.id not in Config.AUTH_USERS:
        await cb.answer(
            "You are not authorized to use this bot. \n\n</> @Its_HellBot",
            show_alert=True,
        )
        return False
    return True


@hellbot.bot.on_callback_query(filters.regex(r"auth_close"))
async def auth_close_cb(_, cb: CallbackQuery):
    if await check_auth_click(cb):
        await cb.message.delete()


@hellbot.bot.on_callback_query(filters.regex(r"close"))
async def close_cb(_, cb: CallbackQuery):
    await cb.message.delete()


@hellbot.bot.on_callback_query(filters.regex(r"bot_help_menu"))
async def bot_help_menu_cb(_, cb: CallbackQuery):
    if not await check_auth_click(cb):
        return

    plugin = str(cb.data.split(":")[1])

    try:
        buttons = [
            InlineKeyboardButton(f"{Symbols.bullet} {i}", f"bot_help_cmd:{plugin}:{i}")
            for i in sorted(Config.BOT_HELP[plugin]["commands"])
        ]
    except KeyError:
        await cb.answer("No description provided for this plugin!", show_alert=True)
        return

    buttons = [buttons[i : i + 2] for i in range(0, len(buttons), 2)]
    buttons.append([InlineKeyboardButton(Symbols.back, "help_data:bothelp")])

    caption = (
        f"**๐–ฏ๐—…๐—Ž๐—€๐—‚๐—‡ ๐–ฅ๐—‚๐—…๐–พ:** `{plugin}`\n"
        f"**๐–ฏ๐—…๐—Ž๐—€๐—‚๐—‡ ๐–จ๐—‡๐–ฟ๐—ˆ:** __{Config.BOT_HELP[plugin]['info']} ๐Ÿ€__\n\n"
        f"**๐Ÿ“ƒ ๐–ซ๐—ˆ๐–บ๐–ฝ๐–พ๐–ฝ ๐–ข๐—ˆ๐—†๐—†๐–บ๐—‡๐–ฝ๐—Œ:** `{len(sorted(Config.BOT_HELP[plugin]['commands']))}`"
    )

    try:
        await cb.edit_message_text(
            caption,
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup(buttons),
        )
    except Exception:
        # handles MessageNotModified error
        pass


@hellbot.bot.on_callback_query(filters.regex(r"bot_help_cmd"))
async def bot_help_cmd_cb(_, cb: CallbackQuery):
    if not await check_auth_click(cb):
        return

    result = ""
    plugin = str(cb.data.split(":")[1])
    command = str(cb.data.split(":")[2])
    cmd_dict = Config.BOT_HELP[plugin]["commands"][command]

    result += f"**{Symbols.radio_select} ๐–ข๐—ˆ๐—†๐—†๐–บ๐—‡๐–ฝ:** `/{cmd_dict['command']}`"
    result += (
        f"\n\n**{Symbols.arrow_right} ๐–ฃ๐–พ๐—Œ๐–ผ๐—‹๐—‚๐—‰๐—๐—‚๐—ˆ๐—‡:** __{cmd_dict['description']}__"
    )
    result += f"\n\n**<\\> @Its_HellBot ๐Ÿ€**"

    buttons = [
        [
            InlineKeyboardButton(Symbols.back, f"bot_help_menu:{plugin}"),
            InlineKeyboardButton(Symbols.close, "help_data:botclose"),
        ]
    ]

    try:
        await cb.edit_message_text(
            result,
            ParseMode.MARKDOWN,
            True,
            InlineKeyboardMarkup(buttons),
        )
    except Exception:
        # handles MessageNotModified error
        pass


@hellbot.bot.on_callback_query(filters.regex(r"help_page"))
async def help_page_cb(_, cb: CallbackQuery):
    if not await check_auth_click(cb):
        return

    page = int(cb.data.split(":")[1])
    buttons, max_page = await gen_inline_help_buttons(page, sorted(Config.CMD_MENU))

    caption = await help_template(
        cb.from_user.mention,
        (len(Config.CMD_INFO), len(Config.CMD_MENU)),
        (page + 1, max_page),
    )

    try:
        await cb.edit_message_text(
            caption,
            reply_markup=InlineKeyboardMarkup(buttons),
        )
    except Exception:
        # handles MessageNotModified error
        pass


@hellbot.bot.on_callback_query(filters.regex(r"help_menu"))
async def help_menu_cb(_, cb: CallbackQuery):
    if not await check_auth_click(cb):
        return

    page = int(cb.data.split(":")[1])
    plugin = str(cb.data.split(":")[2])

    try:
        buttons = [
            InlineKeyboardButton(
                f"{Symbols.bullet} {i}", f"help_cmd:{page}:{plugin}:{i}"
            )
            for i in sorted(Config.HELP_DICT[plugin]["commands"])
        ]
    except KeyError:
        await cb.answer("No description provided for this plugin!", show_alert=True)
        return

    buttons = [buttons[i : i + 2] for i in range(0, len(buttons), 2)]
    buttons.append([InlineKeyboardButton(Symbols.back, f"help_page:{page}")])

    caption = await command_template(
        plugin,
        Config.HELP_DICT[plugin]["info"],
        len(sorted(Config.HELP_DICT[plugin]["commands"])),
    )

    try:
        await cb.edit_message_text(
            caption,
            reply_markup=InlineKeyboardMarkup(buttons),
        )
    except Exception:
        # handles MessageNotModified error
        pass


@hellbot.bot.on_callback_query(filters.regex(r"help_cmd"))
async def help_cmd_cb(_, cb: CallbackQuery):
    if not await check_auth_click(cb):
        return

    page = int(cb.data.split(":")[1])
    plugin = str(cb.data.split(":")[2])
    command = str(cb.data.split(":")[3])
    result = ""
    cmd_dict = Config.HELP_DICT[plugin]["commands"][command]

    if cmd_dict["parameters"] is None:
        result += f"**{Symbols.radio_select} ๐–ข๐—ˆ๐—†๐—†๐–บ๐—‡๐–ฝ:** `{Config.HANDLERS[0]}{cmd_dict['command']}`"
    else:
        result += f"**{Symbols.radio_select} ๐–ข๐—ˆ๐—†๐—†๐–บ๐—‡๐–ฝ:** `{Config.HANDLERS[0]}{cmd_dict['command']} {cmd_dict['parameters']}`"

    if cmd_dict["description"]:
        result += (
            f"\n\n**{Symbols.arrow_right} ๐–ฃ๐–พ๐—Œ๐–ผ๐—‹๐—‚๐—‰๐—๐—‚๐—ˆ๐—‡:** __{cmd_dict['description']}__"
        )

    if cmd_dict["example"]:
        result += f"\n\n**{Symbols.arrow_right} ๐–ค๐—‘๐–บ๐—†๐—‰๐—…๐–พ:** `{Config.HANDLERS[0]}{cmd_dict['example']}`"

    if cmd_dict["note"]:
        result += f"\n\n**{Symbols.arrow_right} ๐–ญ๐—ˆ๐—๐–พ:** __{cmd_dict['note']}__"

    result += f"\n\n**<\\> @Its_HellBot ๐Ÿ€**"

    buttons = [
        [
            InlineKeyboardButton(Symbols.back, f"help_menu:{page}:{plugin}"),
            InlineKeyboardButton(Symbols.close, "help_data:c"),
        ]
    ]

    try:
        await cb.edit_message_text(
            result,
            ParseMode.MARKDOWN,
            reply_markup=InlineKeyboardMarkup(buttons),
        )
    except Exception:
        # handles MessageNotModified error
        pass


@hellbot.bot.on_callback_query(filters.regex(r"help_data"))
async def help_close_cb(_, cb: CallbackQuery):
    if not await check_auth_click(cb):
        return

    action = str(cb.data.split(":")[1])
    if action == "c":
        await cb.edit_message_text(
            "**๐–ง๐–พ๐—…๐—‰ ๐–ฌ๐–พ๐—‡๐—Ž ๐–ข๐—…๐—ˆ๐—Œ๐–พ๐–ฝ!**",
            reply_markup=InlineKeyboardMarkup(
                [[InlineKeyboardButton("Reopen", "help_data:reopen")]]
            ),
        )
    elif action == "reopen":
        buttons, pages = await gen_inline_help_buttons(0, sorted(Config.CMD_MENU))
        caption = await help_template(
            cb.from_user.mention,
            (len(Config.CMD_INFO), len(Config.CMD_MENU)),
            (1, pages),
        )
        await cb.edit_message_text(
            caption,
            reply_markup=InlineKeyboardMarkup(buttons),
        )
    elif action == "botclose":
        await cb.message.delete()
    elif action == "bothelp":
        buttons = await gen_bot_help_buttons()
        await cb.edit_message_text(
            HELP_MSG,
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup(buttons),
        )
    elif action == "source":
        buttons = [
            [
                InlineKeyboardButton("๐Ÿš€ Deploy", url="https://github.com/The-HellBot/HellBot"),
                InlineKeyboardButton("Plugins ๐Ÿ“‚", url="https://github.com/The-HellBot/Plugins"),
            ],
            [
                InlineKeyboardButton("ะฝั”โ„“โ„“ะฒฯƒั‚ ฮทั”ั‚ฯ‰ฯƒัะบ ๐Ÿ‡ฎ๐Ÿ‡ณ", url="https://t.me/HellBot_Networks"),
            ],
            [
                InlineKeyboardButton("๐ŸŽ™๏ธ Support", url="https://t.me/HellBot_Chats"),
                InlineKeyboardButton("Updates ๐Ÿ“ฃ", url="https://t.me/Its_HellBot"),
            ],
            [
                InlineKeyboardButton("๐Ÿ”™", "help_data:start"),
                InlineKeyboardButton(Symbols.close, "help_data:botclose"),
            ],
        ]
        await cb.edit_message_text(
            "__ยป The source code is available on GitHub. You can find the link below.__\n"
            "__ยป Every project available under The-HellBot are open-source and free to use and modify to your needs.__\n"
            "__ยป Anyone pretending to be the developer of this bot and selling the code, is a scammer.__\n\n"
            "__ยป Please consider giving a star to the repository if you liked the project.__\n"
            "__ยป Feel free to contact us if you need any help regarding the source code.__\n\n"
            "**โค๏ธ @HellBot_Networks ๐Ÿ‡ฎ๐Ÿ‡ณ**",
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup(buttons),
        )
    elif action == "start":
        buttons = start_button()
        await cb.edit_message_text(
            START_MSG.format(cb.from_user.mention),
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup(buttons),
        )