-
Notifications
You must be signed in to change notification settings - Fork 88
/
auto_env_gen.py
171 lines (156 loc) · 5.57 KB
/
auto_env_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
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
170
171
import asyncio
import random
import sys
from traceback import format_exc
from telethon import TelegramClient
from telethon.sessions import StringSession
from telethon.tl.functions.channels import CreateChannelRequest
from telethon.tl.functions.contacts import UnblockRequest
DATA = {}
ENV = """
API_ID={}
API_HASH={}
BOT_TOKEN={}
SESSION={}
MAIN_CHANNEL={}
LOG_CHANNEL={}
CLOUD_CHANNEL={}
BACKUP_CHANNEL={}
FIREBASE_URL={}
FIREBASE_SERVICE_ACCOUNT_FILE={}
OWNER={}
"""
async def generate_session_string():
api_id = int(input("Enter your API_ID: "))
api_hash = input("Enter your API_HASH: ")
if api_id and api_hash:
async with TelegramClient(StringSession(), api_id, api_hash) as client:
DATA["api_id"] = api_id
DATA["api_hash"] = api_hash
DATA["session"] = str(client.session.save())
return (str(client.session.save()), api_id, api_hash)
print("API_ID and HASH Not Found!")
sys.exit(1)
def get_firebase():
uri = input("Enter your Firebase Realtime Database Url: ")
_pass = input("Enter your Firebase Realtime Database Service Account File Link: ")
if uri and _pass:
DATA["firebase_uri"] = uri
DATA["firebase_pass"] = _pass
return True
else:
DATA["firebase_uri"] = ""
DATA["firebase_pass"] = ""
return False
async def create_channel(client, title):
try:
r = await client(
CreateChannelRequest(
title=title,
about="Made By https://github.com/kaif-00z/AutoAnimeBot",
megagroup=False,
)
)
created_chat_id = r.chats[0].id
return f"-100{created_chat_id}"
except BaseException:
print("Unable to Create Channel...")
sys.exit(1)
def generate_env():
txt = ENV.format(
DATA["api_id"],
DATA["api_hash"],
DATA["bot_token"],
DATA["session"],
DATA["Ongoing Anime 2024"],
DATA["Ongoing Anime Logs"],
DATA["Ongoing Anime Samples And SS"],
DATA["Ongoing Anime Backup"],
DATA.get("firebase_uri") or "",
DATA.get("firebase_pass") or "",
DATA["owner_id"],
)
with open(".env", "w") as f:
f.write(txt.strip())
print("Succesfully Generated .env File Don't Forget To Save It! For Future Uses.")
async def auto_maker():
string_session, api_id, api_hash = await generate_session_string()
print(string_session)
async with TelegramClient(
StringSession(string_session), api_id, api_hash
) as client:
print("Creating Bot Account...")
who = await client.get_me()
DATA["owner_id"] = who.id
name = who.first_name + "'s Auto Anime Bot"
if who.username:
username = who.username + "_anime_bot"
else:
username = "ongoing_anime_" + (str(who.id))[5:] + "_bot"
bf = "@BotFather"
await client(UnblockRequest(bf))
await client.send_message(bf, "/cancel")
await asyncio.sleep(1)
await client.send_message(bf, "/newbot")
await asyncio.sleep(1)
isdone = (await client.get_messages(bf, limit=1))[0].text
if isdone.startswith("That I cannot do.") or "20 bots" in isdone:
print(
"You Already Made 20 Bots In Your Current Account. You Have To Deleted One Bot To Run This Script."
)
sys.exit(1)
await client.send_message(bf, name)
await asyncio.sleep(1)
isdone = (await client.get_messages(bf, limit=1))[0].text
if not isdone.startswith("Good."):
print(
"Please make a Bot from @BotFather and add it's token in BOT_TOKEN, as an env var and restart me."
)
sys.exit(1)
await client.send_message(bf, username)
await asyncio.sleep(1)
isdone = (await client.get_messages(bf, limit=1))[0].text
await client.send_read_acknowledge("botfather")
if isdone.startswith("Sorry,"):
ran = random.randint(1, 100)
username = "ongoing_anime_" + (str(who.id))[6:] + str(ran) + "_bot"
await client.send_message(bf, username)
await asyncio.sleep(1)
isdone = (await client.get_messages(bf, limit=1))[0].text
if isdone.startswith("Done!"):
bot_token = isdone.split("`")[1]
DATA["bot_token"] = bot_token
print("Succesfully Created Bot Account...")
print("Creating Channels...")
for ch_name in [
"Ongoing Anime Logs",
"Ongoing Anime 2024",
"Ongoing Anime Samples And SS",
"Ongoing Anime Backup",
]:
try:
chat_id = await create_channel(client, ch_name)
await asyncio.sleep(3)
await client.edit_admin(
int(chat_id),
username,
post_messages=True,
edit_messages=True,
delete_messages=True,
ban_users=True,
pin_messages=True,
add_admins=True,
)
DATA[ch_name] = chat_id
except BaseException:
print("Error While Creating Channel And Promoting Bot..")
print(format_exc())
sys.exit(1)
print("Succesfully Created Channel...")
db = get_firebase()
if not db:
print(
"Generating .env Without Firebase URI and Service Account. Now You Have To Add it Manually!"
)
generate_env()
asyncio.run(auto_maker())