Skip to content

Commit

Permalink
Partial new server get fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ultard committed Jul 6, 2023
1 parent 4f34e5f commit ea6665e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ def write_defaults(self):
"token": "Your discord account token",
"prefix": "cp!",
"debug": True,
"new_server_id": 0,
"clone_settings": {
"name_syntax": "%original-copy",
"clone_delay": 0.85,
"clear_guild": True,
"icon": True,
"roles": True,
"channels": True,
Expand Down Expand Up @@ -114,11 +116,13 @@ def write_defaults(self):
token: str = data.read("token")
prefix: str = data.read("prefix")
debug: bool = data.read("debug")
new_server_id: int = data.read("new_server_id")

clone_settings: dict = data.read("clone_settings")

name_syntax: str = clone_settings["name_syntax"]
clone_delay: float = clone_settings["clone_delay"]
clear_guild: bool = clone_settings["clear_guild"]
clone_icon: bool = clone_settings["icon"]
clone_roles: bool = clone_settings["roles"]
clone_channels: bool = clone_settings["channels"]
Expand Down Expand Up @@ -352,15 +356,25 @@ async def copy(ctx: commands.Context, server_id: int = None):
if guild is None and server_id is None:
return
start_time = time.time()
logger.info("Creating server...")
new_guild: discord.Guild = await bot.create_guild(name_syntax.replace("%original", guild.name))

if bot.get_guild(new_server_id) is None:
logger.info("Creating server...")
try:
new_guild: discord.Guild = await bot.create_guild(name_syntax.replace("%original", guild.name))
except:
logger.error("Unable to create server automaticly. Сreate it yourself and enter its id in the config \"new_server_id\"")
else:
logger.info("Getting server...")
new_guild: discord.Guild = bot.get_guild(new_server_id)

cloner: ServerCopy = ServerCopy(from_guild=guild, to_guild=new_guild,
delay=clone_delay, webhook_delay=messages_delay
)
cloner_instances.append(cloner)
logger.info("Processing modules")
logger.info("Preparing guild to process...")
await cloner.prepare_server()
if clear_guild:
logger.info("Preparing guild to process...")
await cloner.prepare_server()
if clone_icon:
logger.info("Cloning server icon...")
await cloner.clone_icon()
Expand Down

0 comments on commit ea6665e

Please sign in to comment.