forked from alenpaulvarghese/pdf_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_handler.py
77 lines (67 loc) · 2.45 KB
/
command_handler.py
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
# (c) AlenPaulVarghese
# -*- coding: utf-8 -*-
from pyrogram.types import (
Message,
CallbackQuery,
InlineKeyboardButton,
InlineKeyboardMarkup,
)
from pyrogram import filters
from pdfbot import Pdfbot # pylint:disable=import-error
__help__ = ["makepdf", "merge", "encrypt", "decrypt", "extract"]
# start command handler
@Pdfbot.on_message(filters.command(["start"]))
async def start_handler(client: Pdfbot, message: Message) -> None:
if len(message.command) > 1 and message.command[1] in __help__:
return_message = await message.reply_text("processing")
await help_cbhandler(
client,
CallbackQuery(
id=123,
client=client,
message=return_message,
chat_instance="-1234",
from_user=message.from_user,
data=f"page-{str(__help__.index(message.command[1]))}",
),
)
return
await message.reply(
client.language["STRINGS"]["help"]["start"],
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("help", "page-help")]]
),
)
@Pdfbot.on_callback_query(
filters.create(lambda _, __, callback: "page" in callback.data),
group=0,
)
async def help_cbhandler(client: Pdfbot, callback: CallbackQuery) -> None:
if callback.data == "page-close":
await callback.message.delete()
elif callback.data == "page-help":
await callback.message.edit(
client.language["STRINGS"]["help"]["help"].format(
bot=(await client.get_me()).username
),
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("✖️", "page-close")]]
),
)
elif "page" in callback.data:
_, next_page = callback.data.split("-")
reply = InlineKeyboardMarkup([[], [InlineKeyboardButton("✖️", "page-close")]])
if int(next_page) != 0:
reply.inline_keyboard[0].append(
InlineKeyboardButton("<<", f"page-{str(int(next_page)-1)}")
)
if not int(next_page) == len(__help__) - 1:
reply.inline_keyboard[0].append(
InlineKeyboardButton(">>", f"page-{str(int(next_page)+1)}")
)
await callback.message.edit(
client.language["STRINGS"]["help"][__help__[int(next_page)]],
reply_markup=reply,
),
if not callback.id == 123:
await callback.answer()