-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathses_gen.py
128 lines (105 loc) · 4.51 KB
/
ses_gen.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
122
123
124
125
126
127
128
#!/usr/bin/python3
# Credits:
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
import os
from time import sleep
USERVER = """
██╗░░░██╗░██████╗███████╗██████╗░██╗░░░██╗███████╗██████╗░
██║░░░██║██╔════╝██╔════╝██╔══██╗██║░░░██║██╔════╝██╔══██╗
██║░░░██║╚█████╗░█████╗░░██████╔╝╚██╗░██╔╝█████╗░░██████╔╝
██║░░░██║░╚═══██╗██╔══╝░░██╔══██╗░╚████╔╝░██╔══╝░░██╔══██╗
╚██████╔╝██████╔╝███████╗██║░░██║░░╚██╔╝░░███████╗██║░░██║
░╚═════╝░╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚══════╝╚═╝░░╚═╝
A TELEGRAM USER ASSISTANT
"""
def spinner():
print("Checking if Telethon is installed...")
for _ in range(3):
for frame in r"-\|/-\|/":
print("\b", frame, sep="", end="", flush=True)
sleep(0.1)
def clear_screen():
# https://www.tutorialspoint.com/how-to-clear-screen-in-python#:~:text=In%20Python%20sometimes%20we%20have,screen%20by%20pressing%20Control%20%2B%20l%20.
if os.name == "posix":
os.system("clear")
else:
# for windows platfrom
os.system("cls")
def get_api_id_and_hash():
print(
"Get your API ID and API HASH from my.telegram.org or @ScrapperRoBot to proceed.\n\n",
)
try:
API_ID = int(input("Please enter your API ID: "))
API_HASH = input("Please enter your API HASH: ")
except ValueError:
print("APP ID must be an integer.\nQuitting...")
exit(0)
return API_ID, API_HASH
def telethon_session():
try:
spinner()
import telethon # ignore: pylint
text = "\bFound an existing installation of Telethon...\nSuccessfully Imported.\n\n"
except ImportError:
print("Installing Telethon...")
os.system("pip uninstall telethon -y && pip install -U telethon")
text = "\bDone. Installed and imported Telethon."
clear_screen()
print(USERVER)
print(text)
# the imports
from telethon.errors.rpcerrorlist import (
ApiIdInvalidError,
PhoneNumberInvalidError,
UserIsBotError,
)
from telethon.sessions import StringSession
from telethon.sync import TelegramClient
API_ID, API_HASH = get_api_id_and_hash()
# logging in
try:
with TelegramClient(StringSession(), API_ID, API_HASH) as ultroid:
print("Generating a string session for USERVER")
try:
ult = ultroid.send_message(
"me",
f"**USERVER** `SESSION`:\n\n`{ultroid.session.save()}`\n\n**Do not share this anywhere!**",
)
print(ultroid.session.save())
print("OR")
print(
"Your SESSION has been generated. Check your Telegram saved messages!"
)
return
except UserIsBotError:
print("You are trying to Generate Session for your Bot's Account?")
print(f"Here is That!\n{ultroid.session.save()}\n\n")
print("NOTE: You can't use that as User Session..")
except ApiIdInvalidError:
print(
"Your API ID/API HASH combination is invalid. Kindly recheck.\nQuitting..."
)
exit(0)
except ValueError:
print("API HASH must not be empty!\nQuitting...")
exit(0)
except PhoneNumberInvalidError:
print("The phone number is invalid!\nQuitting...")
exit(0)
except Exception as er:
print("Unexpected Error Occurred while Creating Session")
print(er)
print("If you think It as a Bug, Report to @UltroidSupport.\n\n")
def main():
clear_screen()
print(USERVER)
telethon_session()
x = input("Run again? (y/n)")
if x.lower() in ["y", "yes"]:
main()
else:
exit(0)
main()