randydev commited on
Commit
1400465
·
verified ·
1 Parent(s): 5bdf343

Upload 5 files

Browse files
StringSessionBot/about.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from Data import Data
2
+ from pyrogram import Client, filters
3
+ from pyrogram.types import InlineKeyboardMarkup
4
+
5
+
6
+ # About Message
7
+ @Client.on_message(filters.private & filters.incoming & filters.command("about"))
8
+ async def about(bot, msg):
9
+ await bot.send_message(
10
+ msg.chat.id,
11
+ Data.ABOUT,
12
+ disable_web_page_preview=True,
13
+ reply_markup=InlineKeyboardMarkup(Data.home_buttons),
14
+ )
StringSessionBot/callbacks.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from Data import Data
2
+ from pyrogram import Client
3
+ from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
4
+ from StringSessionBot.generate import generate_session, ERROR_MESSAGE
5
+
6
+
7
+ # Callbacks
8
+ @Client.on_callback_query()
9
+ async def _callbacks(bot: Client, callback_query: CallbackQuery):
10
+ user = await bot.get_me()
11
+ # user_id = callback_query.from_user.id
12
+ mention = user.mention
13
+ query = callback_query.data.lower()
14
+ if query.startswith("home"):
15
+ if query == 'home':
16
+ chat_id = callback_query.from_user.id
17
+ message_id = callback_query.message.id
18
+ await bot.edit_message_text(
19
+ chat_id=chat_id,
20
+ message_id=message_id,
21
+ text=Data.START.format(callback_query.from_user.mention, mention),
22
+ reply_markup=InlineKeyboardMarkup(Data.buttons),
23
+ )
24
+ elif query == "about":
25
+ chat_id = callback_query.from_user.id
26
+ message_id = callback_query.message.id
27
+ await bot.edit_message_text(
28
+ chat_id=chat_id,
29
+ message_id=message_id,
30
+ text=Data.ABOUT,
31
+ disable_web_page_preview=True,
32
+ reply_markup=InlineKeyboardMarkup(Data.home_buttons),
33
+ )
34
+ elif query == "help":
35
+ chat_id = callback_query.from_user.id
36
+ message_id = callback_query.message.id
37
+ await bot.edit_message_text(
38
+ chat_id=chat_id,
39
+ message_id=message_id,
40
+ text="**Here's How to use me**\n" + Data.HELP,
41
+ disable_web_page_preview=True,
42
+ reply_markup=InlineKeyboardMarkup(Data.home_buttons),
43
+ )
44
+ elif query == "generate":
45
+ await callback_query.message.reply(
46
+ "Please Choose Which String You Want To Take",
47
+ reply_markup=InlineKeyboardMarkup([[
48
+ InlineKeyboardButton("Pyrogram", callback_data="pyrogram"),
49
+ InlineKeyboardButton("Telethon", callback_data="telethon")
50
+ ]])
51
+ )
52
+ elif query in ["pyrogram", "telethon"]:
53
+ await callback_query.answer()
54
+ try:
55
+ if query == "pyrogram":
56
+ await generate_session(bot, callback_query.message)
57
+ else:
58
+ await generate_session(bot, callback_query.message, telethon=True)
59
+ except Exception as e:
60
+ await callback_query.message.reply(ERROR_MESSAGE.format(str(e)))
StringSessionBot/generate.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import string
2
+ from random import choice
3
+ from asyncio.exceptions import TimeoutError
4
+ from Data import Data
5
+ from pyrogram import Client, filters
6
+ from telethon import TelegramClient
7
+ from telethon.sessions import StringSession
8
+ from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
9
+ from pyrogram.errors import (
10
+ ApiIdInvalid,
11
+ PhoneNumberInvalid,
12
+ PhoneCodeInvalid,
13
+ PhoneCodeExpired,
14
+ SessionPasswordNeeded,
15
+ PasswordHashInvalid
16
+ )
17
+ from telethon.errors import (
18
+ ApiIdInvalidError,
19
+ PhoneNumberInvalidError,
20
+ PhoneCodeInvalidError,
21
+ PhoneCodeExpiredError,
22
+ SessionPasswordNeededError,
23
+ PasswordHashInvalidError
24
+ )
25
+
26
+ def generate_random_string(length):
27
+ characters = string.ascii_uppercase + string.digits
28
+ random_string = ''.join(choice(characters) for _ in range(length))
29
+ return random_string
30
+
31
+ ERROR_MESSAGE = "Oops! An exception occurred! \n\n**Error** : {} " \
32
+ "\n\nTolong Laporan ke [Support](t.me/xtdevs) jika eror " \
33
+ "sensitive information and you if want to report this as " \
34
+ "this error message is not being logged by us!"
35
+
36
+ @Client.on_message(filters.private & filters.command('generate'))
37
+ async def main(_, msg):
38
+ await msg.reply(
39
+ "Please press which string you want to take",
40
+ reply_markup=InlineKeyboardMarkup(
41
+ [
42
+ [
43
+ InlineKeyboardButton("Pyrogram", callback_data="pyrogram"),
44
+ InlineKeyboardButton("Telethon", callback_data="telethon")
45
+ ]
46
+ ]
47
+ )
48
+ )
49
+
50
+
51
+ async def generate_session(bot, msg, telethon=False):
52
+ await msg.reply("Starting {} Session Generation...".format("Telethon" if telethon else "Pyrogram"))
53
+ user_id = msg.chat.id
54
+ api_id_msg = await bot.ask(user_id, 'Please Send `API_ID`', filters=filters.text)
55
+ if await cancelled(api_id_msg):
56
+ return
57
+ try:
58
+ api_id = int(api_id_msg.text)
59
+ except ValueError:
60
+ await api_id_msg.reply('not true API_ID (which must be an integer). Please start generating session again.', quote=True, reply_markup=InlineKeyboardMarkup(Data.generate_button))
61
+ return
62
+ api_hash_msg = await bot.ask(user_id, 'Please Send `API_HASH`', filters=filters.text)
63
+ if await cancelled(api_id_msg):
64
+ return
65
+ api_hash = api_hash_msg.text
66
+ phone_number_msg = await bot.ask(user_id, "**Please Enter Your Telegram Phone Number With Country Code Format.**\nExample: +1xxxxxxxx", filters=filters.text)
67
+ if await cancelled(api_id_msg):
68
+ return
69
+ phone_number = phone_number_msg.text
70
+ await msg.reply("Sending OTP...")
71
+ clients_name = generate_random_string(12)
72
+ if telethon:
73
+ client = TelegramClient(StringSession(), api_id, api_hash)
74
+ else:
75
+ client = Client("{}".format(clients_name), api_id, api_hash)
76
+ await client.connect()
77
+ try:
78
+ if telethon:
79
+ code = await client.send_code_request(phone_number)
80
+ else:
81
+ code = await client.send_code(phone_number)
82
+ except (ApiIdInvalid, ApiIdInvalidError):
83
+ await msg.reply('`API_ID` and `API_HASH` combination is invalid. Please start generating session again.', reply_markup=InlineKeyboardMarkup(Data.generate_button))
84
+ return
85
+ except (PhoneNumberInvalid, PhoneNumberInvalidError):
86
+ await msg.reply('`PHONE_NUMBER` is invalid. Please start generating session again.', reply_markup=InlineKeyboardMarkup(Data.generate_button))
87
+ return
88
+ try:
89
+ phone_code_msg = await bot.ask(user_id, "**Please Check OTP Code from Official [Telegram Account](tg://openmessage?user_id=777000).Send OTP Code here after reading Format below.\n\nIf OTP Code is 12345 Please [ ADD SPACE** ] send it Like this `1 2 3 4 5`", filters=filters.text, timeout=600)
90
+ if await cancelled(api_id_msg):
91
+ return
92
+ except TimeoutError:
93
+ await msg.reply('Time limit reached 10 minutes. Please start generating strings again.', reply_markup=InlineKeyboardMarkup(Data.generate_button))
94
+ return
95
+ phone_code = phone_code_msg.text.replace(" ", "")
96
+ try:
97
+ if telethon:
98
+ await client.sign_in(phone_number, phone_code, password=None)
99
+ else:
100
+ await client.sign_in(phone_number, code.phone_code_hash, phone_code)
101
+ except (PhoneCodeInvalid, PhoneCodeInvalidError):
102
+ await msg.reply('OTP is invalid. Please start generating session again.', reply_markup=InlineKeyboardMarkup(Data.generate_button))
103
+ return
104
+ except (PhoneCodeExpired, PhoneCodeExpiredError):
105
+ await msg.reply('OTP is expired. Please start generating session again.', reply_markup=InlineKeyboardMarkup(Data.generate_button))
106
+ return
107
+ except (SessionPasswordNeeded, SessionPasswordNeededError):
108
+ try:
109
+ two_step_msg = await bot.ask(user_id, 'Your account has enabled two-step verification. Please provide the password.', filters=filters.text, timeout=300)
110
+ except TimeoutError:
111
+ await msg.reply('Time limit reached 10 minutes. Please start generating strings again.', reply_markup=InlineKeyboardMarkup(Data.generate_button))
112
+ return
113
+ try:
114
+ password = two_step_msg.text
115
+ if telethon:
116
+ await client.sign_in(password=password)
117
+ else:
118
+ await client.check_password(password=password)
119
+ if await cancelled(api_id_msg):
120
+ return
121
+ except (PasswordHashInvalid, PasswordHashInvalidError):
122
+ await two_step_msg.reply('Invalid Password Provided. Please start generating session again.', quote=True, reply_markup=InlineKeyboardMarkup(Data.generate_button))
123
+ return
124
+ if telethon:
125
+ string_session = client.session.save()
126
+ else:
127
+ string_session = await client.export_session_string()
128
+ text = "**{} STRING SESSION** \n\n`{}` \n\nGenerated by @pantekyks".format("TELETHON" if telethon else "PYROGRAM", string_session)
129
+ await client.send_message("me", text)
130
+ await client.disconnect()
131
+ await phone_code_msg.reply("Successfully Fetched {} session string.\n\nPlease check the Saved Message!\n\nBy @rencprx".format("telethon" if telethon else "pyrogram"))
132
+
133
+
134
+ async def cancelled(msg):
135
+ if "/cancel" in msg.text:
136
+ await msg.reply("Cancel Process!", quote=True, reply_markup=InlineKeyboardMarkup(Data.generate_button))
137
+ return True
138
+ elif "/restart" in msg.text:
139
+ await msg.reply("Restarting Bots!", quote=True, reply_markup=InlineKeyboardMarkup(Data.generate_button))
140
+ return True
141
+ elif msg.text.startswith("/"): # Bot Commands
142
+ await msg.reply("Cancel generation process!", quote=True)
143
+ return True
144
+ else:
145
+ return False
StringSessionBot/help.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from Data import Data
2
+ from pyrogram import Client, filters
3
+ from pyrogram.types import InlineKeyboardMarkup
4
+
5
+
6
+ # Help Message
7
+ @Client.on_message(filters.private & filters.incoming & filters.command("help"))
8
+ async def _help(bot, msg):
9
+ await bot.send_message(
10
+ msg.chat.id,
11
+ "**Here's how to use me **\n" + Data.HELP,
12
+ reply_markup=InlineKeyboardMarkup(Data.home_buttons)
13
+ )
StringSessionBot/start.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from Data import Data
2
+ from pyrogram import Client, filters
3
+ from pyrogram.types import InlineKeyboardMarkup, Message
4
+
5
+
6
+ # Start Message
7
+ @Client.on_message(filters.private & filters.incoming & filters.command("start"))
8
+ async def start(bot: Client, msg: Message):
9
+ user = await bot.get_me()
10
+ mention = user.mention
11
+ await bot.send_message(
12
+ msg.chat.id,
13
+ Data.START.format(msg.from_user.mention, mention),
14
+ reply_markup=InlineKeyboardMarkup(Data.buttons)
15
+ )