Spaces:
Runtime error
Runtime error
| from pyrogram import Client, filters | |
| from pyrogram.errors import SessionPasswordNeeded | |
| from pyrogram.types import ( | |
| CallbackQuery, | |
| InlineKeyboardButton, | |
| InlineKeyboardMarkup, | |
| Message, | |
| ReplyKeyboardRemove, | |
| ) | |
| from ..btnsG import gen_inline_keyboard, start_button | |
| from ..btnsK import session_keyboard | |
| from . import START_MSG, BotHelp, Config, Symbols, db, hellbot | |
| async def session_menu(_, message: Message): | |
| await message.reply_text( | |
| "**๐ ๐ฏ๐ ๐พ๐บ๐๐พ ๐ผ๐๐๐๐๐พ ๐บ๐ ๐๐๐๐๐๐ ๐ฟ๐๐๐ ๐ป๐พ๐ ๐๐:**", | |
| reply_markup=session_keyboard(), | |
| ) | |
| async def new_session(_, message: Message): | |
| await message.reply_text( | |
| "**๐ฎ๐๐บ๐!** ๐ซ๐พ๐'๐ ๐๐พ๐๐๐ ๐บ ๐๐พ๐ ๐๐พ๐๐๐๐๐", | |
| reply_markup=ReplyKeyboardRemove(), | |
| ) | |
| phone_number = await hellbot.bot.ask( | |
| message.chat.id, | |
| "**1.** ๐ค๐๐๐พ๐ ๐๐๐๐ ๐๐พ๐ ๐พ๐๐๐บ๐ ๐บ๐ผ๐ผ๐๐๐๐ ๐๐๐๐๐พ ๐๐๐๐ป๐พ๐ ๐๐ ๐บ๐ฝ๐ฝ ๐๐๐พ ๐๐พ๐๐๐๐๐: \n\n__๐ฒ๐พ๐๐ฝ /cancel ๐๐ ๐ผ๐บ๐๐ผ๐พ๐ ๐๐๐พ ๐๐๐พ๐๐บ๐๐๐๐.__", | |
| filters=filters.text, | |
| timeout=120, | |
| ) | |
| if phone_number.text == "/cancel": | |
| return await message.reply_text("**๐ข๐บ๐๐ผ๐พ๐ ๐ ๐พ๐ฝ!**") | |
| elif not phone_number.text.startswith("+") and not phone_number.text[1:].isdigit(): | |
| return await message.reply_text( | |
| "**๐ค๐๐๐๐!** ๐ฏ๐๐๐๐พ ๐๐๐๐ป๐พ๐ ๐๐๐๐ ๐ป๐พ ๐๐ ๐ฝ๐๐๐๐๐ ๐บ๐๐ฝ ๐๐๐๐๐ ๐ฝ ๐ผ๐๐๐๐บ๐๐ ๐ผ๐๐๐๐๐๐ ๐ผ๐๐ฝ๐พ." | |
| ) | |
| try: | |
| client = Client( | |
| name="Hellbot", | |
| api_id=Config.API_ID, | |
| api_hash=Config.API_HASH, | |
| in_memory=True, | |
| ) | |
| await client.connect() | |
| code = await client.send_code(phone_number.text) | |
| ask_otp = await hellbot.bot.ask( | |
| message.chat.id, | |
| "**2.** ๐ค๐๐๐พ๐ ๐๐๐พ ๐ฎ๐ณ๐ฏ ๐๐พ๐๐ ๐๐ ๐๐๐๐ ๐๐พ๐ ๐พ๐๐๐บ๐ ๐บ๐ผ๐ผ๐๐๐๐ ๐ป๐ ๐๐พ๐๐บ๐๐บ๐๐๐๐ ๐พ๐๐พ๐๐ ๐๐๐๐ป๐พ๐ ๐๐๐๐ ๐บ ๐๐๐บ๐ผ๐พ. \n\n**๐ค๐๐บ๐๐๐ ๐พ:** `2 4 1 7 4`\n\n__๐ฒ๐พ๐๐ฝ /cancel ๐๐ ๐ผ๐บ๐๐ผ๐พ๐ ๐๐๐พ ๐๐๐พ๐๐บ๐๐๐๐.__", | |
| filters=filters.text, | |
| timeout=300, | |
| ) | |
| if ask_otp.text == "/cancel": | |
| return await message.reply_text("**๐ข๐บ๐๐ผ๐พ๐ ๐ ๐พ๐ฝ!**") | |
| otp = ask_otp.text.replace(" ", "") | |
| try: | |
| await client.sign_in(phone_number.text, code.phone_code_hash, otp) | |
| except SessionPasswordNeeded: | |
| two_step_pass = await hellbot.bot.ask( | |
| message.chat.id, | |
| "**3.** ๐ค๐๐๐พ๐ ๐๐๐๐ ๐๐๐ ๐๐๐พ๐ ๐๐พ๐๐๐ฟ๐๐ผ๐บ๐๐๐๐ ๐๐บ๐๐๐๐๐๐ฝ: \n\n__๐ฒ๐พ๐๐ฝ /cancel ๐๐ ๐ผ๐บ๐๐ผ๐พ๐ ๐๐๐พ ๐๐๐พ๐๐บ๐๐๐๐.__", | |
| filters=filters.text, | |
| timeout=120, | |
| ) | |
| if two_step_pass.text == "/cancel": | |
| return await message.reply_text("**๐ข๐บ๐๐ผ๐พ๐ ๐ ๐พ๐ฝ!**") | |
| await client.check_password(two_step_pass.text) | |
| session_string = await client.export_session_string() | |
| await message.reply_text( | |
| f"**๐ฒ๐๐ผ๐ผ๐พ๐๐!** ๐ธ๐๐๐ ๐๐พ๐๐๐๐๐ ๐๐๐๐๐๐ ๐๐ ๐๐พ๐๐พ๐๐บ๐๐พ๐ฝ. ๐ ๐ฝ๐ฝ๐๐๐ ๐๐ ๐๐ ๐ฝ๐บ๐๐บ๐ป๐บ๐๐พ..." | |
| ) | |
| user_id = (await client.get_me()).id | |
| await db.update_session(user_id, session_string) | |
| await client.disconnect() | |
| await message.reply_text( | |
| "**๐ฒ๐๐ผ๐ผ๐พ๐๐!** ๐ฒ๐พ๐๐๐๐๐ ๐๐๐๐๐๐ ๐บ๐ฝ๐ฝ๐พ๐ฝ ๐๐ ๐ฝ๐บ๐๐บ๐ป๐บ๐๐พ. ๐ธ๐๐ ๐ผ๐บ๐ ๐๐๐ ๐๐๐พ ๐ง๐พ๐ ๐ ๐ก๐๐ ๐๐ ๐๐๐๐ ๐บ๐ผ๐ผ๐๐๐๐ ๐บ๐ฟ๐๐พ๐ ๐๐พ๐๐๐บ๐๐๐๐๐ ๐๐๐พ ๐ป๐๐.\n\n**๐ญ๐ฎ๐ณ๐ค:** ๐ฅ๐๐ ๐๐พ๐ผ๐๐๐๐๐ ๐๐๐๐๐๐๐พ๐ ๐๐๐ป๐๐ฝ๐ ๐๐๐ ๐ ๐๐บ๐๐พ ๐๐๐พ ๐บ๐ผ๐ผ๐พ๐๐ ๐๐ ๐๐๐๐ ๐๐พ๐๐๐๐๐ ๐๐๐๐๐๐. ๐ญ๐๐ ๐พ๐๐พ๐ ๐๐๐ ๐๐ ๐๐๐พ ๐ป๐๐." | |
| ) | |
| except TimeoutError: | |
| await message.reply_text( | |
| "**๐ณ๐๐๐พ๐๐๐๐ค๐๐๐๐!** ๐ธ๐๐ ๐๐๐๐ ๐ ๐๐๐๐พ๐ ๐๐๐บ๐ ๐พ๐๐ผ๐๐พ๐ผ๐๐พ๐ฝ ๐๐ ๐ผ๐๐๐๐ ๐พ๐๐พ ๐๐๐พ ๐๐๐๐ผ๐พ๐๐. ๐ฏ๐ ๐พ๐บ๐๐พ ๐๐๐ ๐บ๐๐บ๐๐." | |
| ) | |
| except Exception as e: | |
| await message.reply_text(f"**๐ค๐๐๐๐!** {e}") | |
| async def delete_session(_, message: Message): | |
| all_sessions = await db.get_all_sessions() | |
| if not all_sessions: | |
| return await message.reply_text("๐ญ๐ ๐๐พ๐๐๐๐๐๐ ๐ฟ๐๐๐๐ฝ ๐๐ ๐ฝ๐บ๐๐บ๐ป๐บ๐๐พ.") | |
| collection = [] | |
| for i in all_sessions: | |
| collection.append((i["user_id"], f"rm_session:{i['user_id']}")) | |
| buttons = gen_inline_keyboard(collection, 2) | |
| buttons.append([InlineKeyboardButton("Cancel โ", "auth_close")]) | |
| await message.reply_text( | |
| "**๐ข๐๐๐๐๐พ ๐บ ๐๐พ๐๐๐๐๐ ๐๐ ๐ฝ๐พ๐ ๐พ๐๐พ:**", | |
| reply_markup=InlineKeyboardMarkup(buttons), | |
| ) | |
| async def rm_session_cb(client: Client, cb: CallbackQuery): | |
| collection = [] | |
| user_id = int(cb.data.split(":")[1]) | |
| all_sessions = await db.get_all_sessions() | |
| if not all_sessions: | |
| return await cb.message.delete() | |
| try: | |
| owner = await client.get_users(Config.OWNER_ID) | |
| owner_id = owner.id | |
| owner_name = owner.first_name | |
| except: | |
| owner_id = Config.OWNER_ID | |
| owner_name = "๐ฎ๐๐๐พ๐" | |
| if cb.from_user.id not in [user_id, owner_id]: | |
| return await cb.answer( | |
| f"๐ ๐ผ๐ผ๐พ๐๐ ๐๐พ๐๐๐๐๐ผ๐๐พ๐ฝ ๐๐ ๐บ๐๐๐๐๐พ๐ ๐๐๐พ๐๐. Only {owner_name} and session client can delete this session!", | |
| show_alert=True, | |
| ) | |
| await db.rm_session(user_id) | |
| await cb.answer("**๐ฒ๐๐ผ๐ผ๐พ๐๐!** ๐ฒ๐พ๐๐๐๐๐ ๐ฝ๐พ๐ ๐พ๐๐พ๐ฝ ๐ฟ๐๐๐ ๐ฝ๐บ๐๐บ๐ป๐บ๐๐พ. \n__Restart the bot to apply changes.__", show_alert=True) | |
| for i in all_sessions: | |
| collection.append((i["user_id"], f"rm_session:{i['user_id']}")) | |
| buttons = gen_inline_keyboard(collection, 2) | |
| buttons.append([InlineKeyboardButton("Cancel โ", "auth_close")]) | |
| await cb.message.edit_reply_markup(InlineKeyboardMarkup(buttons)) | |
| async def list_sessions(_, message: Message): | |
| all_sessions = await db.get_all_sessions() | |
| if not all_sessions: | |
| return await message.reply_text("๐ญ๐ ๐๐พ๐๐๐๐๐๐ ๐ฟ๐๐๐๐ฝ ๐๐ ๐ฝ๐บ๐๐บ๐ป๐บ๐๐พ.") | |
| text = f"**{Symbols.cross_mark} ๐ซ๐๐๐ ๐๐ฟ ๐๐พ๐๐๐๐๐๐:**\n\n" | |
| for i, session in enumerate(all_sessions): | |
| text += f"[{'0' if i <= 9 else ''}{i+1}] {Symbols.bullet} **๐ด๐๐พ๐ ๐จ๐ฃ:** `{session['user_id']}`\n" | |
| await message.reply_text(text) | |
| async def go_home(_, message: Message): | |
| await message.reply_text( | |
| "**Home ๐ **", | |
| reply_markup=ReplyKeyboardRemove(), | |
| ) | |
| await message.reply_text( | |
| START_MSG.format(message.from_user.mention), | |
| disable_web_page_preview=True, | |
| reply_markup=InlineKeyboardMarkup(start_button()), | |
| ) | |
| BotHelp("Sessions").add( | |
| "session", "This command is packed with tools to manage userbot sessions." | |
| ).info( | |
| "Session ๐" | |
| ).done() | |