-
Notifications
You must be signed in to change notification settings - Fork 11
/
serverclone.py
212 lines (193 loc) · 9.2 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
209
210
211
212
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"Deleted Role: {role.name}")
except discord.Forbidden:
print_error(f"Error While Deleting Role: {role.name}")
except discord.HTTPException:
print_error(f"Unable to Delete Role: {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]
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"Created Role {role.name}")
except discord.Forbidden:
print_error(f"Error While Creating Role: {role.name}")
except discord.HTTPException:
print_error(f"Unable to Create Role: {role.name}")
@staticmethod
async def channels_delete(guild_to: discord.Guild):
for channel in guild_to.channels:
try:
await channel.delete()
print_delete(f"Deleted Channel: {channel.name}")
except discord.Forbidden:
print_error(f"Error While Deleting Channel: {channel.name}")
except discord.HTTPException:
print_error(f"Unable To Delete Channel: {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"Created Category: {channel.name}")
except discord.Forbidden:
print_error(f"Error While Deleting Category: {channel.name}")
except discord.HTTPException:
print_error(f"Unable To Delete Category: {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"Channel {channel_text.name} doesn't have any category!")
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"Created Text Channel: {channel_text.name}")
except discord.Forbidden:
print_error(f"Error While Creating Text Channel: {channel_text.name}")
except discord.HTTPException:
print_error(f"Unable To Creating Text Channel: {channel_text.name}")
except:
print_error(f"Error While Creating Text Channel: {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"Channel {channel_voice.name} doesn't have any category!")
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"Created Voice Channel: {channel_voice.name}")
except discord.Forbidden:
print_error(f"Error While Creating Voice Channel: {channel_voice.name}")
except discord.HTTPException:
print_error(f"Unable To Creating Voice Channel: {channel_voice.name}")
except:
print_error(f"Error While Creating Voice Channel: {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"Deleted Emoji: {emoji.name}")
except discord.Forbidden:
print_error(f"Error While Deleting Emoji{emoji.name}")
except discord.HTTPException:
print_error(f"Error While Deleting Emoji {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"Created Emoji {emoji.name}")
except discord.Forbidden:
print_error(f"Error While Creating Emoji {emoji.name} ")
except discord.HTTPException:
print_error(f"Error While Creating Emoji {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"Can't read icon image from {guild_from.name}")
icon_image = None
await guild_to.edit(name=f'{guild_from.name}')
if icon_image is not None:
try:
await guild_to.edit(icon=icon_image)
print_add(f"Guild Icon Changed: {guild_to.name}")
except:
print_error(f"Error While Changing Guild Icon: {guild_to.name}")
except discord.Forbidden:
print_error(f"Error While Changing Guild Icon: {guild_to.name}")