From 7e5c4031c03cdf5f79976a064faefa70c6ad3742 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Sat, 19 Jun 2021 20:31:31 +0200 Subject: [PATCH] Check for non-existing files & init with default values fixes #63 --- files/default/hangman.json | 5 +++++ files/default/lastTasks.json | 9 +++++++++ files/default/locked.json | 4 ++++ files/default/lost.json | 4 ++++ files/default/stats.json | 19 +++++++++++++++++++ files/default/ufora_notifications.json | 12 ++++++++++++ startup/didier.py | 5 +++++ startup/init_files.py | 10 +++++++++- 8 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 files/default/hangman.json create mode 100644 files/default/lastTasks.json create mode 100644 files/default/locked.json create mode 100644 files/default/lost.json create mode 100644 files/default/stats.json create mode 100644 files/default/ufora_notifications.json diff --git a/files/default/hangman.json b/files/default/hangman.json new file mode 100644 index 0000000..6c20ddf --- /dev/null +++ b/files/default/hangman.json @@ -0,0 +1,5 @@ +{ + "guessed": [], + "guesses": 0, + "word": "" +} \ No newline at end of file diff --git a/files/default/lastTasks.json b/files/default/lastTasks.json new file mode 100644 index 0000000..bcf16cc --- /dev/null +++ b/files/default/lastTasks.json @@ -0,0 +1,9 @@ +{ + "interest": 0, + "lost": 0, + "poke": 0, + "prison": 0, + "birthdays": 0, + "channels": 0, + "remind": 0 +} \ No newline at end of file diff --git a/files/default/locked.json b/files/default/locked.json new file mode 100644 index 0000000..4b7fab0 --- /dev/null +++ b/files/default/locked.json @@ -0,0 +1,4 @@ +{ + "locked": false, + "until": -1 +} \ No newline at end of file diff --git a/files/default/lost.json b/files/default/lost.json new file mode 100644 index 0000000..57e53fe --- /dev/null +++ b/files/default/lost.json @@ -0,0 +1,4 @@ +{ + "lost": 0, + "today": 0 +} \ No newline at end of file diff --git a/files/default/stats.json b/files/default/stats.json new file mode 100644 index 0000000..d3ef932 --- /dev/null +++ b/files/default/stats.json @@ -0,0 +1,19 @@ +{ + "cf": { + "h": 0, + "t": 0 + }, + "dice": { + "2": 0, + "5": 0, + "3": 0, + "6": 0, + "1": 0, + "4": 0 + }, + "rob": { + "robs_success": 0, + "robs_failed": 0, + "bail_paid": 0.0 + } +} \ No newline at end of file diff --git a/files/default/ufora_notifications.json b/files/default/ufora_notifications.json new file mode 100644 index 0000000..0aa02a4 --- /dev/null +++ b/files/default/ufora_notifications.json @@ -0,0 +1,12 @@ +{ + "Algoritmen en Datastructuren 2": [], + "Communicatienetwerken": [], + "Computerarchitectuur": [], + "Functioneel Programmeren": [], + "Multimedia": [], + "Software Engineering Lab 1": [], + "Statistiek en Probabiliteit": [], + "Systeemprogrammeren": [], + "Webdevelopment": [], + "Wetenschappelijk Rekenen": [] +} \ No newline at end of file diff --git a/startup/didier.py b/startup/didier.py index c9d545d..9cd9874 100644 --- a/startup/didier.py +++ b/startup/didier.py @@ -1,5 +1,6 @@ from discord.ext import commands, ipc from settings import HOST_IPC +from startup.init_files import check_all import os @@ -22,8 +23,12 @@ class Didier(commands.Bot): # Remove default help command self.remove_command("help") + # Load all extensions self.init_extensions() + # Check missing files + check_all() + def init_extensions(self): # Load initial extensions for ext in self._preload: diff --git a/startup/init_files.py b/startup/init_files.py index eeecc55..451ad0a 100644 --- a/startup/init_files.py +++ b/startup/init_files.py @@ -1,5 +1,13 @@ +import json from os import path def check_all(): - pass + files = ["hangman", "lastTasks", "locked", "lost", "stats", "ufora_notifications"] + + for f in files: + if not path.isfile(path.join(f"files/{f}.json")): + with open(f"files/{f}.json", "w+") as new_file, open(f"files/default/{f}.json", "r") as default: + content = json.load(default) + json.dump(content, new_file) + print(f"Created missing file: files/{f}.json")