From 2eff315a16936a8b326ce91e0290956a54a4f2c9 Mon Sep 17 00:00:00 2001 From: itskekoff Date: Sun, 14 Jan 2024 20:55:25 +1000 Subject: [PATCH] new_server_id removed from config. --- README.md | 4 +++- main.py | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index eb478c9..e248c03 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.py b/main.py index 8d0bbc5..751194f 100644 --- a/main.py +++ b/main.py @@ -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, @@ -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"] @@ -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, @@ -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): @@ -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, @@ -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): @@ -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)) @@ -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() @@ -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: