-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
240 lines (209 loc) · 9.16 KB
/
main.py
File metadata and controls
240 lines (209 loc) · 9.16 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
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
import asyncio
from pyromod import listen
from pyrogram import filters, Client
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.errors import (
SessionPasswordNeeded, FloodWait,
PhoneNumberInvalid, ApiIdInvalid,
PhoneCodeInvalid, PhoneCodeExpired
)
import os
from pyrogram import Client
from pyromod import listen
API_ID = int(os.environ.get("API_ID", 0))
API_HASH = os.environ.get("API_HASH", None)
BOT_TOKEN = os.environ.get("BOT_TOKEN", None)
MY_CHANNEL = os.environ.get("MY_CHANNEL", None)
MY_CHANNEL_LINK = os.environ.get("MY_CHANNEL_LINK", None)
CHANNEL_NAME = os.environ.get("CHANNEL_NAME", None)
BOT_USERNAME = os.environ.get("BOT_USERNAME", None)
__all__ = ["logging"]
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logging.getLogger("pyrogram").setLevel(logging.WARNING)
bot = Client(":memory:",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN)
API_TEXT = """
OK now send me Your **`API_ID`** to Start Generating String Session.
Type /help To Mor\n/cancel to Cancel Current Process.e\n\n👇Send Below👇"""
HASH_TEXT = "Ok now send your **`API_HASH`**.\n\nPress /cancel to Cancel Current Task ???\n\n👇Send Below👇."
PHONE_NUMBER_TEXT = (
"Ok now send me your Phone Number in International Format. \n"
"Including Country code. For a Example: **+94707172659**\n\n"
"Press /cancel to Cancel Current Task ???\n\n👇Send Below👇."
)
@bot.on_message(filters.private & filters.command("start"))
async def restart(_, msg: Message):
out = f"""Send /gen to Start your Process.
You must Join My Updates Channel for Updates! **Hosted and Maintained with ?? by ||{MY_CHANNEL}||**
A telegram bot to generate pyrogram and telethon string session...
[Pyrogram]
Language : [Python]
**Regarding ~**[{CHANNEL_NAME}]({MY_CHANNEL_LINK})**
🥀All Commands🥀
🥀/gen - Start Gen Sessions
🥀/help - For help
🥀/start - Start This Bot
🥀/cancel - Cancel Current Process.
"""
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('✨✨Support Group✨✨', url='https://t.me/+xKOF9u8ybDo1OTQ1'),
InlineKeyboardButton('✨✨ Devs✨✨ ', url='https://t.me/Alpha_Devs/5')
],
[
InlineKeyboardButton('✨✨ Bot Channel ✨✨', url='https://t.me/Alpha_network'),
]
]
)
await msg.reply(out, reply_markup=reply_markup)
@bot.on_message(filters.private & filters.command("gen"))
async def genStr(_, msg: Message):
chat = msg.chat
api = await bot.ask(
chat.id, API_TEXT.format(msg.from_user.mention)
)
if await is_cancel(msg, api.text):
return
try:
check_api = int(api.text)
except Exception:
await msg.reply("Hmm...🤔 **`API_ID`** is Invalid ???.\nPress /start to Try Again.\nPress /help For More")
return
api_id = api.text
hash = await bot.ask(chat.id, HASH_TEXT)
if await is_cancel(msg, hash.text):
return
if not len(hash.text) >= 30:
await msg.reply("Hmm...🤔 **`API_HASH`** is Invalid ???.\nPress /start to Try Again.")
return
api_hash = hash.text
while True:
number = await bot.ask(chat.id, PHONE_NUMBER_TEXT)
if not number.text:
continue
if await is_cancel(msg, number.text):
return
phone = number.text
confirm = await bot.ask(chat.id, f'`Is "{phone}" Number correct? ??? (Y/N): \n\nSend: If Yes Send **`y`**\nIf Not Send **`n`**\n\n👇Send Below👇')
if await is_cancel(msg, confirm.text):
return
if "y" in confirm.text:
break
try:
client = Client("my_account", api_id=api_id, api_hash=api_hash)
except Exception as e:
await bot.send_message(chat.id ,f"**ERROR:** `{str(e)}`\nPress /start to Try Again.\n\nPress /help For More")
return
try:
await client.connect()
except ConnectionError:
await client.disconnect()
await client.connect()
try:
code = await client.send_code(phone)
await asyncio.sleep(1)
except FloodWait as e:
await msg.reply(f"⚠️You have Floodwait of {e.x} Seconds ???⚠️")
return
except ApiIdInvalid:
await msg.reply("**API ID** and **API Hash** are Invalid ???.\n\nPress /start to Try Again\n\nPress /help For More.")
return
except PhoneNumberInvalid:
await msg.reply("**Your Phone Number** is Invalid ???.\n\nPress /start to Try Again.\n\nPress /help For More")
return
try:
otp = await bot.ask(
chat.id, ("An **OTP** is sent to your phone number, "
"Please enter OTP in `1 2 3 4 5` format. __(Space between each numbers!)__ \n\n"
"If Bot not sending OTP then try /restart and Start Task again with /start command to Bot.\n"
"Press /cancel to Cancel Current Task.\n\n👇Send Below👇"), timeout=300)
except TimeoutError:
await msg.reply("⚠️Hmm.. Time limit reached of 5 min ???⚠️.\nPress /start to try Again.")
return
if await is_cancel(msg, otp.text):
return
otp_code = otp.text
try:
await client.sign_in(phone, code.phone_code_hash, phone_code=' '.join(str(otp_code)))
except PhoneCodeInvalid:
await msg.reply("⚠️⚠️Why you entered an **Invalid Code** ???⚠️⚠️.\n\nPress /start to Try Again.")
return
except PhoneCodeExpired:
await msg.reply("🙁Oops..! Code is Expired ???🙁.\n\nPress /start to Try Again.")
return
except SessionPasswordNeeded:
try:
two_step_code = await bot.ask(
chat.id,
"Oh You are a Smart Guy!??? Your account have Two-Step Verification.\nNow Please enter your Password.\n\n👇Below👇\n\nPress /cancel to Cancel Current Process.",
timeout=300
)
except TimeoutError:
await msg.reply("`⚠️⚠️Time limit reached of 5 minutes⚠️.\n\nPress /start to Try Again.`")
return
if await is_cancel(msg, two_step_code.text):
return
new_code = two_step_code.text
try:
await client.check_password(new_code)
except Exception as e:
await msg.reply(f"**ERROR:** `{str(e)}`")
return
except Exception as e:
await bot.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
return
try:
session_string = await client.export_session_string()
await client.send_message("me", f"#PYRO #STRING_SESSION \n\n```{session_string}``` \n\nBy [@{BOT_USERNAME}](https://t.me/Gishankrishka_Sessionget_Bot) \nA Powerful Bot by **@Gishankrishka1_cloud**")
await client.disconnect()
print(session_string)
text = f"#PYRO #STRING_SESSION\n\nThis Is Your Pyrogram StringSession\n⚠️DO NOT SHARE WITH ANYONE⚠️.\n\n `{session_string}`\n\n**Regards**"
await bot.send_message(chat.id, text,)
except Exception as e:
await bot.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
return
@bot.on_message(filters.private & filters.command("restart"))
async def restart(_, msg: Message):
await msg.reply("Restarted Bot!")
HU_APP.restart()
@bot.on_message(filters.private & filters.command("help"))
async def restart(_, msg: Message):
out = f"""
Hi, {msg.from_user.mention}. I'm **Pyro String Session Bot** \
I can generate String Session for Your Telegram Account ???(UserBot) !
It needs Your **`API_ID`**, **`API_HASH`**, **Phone Number** and **One Time Verification Code**. \
Which will be sent to your Phone Number.
You have to put **OTP** in `1 2 3 4 5` this format. __(Space between each numbers!)__
**NOTE:** If bot not Sending OTP to your Phone Number than send /restart Command and again send /start to Start your Process.
You must Join My Updates Channel for Updates! **Hosted and Maintained with ?? by ||@Gishankrishka1_cloud||**
A telegram bot to generate pyrogram and telethon string session...
[Pyrogram](docs.pyrogram.org)
Language : [Python](www.python.org)
**Regarding ~**[{CHANNEL_NAME}]({MY_CHANNEL_LINK})**
"""
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('✨✨Support Group✨✨', url='https://t.me/+xKOF9u8ybDo1OTQ1'),
InlineKeyboardButton('✨✨ Dev✨✨ ', url='https://t.me/Alpha_Devs/5')
],
[
InlineKeyboardButton('✨✨ Bot Channel ✨✨', url='https://t.me/Alpha_network'),
]
]
)
await msg.reply(out, reply_markup=reply_markup)
async def is_cancel(msg: Message, text: str):
if text.startswith("/cancel"):
await msg.reply("Process Is Successfully Cancelled.")
return True
return False
if __name__ == "__main__":
bot.run()