forked from ShivangKakkar/StringSessionBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks.py
More file actions
70 lines (65 loc) · 2.77 KB
/
callbacks.py
File metadata and controls
70 lines (65 loc) · 2.77 KB
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
import traceback
from Data import Data
from pyrogram import Client
from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
from StringSessionBot.generate import generate_session
# Callbacks
@Client.on_callback_query()
async def _callbacks(bot: Client, callback_query: CallbackQuery):
user = await bot.get_me()
# user_id = callback_query.from_user.id
mention = user["mention"]
query = callback_query.data.lower()
if query.startswith("home"):
if query == 'home':
chat_id = callback_query.from_user.id
message_id = callback_query.message.message_id
await bot.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=Data.START.format(callback_query.from_user.mention, mention),
reply_markup=InlineKeyboardMarkup(Data.buttons),
)
elif query == "about":
chat_id = callback_query.from_user.id
message_id = callback_query.message.message_id
await bot.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=Data.ABOUT,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(Data.home_buttons),
)
elif query == "help":
chat_id = callback_query.from_user.id
message_id = callback_query.message.message_id
await bot.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text="**Here's How to use me**\n" + Data.HELP,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(Data.home_buttons),
)
elif query == "generate":
await callback_query.message.reply(
"Please choose the python library you want to generate string session for",
reply_markup=InlineKeyboardMarkup([[
InlineKeyboardButton("Pyrogram", callback_data="pyrogram"),
InlineKeyboardButton("Telethon", callback_data="telethon")
]])
)
elif query in ["pyrogram", "telethon"]:
await callback_query.answer()
try:
if query == "pyrogram":
await generate_session(bot, callback_query.message)
else:
await generate_session(bot, callback_query.message, telethon=True)
except Exception as e:
print(traceback.format_exc())
print(e)
await callback_query.message.reply(ERROR_MESSAGE.format(str(e)))
ERROR_MESSAGE = "Oops! An exception occurred! \n\n**Error** : {} " \
"\n\nPlease visit @StarkBotsChat if this message doesn't contain any " \
"sensitive information and you if want to report this as " \
"this error message is not being logged by us!"