diff --git a/.gitignore b/.gitignore index 794323df..26d51596 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ api/runtimeconfig.json +database database/currency.json database/items.json database/isotokens.json @@ -7,7 +8,6 @@ database/presence.json database/user_data.json database/weather.json database/automod.json -database/isobank/* *.log *.pyc logs diff --git a/cogs/isocoin.py b/cogs/isocoin.py index 2baef25e..2ef0324c 100644 --- a/cogs/isocoin.py +++ b/cogs/isocoin.py @@ -3,11 +3,19 @@ # Imports import random import json +import os import discord from discord import ApplicationContext, SlashCommandGroup 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: + json.dump({}, f) + f.close() + with open("database/isotokens.json", 'r', encoding="utf-8") as f: isocoins = json.load(f) def save(): diff --git a/database/automod.json b/database/automod.json deleted file mode 100644 index 0967ef42..00000000 --- a/database/automod.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/database/currency.json b/database/currency.json deleted file mode 100644 index 0b8c97ac..00000000 --- a/database/currency.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "treasury": 10000000000, - "wallet": {}, - "bank": {} -} diff --git a/database/isobank/accounts.json b/database/isobank/accounts.json deleted file mode 100644 index 9e26dfee..00000000 --- a/database/isobank/accounts.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/database/isobank/auth.json b/database/isobank/auth.json deleted file mode 100644 index 9e26dfee..00000000 --- a/database/isobank/auth.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/database/isocard.json b/database/isocard.json deleted file mode 100644 index 0967ef42..00000000 --- a/database/isocard.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/database/isotokens.json b/database/isotokens.json deleted file mode 100644 index 0967ef42..00000000 --- a/database/isotokens.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/database/items.json b/database/items.json deleted file mode 100644 index 0967ef42..00000000 --- a/database/items.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/database/levels.json b/database/levels.json deleted file mode 100644 index 9e26dfee..00000000 --- a/database/levels.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/database/presence.json b/database/presence.json deleted file mode 100644 index 0967ef42..00000000 --- a/database/presence.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/database/user_data.json b/database/user_data.json deleted file mode 100644 index 0967ef42..00000000 --- a/database/user_data.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/database/weather.json b/database/weather.json deleted file mode 100644 index 0967ef42..00000000 --- a/database/weather.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/main.py b/main.py index 62c9793a..e9974207 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,7 @@ 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: - paths = ["database", "config", "logs", "themes"] + paths = ["database", "database/isobank", "config", "logs", "themes"] for p in paths: if not os.path.isdir(p): logger.warn(f"'{p}' directory appears to be missing. Created new directory for '{p}'.", module="main/Setup", nolog=True) @@ -40,16 +40,18 @@ def initial_setup(): # Generating database files try: - databases = ["automod", "currency", "isocard", "isotokens", "items", "levels", "presence", "user_data", "weather"] + databases = ["automod", "currency", "isocard", "items", "levels", "presence", "user_data", "weather", "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: - json.dump({"treasury": 1000000, "wallet": {}, "bank": {}}, f, encoding="utf-8") + json.dump({"treasury": 100000000, "wallet": {}, "bank": {}}, f) + f.close() else: with open(f"database/{f}.json", 'x', encoding="utf-8") as f: - json.dump({}, f, encoding="utf-8") + json.dump({}, f) + f.close() time.sleep(0.5) except IOError as e: logger.error(f"Failed to make database file: {e}", module="main/Setup")