MCPcopy Create free account
hub / github.com/VJBots/VJ-Forward-Bot / add_session

Method add_session

plugins/test.py:82–139  ·  view source on GitHub ↗
(self, bot, message)

Source from the content-addressed store, hash-verified

80 return True
81
82 async def add_session(self, bot, message):
83 user_id = int(message.from_user.id)
84 text = "<b>⚠️ DISCLAIMER ⚠️</b>\n\n<code>you can use your session for forward message from private chat to another chat.\nPlease add your pyrogram session with your own risk. Their is a chance to ban your account. My developer is not responsible if your account may get banned.</code>"
85 await bot.send_message(user_id, text=text)
86 phone_number_msg = await bot.ask(chat_id=user_id, text="<b>Please send your phone number which includes country code</b>\n<b>Example:</b> <code>+13124562345</code>")
87 if phone_number_msg.text=='/cancel':
88 return await phone_number_msg.reply('<b>process cancelled !</b>')
89 phone_number = phone_number_msg.text
90 client = Client(":memory:", Config.API_ID, Config.API_HASH)
91 await client.connect()
92 await phone_number_msg.reply("Sending OTP...")
93 try:
94 code = await client.send_code(phone_number)
95 phone_code_msg = await bot.ask(user_id, "Please check for an OTP in official telegram account. If you got it, send OTP here after reading the below format. \n\nIf OTP is `12345`, **please send it as** `1 2 3 4 5`.\n\n**Enter /cancel to cancel The Procces**", filters=filters.text, timeout=600)
96 except PhoneNumberInvalid:
97 await phone_number_msg.reply('`PHONE_NUMBER` **is invalid.**')
98 return
99 if phone_code_msg.text=='/cancel':
100 return await phone_code_msg.reply('<b>process cancelled !</b>')
101 try:
102 phone_code = phone_code_msg.text.replace(" ", "")
103 await client.sign_in(phone_number, code.phone_code_hash, phone_code)
104 except PhoneCodeInvalid:
105 await phone_code_msg.reply('**OTP is invalid.**')
106 return
107 except PhoneCodeExpired:
108 await phone_code_msg.reply('**OTP is expired.**')
109 return
110 except SessionPasswordNeeded:
111 two_step_msg = await bot.ask(user_id, '**Your account has enabled two-step verification. Please provide the password.\n\nEnter /cancel to cancel The Procces**', filters=filters.text, timeout=300)
112 if two_step_msg.text=='/cancel':
113 return await two_step_msg.reply('<b>process cancelled !</b>')
114 try:
115 password = two_step_msg.text
116 await client.check_password(password=password)
117 except PasswordHashInvalid:
118 await two_step_msg.reply('**Invalid Password Provided**')
119 return
120 string_session = await client.export_session_string()
121 await client.disconnect()
122 if len(string_session) < SESSION_STRING_SIZE:
123 return await msg.reply('<b>invalid session sring</b>')
124 try:
125 _client = Client("USERBOT", self.api_id, self.api_hash, session_string=string_session)
126 client = await _client.start()
127 except Exception as e:
128 return await msg.reply_text(f"<b>USER BOT ERROR:</b> `{e}`")
129 user = _client.me
130 details = {
131 'id': user.id,
132 'is_bot': False,
133 'user_id': user_id,
134 'name': user.first_name,
135 'session': string_session,
136 'username': user.username
137 }
138 await db.add_userbot(details)
139 return True

Callers 1

settings_queryFunction · 0.80

Calls 2

connectMethod · 0.80
add_userbotMethod · 0.80

Tested by

no test coverage detected