From ca7730748eda75c9a953945626ba880599dfb8f5 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 1 May 2024 10:40:39 +0530 Subject: [PATCH 1/4] Add some missing indents to `config.json` --- config.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config.json b/config.json index 1b1eeb8..c732735 100644 --- a/config.json +++ b/config.json @@ -1,12 +1,12 @@ { - "auth": { - "token": "" - }, - "config": { - "owner_name": "", - "logs": { - "snipe": true, - "editsnipe": true - } - } + "auth": { + "token": "" + }, + "config": { + "owner_name": "", + "logs": { + "snipe": true, + "editsnipe": true + } + } } From 15e780c5d2be82588eecf2625dced025ce3a75ac Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 1 May 2024 10:41:17 +0530 Subject: [PATCH 2/4] Add `config.json` to `.gitignore` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0dacca0..fdfb52e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ logs snipe.json editsnipe.json database.json +config.json From 132c15cc043a3bdfd6abf33d685b175f713de326 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 1 May 2024 10:49:53 +0530 Subject: [PATCH 3/4] Autogenerate `config.json` db if missing from client directory --- config.json | 12 ------------ framework/auth.py | 8 ++++++++ 2 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 config.json diff --git a/config.json b/config.json deleted file mode 100644 index c732735..0000000 --- a/config.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "auth": { - "token": "" - }, - "config": { - "owner_name": "", - "logs": { - "snipe": true, - "editsnipe": true - } - } -} diff --git a/framework/auth.py b/framework/auth.py index ea23a9b..050aa7d 100644 --- a/framework/auth.py +++ b/framework/auth.py @@ -1,6 +1,7 @@ """The authorization library for Discord Snipe Bot.""" # Imports import json +import os.path # Classes class Auth: @@ -15,6 +16,13 @@ def save(self, data: dict): def initial_setup(self): """Runs the bot's initial setup by generating a `config.json` file if missing, and asking for bot token/owner username if not provided.""" + # Generate config.json file if its missing. + if not os.path.isfile("config.json"): + with open("config.json", 'x', encoding="utf-8") as f: + json.dump({"auth": {"token": ""}, "config": {"owner_name": "", "logs": {"snipe": True, "editsnipe": True}}}, f) + f.close() + + # Ask for bot token and owner name, if missing from config.json file. config = self.load() if config["auth"]["token"] == "": confirmation = input("[!] No bot token was detected in config.json. Would you like to input a token? (Y/n): ") From 38a9ef5bd6f4ae4391f1ec74b2ccfe7a6145e8cd Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 1 May 2024 10:57:12 +0530 Subject: [PATCH 4/4] Rearrange `config.json` autogeneration from `initial_setup()` to `load()` --- framework/auth.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/framework/auth.py b/framework/auth.py index 050aa7d..e111813 100644 --- a/framework/auth.py +++ b/framework/auth.py @@ -7,6 +7,13 @@ class Auth: def load(self): """Loads the latest content from the database from machine local storage.""" + # Generate config.json file if its missing. + if not os.path.isfile("config.json"): + with open("config.json", 'x', encoding="utf-8") as f: + json.dump({"auth": {"token": ""}, "config": {"owner_name": "", "logs": {"snipe": True, "editsnipe": True}}}, f) + f.close() + + # Load config.json database with open("config.json", 'r', encoding="utf-8") as f: config = json.load(f) return config @@ -16,13 +23,6 @@ def save(self, data: dict): def initial_setup(self): """Runs the bot's initial setup by generating a `config.json` file if missing, and asking for bot token/owner username if not provided.""" - # Generate config.json file if its missing. - if not os.path.isfile("config.json"): - with open("config.json", 'x', encoding="utf-8") as f: - json.dump({"auth": {"token": ""}, "config": {"owner_name": "", "logs": {"snipe": True, "editsnipe": True}}}, f) - f.close() - - # Ask for bot token and owner name, if missing from config.json file. config = self.load() if config["auth"]["token"] == "": confirmation = input("[!] No bot token was detected in config.json. Would you like to input a token? (Y/n): ")