forked from iiiiii1wepfj/antiservicemessage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.py
176 lines (163 loc) · 6.53 KB
/
string.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
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
import asyncio
from string import string, HU_APP
from asyncio.exceptions import TimeoutError
import asyncio
import logging
import os
import random
import sys
from telethon import TelegramClient, events, custom
from telethon.sessions import StringSession
from telethon.errors.rpcerrorlist import SessionPasswordNeededError, PhoneCodeInvalidError, FloodWaitError, PhoneNumberInvalidError, ApiIdInvalidError, PhoneCodeInvalidError, PhoneCodeExpiredError
API_TEXT = """Hi, {}.
Welcome to Eliza userbot String Session Generator Bot.
Bot by @PeRu_MoNsteR for Eliza userbot.
Now send your `API_ID` same as `APP_ID` to Start Generating Session."""
HASH_TEXT = "Now send your `API_HASH`.\n\nPress /cancel to Cancel Task."
PHONE_NUMBER_TEXT = (
"Now send your Telegram account's Phone number in International Format. \n"
"Including Country code. Example: **+91XXXXXXXXXX**\n\n"
"Press /cancel to Cancel Task."
)
@bot.on_message(filters.private & filters.command("start"))
async def string(_, 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("`API_ID` is Invalid.\nPress /start to Start again.")
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("`API_HASH` is Invalid.\nPress /start to Start 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}" correct? (y/n):` \n\nSend: `y` (If Yes)\nSend: `n` (If No)')
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 Start again.")
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 Start again.")
return
except PhoneNumberInvalid:
await msg.reply("Your Phone Number is Invalid.\n\nPress /start to Start again.")
return
try:
otp = await bot.ask(
chat.id, ("An OTP is sent to your telegram 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."), timeout=300)
except TimeoutError:
await msg.reply("Time limit reached of 5 min.\nPress /start to Start 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("Invalid Code.\n\nPress /start to Start again.")
return
except PhoneCodeExpired:
await msg.reply("Code is Expired.\n\nPress /start to Start again.")
return
except SessionPasswordNeeded:
try:
two_step_code = await bot.ask(
chat.id,
"Your account have Two-Step Verification.\nPlease enter your Password.\n\nPress /cancel to Cancel.",
timeout=300
)
except TimeoutError:
await msg.reply("`Time limit reached of 5 min.\n\nPress /start to Start 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"Tap to copy #STRING_SESSION\n\n```{session_string}``` \n\nBy @PerU_MonSteR")
await client.disconnect()
text = "String Session is Successfully Generated.\nClick on Below Button."
reply_markup = InlineKeyboardMarkup(
[[InlineKeyboardButton(text="Show String Session", url=f"tg://openmessage?user_id={chat.id}")]]
)
await bot.send_message(chat.id, text, reply_markup=reply_markup)
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}. This is Session String Generator Bot. \
I will give you `STRING_SESSION` for your UserBot.
It needs `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.
Must Join Channel for Bot Updates !!
"""
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Support Group', url='https://t.me/elizasupport01'),
InlineKeyboardButton('Developer', url='https://t.me/peru_monster')
],
[
InlineKeyboardButton('Bots Updates Channel', url='https://t.me/Eliza_userbot_support'),
]
]
)
await msg.reply(out, reply_markup=reply_markup)
async def is_cancel(msg: Message, text: str):
if text.startswith("/cancel"):
await msg.reply("Process Cancelled.")
return True
return False
if __name__ == "__main__":
bot.run()