-
Notifications
You must be signed in to change notification settings - Fork 532
/
cloner.py
327 lines (307 loc) · 14.1 KB
/
cloner.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
import discord
import asyncio
import random
import requests
from colorama import Fore, init, Style
class Clone:
@staticmethod
async def roles_delete(guild_to: discord.Guild):
for role in guild_to.roles:
try:
if role.name != "@everyone":
await role.delete()
print_delete(
f"O cargo {Fore.YELLOW}{role.name}{Fore.BLUE} Foi deletado"
)
await asyncio.sleep(random.randint(0.15, 0.10))
except discord.Forbidden:
print_error(
f"Erro ao excluir o cargo: {Fore.YELLOW}{role.name}{Fore.RED} Permissões insuficientes.{Fore.RESET}"
)
except discord.HTTPException as e:
if e.status == 429:
print_warning(
f"Muitas solicitações foram feitas. Esperando 60 segundos. Detalhes: {e}"
)
await asyncio.sleep(60)
@staticmethod
async def roles_create(guild_to: discord.Guild, guild_from: discord.Guild):
roles = []
role: discord.Role
for role in guild_from.roles:
if role.name != "@everyone":
roles.append(role)
roles = roles[::-1]
for role in roles:
try:
await guild_to.create_role(name=role.name,
permissions=role.permissions,
colour=role.colour,
hoist=role.hoist,
mentionable=role.mentionable)
print_add(
f"O cargo {Fore.YELLOW}{role.name}{Fore.BLUE} Foi criado")
await asyncio.sleep(random.uniform(0.3, 0.6))
except discord.Forbidden:
print_error(
f"Erro ao criar o cargo: {Fore.YELLOW}{role.name}{Fore.RED} Permissões insuficientes.{Fore.RESET}"
)
await asyncio.sleep(random.randint(0.20, 0.40))
except discord.HTTPException as e:
if e.status == 429:
print_warning(
f"Muitas solicitações foram feitas. Esperando 60 segundos. Detalhes: {e}"
)
await asyncio.sleep(60)
@staticmethod
async def channels_delete(guild_to: discord.Guild):
for channel in guild_to.channels:
try:
await channel.delete()
print_delete(
f"A categoria {Fore.YELLOW}{channel.name}{Fore.BLUE} Foi deletado"
)
await asyncio.sleep(0.6)
except discord.Forbidden:
print_error(
f"Erro ao excluir a categoria: {Fore.YELLOW}{channel.name}{Fore.RED} Permissões insuficientes.{Fore.RESET}"
)
await asyncio.sleep(random.randint(2, 3))
except discord.HTTPException as e:
if e.status == 429:
print_warning(
f"Muitas solicitações foram feitas. Esperando 60 segundos. Detalhes: {e}"
)
await asyncio.sleep(60)
except:
print_error(
f"Não foi possivel excluir o canal {Fore.YELLOW}{channel.name}{Fore.RED} Erro não identificado"
)
await asyncio.sleep(random.randint(9, 12))
@staticmethod
async def categories_create(guild_to: discord.Guild,
guild_from: discord.Guild):
channels = guild_from.categories
channel: discord.CategoryChannel
new_channel: discord.CategoryChannel
for channel in channels:
try:
overwrites_to = {}
for key, value in channel.overwrites.items():
role = discord.utils.get(guild_to.roles, name=key.name)
overwrites_to[role] = value
new_channel = await guild_to.create_category(
name=channel.name, overwrites=overwrites_to)
await new_channel.edit(position=channel.position)
print_add(
f"A categoria {Fore.YELLOW}{channel.name}{Fore.BLUE} Foi criada"
)
await asyncio.sleep(random.randint(1, 3))
except discord.Forbidden:
print_error(
f"Erro ao criar a categoria: {Fore.YELLOW}{channel.name}{Fore.RED} Permissões insuficientes.{Fore.RESET}"
)
await asyncio.sleep(random.randint(2, 3))
except discord.HTTPException as e:
if e.status == 429:
print_warning(
f"Muitas solicitações foram feitas. Esperando 60 segundos. Detalhes: {e}"
)
await asyncio.sleep(60)
except:
print_error(
f"Não foi possivel criar a categoria {Fore.YELLOW}{channel.name}{Fore.RED} Erro não identificado"
)
await asyncio.sleep(random.randint(9, 12))
@staticmethod
async def channels_create(guild_to: discord.Guild,
guild_from: discord.Guild):
channel_text: discord.TextChannel
channel_voice: discord.VoiceChannel
category = None
for channel_text in guild_from.text_channels:
try:
for category in guild_to.categories:
try:
if category.name == channel_text.category.name:
break
except AttributeError:
category = None
break
overwrites_to = {}
for key, value in channel_text.overwrites.items():
role = discord.utils.get(guild_to.roles, name=key.name)
overwrites_to[role] = value
try:
new_channel = await guild_to.create_text_channel(
name=channel_text.name,
overwrites=overwrites_to,
position=channel_text.position,
topic=channel_text.topic,
slowmode_delay=channel_text.slowmode_delay,
nsfw=channel_text.nsfw)
except:
new_channel = await guild_to.create_text_channel(
name=channel_text.name,
overwrites=overwrites_to,
position=channel_text.position)
if category is not None:
await new_channel.edit(category=category)
print_add(
f"O canal de texto {Fore.YELLOW}{channel_text.name}{Fore.BLUE} Foi criado"
)
await asyncio.sleep(0.59)
except discord.Forbidden:
print_error(
f"Erro ao criar canal de texto: {channel_text.name}")
await asyncio.sleep(random.randint(8, 10))
except discord.HTTPException as e:
if e.status == 429:
print_warning(
f"Muitas solicitações foram feitas. Esperando 60 segundos. Detalhes: {e}"
)
await asyncio.sleep(60)
new_channel = await guild_to.create_text_channel(
name=channel_text.name,
overwrites=overwrites_to,
position=channel_text.position)
if category is not None:
await new_channel.edit(category=category)
print_add(
f"O canal {Fore.YELLOW}{channel_text.name}{Fore.BLUE} Foi criado"
)
except:
print_error(
f"Erro ao criar canal de texto: {channel_text.name}")
await asyncio.sleep(random.randint(9, 12))
category = None
for channel_voice in guild_from.voice_channels:
try:
for category in guild_to.categories:
try:
if category.name == channel_voice.category.name:
break
except AttributeError:
print_warning(
f"Canal de voz {channel_voice.name} não tem nenhuma categoria!"
)
category = None
break
overwrites_to = {}
for key, value in channel_voice.overwrites.items():
role = discord.utils.get(guild_to.roles, name=key.name)
overwrites_to[role] = value
try:
new_channel = await guild_to.create_voice_channel(
name=channel_voice.name,
overwrites=overwrites_to,
position=channel_voice.position,
bitrate=channel_voice.bitrate,
user_limit=channel_voice.user_limit,
)
except:
new_channel = await guild_to.create_voice_channel(
name=channel_voice.name,
overwrites=overwrites_to,
position=channel_voice.position)
if category is not None:
await new_channel.edit(category=category)
print_add(
f"O canal de voz {Fore.YELLOW}{channel_voice.name}{Fore.BLUE} Foi criado"
)
await asyncio.sleep(0.48)
except discord.Forbidden:
print_error(
f"Erro ao criar o canal de voz: {channel_voice.name}")
await asyncio.sleep(random.randint(6, 7))
except discord.HTTPException as e:
if e.status == 429:
print_warning(
f"Muitas solicitações foram feitas. Esperando 60 segundos. Detalhes: {e}"
)
await asyncio.sleep(60)
new_channel = await guild_to.create_voice_channel(
name=channel_voice.name,
overwrites=overwrites_to,
position=channel_voice.position)
if category is not None:
await new_channel.edit(category=category)
print_add(
f"O canal de voz {Fore.YELLOW}{channel_voice.name}{Fore.BLUE} Foi criado"
)
except:
print_error(
f"Erro ao criar o canal de voz: {channel_voice.name}")
@staticmethod
async def emojis_create(guild_to: discord.Guild,
guild_from: discord.Guild):
emojis = guild_from.emojis
if not emojis:
print_warning("Nenhum emoji encontrado.")
return
for emoji in guild_from.emojis:
try:
existing_emoji = discord.utils.get(guild_to.emojis,
name=emoji.name)
if existing_emoji:
print_add(
f"Já existe um emoji com o nome {Fore.YELLOW}{emoji.name}{Fore.BLUE} no servidor."
)
else:
emoji_url = str(emoji.url)
response = requests.get(emoji_url)
emoji_image = response.content
await guild_to.create_custom_emoji(name=emoji.name,
image=emoji_image)
print_add(
f"O emoji {Fore.YELLOW}{emoji.name}{Fore.BLUE} foi criado."
)
await asyncio.sleep(1)
except discord.Forbidden:
print_error(
f"Erro ao criar o emoji: {Fore.YELLOW}{emoji.name}{Fore.RED} Permissões insuficientes.{Fore.RESET}"
)
await asyncio.sleep(random.uniform(2, 3))
except discord.HTTPException as e:
if e.status == 429:
print_warning(
f"Muitas solicitações foram feitas. Esperando 10 segundos. Detalhes: {e}"
)
await asyncio.sleep(10)
await guild_to.create_custom_emoji(name=emoji.name,
image=emoji_image)
except Exception:
print_warning(f"Ocorreu um erro em {emoji.name}")
except asyncio.TimeoutError:
print_error(f"Ocorreu um erro em {emoji.name} TimeOut")
@staticmethod
async def guild_edit(guild_to: discord.Guild, guild_from: discord.Guild):
try:
try:
icon_content = requests.get(guild_from.icon_url).content
except requests.exceptions.RequestException:
print_error(
f"Não é possível baixar o ícone de {guild_from.name}")
icon_content = None
await guild_to.edit(name=guild_from.name)
if icon_content is not None:
try:
await guild_to.edit(icon=icon_content)
print_add(f"Ícone do grupo Alterado: {guild_to.name}")
except:
print_error(
f"Erro ao alterar o ícone do grupo: {guild_to.name}")
except discord.LoginFailure:
print(
"Não foi possível autenticar na conta. Verifique se o token está correto."
)
except discord.Forbidden:
print_error(f"Erro ao alterar o ícone do grupo: {guild_to.name}")
def print_add(message):
print(f'{Style.BRIGHT}{Fore.CYAN} {message}{Fore.RESET}')
def print_delete(message):
print(f'{Style.BRIGHT}{Fore.CYAN} {message}{Fore.RESET}')
def print_warning(message):
print(f'{Style.BRIGHT}{Fore.YELLOW} {message}{Fore.RESET}')
def print_error(message):
print(f'{Style.BRIGHT}{Fore.RED} {message}{Fore.RESET}')