File size: 9,314 Bytes
78b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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


@hellbot.bot.on_message(

    filters.command("session") & Config.AUTH_USERS & filters.private

)
async def session_menu(_, message: Message):
    await message.reply_text(
        "**๐Ÿ€ ๐–ฏ๐—…๐–พ๐–บ๐—Œ๐–พ ๐–ผ๐—๐—ˆ๐—ˆ๐—Œ๐–พ ๐–บ๐—‡ ๐—ˆ๐—‰๐—๐—‚๐—ˆ๐—‡ ๐–ฟ๐—‹๐—ˆ๐—† ๐–ป๐–พ๐—…๐—ˆ๐—:**",
        reply_markup=session_keyboard(),
    )


@hellbot.bot.on_message(filters.regex(r"New ๐Ÿ’ซ") & Config.AUTH_USERS & filters.private)
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}")


@hellbot.bot.on_message(

    filters.regex(r"Delete โŒ") & Config.AUTH_USERS & filters.private

)
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),
    )


@hellbot.bot.on_callback_query(filters.regex(r"rm_session"))
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))


@hellbot.bot.on_message(filters.regex(r"List ๐Ÿ“œ") & Config.AUTH_USERS & filters.private)
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)


@hellbot.bot.on_message(filters.regex(r"Home ๐Ÿ ") & filters.private & Config.AUTH_USERS)
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()