-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserverclone.py
208 lines (189 loc) · 9.14 KB
/
serverclone.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
import discord
from colorama import Fore, init, Style
def print_add(message):
print(f'{Fore.GREEN}[+]{Style.RESET_ALL} {message}')
def print_delete(message):
print(f'{Fore.RED}[-]{Style.RESET_ALL} {message}')
def print_warning(message):
print(f'{Fore.RED}[WARNING]{Style.RESET_ALL} {message}')
def print_error(message):
print(f'{Fore.RED}[ERROR]{Style.RESET_ALL} {message}')
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"Silinen Rol: {role.name}")
except discord.Forbidden:
print_error(f"Rol Silinirken Hata olustu: {role.name}")
except discord.HTTPException:
print_error(f"Rol Silinemiyor: {role.name}")
@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] # ROLLER TERS OLUŞTUYSA " - " Yİ KALDIR
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"Oluşturulan Rol {role.name}")
except discord.Forbidden:
print_error(f"Rol Oluştururken Hata: {role.name}")
except discord.HTTPException:
print_error(f"Rol Oluşturulamıyor: {role.name}")
@staticmethod
async def channels_delete(guild_to: discord.Guild):
for channel in guild_to.channels:
try:
await channel.delete()
print_delete(f"Silinen Kanal: {channel.name}")
except discord.Forbidden:
print_error(f"Kanal Silinirken Hata: {channel.name}")
except discord.HTTPException:
print_error(f"Kanal Silinemiyor: {channel.name}")
@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"Oluşturulan Kategori: {channel.name}")
except discord.Forbidden:
print_error(f"Kategori Silinirken Hata: {channel.name}")
except discord.HTTPException:
print_error(f"Kategori Silinemiyor: {channel.name}")
@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:
print_warning(f"Kanalın {channel_text.name} herhangi bir kategorisi Yok Aktarım Devam Ediyor")
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"Oluşturulan Metin Kanalı: {channel_text.name}")
except discord.Forbidden:
print_error(f"Metin Kanalı Oluşturulurken Hata: {channel_text.name}")
except discord.HTTPException:
print_error(f"Metin Kanalı Oluşturulamıyor: {channel_text.name}")
except:
print_error(f"Metin Kanalı Oluşturulurken Hata: {channel_text.name}")
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"Kanalın {channel_voice.name} herhangi bir kategorisi Yok Aktarım Devam Ediyor")
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"Oluşturulan Ses Kanalı: {channel_voice.name}")
except discord.Forbidden:
print_error(f"Ses Kanalı Oluşturulurken Hata: {channel_voice.name}")
except discord.HTTPException:
print_error(f"Ses Kanalı Oluşturulamıyor: {channel_voice.name}")
except:
print_error(f"Ses Kanalı Oluşturulurken Hata: {channel_voice.name}")
@staticmethod
async def emojis_delete(guild_to: discord.Guild):
for emoji in guild_to.emojis:
try:
await emoji.delete()
print_delete(f"Silinen Emoji: {emoji.name}")
except discord.Forbidden:
print_error(f"Emoji Silinirken Hata Oluştu AMK{emoji.name}")
except discord.HTTPException:
print_error(f"Emoji Silinirken Hata Oluştu AMK {emoji.name}")
@staticmethod
async def emojis_create(guild_to: discord.Guild, guild_from: discord.Guild):
emoji: discord.Emoji
for emoji in guild_from.emojis:
try:
emoji_image = await emoji.url.read()
await guild_to.create_custom_emoji(
name=emoji.name,
image=emoji_image)
print_add(f"Oluşturulan Emoji {emoji.name}")
except discord.Forbidden:
print_error(f"Emoji Oluştururken Hata AMK {emoji.name} ")
except discord.HTTPException:
print_error(f"Emoji Oluştururken Hata AMK {emoji.name}")
@staticmethod
async def guild_edit(guild_to: discord.Guild, guild_from: discord.Guild):
try:
try:
icon_image = await guild_from.icon_url.read()
except discord.errors.DiscordException:
print_error(f"Simge görüntüsü okunamıyor AMK {guild_from.name}")
icon_image = None
await guild_to.edit(name=f'{guild_from.name}')
if icon_image is not None:
print_error(f"Sunucu Simgesini Değiştirirken Hata: {guild_to.name}")
except discord.Forbidden:
print_error(f"Sunucu Simgesini Değiştirirken Hata: {guild_to.name}")