-
Notifications
You must be signed in to change notification settings - Fork 91
/
strNana.py
103 lines (87 loc) · 2.63 KB
/
strNana.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
import os, asyncio, re
try:
import pyrogram
except ModuleNotFoundError:
print("You need to install pyrogram first!\nSee: https://github.com/AyraHikari/pyrogram-session-maker")
exit(1)
# Cleanup
try:
os.remove("my.session")
except:
pass
try:
os.remove("bot.session")
except:
pass
def clear():
if os.name == "posix":
os.system("clear")
elif os.name == "nt":
os.system("cls")
else:
pass
clear()
def initial_selection(api_id, app_hash):
clear()
while True:
print("You want to make session for user bot or real bot?")
print("1 = user bot")
print("2 = real bot")
createbot = input("[1/2] ")
if str(createbot).isdigit() and int(createbot) in (1, 2):
createbot = int(createbot)
break
print("Invaild selection!\n")
session_maker(createbot, api_id, app_hash)
def fill_api():
clear()
while True:
api_id = input("Insert app_id: ")
if str(api_id).isdigit():
break
print("Invaild app_id!\n")
while True:
app_hash = input("Insert api_hash: ")
if app_hash:
break
print("Invaild api_hash!\n")
initial_selection(api_id, app_hash)
def session_maker(createbot, api_id, app_hash):
clear()
if re.search("asyncio", pyrogram.__version__):
if createbot == 1:
app = pyrogram.Client("my", api_id=api_id, api_hash=app_hash)
ses = "my.session"
sestxt = "my.txt"
elif createbot == 2:
bot_token = input("Insert bot token: ")
app = pyrogram.Client("bot", api_id=api_id, api_hash=app_hash, bot_token=bot_token)
ses = "bot.session"
sestxt = "bot.txt"
async def start_app():
await app.start()
session = app.export_session_string()
print(f"Done!\nYour session string is:\n\n{session}")
print(f"\n\nSession string will saved as {sestxt}, Also you can copy {ses} to session dir if need.\nNever share this to anyone!")
open(sestxt, "w").write(str(session))
asyncio.get_event_loop().run_until_complete(start_app())
else:
if createbot == 1:
app = pyrogram.Client("my", api_id=api_id, api_hash=app_hash)
ses = "my.session"
sestxt = "my.txt"
elif createbot == 2:
bot_token = input("Insert bot token: ")
app = pyrogram.Client("bot", api_id=api_id, api_hash=app_hash, bot_token=bot_token)
ses = "bot.session"
sestxt = "bot.txt"
with app as generation:
session = generation.export_session_string()
print(f"Done!\nYour session string is:\n\n{session}")
print(f"\n\nSession string will saved as {sestxt}, Also you can copy {ses} to session dir if need.\nNever share this to anyone!")
open(sestxt, "w").write(str(session))
print("\n\nDo you want to create again with same API?")
ask = input("[Y/N] ")
if ask.lower() == "y":
initial_selection(api_id, app_hash)
fill_api()