-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
sessiongen.py
169 lines (145 loc) · 5.13 KB
/
sessiongen.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
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
import os
from time import sleep
AKENO = r"""
_____ __ ____ ___ ___. __
/ _ \ | | __ ____ ____ ____ | | \______ __________\_ |__ _____/ |_
/ /_\ \| |/ // __ \ / \ / _ \ ______ | | / ___// __ \_ __ \ __ \ / _ \ __\
/ | \ <\ ___/| | ( <_> ) /_____/ | | /\___ \\ ___/| | \/ \_\ ( <_> ) |
\____|__ /__|_ \\___ >___| /\____/ |______//____ >\___ >__| |___ /\____/|__|
\/ \/ \/ \/ \/ \/ \/
"""
def spinner(x):
if x == "tele":
print("Checking if Telethon is installed...")
else:
print("Checking if Pyrogram is installed...")
for _ in range(3):
for frame in r"-\|/-\|/":
print("\b", frame, sep="", end="", flush=True)
sleep(0.1)
def clear_screen():
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: "))
except ValueError:
print("APP ID must be an integer.\nQuitting...")
exit(0)
API_HASH = input("Please enter your API HASH: ")
return API_ID, API_HASH
def telethon_session():
try:
spinner("tele")
import telethon
x = "\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")
x = "\bDone. Installed and imported Telethon."
clear_screen()
print(AKENO)
print(x)
# 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 akeno:
print("Generating a string session for •AKENO•")
try:
akeno.send_message(
"me",
f"**AKENO** `SESSION`:\n\n`{akeno.session.save()}`\n\n**Do not share this anywhere!**",
)
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("Here is That!\n{akeno.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 @TeamKillerX.\n\n")
def pyro_session():
try:
spinner("pyro")
from pyrogram import Client
x = "\bFound an existing installation of Pyrogram...\nSuccessfully Imported.\n\n"
except BaseException:
print("Installing Pyrogram...")
os.system("pip install pyrogram tgcrypto")
x = "\bDone. Installed and imported Pyrogram."
from pyrogram import Client
clear_screen()
print(AKENO)
print(x)
# generate a session
API_ID, API_HASH = get_api_id_and_hash()
print("Enter phone number when asked.\n\n")
try:
with Client(
name="akeno", api_id=API_ID, api_hash=API_HASH, in_memory=True
) as pyro:
ss = pyro.export_session_string()
pyro.send_message(
"me",
f"`{ss}`\n\nAbove is your Pyrogram Session String for akeno. **DO NOT SHARE it.**",
)
print("Session has been sent to your saved messages!")
exit(0)
except Exception as er:
print(
"Unexpected error occurred while creating session, make sure to validate your inputs."
)
print(er)
def main():
clear_screen()
print(AKENO)
try:
type_of_ss = int(
input(
"\nakeno supports both telethon as well as pyrogram sessions.\n\nWhich session do you want to generate?\n1. Telethon Session.\n2. Pyrogram Session.\n\nEnter choice: "
)
)
except Exception as e:
print(e)
exit(0)
if type_of_ss == 1:
telethon_session()
elif type_of_ss == 2:
pyro_session()
else:
print("Invalid choice.")
x = input("Run again? (Y/n)")
if x.lower() in ["y", "yes"]:
main()
else:
exit(0)
main()