2023-10-01 14:20:22 +00:00
|
|
|
"""
|
|
|
|
This module loads and parses the config.yaml file.
|
|
|
|
"""
|
|
|
|
|
2023-10-01 01:05:53 +00:00
|
|
|
from typing import Any, List, Optional
|
2023-10-01 14:20:22 +00:00
|
|
|
import yaml
|
2023-10-01 01:05:53 +00:00
|
|
|
|
|
|
|
with open('config.yaml', 'r') as open_file:
|
|
|
|
SETTINGS = yaml.load(open_file)
|
|
|
|
|
|
|
|
def at(keys : List[str]) -> Optional[Any]:
|
|
|
|
"""
|
|
|
|
Potentially get a value. If it doesn't exist, return None.
|
|
|
|
"""
|
|
|
|
return at_value(keys, SETTINGS)
|
|
|
|
|
|
|
|
def at_value(keys : List[str], value : Any) -> Optional[Any]:
|
|
|
|
try:
|
|
|
|
head, tail = keys[0], keys[1:]
|
|
|
|
except IndexError:
|
|
|
|
return value
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
new_value = value[head]
|
|
|
|
except TypeError:
|
|
|
|
return None
|
|
|
|
except KeyError:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return at_value(tail, new_value)
|
|
|
|
|
|
|
|
# EULA
|
2023-10-01 14:20:22 +00:00
|
|
|
EULA = at(['config', 'eula']) or False
|
2021-07-31 13:26:09 +00:00
|
|
|
|
2021-06-27 19:24:20 +00:00
|
|
|
# Minecraft bridge credentials
|
2023-10-01 01:05:53 +00:00
|
|
|
MATRIX_HOMESERVER = at(['matrix', 'homeserver']) or "https://matrix.example.org/"
|
|
|
|
MATRIX_USERNAME = at(['matrix', 'username']) or "@alice:example.org"
|
|
|
|
MATRIX_PASSWORD = at(['matrix', 'password']) or "bridge_password"
|
|
|
|
|
|
|
|
# Matrix bridge room
|
|
|
|
MATRIX_ROOM = at(['matrix', 'room_id']) or "!channel_id:example.org"
|
2021-07-31 13:26:09 +00:00
|
|
|
|
2023-10-01 14:20:22 +00:00
|
|
|
SERVER_IP = at(['matrix', 'server_address']) or 'unknown ip'
|
2021-06-27 19:24:20 +00:00
|
|
|
|
2023-10-01 12:07:13 +00:00
|
|
|
MATRIX_ADMINS = at(['matrix', 'mc-admins']) or []
|
2023-10-01 14:20:22 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
RAM_SIZE = int(at(['config', 'ram']))
|
|
|
|
except TypeError:
|
|
|
|
RAM_SIZE = 1024
|
|
|
|
except ValueError:
|
|
|
|
RAM_SIZE = 1024
|
|
|
|
|
|
|
|
SERVER_JAR_LOCATION = at(['config', 'server_jar']) or 'server.jar'
|
|
|
|
|
|
|
|
RUN_COMMAND = [
|
|
|
|
'java',
|
|
|
|
f'-Xmx{RAM_SIZE}M',
|
|
|
|
f'-Xms{RAM_SIZE}M',
|
|
|
|
'-jar', SERVER_JAR_LOCATION,
|
|
|
|
'nogui'
|
|
|
|
]
|