From 21a5f349023d906d553722f12e852b2c34f1c72c Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 10 Mar 2025 22:24:54 +0530 Subject: [PATCH 1/3] Set `api.auth` library to be imported after initial setup This is so that the `.isobot` data directory is guaranteed to exist before running the bot client. --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index ce00360..e53a88b 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,6 @@ import datetime import discord, discord.errors import asyncio -import api.auth import config_updater # Run Config Updater @@ -126,6 +125,9 @@ def initial_setup(): initial_setup() # Check for any missing sub-directories or databases in bot directory +# Import Client API Library +import api.auth + # Framework Module Loader colors = colors.Colors() s = logger.StartupLog(f"{client_data_dir}/logs/startup-log.txt", clear_old_logs=True) From a55d3496aed0967a2ff1b93f4663e68262a8960d Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 10 Mar 2025 22:25:24 +0530 Subject: [PATCH 2/3] Switch `runtimeconfig.json` path to `.isobot` directory --- api/auth.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/api/auth.py b/api/auth.py index 1cce69a..6438066 100644 --- a/api/auth.py +++ b/api/auth.py @@ -3,30 +3,26 @@ from typing_extensions import Literal # Config -wdir = os.getcwd() +wdir = f"{os.path.expanduser('~')}/.isobot" # Setup def load_config() -> dict: """Loads the runtimeconfig file and returns the contents as a `dict`.""" - with open(f'{wdir}/api/runtimeconfig.json', 'r') as f: + with open(f'{wdir}/runtimeconfig.json', 'r') as f: return json.load(f) def initial_setup() -> Literal[0]: # Building runtimeconfig files and directory IF missing: """Checks whether the required runtimeconfig files are present in the bot runtime directory.\n\nReturns `0` if successful.""" - if not os.path.isdir("api"): - print(f"[!] Runtimeconfig directory not found. Building runtime configuration files...") - print(" > [1/3] Creating client api directory...") - os.mkdir("api") - if not os.path.isfile("api/runtimeconfig.json"): + if not os.path.isfile(f"{wdir}/runtimeconfig.json"): print(f"[!] Runtimeconfig not found. Building runtime configuration files...") print(" > Creating runtimeconfig file...") - with open('api/runtimeconfig.json', 'x') as f: # Create a new file for runtimeconfig + with open(f'{wdir}/runtimeconfig.json', 'x') as f: # Create a new file for runtimeconfig json.dump({}, f) f.close() # Check whether any keys are missing in runtimeconfig file, and add them accordingly: - with open('api/runtimeconfig.json', 'r') as f: runtimeconfig_db = json.load(f) + with open(f'{wdir}/runtimeconfig.json', 'r') as f: runtimeconfig_db = json.load(f) required_keys = ("token", "alt_token_path", "secret", "public_key", "runtime_options", "replit", "other_keys") for key in required_keys: if key not in runtimeconfig_db: @@ -39,7 +35,7 @@ def initial_setup() -> Literal[0]: runtimeconfig_db[key] = False else: runtimeconfig_db[key] = "" - with open('api/runtimeconfig.json', 'w+') as f: json.dump(runtimeconfig_db, f, indent=4) + with open(f'{wdir}/runtimeconfig.json', 'w+') as f: json.dump(runtimeconfig_db, f, indent=4) default_runtime_option_values = { "themes": False, @@ -63,7 +59,7 @@ def initial_setup() -> Literal[0]: print(f"[!] Update available for runtimeconfig. Updating configuration...") runtimeconfig_db["other_keys"][key] = "" - with open('api/runtimeconfig.json', 'w+') as f: json.dump(runtimeconfig_db, f, indent=4) + with open(f'{wdir}/runtimeconfig.json', 'w+') as f: json.dump(runtimeconfig_db, f, indent=4) return 0 # Commands @@ -84,7 +80,7 @@ def get_token(): if arg1.lower() == "y" or arg1.lower() == "yes": arg2 = input("Enter your custom token: ") config["token"] = str(arg2) - with open(f'{wdir}/api/runtimeconfig.json', 'w+') as f: json.dump(config, f, indent=4) + with open(f'{wdir}/runtimeconfig.json', 'w+') as f: json.dump(config, f, indent=4) print("[✅] Setup successful!") elif arg1.lower() == "n" or arg1.lower() == "no": return return str(config["token"]) From 75a1733d6cbdf446f84544e70bb2f3de3c6f77b2 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Mon, 10 Mar 2025 22:26:18 +0530 Subject: [PATCH 3/3] Remove `runtimeconfig.json` from `.gitignore` --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 68427f6..c3e73a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -api/runtimeconfig.json *.log *.pyc __pycache__