|
1 | | -from pyrogram import filters |
2 | | -from pyrogram import Client |
3 | | -from pyrogram.errors import FloodWait |
4 | | -from pyrogram import errors |
5 | | -from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply |
| 1 | +from pyrogram import filters, Client, errors |
| 2 | +from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton |
| 3 | +from pyromod import listen |
6 | 4 |
|
7 | 5 | import asyncio |
8 | 6 |
|
9 | 7 | from psm import psm |
10 | | -from psm.plugins.dictionaries import code_caches, app_ids, app_hashs, passwords |
| 8 | +from psm.strings import strings |
11 | 9 |
|
12 | 10 |
|
13 | | -async def client_session(message): |
14 | | - return Client( |
15 | | - ":memory:", |
16 | | - api_id=int(app_ids[message.from_user.id]), |
17 | | - api_hash=str(app_hashs[message.from_user.id]), |
18 | | - ) |
| 11 | +async def client_session(message, api_id, api_hash): |
| 12 | + return Client(":memory:", api_id=int(api_id), api_hash=str(api_hash)) |
19 | 13 |
|
20 | 14 |
|
21 | | -@psm.on_message(filters.command("phone")) |
22 | | -async def phone_number(_, message): |
23 | | - try: |
24 | | - app = await client_session(message) |
25 | | - except KeyError: |
26 | | - await message.reply("You did not set Variables correctly, read /start again.") |
27 | | - return |
28 | | - try: |
29 | | - phonenum = message.text.split(None, 1)[1].replace(" ", "") |
30 | | - except IndexError: |
31 | | - await message.reply("Must pass args, example: `/phone +1234578900`") |
32 | | - return |
33 | | - try: |
34 | | - await app.connect() |
35 | | - except ConnectionError: |
36 | | - await app.disconnect() |
37 | | - await app.connect() |
38 | | - try: |
39 | | - sent_code = await app.send_code(phonenum) |
40 | | - except FloodWait as e: |
41 | | - await message.reply( |
42 | | - f"I cannot create session for you.\nYou have a floodwait of: `{e.x} seconds`" |
43 | | - ) |
44 | | - return |
45 | | - except errors.exceptions.bad_request_400.PhoneNumberInvalid: |
46 | | - await message.reply( |
47 | | - "Phone number is invalid, Make sure you double check before sending." |
48 | | - ) |
49 | | - return |
50 | | - await message.reply( |
51 | | - "send me your code in 25 seconds, make sure you reply to this message and wait for a response.", |
52 | | - reply_markup=ForceReply(True), |
53 | | - ) |
54 | | - await asyncio.sleep(25) |
55 | | - try: |
56 | | - await app.sign_in( |
57 | | - phonenum, sent_code.phone_code_hash, code_caches[message.from_user.id] |
58 | | - ) |
59 | | - except KeyError: |
60 | | - await message.reply("Timed out, Try again.") |
61 | | - return |
62 | | - except errors.exceptions.unauthorized_401.SessionPasswordNeeded: |
| 15 | +@psm.on_message(filters.command("proceed") | ~filters.command("start")) |
| 16 | +async def sessions_make(client, message): |
| 17 | + apid = await client.ask(message.chat.id, strings.APIID) |
| 18 | + aphash = await client.ask(message.chat.id, strings.APIHASH) |
| 19 | + phone_token = await client.ask(message.chat.id, strings.PHONETOKEN) |
| 20 | + if str(phone_token.text).startswith("+"): |
| 21 | + try: |
| 22 | + app = await client_session(message, api_id=apid.text, api_hash=aphash.text) |
| 23 | + except Exception as err: |
| 24 | + await message.reply(strings.ERROR.format(err=err)) |
| 25 | + return |
| 26 | + try: |
| 27 | + await app.connect() |
| 28 | + except ConnectionError: |
| 29 | + await app.disconnect() |
| 30 | + await app.connect() |
63 | 31 | try: |
64 | | - await app.check_password(passwords[message.from_user.id]) |
65 | | - except KeyError: |
| 32 | + sent_code = await app.send_code(phone_token.text) |
| 33 | + except errors.FloodWait as e: |
66 | 34 | await message.reply( |
67 | | - "You have not set your password in the `/variables`, try doing that before you continue" |
| 35 | + f"I cannot create session for you.\nYou have a floodwait of: `{e.x} seconds`" |
68 | 36 | ) |
69 | 37 | return |
70 | | - except errors.exceptions.bad_request_400.PhoneCodeInvalid: |
71 | | - await message.reply("The code you sent seems Invalid, Try again.") |
72 | | - return |
73 | | - except errors.exceptions.bad_request_400.PhoneCodeExpired: |
74 | | - await message.reply("The Code you sent seems Expired. Try again.") |
75 | | - return |
76 | | - await app.send_message("me", f"```{(await app.export_session_string())}```") |
77 | | - button = InlineKeyboardMarkup( |
78 | | - [ |
| 38 | + except errors.PhoneNumberInvalid: |
| 39 | + await message.reply(strings.INVALIDNUMBER) |
| 40 | + return |
| 41 | + except errors.ApiIdInvalid: |
| 42 | + await message.reply(strings.APIINVALID) |
| 43 | + return |
| 44 | + ans = await client.ask(message.chat.id, strings.PHONECODE) |
| 45 | + |
| 46 | + try: |
| 47 | + await app.sign_in(phone_token.text, sent_code.phone_code_hash, ans.text) |
| 48 | + except errors.SessionPasswordNeeded: |
| 49 | + pas = await client.ask(message.chat.id, strings.PASSWORD) |
| 50 | + try: |
| 51 | + await app.check_password(pas.text) |
| 52 | + except Exception as err: |
| 53 | + await message.reply(strings.ERROR.format(err=err)) |
| 54 | + return |
| 55 | + except errors.PhoneCodeInvalid: |
| 56 | + await message.reply(strings.PHONECODEINVALID) |
| 57 | + return |
| 58 | + except errors.PhoneCodeExpired: |
| 59 | + await message.reply(strings.PHONECODEINVALID) |
| 60 | + return |
| 61 | + await app.send_message("me", f"```{(await app.export_session_string())}```") |
| 62 | + button = InlineKeyboardMarkup( |
79 | 63 | [ |
80 | | - InlineKeyboardButton( |
81 | | - "Go to Saved Messages", url=f"tg://user?id={message.from_user.id}" |
82 | | - ) |
| 64 | + [ |
| 65 | + InlineKeyboardButton( |
| 66 | + "Go to Saved Messages", |
| 67 | + url=f"tg://user?id={message.from_user.id}", |
| 68 | + ) |
| 69 | + ] |
83 | 70 | ] |
84 | | - ] |
85 | | - ) |
86 | | - await message.reply( |
87 | | - "All Done! Check your Saved Messages for your Session String.\n\nMake sure you run /clear to clear caches of your variables", |
88 | | - reply_markup=button, |
89 | | - ) |
90 | | - |
91 | | - |
92 | | -@psm.on_message(filters.command("token")) |
93 | | -async def bot_token(_, message): |
94 | | - try: |
95 | | - app = await client_session(message) |
96 | | - except KeyError: |
97 | | - await message.reply("You did not set Variables correctly, read /start again.") |
98 | | - return |
99 | | - try: |
100 | | - bottoken = message.text.split(None, 1)[1].replace(" ", "") |
101 | | - except IndexError: |
102 | | - await message.reply("Must pass args, example: `/token 1234:ABCD1234`") |
103 | | - return |
104 | | - try: |
105 | | - await app.connect() |
106 | | - except ConnectionError: |
107 | | - await app.disconnect() |
108 | | - await app.connect() |
109 | | - try: |
110 | | - await app.sign_in_bot(bottoken) |
111 | | - except errors.exceptions.bad_request_400.AccessTokenInvalid: |
| 71 | + ) |
| 72 | + await message.reply( |
| 73 | + strings.DONEPHONE, |
| 74 | + reply_markup=button, |
| 75 | + ) |
| 76 | + else: |
| 77 | + try: |
| 78 | + app = await client_session(message, api_id=apid.text, api_hash=aphash.text) |
| 79 | + except Exception as err: |
| 80 | + await message.reply(strings.ERROR.format(err=err)) |
| 81 | + return |
| 82 | + try: |
| 83 | + await app.connect() |
| 84 | + except ConnectionError: |
| 85 | + await app.disconnect() |
| 86 | + await app.connect() |
| 87 | + try: |
| 88 | + await app.sign_in_bot(phone_token.text) |
| 89 | + except errors.AccessTokenInvalid: |
| 90 | + await message.reply(strings.BOTTOKENINVALID) |
| 91 | + return |
112 | 92 | await message.reply( |
113 | | - "BotToken Invalid: make sure you are sending a valid BotToken from @BotFather" |
| 93 | + f"**Here is your Bot Session:**\n```{(await app.export_session_string())}```\n\nHappy pyrogramming" |
114 | 94 | ) |
115 | | - return |
116 | | - await message.reply( |
117 | | - f"**Here is your Bot Session:**\n```{(await app.export_session_string())}```\n\nMake sure you run /clear to clear caches of your variables" |
118 | | - ) |
0 commit comments