#195 Add config mitigation for new settings

This commit is contained in:
Frisk 2021-04-16 20:37:09 +02:00
parent 8abd8dfd23
commit 065d67c90c
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
3 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,23 @@
from src.configloader import settings
import logging
from src.migrations.utils import return_example_file
logger = logging.getLogger("rcgcdw.migrations.1.13.1.1")
base_file = return_example_file()
new_settings = settings.copy()
def run():
if "event_appearance" not in settings:
try:
settings["event_appearance"] = {}
struct = settings['appearance']['embed']
for key, value in struct.items():
settings["event_appearance"][key] = value
settings["event_appearance"][key]["emoji"] = base_file["event_appearance"]
except KeyError:
logger.error("Failed to migrate appearance embed.")
else: # Don't do migrations
return

View file

18
src/migrations/utils.py Normal file
View file

@ -0,0 +1,18 @@
import requests
import logging
import json
discussion_logger = logging.getLogger("rcgcdw.migrations.utils")
def return_example_file() -> dict:
try:
with open('settings.json.example', 'r') as example_file:
return json.loads(example_file.read())
except FileNotFoundError:
try:
f = requests.get("https://gitlab.com/piotrex43/RcGcDw/-/raw/master/settings.json.example")
except:
raise
return json.loads(f.text)