Skip to content

Commit

Permalink
big bug fixes, new help command
Browse files Browse the repository at this point in the history
  • Loading branch information
itskekoff committed Apr 28, 2024
1 parent 8fd57fa commit c356faf
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 81 deletions.
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,41 @@ Obtaining your Discord token is the first step:
(webpackChunkdiscord_app.push([[''],{},e=>{m=[];for(let c in e.c)m.push(e.c[c])}]),m).find(m=>m?.exports?.default?.getToken!==void 0).exports.default.getToken()
```
Executing start.bat sets up the required configuration. Adjust as needed and rerun start.bat.
### Creating Virtual Environment
```bash
python3 -m venv venv
source venv/bin/activate
```
### Getting started
Navigate to project directory and execute this commands:
```bash
pip install -r requirements.txt
python main.py
```
Within any guild, execute your clone command (default prefix is cp! as set in config.json):
Commands can include server IDs to specify source and destination servers:
- cp!clone duplicates the current server.
- cp!clone from=0 clones from the specified server.
- cp!clone new=0 directs cloning to the specified server.
- cp!clone from=0 new=0 dictates both source and destination servers.
- `cp!clone` duplicates the current server.
- `cp!clone from=0` clones from the specified server.
- `cp!clone new=0` directs cloning to the specified server.
- `cp!clone from=0 new=0` dictates both source and destination servers.
Config settings can be adjusted on-the-fly via clone commands, e.g.,
cp!clone from=1337 live_update=true clone_message=false
`cp!clone from=1337 live_update=true clone_message=false`
More detailed command help in "help" command, e.g. `cp!help`
### Arguments List
Use with default values from config.json or specify as needed:
1. from=0 – Source server ID
2. new=0 – Destination server ID
3. clear_guild=true/false – Whether to clear the new or specified guild
4. clone_icon=true/false – Clone server icon
5. ... and so on for other cloning aspects like roles, channels, banners, emojis, stickers, and messages with live updates.
1. `from=0` – Source server ID
2. `new=0` – Destination server ID
3. `clear_guild=true/false` – Whether to clear the new or specified guild
4. `clone_icon=true/false` – Clone server icon
5. ... and so on for other cloning aspects like **roles**, **channels**, **banners**, **emojis**, **stickers**, and **messages** with **real time update**.
## 📋 Requirements
- Python 3.10 (default) - also compatible with versions 3.9 (updated testing range).
Expand Down
25 changes: 21 additions & 4 deletions cogs/cloner.py → cogs/cloner_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@ def format_guild_name(target_guild: discord.Guild) -> str:
class ClonerCog(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot
self.cloners: list[ServerCopy] = []

@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if self.cloners:
for cloner in self.cloners:
await cloner.on_message(message=message)

@commands.command(name="copy", aliases=["clone", "paste", "parse", "start"])
async def copy(self, ctx: commands.Context, *, args_str: str = ""):
"""
Fully copies discord server including messages
Clones an entire Discord server, including all messages. Specifies behavior for the optional 'from' and 'new' arguments.
Main arguments:
- from (default: None): Specifies the source server ID for cloning. If omitted or set to None,
the server where the command is executed will be used as the source.
- new (default: None): Determines the name of the new cloned server. If omitted or set to None,
a new server with a default name will be created.
"""

await ctx.message.delete()
Expand All @@ -37,7 +51,7 @@ async def copy(self, ctx: commands.Context, *, args_str: str = ""):
"clone_emojis": main.clone_emojis,
"clone_stickers": main.clone_stickers,
"clone_messages": main.clone_messages_enabled,
"live_update": main.live_update_enabled
"real_time_messages": main.live_update_enabled
}

args = parse_args(args_str, defaults)
Expand All @@ -54,11 +68,12 @@ async def copy(self, ctx: commands.Context, *, args_str: str = ""):
to_guild=None,
delay=main.clone_delay,
webhook_delay=main.messages_delay,
live_update_toggled=args["live_update"],
live_update_toggled=args["real_time_messages"],
clone_messages_toggled=args["clone_messages"],
oldest_first=main.clone_oldest_first,
)
logger = cloner.logger
self.cloners.append(cloner)

if args["new"] is None or await self.bot.fetch_guild(args["new"]) is None:
logger.info("Creating server...")
Expand All @@ -80,7 +95,6 @@ async def copy(self, ctx: commands.Context, *, args_str: str = ""):
await new_guild.edit(name=target_name)

cloner.new_guild = new_guild
main.cloner_instances.append(cloner)

logger.info("Processing modules")

Expand Down Expand Up @@ -111,6 +125,9 @@ async def copy(self, ctx: commands.Context, *, args_str: str = ""):
logger.info(message)
await function()

if not args["real_time_messages"]:
self.cloners.remove(cloner)

logger.success(f"Done in {round((time.time() - start_time), 2)} seconds.")


Expand Down
19 changes: 12 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from modules.logger import Logger
from modules.configuration import Configuration, check_missing_keys
from modules.updater import Updater
from modules.utilities import get_command_info

VERSION = "1.4.1"
VERSION = "1.4.2"

config_path = "config.json"
data: Configuration = Configuration(config_path)
Expand Down Expand Up @@ -53,7 +54,7 @@
data.set_default(default=default_config)

logger = Logger()
logger.bind(server="CONFIGURATION")
logger.bind(source="Configuration")

if not data.file_exists(config_path):
data.write_defaults().flush()
Expand Down Expand Up @@ -114,8 +115,6 @@

logger = Logger(debug_enabled=debug)

cloner_instances = []

if clone_channels and (not clone_roles and clone_overwrites):
clone_roles = True
logger.warning(
Expand All @@ -131,6 +130,7 @@
logger.warning("Messages disabled because its limit is zero.")

bot = commands.Bot(command_prefix=prefix, case_insensitive=True, self_bot=True)
bot.remove_command('help')

logger.reset()

Expand All @@ -148,12 +148,17 @@ async def on_connect():

@bot.event
async def on_message(message: discord.Message):
if cloner_instances:
for instance in cloner_instances:
await instance.on_message(message=message)
await bot.process_commands(message)


@bot.command(name="help")
async def print_help(ctx: commands.Context):
"""
Displays help message
"""
await ctx.message.edit(content=f"```\n{get_command_info(bot)}```")


if __name__ == "__main__":
Updater(current_version=VERSION)
file_handler = logging.FileHandler(
Expand Down
Loading

0 comments on commit c356faf

Please sign in to comment.