Skip to content

Commit

Permalink
new_server_id removed from config.
Browse files Browse the repository at this point in the history
  • Loading branch information
itskekoff committed Jan 14, 2024
1 parent eb5d559 commit 2eff315
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ The main thing is just to go to the server.
Example commands:
* cp!clone - Copy the server in which the command was executed.
* cp!clone 0000000000000000000 - Copy the server whose ID was specified in the executed command.
* cp!clone 0 - Copy the server whose ID was specified.
* cp!clone new_server=0 - Copy the server in specified server id
* cp!clone 0 new_server=0 - Copy the server whose ID was specified but in new server that specified.
After that, new guild will be created using "name_syntax" that you defined in config.json
"name_syntax" supports only "%original" parameter
Expand Down
25 changes: 16 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ 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": 1.337,
Expand Down Expand Up @@ -126,8 +125,6 @@ def write_defaults(self):

LoggerSetup(debug_enabled=debug)

new_server_id: int = data.read("new_server_id")

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

name_syntax: str = clone_settings["name_syntax"]
Expand Down Expand Up @@ -294,7 +291,7 @@ async def clone_channels(self, perms: bool = True):
default_thread_slowmode_delay=channel.default_thread_slowmode_delay)
self.mappings["channels"][channel] = new_channel
if self.debug:
logger.debug("Created text channel {} | {}".format(new_channel.name, str(channel.id)))
logger.debug("Created text channel #{} | {}".format(new_channel.name, str(channel.id)))
elif isinstance(channel, discord.VoiceChannel):
bitrate = self.get_bitrate(channel)
new_channel = await self.new_guild.create_voice_channel(name=channel.name,
Expand All @@ -305,7 +302,7 @@ async def clone_channels(self, perms: bool = True):
overwrites=overwrites)
self.mappings["channels"][channel] = new_channel
if self.debug:
logger.debug("Created voice channel {} | {}".format(new_channel.name, str(channel.id)))
logger.debug("Created voice channel #{} | {}".format(new_channel.name, str(channel.id)))
await asyncio.sleep(self.delay)

async def process_community(self):
Expand Down Expand Up @@ -361,7 +358,7 @@ async def add_community_channels(self, perms: bool = True):
default_thread_slowmode_delay=channel.default_thread_slowmode_delay,
available_tags=tags)
if self.debug:
logger.debug("Created forum channel {} | {}".format(new_channel.name, str(channel.id)))
logger.debug("Created forum channel #{} | {}".format(new_channel.name, str(channel.id)))
if isinstance(channel, discord.StageChannel):
bitrate = self.get_bitrate(channel)
new_channel = await self.new_guild.create_stage_channel(name=channel.name,
Expand All @@ -374,7 +371,7 @@ async def add_community_channels(self, perms: bool = True):
overwrites=overwrites)

if self.debug:
logger.debug("Created stage channel {} | {}".format(new_channel.name, str(channel.id)))
logger.debug("Created stage channel #{} | {}".format(new_channel.name, str(channel.id)))
await asyncio.sleep(self.delay)

async def clone_emojis(self):
Expand Down Expand Up @@ -422,7 +419,7 @@ async def send_webhook(self, webhook: discord.Webhook, message: discord.Message,
username=name, embeds=message.embeds,
files=files)
if self.debug:
logger.debug("Cloned message from {}: {}".format(author.name, message.content))
logger.debug("Cloned message from @{}: {}".format(author.name, message.content))
except discord.errors.HTTPException:
if self.debug:
logger.debug("Can't send, skipping message in #{}".format(webhook.channel.name))
Expand Down Expand Up @@ -486,7 +483,7 @@ async def on_message(message: discord.Message):


@bot.command(name="copy", aliases=["clone", "paste", "parse", "start"])
async def copy(ctx: commands.Context, server_id: int = None):
async def copy(ctx: commands.Context, server_id: int = None, *, args: str = ""):
global cloner_instances, register_on_message
await ctx.message.delete()

Expand All @@ -496,6 +493,16 @@ async def copy(ctx: commands.Context, server_id: int = None):

start_time = time.time()

new_server_id = 0
for arg in args.split():
if arg.startswith("new_server="):
try:
new_server_id = int(arg.split("=")[1])
except ValueError:
logger.error("Invalid new server id format (required - int, provided - shit)")
return
break

if bot.get_guild(new_server_id) is None:
logger.info("Creating server...")
try:
Expand Down

0 comments on commit 2eff315

Please sign in to comment.