From fedf23fcbf4d16257e575f7842d7af8d39171bbc Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:36:06 +0530 Subject: [PATCH 1/6] Move `isotokens` database auto-generation to `isocoin` cog --- cogs/isocoin.py | 6 ++++++ main.py | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cogs/isocoin.py b/cogs/isocoin.py index 2baef25e..5ecaa5ef 100644 --- a/cogs/isocoin.py +++ b/cogs/isocoin.py @@ -3,11 +3,17 @@ # Imports import random import json +import os import discord from discord import ApplicationContext, SlashCommandGroup from discord.ext import commands # Variables +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/main.py b/main.py index 62c9793a..3b1c4c87 100644 --- a/main.py +++ b/main.py @@ -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"] 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": 1000000, "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") From 47e6e433e5b9cd39bb56dc0707df5f1f8aea9c3c Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:43:16 +0530 Subject: [PATCH 2/6] Allow `isocoin` cog to temporarily handle `database` dir generation --- cogs/isocoin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cogs/isocoin.py b/cogs/isocoin.py index 5ecaa5ef..2ef0324c 100644 --- a/cogs/isocoin.py +++ b/cogs/isocoin.py @@ -9,6 +9,8 @@ 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) From 66bc86120f3e53b4b8d2e34ff4469dcf2182565e Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:48:50 +0530 Subject: [PATCH 3/6] Fix base isobot currency treasury amount --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 3b1c4c87..02c69cfc 100644 --- a/main.py +++ b/main.py @@ -46,7 +46,7 @@ def initial_setup(): 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) + json.dump({"treasury": 100000000, "wallet": {}, "bank": {}}, f) f.close() else: with open(f"database/{f}.json", 'x', encoding="utf-8") as f: From e73074b7a7051f596dee8bc3bfcddf2eb5fb8e82 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:53:28 +0530 Subject: [PATCH 4/6] Add database autogeneration for all `isobank/` dbs --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 02c69cfc..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,7 +40,7 @@ def initial_setup(): # Generating database files try: - databases = ["automod", "currency", "isocard", "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) From b090b0d166c262e0f0f1c9d096554851ddc96193 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:54:44 +0530 Subject: [PATCH 5/6] Remove all manually-generated bot databases --- database/automod.json | 1 - database/currency.json | 5 ----- database/isobank/accounts.json | 1 - database/isobank/auth.json | 1 - database/isocard.json | 1 - database/isotokens.json | 1 - database/items.json | 1 - database/levels.json | 1 - database/presence.json | 1 - database/user_data.json | 1 - database/weather.json | 1 - 11 files changed, 15 deletions(-) delete mode 100644 database/automod.json delete mode 100644 database/currency.json delete mode 100644 database/isobank/accounts.json delete mode 100644 database/isobank/auth.json delete mode 100644 database/isocard.json delete mode 100644 database/isotokens.json delete mode 100644 database/items.json delete mode 100644 database/levels.json delete mode 100644 database/presence.json delete mode 100644 database/user_data.json delete mode 100644 database/weather.json 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 @@ -{} From 899cfae8149d3cddded5b8cb99aa54aa9aca845c Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:56:09 +0530 Subject: [PATCH 6/6] Add autogenerated db patterns to `.gitignore` --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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