-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.py
307 lines (252 loc) · 11.8 KB
/
main.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
from httpx import Client
from base64 import b64encode
from time import sleep, strftime
from colorama import Fore, init
import time
import os
from json import loads
init(autoreset=True)
def p(text: str) -> None:
print(
f"{Fore.LIGHTWHITE_EX}[{Fore.CYAN}{strftime('%H:%M:%S')}{Fore.LIGHTWHITE_EX}] {text}"
.replace('[+]', f'[{Fore.LIGHTGREEN_EX}+{Fore.LIGHTWHITE_EX}]')
.replace('[*]', f'[{Fore.LIGHTYELLOW_EX}*{Fore.LIGHTWHITE_EX}]')
.replace('[>]', f'[{Fore.CYAN}>{Fore.LIGHTWHITE_EX}]')
.replace('[-]', f'[{Fore.RED}-{Fore.LIGHTWHITE_EX}]')
)
class Scrape:
def __init__(self, token: str, id: str) -> None:
self.token = token
self.id = id
self.baseurl = f"https://discord.com/api/v9/guilds/{self.id}"
self.session = Client()
self.headers = {"Authorization": self.token}
def do_request(self, url) -> dict:
return self.session.get(
url = url,
headers = self.headers,
).json()
def get_channels(self) -> dict:
return self.do_request(f"{self.baseurl}/channels")
def get_info(self) -> dict:
return self.do_request(self.baseurl)
def get_data(self) -> dict:
info = self.get_info()
channels = self.get_channels()
return {
"info" : info,
"channels" : channels,
"roles" : info.get("roles", []),
"emojis" : info.get("emojis", []),
}
class Create:
def __init__(self, token: str, data: dict) -> None:
self.token = token
self.baseurl = "https://discord.com/api/v9"
self.session = Client()
self.data = data
self.headers = {"Authorization": self.token}
self.delay = 0.5
self.id = None # Initialize self.id as None
def create_server(self):
p("[>] Creating server")
img = f"https://cdn.discordapp.com/icons/{self.data['info']['id']}/{self.data['info']['icon']}.webp?size=96"
img = f"data:image/png;base64,{b64encode(self.session.get(img).content).decode('utf-8')}"
data = {
"name" : self.data["info"]["name"],
"icon" : img,
"channels" : [],
"system_channel_id" : None,
"guild_template_code" : "8ewECn5UKpDY",
}
res = self.session.post(
url = f"{self.baseurl}/guilds",
headers = self.headers,
json = data,
).json()
print(res) # Added row
self.id = res["id"] # Corrected line
self.everyone = res["roles"][0]["id"]
url = f"{self.baseurl}/guilds/{self.id}/roles/{self.everyone}"
data = {
"name" : "@everyone",
"permissions" : "1071698529857",
"color" : 0,
"hoist" : False,
"mentionable" : False,
"icon" : None,
"unicode_emoji" : None,
}
self.session.patch(
url = url,
headers = self.headers,
json = data,
)
url = f"{self.baseurl}/guilds/{self.id}"
data = {
"features" : ["APPLICATION_COMMAND_PERMISSIONS_V2", "COMMUNITY"],
"verification_level" : 1,
"default_message_notifications" : 1,
"explicit_content_filter" : 2,
"rules_channel_id" : "1",
"public_updates_channel_id" : "1",
}
self.session.patch(
url = url,
headers = self.headers,
json = data,
)
p(f"[+] Created server {self.data['info']['name']} -> {res['id']}")
def delete_channels(self):
channels = self.session.get(
url=f"{self.baseurl}/guilds/{self.id}/channels",
headers=self.headers,
).json()
for channel in channels:
s = self.session.delete(
url=f"{self.baseurl}/channels/{channel['id']}",
headers=self.headers,
).status_code
p(f"[+] Deleted channel {channel['name']} -> {s}" if s == 200 else f"[-] Failed to delete channel {channel['name']} -> {s}")
def create_channels(self):
parentchannels = sorted([channel for channel in self.data["channels"] if channel["type"] == 4], key=lambda x: x["position"])
prnt = {}
p(f"[>] Creating {len(parentchannels)} parent channels")
for channel in parentchannels:
data = {
"name" : channel["name"],
"type" : channel["type"],
"permission_overwrites" : channel["permission_overwrites"],
}
res = self.session.post(
url = f"{self.baseurl}/guilds/{self.id}/channels",
headers = self.headers,
json = data,
)
p(f"[+] Created channel {channel['name']} -> {res.status_code}" if res.status_code == 201 else f"[-] Failed to create channel {channel['name']} -> {res.status_code}")
if res.status_code == 201:
prnt[channel["id"]] = res.json()["id"]
sleep(self.delay)
p(f"[>] Creating {len(self.data['channels']) - len(parentchannels)} channels")
for channel in self.data["channels"]:
if channel["type"] == 4:
continue
data = {
"name" : channel["name"],
"type" : channel["type"],
"permission_overwrites" : channel["permission_overwrites"],
}
if channel["parent_id"]:
data["parent_id"] = prnt[channel["parent_id"]]
res = self.session.post(
url = f"{self.baseurl}/guilds/{self.id}/channels",
headers = self.headers,
json = data,
)
p(f"[+] Created channel {channel['name']} -> {res.status_code}" if res.status_code == 201 else f"[-] Failed to create channel {channel['name']} -> {res.status_code}")
sleep(self.delay)
def create_roles(self):
roles = self.data["roles"]
roles = sorted(roles, key=lambda x: x["position"], reverse=True)
p(f"[>] Creating {len(roles)} roles")
for role in roles:
if role["name"] == "@everyone":
for channel in self.data["channels"]:
for permission in channel["permission_overwrites"]:
if permission["id"] == role["id"]:
permission["id"] = self.everyone
continue
data = {
"name" : role["name"],
"permissions" : role["permissions"],
"color" : role["color"],
"hoist" : role["hoist"],
"mentionable" : role["mentionable"],
"icon" : None,
"unicode_emoji" : None,
}
res = self.session.post(
url = f"{self.baseurl}/guilds/{self.id}/roles",
headers = self.headers,
json = data,
)
p(f"[+] Created role {role['name']} -> {res.status_code}" if res.status_code == 200 else f"[-] Failed to create role {role['name']} -> {res.status_code}")
if res.status_code == 200:
for channel in self.data["channels"]:
if channel["type"] == 4:
continue
for permission in channel["permission_overwrites"]:
if permission["id"] == role["id"]:
permission["id"] = res.json()["id"]
sleep(self.delay)
def create_emojis(self):
p(f"[>] Creating {len(self.data['emojis'])} emojis" if len(self.data["emojis"]) > 0 else "[!] No emojis to create")
for emoji in self.data["emojis"]:
img = f"https://cdn.discordapp.com/emojis/{emoji['id']}.png"
img = f"data:image/png;base64,{b64encode(self.session.get(img).content).decode('utf-8')}"
data = {
"name" : emoji["name"],
"image" : img,
"roles" : emoji["roles"]
}
s = self.session.post(
url = f"{self.baseurl}/guilds/{self.id}/emojis",
headers = self.headers,
json = data,
).status_code
p(f"[+] Created emoji {emoji['name']} -> {s}" if s == 201 else f"[-] Failed to create emoji {emoji['name']} -> {s}")
sleep(self.delay)
def all(self):
tasks = [
self.create_server,
self.delete_channels,
self.create_channels,
self.create_roles,
self.create_emojis,
]
for task in tasks:
try:
task()
except Exception as e:
p(f"[*] {e}")
pass
def print_blinking_banner(banner, blink_duration=1.5, blink_rate=0.3):
start_time = time.time()
elapsed_time = 0
while elapsed_time < blink_duration:
os.system("cls" if os.name == "nt" else "clear") # Clear Console/Window
print(banner)
time.sleep(blink_rate)
os.system("cls" if os.name == "nt" else "clear") # Clear Console/Window
time.sleep(blink_rate)
elapsed_time = time.time() - start_time
def print_banner():
banner = f"""
{Fore.RED} ______ ________ _______ __ __ ________ _______ ______ __ ______ __ __ ________
{Fore.BLUE} / \ / |/ \ / | / |/ |/ \ / \ / | / \ / \ / |/ |
{Fore.GREEN} /$$$$$$ |$$$$$$$$/ $$$$$$$ |$$ | $$ |$$$$$$$$/ $$$$$$$ | /$$$$$$ |$$ | /$$$$$$ |$$ \ $$ |$$$$$$$$/
{Fore.YELLOW} $$ \__$$/ $$ |__ $$ |__$$ |$$ | $$ |$$ |__ $$ |__$$ | $$ | $$/ $$ | $$ | $$ |$$$ \$$ |$$ |__
{Fore.RED} $$ \ $$ | $$ $$< $$ \ /$$/ $$ | $$ $$< $$ | $$ | $$ | $$ |$$$$ $$ |$$ |
{Fore.GREEN} $$$$$$ |$$$$$/ $$$$$$$ | $$ /$$/ $$$$$/ $$$$$$$ | $$ | __ $$ | $$ | $$ |$$ $$ $$ |$$$$$/
{Fore.RED} / \__$$ |$$ |_____ $$ | $$ | $$ $$/ $$ |_____ $$ | $$ | $$ \__/ |$$ |_____ $$ \__$$ |$$ |$$$$ |$$ |_____
{Fore.BLUE} $$ $$/ $$ |$$ | $$ | $$$/ $$ |$$ | $$ | $$ $$/ $$ |$$ $$/ $$ | $$$ |$$ |
{Fore.GREEN} $$$$$$/ $$$$$$$$/ $$/ $$/ $/ $$$$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$$/ $$$$$$/ $$/ $$/ $$$$$$$$/
"""
return banner
if __name__ == "__main__":
config = loads(open("config.json", "r").read())
token = config["token"]
blinking_banner = print_banner()
print_blinking_banner(blinking_banner)
source_server_id = input("⭐ Source Server ID: ")
target_server_id = input("⭐ Target Server ID: ")
# Get source server information
source_scraper = Scrape(token, source_server_id)
source_data = source_scraper.get_data()
# Get target server information
target_scraper = Scrape(token, target_server_id)
target_data = target_scraper.get_data()
# Create the target server
target_creator = Create(token, source_data)
target_creator.all()
input("Press any key to exit...")