-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaker.py
121 lines (105 loc) · 3.2 KB
/
maker.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
import os
import pyfiglet
from time import sleep
from pyrogram import Client
from datetime import datetime
from requests.exceptions import ConnectionError
# Clean up os
try:
os.remove("my.session")
except Exception:
pass
try:
os.remove("bot.session")
except Exception:
pass
# Clean Screen
def clear():
if os.name == "posix": # Unix/Linux/MacOS/BSD/etc
os.system("clear")
elif os.name == "nt": # Windows
os.system("cls")
else:
pass
# Start fn
def start():
clear()
initial_screen()
#Info Screen
def initial_screen():
banner = pyfiglet.figlet_format("m4mallu")
print(banner)
print("You need to register to get app_id and api_hash in here:\nhttps://my.telegram.org/apps")
print("\nProject source:\nhttps://github.com/m4mallu/Pyrogram-V2-SessionStringMaker")
input("\nPress 'Enter' key to continue >>>")
fill_api()
# Fill the user credentials
def fill_api():
clear()
while True:
api_id = input("Insert app_id: ")
if str(api_id).isdigit():
break
clear()
print("Invalid app_id!")
sleep(2)
clear()
app_hash = input("Insert api_hash: ")
if app_hash:
create_session(api_id, app_hash)
#Session creation
def create_session(api_id, app_hash):
app = Client("session", int(api_id), app_hash)
try:
clear()
app.start()
except Exception:
clear()
input("Invalid Id/Hash/Mobile Number (Mobile number should be in international format).\nPress 'Enter' key to continue >>>")
fill_api()
except ConnectionError:
clear()
input("Network Error! Please try again later.\nPress 'Enter' key to continue >>>")
fill_api()
session = app.export_session_string()
dt_string = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
try:
Client.send_message(self=app,
chat_id='me',
text=str(f'<b>Session created on: </b>{dt_string}\n\n<code>{session}</code>\n\n'
f'⚠️<b> keep this code confidential</b> ⚠\n\n<b>Credits: '
f'</b>https://github.com/m4mallu'),
disable_web_page_preview=True,
)
except Exception:
print("Error saving session to saved messages\n\n")
pass
clear()
print(f"Done! Your session string is:\n\n{session}")
print("\n\n1. A copy of session string has been send to your >>Saved Messages<<\n2. Save this session string to a "
"file and use it in your bot.\nCredits: https://github.com/m4mallu")
input("\nPress 'Enter' key for main menu >>>")
app.stop()
loop()
# Main loop
def loop():
clear()
print(pyfiglet.figlet_format("Coded by", font="digital"))
print(pyfiglet.figlet_format("m4mallu", font="banner3-D"))
sleep(3)
clear()
x = input("Enter 1 to continue\n\nEnter 2 to exit\n\n>>>")
if x == "1":
start()
elif x == "2":
clear()
print("Thanks for using m4mallu's session string maker!")
exit()
else:
clear()
print("Invalid input!")
sleep(2)
clear()
loop()
clear()
loop()