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
77 lines (73 loc) · 3.42 KB
/
callbacks.py
File metadata and controls
77 lines (73 loc) · 3.42 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
71
72
73
74
75
76
77
import traceback
from data import Data
from pyrogram import Client
from pyrogram.types import CallbackQuery, InlineKeyboardMarkup
from StringSessionBot.generate import generate_session, ask_ques, buttons_ques
# 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.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.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.id
await bot.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=Data.HELP,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(Data.home_buttons),
)
elif query == "generate":
await callback_query.answer()
await callback_query.message.reply(ask_ques, reply_markup=InlineKeyboardMarkup(buttons_ques))
elif query.startswith("pyrogram") or query.startswith("telethon"):
try:
if query == "pyrogram":
#await callback_query.answer("Please note that the new type of string sessions may not work in all bots, i.e, only the bots that have been updated to pyrogram v2 will work!", show_alert=True)
await generate_session(bot, callback_query.message)
"""
# Maybe in future it'll come back.
elif query == "pyrogram1":
await callback_query.answer()
await generate_session(bot, callback_query.message, old_pyro=True)
"""
elif query == "pyrogram_bot":
await callback_query.answer("Please note that this bot session will be of pyrogram v2", show_alert=True)
await generate_session(bot, callback_query.message, is_bot=True)
elif query == "telethon_bot":
await callback_query.answer()
await generate_session(bot, callback_query.message, telethon=True, is_bot=True)
elif query == "telethon":
await callback_query.answer()
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!"