fixing blackjack and improving lookup

This commit is contained in:
Nikolaj
2022-01-28 11:33:47 +01:00
parent cbf2ca765e
commit 05cd5831e1
10 changed files with 219 additions and 160 deletions

View File

@ -109,7 +109,7 @@ def get_options():
options: dict
The options of the bot.
"""
with open("options.txt", "r") as file_pointer:
with open("options.txt", "r", encoding="utf-8") as file_pointer:
data = sanitize(file_pointer.read(), True)
options = {}
@ -128,7 +128,7 @@ def get_credentials():
credentials: dict
The credentials used by the bot.
"""
with open("credentials.txt", "r") as file_pointer:
with open("credentials.txt", "r", encoding="utf-8") as file_pointer:
data = sanitize(file_pointer.read())
credentials = {}
@ -155,7 +155,8 @@ def long_strings():
data: dict
The long strings and their keys.
"""
with open("gwendolyn/resources/long_strings.json", "r") as file_pointer:
long_strings_path = "gwendolyn/resources/long_strings.json"
with open(long_strings_path, "r", encoding="utf-8") as file_pointer:
data = json.load(file_pointer)
return data
@ -170,7 +171,8 @@ def get_params():
params: dict
The parameters for every slash command.
"""
with open("gwendolyn/resources/slash_parameters.json", "r") as file_pointer:
path = "gwendolyn/resources/slash_parameters.json"
with open(path, "r", encoding="utf-8") as file_pointer:
slash_parameters = json.load(file_pointer)
options = get_options()
@ -256,14 +258,14 @@ def make_files():
"""Create json file if it doesn't exist."""
if not os.path.isfile(path):
log_this(path.split("/")[-1]+" didn't exist. Making it now.")
with open(path, "w") as file_pointer:
with open(path, "w", encoding="utf-8") as file_pointer:
json.dump(content, file_pointer, indent=4)
def make_txt_file(path, content):
"""Create txt file if it doesn't exist."""
if not os.path.isfile(path):
log_this(path.split("/")[-1]+" didn't exist. Making it now.")
with open(path, "w") as file_pointer:
with open(path, "w", encoding="utf-8") as file_pointer:
file_pointer.write(content)
def directory(path):
@ -272,7 +274,8 @@ def make_files():
os.makedirs(path)
log_this("The "+path.split("/")[-1]+" directory didn't exist")
with open("gwendolyn/resources/starting_files.json") as file_pointer:
file_path = "gwendolyn/resources/starting_files.json"
with open(file_path, "r", encoding="utf-8") as file_pointer:
data = json.load(file_pointer)
for path, content in data["json"].items():