From 0dbffe78aa34cdf105c80f7053e3ff6ee514a80d Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 19:40:26 +0530 Subject: [PATCH 01/10] Optimize some code in `initial_setup()` --- main.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index bcba8c2..226331b 100644 --- a/main.py +++ b/main.py @@ -65,15 +65,13 @@ def initial_setup(): "isobank/accounts", "isobank/auth" ) - for f in databases: - if not os.path.isfile(f"database/{f}.json"): - logger.warn(f"[main/Setup] '{f}.json' was not found in database directory. Creating new database...", module="main/Setup", nolog=True) - if f == "currency": - with open(f"database/{f}.json", 'x', encoding="utf-8") as f: + for _file in databases: + if not os.path.isfile(f"database/{_file}.json"): + logger.warn(f"[main/Setup] '{_file}.json' was not found in database directory. Creating new database...", module="main/Setup", nolog=True) + with open(f"database/{_file}.json", 'x', encoding="utf-8") as f: + if _file == "currency": json.dump({"treasury": 100000000, "wallet": {}, "bank": {}}, f) - f.close() - else: - with open(f"database/{f}.json", 'x', encoding="utf-8") as f: + else: json.dump({}, f) f.close() time.sleep(0.5) From 2a05fd563cf536b8d3d1b7ccf470e200578d4efe Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 19:41:15 +0530 Subject: [PATCH 02/10] Fix some indentation --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 226331b..b2cc79a 100644 --- a/main.py +++ b/main.py @@ -73,7 +73,7 @@ def initial_setup(): json.dump({"treasury": 100000000, "wallet": {}, "bank": {}}, f) else: json.dump({}, f) - f.close() + f.close() time.sleep(0.5) except IOError as e: logger.error(f"Failed to make database file: {e}", module="main/Setup") From 959291946334cd25d6fe2c031fe0e8533baf0dac Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 20:07:32 +0530 Subject: [PATCH 03/10] Set autogenerate for all databases, logs and config files to system home directory This helps reduce clutter in the main client directory. --- config_updater.py | 5 ++++- main.py | 37 +++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/config_updater.py b/config_updater.py index 52ed27c..e0a350e 100644 --- a/config_updater.py +++ b/config_updater.py @@ -17,12 +17,15 @@ import json from typing_extensions import Literal +# Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Configuration class UpdaterConfig: """This class contains the full configuration for the updater.""" update_server_target = "https://raw.githubusercontent.com/PyBotDevs/resources/refs/heads/base/isobot-config-data" use_raw_file_data = False - config_files_path = "config/" + config_files_path = f"{client_data_dir}/config/" config_files_list = ("commands.json", "shop.json", "words.json") # Functions diff --git a/main.py b/main.py index b2cc79a..baafb72 100644 --- a/main.py +++ b/main.py @@ -31,17 +31,22 @@ client = discord.Bot(intents=intents) color = discord.Color.random() start_time = "" +home_dir = os.path.expanduser('~') +client_data_dir = f"{home_dir}/.isobot" # Pre-Initialization Commands def initial_setup(): """Runs the initial setup for isobot's directories.\nThis creates missing directories, new log files, as well as new databases for any missing `.json` database files.""" # Create required client directories try: + if not os.path.isdir(f"{home_dir}/.isobot"): + os.mkdir(f"{home_dir}/.isobot") + paths = ("database", "database/isobank", "config", "logs", "themes") for p in paths: - if not os.path.isdir(p): + if not os.path.isdir(f"{client_data_dir}/{p}"): logger.warn(f"'{p}' directory appears to be missing. Created new directory for '{p}'.", module="main/Setup", nolog=True) - os.mkdir(p) + os.mkdir(f"{client_data_dir}/{p}") except OSError: logger.error(f"Failed to make directory: {e}", module="main/Setup") @@ -66,9 +71,9 @@ def initial_setup(): "isobank/auth" ) for _file in databases: - if not os.path.isfile(f"database/{_file}.json"): + if not os.path.isfile(f"{client_data_dir}/database/{_file}.json"): logger.warn(f"[main/Setup] '{_file}.json' was not found in database directory. Creating new database...", module="main/Setup", nolog=True) - with open(f"database/{_file}.json", 'x', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/{_file}.json", 'x', encoding="utf-8") as f: if _file == "currency": json.dump({"treasury": 100000000, "wallet": {}, "bank": {}}, f) else: @@ -90,29 +95,29 @@ def initial_setup(): # Generating client log files try: - if not os.path.isfile("logs/info-log.txt"): - with open('logs/info-log.txt', 'x', encoding="utf-8") as this: + if not os.path.isfile(f"{client_data_dir}/logs/info-log.txt"): + with open(f'{client_data_dir}/logs/info-log.txt', 'x', encoding="utf-8") as this: this.write("# All information and warnings will be logged here!\n") this.close() logger.info("Created info log", module="main/Setup", nolog=True) time.sleep(0.5) - if not os.path.isfile("logs/error-log.txt"): - with open('logs/error-log.txt', 'x', encoding="utf-8") as this: + if not os.path.isfile(f"{client_data_dir}/logs/error-log.txt"): + with open(f'{client_data_dir}/logs/error-log.txt', 'x', encoding="utf-8") as this: this.write("# All exceptions will be logged here!\n") this.close() logger.info("Created error log", module="main/Setup", nolog=True) time.sleep(0.5) - if not os.path.isfile("logs/currency.log"): - with open('logs/currency.log', 'x', encoding="utf-8") as this: + if not os.path.isfile(f"{client_data_dir}/logs/currency.log"): + with open(f'{client_data_dir}/logs/currency.log', 'x', encoding="utf-8") as this: this.close() logger.info("Created currency log", module="main/Setup", nolog=True) time.sleep(0.5) - if not os.path.isfile("logs/startup-log.txt"): - with open("logs/startup-log.txt", 'x', encoding="utf-8") as this: + if not os.path.isfile(f"{client_data_dir}/logs/startup-log.txt"): + with open(f"{client_data_dir}/logs/startup-log.txt", 'x', encoding="utf-8") as this: this.close() time.sleep(0.5) - if not os.path.isfile("logs/isocard_transactions.log"): - with open("logs/isocard_transactions.log", 'x', encoding="utf-8") as this: + if not os.path.isfile(f"{client_data_dir}/logs/isocard_transactions.log"): + with open(f"{client_data_dir}/logs/isocard_transactions.log", 'x', encoding="utf-8") as this: this.write("# All IsoCard transaction updates will be logged here.\n") this.close() time.sleep(0.5) @@ -123,8 +128,8 @@ def initial_setup(): # Framework Module Loader colors = colors.Colors() -s = logger.StartupLog("logs/startup-log.txt", clear_old_logs=True) -currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log") +s = logger.StartupLog(f"{client_data_dir}/logs/startup-log.txt", clear_old_logs=True) +currency = currency.CurrencyAPI(f"{client_data_dir}/database/currency.json", f"{client_data_dir}/logs/currency.log") settings = settings.Configurator() levelling = levelling.Levelling() items = items.Items() From 153266f77119ecac48222aa565cfffc5417a92f6 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 20:26:02 +0530 Subject: [PATCH 04/10] Add home dir database support for some modules --- cogs/afk.py | 4 +++- cogs/economy.py | 5 +++-- cogs/fun.py | 3 ++- cogs/isobank.py | 3 ++- cogs/isocard.py | 5 +++-- cogs/isocoin.py | 13 +++++++------ cogs/minigames.py | 3 ++- cogs/serverconfig.py | 7 ++++--- cogs/utils.py | 3 ++- framework/isobot/commands.py | 7 +++++-- framework/isobot/isocard.py | 11 ++++++----- framework/isobot/isocardtxn.py | 13 +++++++------ framework/isobot/settings.py | 18 ++++++++++-------- 13 files changed, 56 insertions(+), 39 deletions(-) diff --git a/cogs/afk.py b/cogs/afk.py index 7126d25..d91929f 100644 --- a/cogs/afk.py +++ b/cogs/afk.py @@ -3,12 +3,14 @@ # Imports import discord import json +import os from discord import option, ApplicationContext, SlashCommandGroup from discord.ext import commands from framework.isobot.db.presence import Presence # Variables -with open("database/presence.json", 'r', encoding="utf-8") as f: presence = json.load(f) +client_data_dir = f"{os.path.expanduser('~')}/.isobot" +with open(f"{client_data_dir}/database/presence.json", 'r', encoding="utf-8") as f: presence = json.load(f) presence = Presence() # Commands diff --git a/cogs/economy.py b/cogs/economy.py index 038c51e..20e14ef 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -15,12 +15,13 @@ from discord.ext import commands # Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" color = discord.Color.random() -currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log") +currency = framework.isobot.currency.CurrencyAPI(f"{client_data_dir}/database/currency.json", f"{client_data_dir}/logs/currency.log") levelling = levelling.Levelling() items = items.Items() userdata = userdata.UserData() -shop_data = ShopData("config/shop.json") +shop_data = ShopData(f"{client_data_dir}/config/shop.json") all_item_ids = shop_data.get_item_ids() shopitem = shop_data.get_raw_data() jobs = ( diff --git a/cogs/fun.py b/cogs/fun.py index cc4b1f2..8dd33d6 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -9,6 +9,7 @@ from discord.ext import commands # Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" color = discord.Color.random() # Functions @@ -24,7 +25,7 @@ def __init__(self, bot): async def stroketranslate(self, ctx: ApplicationContext, strok: str): if len(strok) > 300: return await ctx.respond("Please use no more than `300` character length", ephemeral=True) else: - with open(f"{os.getcwd()}/config/words.json", "r", encoding="utf-8") as f: words = json.load(f) + with open(f"{client_data_dir}/config/words.json", "r", encoding="utf-8") as f: words = json.load(f) var = str() s = strok.lower() for i, c in enumerate(s): var += random.choice(words[c]) diff --git a/cogs/isobank.py b/cogs/isobank.py index 18411ff..bf5446b 100644 --- a/cogs/isobank.py +++ b/cogs/isobank.py @@ -9,10 +9,11 @@ from framework.isobank import manager, authorize # Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" color = discord.Color.random() # Isobot Framework -isobankauth = authorize.IsobankAuth("database/isobank/auth.json", "database/isobank/accounts.json") +isobankauth = authorize.IsobankAuth(f"{client_data_dir}/database/isobank/auth.json", f"{client_data_dir}/database/isobank/accounts.json") # Commands class IsoBank(commands.Cog): diff --git a/cogs/isocard.py b/cogs/isocard.py index 8337990..a678d39 100644 --- a/cogs/isocard.py +++ b/cogs/isocard.py @@ -11,6 +11,7 @@ from discord.ext import commands # Variables and Functions +client_data_dir = f"{os.path.expanduser('~')}/.isobot" isocard_db = IsoCard() isocardtxn = IsoCardTxn() @@ -120,10 +121,10 @@ async def options_label(self, ctx: ApplicationContext, card_number: int, new_lab @option(name="verification_code", description="The 6-digit verification code for your transaction", type=int) async def verify_transaction(self, ctx: ApplicationContext, verification_code: int): try: - with open("database/isocard_transactions.json", 'r') as f: transactions_db = json.load(f) + with open(f"{client_data_dir}/database/isocard_transactions.json", 'r') as f: transactions_db = json.load(f) if transactions_db[str(verification_code)]["payer_id"] == ctx.author.id: transactions_db[str(verification_code)]["status"] = "complete" - with open("database/isocard_transactions.json", 'w+') as f: json.dump(transactions_db, f, indent=4) + with open(f"{client_data_dir}/database/isocard_transactions.json", 'w+') as f: json.dump(transactions_db, f, indent=4) localembed = discord.Embed( title="Transaction successfully verified.", description="Please wait patiently until the merchant has verified the transaction.", diff --git a/cogs/isocoin.py b/cogs/isocoin.py index 2ef0324..e76567a 100644 --- a/cogs/isocoin.py +++ b/cogs/isocoin.py @@ -9,17 +9,18 @@ from discord.ext import commands # Variables -if not os.path.isdir("database"): # TEMPORARY: Allow cog to handle "database" directory generation (for now) - os.mkdir("database") -if not os.path.isfile("database/isotokens.json"): # Generate database file, if missing. - with open("database/isotokens.json", 'x', encoding="utf-8") as f: +client_data_dir = f"{os.path.expanduser('~')}/.isobot" +# if not os.path.isdir("database"): # TEMPORARY: Allow cog to handle "database" directory generation (for now) +# os.mkdir("database") +if not os.path.isfile(f"{client_data_dir}/database/isotokens.json"): # Generate database file, if missing. + with open(f"{client_data_dir}/database/isotokens.json", 'x', encoding="utf-8") as f: json.dump({}, f) f.close() -with open("database/isotokens.json", 'r', encoding="utf-8") as f: isocoins = json.load(f) +with open(f"{client_data_dir}/database/isotokens.json", 'r', encoding="utf-8") as f: isocoins = json.load(f) def save(): - with open("database/isotokens.json", 'w+', encoding="utf-8") as f: json.dump(isocoins, f) + with open(f"{client_data_dir}/database/isotokens.json", 'w+', encoding="utf-8") as f: json.dump(isocoins, f) # Functions def create_isocoin_key(user_id: int) -> int: diff --git a/cogs/minigames.py b/cogs/minigames.py index 69d637f..5618265 100644 --- a/cogs/minigames.py +++ b/cogs/minigames.py @@ -8,8 +8,9 @@ from discord.ext import commands # Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" color = discord.Color.random() -currency = framework.isobot.currency.CurrencyAPI("database/currency.json", "logs/currency.log") +currency = framework.isobot.currency.CurrencyAPI(f"{client_data_dir}/database/currency.json", f"{client_data_dir}/logs/currency.log") # Commands class Minigames(commands.Cog): diff --git a/cogs/serverconfig.py b/cogs/serverconfig.py index 6364176..2ac845d 100644 --- a/cogs/serverconfig.py +++ b/cogs/serverconfig.py @@ -8,6 +8,7 @@ from framework.isobot.db import serverconfig # Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" serverconf = serverconfig.ServerConfig() # Functions @@ -16,7 +17,7 @@ def __init__(self, bot): self.bot = bot # Load Verification Database - with open("database/serververification.json", 'r', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/serververification.json", 'r', encoding="utf-8") as f: self.verification_db: dict = json.load(f) serverconfig_cmds = SlashCommandGroup(name="serverconfig", description="Commands related to server customization and configuration.") @@ -230,7 +231,7 @@ async def start_verification(self, ctx: ApplicationContext): return await ctx.respond("Your verification process is already ongoing in this server!", ephemeral=True) self.verification_db[str(ctx.author.id)][str(verify_code)] = {"guild_id": ctx.guild.id} - with open("database/serververification.json", 'w+', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/serververification.json", 'w+', encoding="utf-8") as f: json.dump(self.verification_db, f, indent=4) localembed = discord.Embed( @@ -260,7 +261,7 @@ async def verify(self, ctx: ApplicationContext, verification_code: int): await server_context_user.add_roles(verification_role, reason="Member has been successfully verified in server.") del self.verification_db[str(ctx.author.id)][str(verification_code)] - with open("database/serververification.json", 'w+', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/serververification.json", 'w+', encoding="utf-8") as f: json.dump(self.verification_db, f, indent=4) return await ctx.respond(f"You have been successfully verified in **{vcode_guild.name}**!") diff --git a/cogs/utils.py b/cogs/utils.py index 4e02265..bc07220 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -18,8 +18,9 @@ from framework.isobot.db.presence import Presence # Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" color = discord.Color.random() -currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log") +currency = currency.CurrencyAPI(f"{client_data_dir}/database/currency.json", f"{client_data_dir}/logs/currency.log") levelling = levelling.Levelling() _commands = cmds.Commands() _embeds = _embeds.Embeds() diff --git a/framework/isobot/commands.py b/framework/isobot/commands.py index 9014e99..f5b5bba 100644 --- a/framework/isobot/commands.py +++ b/framework/isobot/commands.py @@ -2,6 +2,9 @@ import json from framework.isobot.colors import Colors as colors +# Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Classes class Commands(): """The library used to fetch information about isobot commands, and manage them.""" @@ -10,12 +13,12 @@ def __init__(self): def load(self) -> dict: """Loads the latest content from the commands database onto memory.""" - with open("config/commands.json", 'r', encoding="utf-8") as f: data = json.load(f) + with open(f"{client_data_dir}/config/commands.json", 'r', encoding="utf-8") as f: data = json.load(f) return data def save(self, data: dict) -> int: """Saves the cached database to local machine storage.""" - with open("config/commands.json", 'w+', encoding="utf-8") as f: json.dump(data, f) + with open(f"{client_data_dir}/config/commands.json", 'w+', encoding="utf-8") as f: json.dump(data, f) return 0 def fetch_raw(self) -> dict: diff --git a/framework/isobot/isocard.py b/framework/isobot/isocard.py index c8af0e8..fe34291 100644 --- a/framework/isobot/isocard.py +++ b/framework/isobot/isocard.py @@ -11,20 +11,21 @@ from threading import Thread # Configuration +client_data_dir = f"{os.path.expanduser('~')}/.isobot" log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) app = Flask('') isocardtxn = isocardtxn_.IsoCardTxn() -currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log") +currency = currency.CurrencyAPI(f"{client_data_dir}/database/currency.json", f"{client_data_dir}/logs/currency.log") def call_isocards_database() -> dict: """Calls all of the latest information from the IsoCards database.""" - with open("database/isocard.json", 'r') as f: isocards = json.load(f) + with open(f"{client_data_dir}/database/isocard.json", 'r') as f: isocards = json.load(f) return isocards def save(data): """Dumps all cached databases to the local machine.""" - with open("database/isocard_transactions.json", 'w+') as f: json.dump(data, f, indent=4) + with open(f"{client_data_dir}/database/isocard_transactions.json", 'w+') as f: json.dump(data, f, indent=4) # Functions def generate_verification_code() -> int: @@ -57,7 +58,7 @@ def main(): def requestpayment(): try: isocards = call_isocards_database() - with open("database/isocard_transactions.json", 'r') as f: transactions_db = json.load(f) + with open(f"{client_data_dir}/database/isocard_transactions.json", 'r') as f: transactions_db = json.load(f) args = request.args card_number = args.get("cardnumber") ssc = args.get("ssc") @@ -103,7 +104,7 @@ def requestpayment(): @app.route('/checkpayment', methods=["GET"]) def checkpayment(): - with open("database/isocard_transactions.json", 'r') as f: transactions_db = json.load(f) + with open(f"{client_data_dir}/database/isocard_transactions.json", 'r') as f: transactions_db = json.load(f) try: args = request.args verification_code = args.get("verificationcode") diff --git a/framework/isobot/isocardtxn.py b/framework/isobot/isocardtxn.py index 0bcb234..c2e893f 100644 --- a/framework/isobot/isocardtxn.py +++ b/framework/isobot/isocardtxn.py @@ -5,6 +5,7 @@ from typing_extensions import Union # Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" log_file_path = "logs/isocard_transactions.log" # Initialization @@ -19,7 +20,7 @@ def read(self) -> dict: ### Note: This command should only be used for internal module use. ### To use this elsewhere, use the alternate command `fetch_raw()`. """ - with open("database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: txn_db = json.load(f) return txn_db @@ -35,7 +36,7 @@ def save(self, data: dict) -> int: ### If not successful: - Returns the respective exception class """ - with open("database/isocard_transaction_history.json", 'w+', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/isocard_transaction_history.json", 'w+', encoding="utf-8") as f: json.dump(data, f, indent=4) return 0 @@ -92,7 +93,7 @@ def read_transaction(self, txn_id: str) -> dict: ``` """ try: - with open("database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: txn_db = json.load(f) return txn_db[str(txn_id)] except KeyError: @@ -127,7 +128,7 @@ def write_transaction(self, txn_id: str, payer_id: str, merchant_id: str, card_n - Note: This format can be refered to, while working with the output from the `read_transaction()` command. """ - with open("database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: txn_db = json.load(f) txn_db[str(txn_id)] = { "payer_id": payer_id, @@ -154,7 +155,7 @@ def update_transaction_status(self, txn_id: str, new_status: str) -> int: - Returns `1` """ try: - with open("database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: txn_db = json.load(f) txn_db[str(txn_id)]["status"] = new_status self.save(txn_db) @@ -183,6 +184,6 @@ def fetch_raw(self) -> dict: } ``` """ - with open("database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: + with open(f"{client_data_dir}/database/isocard_transaction_history.json", 'r', encoding="utf-8") as f: txn_db = json.load(f) return txn_db diff --git a/framework/isobot/settings.py b/framework/isobot/settings.py index 5237b50..8330827 100644 --- a/framework/isobot/settings.py +++ b/framework/isobot/settings.py @@ -4,7 +4,9 @@ import json from typing import Union, Literal -# Classes and Functions +# Classes and Variables +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + class Colors: """Contains general stdout colors.""" cyan = '\033[96m' @@ -22,33 +24,33 @@ def generate(self, user_id: int) -> Literal[0, 1]: """Generates a new settings configuration for the specified user. Does not do anything if a configuration already exists.\n Returns 0 if the request was successful, returns 1 if the configuration already exists.""" - with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) + with open(f"{client_data_dir}/config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) if str(user_id) in db.keys(): return 1 template = { "levelup_messages": True } db[str(user_id)] = template - with open("config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4) + with open(f"{client_data_dir}/config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4) return 0 def fetch_setting(self, user_id: int, setting: str) -> Union[int, str, bool]: """Fetches the current value of a user setting.""" - with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) + with open(f"{client_data_dir}/config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) return db[str(user_id)][setting] def edit_setting(self, user_id: int, setting: str, value) -> Literal[0]: """Modifies the value of a user setting.""" - with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) + with open(f"{client_data_dir}/config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) db[str(user_id)][setting] = value - with open("config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4) + with open(f"{client_data_dir}/config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4) return 0 def reset(self, user_id: int): """Completely resets the specified user's configuration.""" - with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) + with open(f"{client_data_dir}/config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f) template = { "levelup_messages": True } db[str(user_id)] = template - with open("config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4) + with open(f"{client_data_dir}/config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4) return 0 From 848900be1a700504c5f68b347258f943537ae10e Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 20:32:26 +0530 Subject: [PATCH 05/10] Add home dir database support for some more modules --- framework/isobot/db/automod.py | 6 ++++-- framework/isobot/db/embeds.py | 6 ++++-- framework/isobot/db/isocard.py | 6 ++++-- framework/isobot/db/items.py | 7 ++++--- framework/isobot/db/levelling.py | 6 ++++-- framework/isobot/db/presence.py | 6 ++++-- framework/isobot/db/serverconfig.py | 6 ++++-- framework/isobot/db/userdata.py | 6 ++++-- framework/isobot/db/warnings.py | 6 ++++-- framework/isobot/db/weather.py | 6 ++++-- 10 files changed, 40 insertions(+), 21 deletions(-) diff --git a/framework/isobot/db/automod.py b/framework/isobot/db/automod.py index a929be1..c1a24b5 100644 --- a/framework/isobot/db/automod.py +++ b/framework/isobot/db/automod.py @@ -4,6 +4,8 @@ import json from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class Automod(): """Initializes the Automod database system.""" @@ -12,12 +14,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the items database.""" - with open("database/automod.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/automod.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/automod.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/automod.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def generate(self, server_id: int) -> int: diff --git a/framework/isobot/db/embeds.py b/framework/isobot/db/embeds.py index 7979a81..16d4a90 100644 --- a/framework/isobot/db/embeds.py +++ b/framework/isobot/db/embeds.py @@ -6,6 +6,8 @@ from typing_extensions import Union from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class Embeds(): """Initializes the Embed database system.""" @@ -14,12 +16,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the embeds database.""" - with open("database/embeds.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/embeds.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/embeds.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/embeds.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def generate_server_key(self, server_id: Union[str, int]) -> int: diff --git a/framework/isobot/db/isocard.py b/framework/isobot/db/isocard.py index 43b7a7c..82456c6 100644 --- a/framework/isobot/db/isocard.py +++ b/framework/isobot/db/isocard.py @@ -5,6 +5,8 @@ import time from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class IsoCard: def __init__(self): @@ -12,12 +14,12 @@ def __init__(self): def load(self) -> dict: """Loads the latest IsoCard database content from local storage.""" - with open("database/isocard.json", "r", encoding="utf-8") as f: data = json.load(f) + with open(f"{client_data_dir}/database/isocard.json", "r", encoding="utf-8") as f: data = json.load(f) return data def save(self, data: dict) -> int: """Saves the latest cached database to local storage.""" - with open("database/isocard.json", 'w+', encoding="utf-8") as f: json.dump(data, f, indent=4) + with open(f"{client_data_dir}/database/isocard.json", 'w+', encoding="utf-8") as f: json.dump(data, f, indent=4) return 0 def raw(self) -> dict: diff --git a/framework/isobot/db/items.py b/framework/isobot/db/items.py index 47d73c3..f156c9d 100644 --- a/framework/isobot/db/items.py +++ b/framework/isobot/db/items.py @@ -5,7 +5,8 @@ from framework.isobot.shop import ShopData # Variables -shop = ShopData("config/shop.json") +client_data_dir = f"{os.path.expanduser('~')}/.isobot" +shop = ShopData(f"{client_data_dir}/config/shop.json") shopitem = shop.get_item_ids() # Functions @@ -16,12 +17,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the items database.""" - with open("database/items.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/items.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/items.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/items.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def generate(self, user_id: int) -> int: diff --git a/framework/isobot/db/levelling.py b/framework/isobot/db/levelling.py index fd3f155..0d203ae 100644 --- a/framework/isobot/db/levelling.py +++ b/framework/isobot/db/levelling.py @@ -3,6 +3,8 @@ import json from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class Levelling(): """Used to initialize the levelling database.""" @@ -11,12 +13,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the levelling database.""" - with open("database/levels.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/levels.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/levels.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/levels.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def generate(self, user_id: int) -> int: diff --git a/framework/isobot/db/presence.py b/framework/isobot/db/presence.py index b06934d..a9e536c 100644 --- a/framework/isobot/db/presence.py +++ b/framework/isobot/db/presence.py @@ -5,6 +5,8 @@ import time from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class Presence(): """Used to initialize the User Presence system.""" @@ -13,12 +15,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the presence database.""" - with open("database/presence.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/presence.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/presence.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/presence.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def add_afk(self, guild_id: int, user_id: int, response: str) -> int: diff --git a/framework/isobot/db/serverconfig.py b/framework/isobot/db/serverconfig.py index fbebfcf..6560f27 100644 --- a/framework/isobot/db/serverconfig.py +++ b/framework/isobot/db/serverconfig.py @@ -5,6 +5,8 @@ from typing_extensions import Literal, Union from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class ServerConfig: def __init__(self): @@ -12,12 +14,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the items database.""" - with open("database/serverconfig.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/serverconfig.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/serverconfig.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/serverconfig.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def generate(self, server_id: int) -> int: diff --git a/framework/isobot/db/userdata.py b/framework/isobot/db/userdata.py index a352219..b72e43d 100644 --- a/framework/isobot/db/userdata.py +++ b/framework/isobot/db/userdata.py @@ -4,6 +4,8 @@ import json from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class UserData(): """Used to initialize the UserData system.""" @@ -12,12 +14,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the levelling database.""" - with open("database/user_data.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/user_data.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/user_data.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/user_data.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def generate(self, user_id: int) -> int: diff --git a/framework/isobot/db/warnings.py b/framework/isobot/db/warnings.py index 5c19bbd..97a7925 100644 --- a/framework/isobot/db/warnings.py +++ b/framework/isobot/db/warnings.py @@ -4,6 +4,8 @@ import json from framework.isobot.colors import Colors as colors +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class Warnings: """Used to initialize the warnings database.""" @@ -12,12 +14,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the warnings database.""" - with open("database/warnings.json", 'r', encoding="utf8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/warnings.json", 'r', encoding="utf8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/warnings.json", 'w+', encoding="utf8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/warnings.json", 'w+', encoding="utf8") as f: json.dump(data, f) return 0 def generate(self, guild_id: int, user_id: int) -> int: diff --git a/framework/isobot/db/weather.py b/framework/isobot/db/weather.py index e6cc069..2bdda91 100644 --- a/framework/isobot/db/weather.py +++ b/framework/isobot/db/weather.py @@ -3,6 +3,8 @@ from framework.isobot.colors import Colors as colors from discord import User +client_data_dir = f"{os.path.expanduser('~')}/.isobot" + # Functions class Weather(): """Class to manage the weather db""" @@ -11,12 +13,12 @@ def __init__(self): def load(self) -> dict: """Fetches and returns the latest data from the levelling database.""" - with open("database/weather.json", 'r', encoding="utf-8") as f: db = json.load(f) + with open(f"{client_data_dir}/database/weather.json", 'r', encoding="utf-8") as f: db = json.load(f) return db def save(self, data: dict) -> int: """Dumps all cached data to your local machine.""" - with open("database/weather.json", 'w+', encoding="utf-8") as f: json.dump(data, f) + with open(f"{client_data_dir}/database/weather.json", 'w+', encoding="utf-8") as f: json.dump(data, f) return 0 def new(self, user_id: User): From a03229e30374d523ca8b9f43c1bc3d58bced4460 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 20:45:05 +0530 Subject: [PATCH 06/10] Add home dir database support for more modules --- main.py | 8 ++++---- utils/logger.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index baafb72..ce00360 100644 --- a/main.py +++ b/main.py @@ -85,9 +85,9 @@ def initial_setup(): # Generating other files try: - if not os.path.isfile(f"config/settings.json"): + if not os.path.isfile(f"{client_data_dir}/config/settings.json"): logger.warn(f"[main/Setup] Settings database file was not found in config directory. Creating new database...", module="main/Setup", nolog=True) - with open(f"config/settings.json", 'x', encoding="utf-8") as f: + with open(f"{client_data_dir}/config/settings.json", 'x', encoding="utf-8") as f: json.dump({}, f) f.close() except IOError as e: @@ -141,11 +141,11 @@ def initial_setup(): weather = weather.Weather() embeds = embeds.Embeds() _commands = _commands.Commands() -shop_data = ShopData("config/shop.json") +shop_data = ShopData(f"{client_data_dir}/config/shop.json") # Theme Loader if api.auth.get_runtime_options()["themes"]: - with open("themes/halloween.theme.json", 'r', encoding="utf-8") as f: + with open(f"{client_data_dir}/themes/halloween.theme.json", 'r', encoding="utf-8") as f: theme = json.load(f) try: color_loaded = theme["theme"]["embed_color"] diff --git a/utils/logger.py b/utils/logger.py index 9f337d9..110276a 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -3,8 +3,9 @@ import datetime # Variables and Classes -log_path = "logs/info-log.txt" -error_path = "logs/error-log.txt" +client_data_dir = f"{os.path.expanduser('~')}/.isobot" +log_path = f"{client_data_dir}/logs/info-log.txt" +error_path = f"{client_data_dir}/logs/error-log.txt" class colours: error = '\033[91m' success = '\033[92m' From 51d0185b8a861b056a8202eb785211727d1f33bd Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 20:51:10 +0530 Subject: [PATCH 07/10] Add home dir database support for one last module --- framework/isobot/isocardtxn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/isobot/isocardtxn.py b/framework/isobot/isocardtxn.py index c2e893f..41891d3 100644 --- a/framework/isobot/isocardtxn.py +++ b/framework/isobot/isocardtxn.py @@ -6,7 +6,7 @@ # Variables client_data_dir = f"{os.path.expanduser('~')}/.isobot" -log_file_path = "logs/isocard_transactions.log" +log_file_path = f"{client_data_dir}/logs/isocard_transactions.log" # Initialization class IsoCardTxn: From f97211c0ca8c012eb627d3509203be1699321fac Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 21:01:20 +0530 Subject: [PATCH 08/10] Add missing required `os` imports for some modules --- cogs/economy.py | 1 + cogs/isobank.py | 1 + cogs/isocard.py | 1 + cogs/minigames.py | 1 + cogs/serverconfig.py | 1 + framework/isobot/commands.py | 1 + framework/isobot/db/automod.py | 1 + framework/isobot/db/embeds.py | 1 + framework/isobot/db/isocard.py | 1 + framework/isobot/db/items.py | 1 + framework/isobot/db/levelling.py | 1 + framework/isobot/db/presence.py | 1 + framework/isobot/db/serverconfig.py | 1 + framework/isobot/db/userdata.py | 1 + framework/isobot/db/warnings.py | 1 + framework/isobot/db/weather.py | 1 + framework/isobot/isocard.py | 1 + framework/isobot/isocardtxn.py | 1 + framework/isobot/settings.py | 1 + framework/logger.py | 2 +- utils/logger.py | 1 + 21 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cogs/economy.py b/cogs/economy.py index 20e14ef..dc09c06 100644 --- a/cogs/economy.py +++ b/cogs/economy.py @@ -5,6 +5,7 @@ import random import math import utils.logger +import os import asyncio import framework.isobot.currency import framework.isobot.algorithms diff --git a/cogs/isobank.py b/cogs/isobank.py index bf5446b..a1be55c 100644 --- a/cogs/isobank.py +++ b/cogs/isobank.py @@ -4,6 +4,7 @@ # Imports import discord import json +import os from discord import option, ApplicationContext from discord.ext import commands from framework.isobank import manager, authorize diff --git a/cogs/isocard.py b/cogs/isocard.py index a678d39..adb01f5 100644 --- a/cogs/isocard.py +++ b/cogs/isocard.py @@ -5,6 +5,7 @@ import random import json import math +import os from framework.isobot.isocardtxn import IsoCardTxn from framework.isobot.db.isocard import IsoCard from discord import option, ApplicationContext, SlashCommandGroup diff --git a/cogs/minigames.py b/cogs/minigames.py index 5618265..9def8c2 100644 --- a/cogs/minigames.py +++ b/cogs/minigames.py @@ -2,6 +2,7 @@ # Imports import discord +import os import framework.isobot.currency from random import randint from discord import ApplicationContext diff --git a/cogs/serverconfig.py b/cogs/serverconfig.py index 2ac845d..aab061f 100644 --- a/cogs/serverconfig.py +++ b/cogs/serverconfig.py @@ -2,6 +2,7 @@ import discord import random import json +import os from discord import option, ApplicationContext from discord.commands import SlashCommandGroup from discord.ext import commands diff --git a/framework/isobot/commands.py b/framework/isobot/commands.py index f5b5bba..77a2a9c 100644 --- a/framework/isobot/commands.py +++ b/framework/isobot/commands.py @@ -1,5 +1,6 @@ # Imports import json +import os from framework.isobot.colors import Colors as colors # Variables diff --git a/framework/isobot/db/automod.py b/framework/isobot/db/automod.py index c1a24b5..6641d2b 100644 --- a/framework/isobot/db/automod.py +++ b/framework/isobot/db/automod.py @@ -2,6 +2,7 @@ # Imports import json +import os from framework.isobot.colors import Colors as colors client_data_dir = f"{os.path.expanduser('~')}/.isobot" diff --git a/framework/isobot/db/embeds.py b/framework/isobot/db/embeds.py index 16d4a90..a29e39b 100644 --- a/framework/isobot/db/embeds.py +++ b/framework/isobot/db/embeds.py @@ -2,6 +2,7 @@ import json import discord import datetime +import os import framework.types from typing_extensions import Union from framework.isobot.colors import Colors as colors diff --git a/framework/isobot/db/isocard.py b/framework/isobot/db/isocard.py index 82456c6..6211664 100644 --- a/framework/isobot/db/isocard.py +++ b/framework/isobot/db/isocard.py @@ -3,6 +3,7 @@ # Imports import json import time +import os from framework.isobot.colors import Colors as colors client_data_dir = f"{os.path.expanduser('~')}/.isobot" diff --git a/framework/isobot/db/items.py b/framework/isobot/db/items.py index f156c9d..6e63b7e 100644 --- a/framework/isobot/db/items.py +++ b/framework/isobot/db/items.py @@ -1,6 +1,7 @@ """The framework module library used for managing isobot's items database.""" # Imports import json +import os from framework.isobot.colors import Colors as colors from framework.isobot.shop import ShopData diff --git a/framework/isobot/db/levelling.py b/framework/isobot/db/levelling.py index 0d203ae..c2ddc1d 100644 --- a/framework/isobot/db/levelling.py +++ b/framework/isobot/db/levelling.py @@ -1,6 +1,7 @@ """The framework module library used for managing isobot's levelling database.""" # Imports import json +import os from framework.isobot.colors import Colors as colors client_data_dir = f"{os.path.expanduser('~')}/.isobot" diff --git a/framework/isobot/db/presence.py b/framework/isobot/db/presence.py index a9e536c..a4a3cc4 100644 --- a/framework/isobot/db/presence.py +++ b/framework/isobot/db/presence.py @@ -3,6 +3,7 @@ # Imports import json import time +import os from framework.isobot.colors import Colors as colors client_data_dir = f"{os.path.expanduser('~')}/.isobot" diff --git a/framework/isobot/db/serverconfig.py b/framework/isobot/db/serverconfig.py index 6560f27..fd062e0 100644 --- a/framework/isobot/db/serverconfig.py +++ b/framework/isobot/db/serverconfig.py @@ -2,6 +2,7 @@ # Imports import json +import os from typing_extensions import Literal, Union from framework.isobot.colors import Colors as colors diff --git a/framework/isobot/db/userdata.py b/framework/isobot/db/userdata.py index b72e43d..21ccf5b 100644 --- a/framework/isobot/db/userdata.py +++ b/framework/isobot/db/userdata.py @@ -2,6 +2,7 @@ # Imports import json +import os from framework.isobot.colors import Colors as colors client_data_dir = f"{os.path.expanduser('~')}/.isobot" diff --git a/framework/isobot/db/warnings.py b/framework/isobot/db/warnings.py index 97a7925..20dea00 100644 --- a/framework/isobot/db/warnings.py +++ b/framework/isobot/db/warnings.py @@ -2,6 +2,7 @@ # Imports import json +import os from framework.isobot.colors import Colors as colors client_data_dir = f"{os.path.expanduser('~')}/.isobot" diff --git a/framework/isobot/db/weather.py b/framework/isobot/db/weather.py index 2bdda91..c6e1344 100644 --- a/framework/isobot/db/weather.py +++ b/framework/isobot/db/weather.py @@ -1,5 +1,6 @@ # Imports import json +import os from framework.isobot.colors import Colors as colors from discord import User diff --git a/framework/isobot/isocard.py b/framework/isobot/isocard.py index fe34291..17c30a2 100644 --- a/framework/isobot/isocard.py +++ b/framework/isobot/isocard.py @@ -3,6 +3,7 @@ import json import random import logging +import os from framework.isobot import isocardtxn as isocardtxn_ from api import auth from flask import Flask diff --git a/framework/isobot/isocardtxn.py b/framework/isobot/isocardtxn.py index 41891d3..0620545 100644 --- a/framework/isobot/isocardtxn.py +++ b/framework/isobot/isocardtxn.py @@ -2,6 +2,7 @@ import json import time import datetime +import os from typing_extensions import Union # Variables diff --git a/framework/isobot/settings.py b/framework/isobot/settings.py index 8330827..088aa01 100644 --- a/framework/isobot/settings.py +++ b/framework/isobot/settings.py @@ -2,6 +2,7 @@ # Imports import json +import os from typing import Union, Literal # Classes and Variables diff --git a/framework/logger.py b/framework/logger.py index 7e7f25e..a93c5e4 100644 --- a/framework/logger.py +++ b/framework/logger.py @@ -1,4 +1,4 @@ -import time, datetime +import time, datetime, os from isobot.colors import Colors class Logger(Colors): diff --git a/utils/logger.py b/utils/logger.py index 110276a..9ce6ba2 100644 --- a/utils/logger.py +++ b/utils/logger.py @@ -1,6 +1,7 @@ # Imports import time import datetime +import os # Variables and Classes client_data_dir = f"{os.path.expanduser('~')}/.isobot" From 45153d32073de3c819ce3e8e1d9c89a68d0aa325 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 21:05:13 +0530 Subject: [PATCH 09/10] Fix path for `config` directory generation --- config_updater.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config_updater.py b/config_updater.py index e0a350e..f6158ec 100644 --- a/config_updater.py +++ b/config_updater.py @@ -44,8 +44,8 @@ def check_for_updates() -> Literal[True]: Returns `True` if client-side process is successful. """ # Check if all config files exist, and download them if they don't - if not os.path.isdir("config"): - os.mkdir("config") + if not os.path.isdir(f"{client_data_dir}/config"): + os.mkdir(f"{client_data_dir}/config") for _file in UpdaterConfig.config_files_list: if not os.path.exists(UpdaterConfig.config_files_path + _file): From 56193b602446fb679ab1e27770435bedcff341fc Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Mar 2025 21:05:47 +0530 Subject: [PATCH 10/10] Remove a bunch of redundant matches from `.gitignore` --- .gitignore | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/.gitignore b/.gitignore index e96908b..68427f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,6 @@ api/runtimeconfig.json -database -database/currency.json -database/items.json -database/isotokens.json -database/levels.json -database/presence.json -database/user_data.json -database/weather.json -database/automod.json *.log *.pyc -logs -logs/currency.log -logs/error-log.txt -logs/info-log.txt -logs/startup-log.txt -config -config/settings.json -config/commands.json -config/shop.json -config/words.json __pycache__ *.bak venv