mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add config compare to not overwrite user changes
This commit is contained in:
parent
a96753d3a7
commit
3f2e50a5dd
@ -376,6 +376,38 @@ class Helpers:
|
||||
|
||||
return default_return
|
||||
|
||||
def set_settings(self, data):
|
||||
try:
|
||||
with open(self.settings_file, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=4)
|
||||
|
||||
except Exception as e:
|
||||
logger.critical(
|
||||
f"Config File Error: Unable to read {self.settings_file} due to {e}"
|
||||
)
|
||||
Console.critical(
|
||||
f"Config File Error: Unable to read {self.settings_file} due to {e}"
|
||||
)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def get_all_settings(self):
|
||||
try:
|
||||
with open(self.settings_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
except Exception as e:
|
||||
data = {}
|
||||
logger.critical(
|
||||
f"Config File Error: Unable to read {self.settings_file} due to {e}"
|
||||
)
|
||||
Console.critical(
|
||||
f"Config File Error: Unable to read {self.settings_file} due to {e}"
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
def set_setting(self, key, new_value):
|
||||
try:
|
||||
with open(self.settings_file, "r", encoding="utf-8") as f:
|
||||
|
@ -243,6 +243,52 @@ class Controller:
|
||||
exec_user["user_id"], "support_status_update", results
|
||||
)
|
||||
|
||||
def get_config_diff(self):
|
||||
master_config = {
|
||||
"config_ver": 1,
|
||||
"http_port": 8000,
|
||||
"https_port": 8443,
|
||||
"language": "en_EN",
|
||||
"cookie_expire": 30,
|
||||
"cookie_secret": "random",
|
||||
"apikey_secret": "random",
|
||||
"show_errors": True,
|
||||
"history_max_age": 7,
|
||||
"stats_update_frequency": 30,
|
||||
"delete_default_json": False,
|
||||
"show_contribute_link": True,
|
||||
"virtual_terminal_lines": 70,
|
||||
"max_log_lines": 700,
|
||||
"max_audit_entries": 300,
|
||||
"disabled_language_files": ["lol_EN.json", ""],
|
||||
"stream_size_GB": 1,
|
||||
"keywords": ["help", "chunk"],
|
||||
"allow_nsfw_profile_pictures": False,
|
||||
"enable_user_self_delete": False,
|
||||
}
|
||||
user_config = self.helper.get_all_settings()
|
||||
try:
|
||||
if user_config["config_ver"] == master_config["config_ver"]:
|
||||
return user_config
|
||||
else:
|
||||
user_config["config_ver"] = master_config["config_ver"]
|
||||
except:
|
||||
logger.debug("No config version found")
|
||||
items_to_del = []
|
||||
|
||||
for key in user_config:
|
||||
if key not in master_config.keys():
|
||||
items_to_del.append(key)
|
||||
|
||||
for item in items_to_del[:]:
|
||||
del user_config[item]
|
||||
|
||||
for key, value in master_config.items():
|
||||
if key not in user_config.keys():
|
||||
user_config[key] = value
|
||||
|
||||
self.helper.set_settings(user_config)
|
||||
|
||||
def send_log_status(self):
|
||||
try:
|
||||
return self.log_stats
|
||||
|
Loading…
Reference in New Issue
Block a user