-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.py
More file actions
42 lines (33 loc) · 1.65 KB
/
utilities.py
File metadata and controls
42 lines (33 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import platform
from os import getenv
from typing import List, Dict, Any, Optional, Final, TypeAlias
from discord.app_commands import Choice, Range
from dotenv import load_dotenv
# Load the local environment
load_dotenv()
# Custom types
LevelIDInt: TypeAlias = Range[int, 1000]
PercentageInt: TypeAlias = Range[int, 1, 100]
PlacementInt: TypeAlias = Range[int, 1]
# Secrets
TOKEN: Final[Optional[str]] = getenv('LIVE_TOKEN') if getenv('ENV') == 'LIVE' else getenv('DEV_TOKEN')
MYSQL_USER: Final[Optional[str]] = getenv('MYSQL_USER')
MYSQL_PASSWORD: Final[Optional[str]] = getenv('MYSQL_PASSWORD')
THUMBNAILS_PATH: Final[Optional[str]] = getenv('THUMBNAILS_PATH')
# Checking IP
IS_NAS: Final[bool] = platform.system() == 'Linux'
HOST_IP: Final[Optional[str]] = '172.17.0.1' if IS_NAS else getenv('SYNOLOGY_IP')
# Constants
with open('config/constants.json', 'r', encoding='utf-8') as file:
config: Dict[str, Any] = json.load(file)
LOGGING_FORMAT: Final[str] = config.get('logging_format', None)
DATABASE: Final[str] = config.get('database', None)
DIFFICULTIES: Final[List[Choice]] = [Choice(name=name, value=value) for name, value in config.get('difficulties', {}).items()]
RATINGS: Final[List[Choice]] = [Choice(name=name, value=value) for name, value in config.get('ratings', {}).items()]
MODERATORS: Final[List[int]] = config.get('moderators', [])
DESCRIBED_PARAMETERS: Final[Dict[str, str]] = config.get('described_parameters', [])
with open('config/info_template.md', 'r', encoding='utf-8') as file:
INFORMATION_MESSAGE: Final[str] = file.read()
with open('config/countries.json', 'r', encoding='utf-8') as file:
COUNTRIES: Final[Dict[str, str]] = json.load(file)