1
Fork 0
mirror of https://github.com/allthingslinux/tux.git synced 2024-10-02 16:43:12 +00:00

chore: switch from JSON to YAML for configuration file

feat: add pyyaml to dependencies to parse YAML files
fix: remove unused LOG_CHANNELS constant from constants.py
refactor: add default values for environment variables in constants.py
feat: ignore YAML configuration file in .gitignore
refactor: delete unused JSON example configuration file
This commit is contained in:
kzndotsh 2024-08-22 01:44:00 +00:00
parent 94516adcc0
commit 829762d8d1
5 changed files with 15 additions and 76 deletions

3
.gitignore vendored
View file

@ -164,6 +164,7 @@ github-private-key.pem
# Miscellaneous
/debug.csv
config/settings.json
config/settings.yml
# MacOS
.DS_Store
.DS_Store

View file

@ -1,58 +0,0 @@
{
"PREFIX": {
"PROD": "$",
"DEV": "$"
},
"ROLES": {
"ADMIN": 123456789012345679,
"MOD": 123456789012345679,
"JR_MOD": 123456789012345679,
"OWNER": 123456789012345679,
"TESTING": 123456789012345679
},
"USER_IDS": {
"SYSADMINS": [
123456789012345679,
123456789012345679
],
"BOT_OWNER": 123456789012345679
},
"TEMPVC_CATEGORY_ID": 1235096247442870292,
"TEMPVC_CHANNEL_ID": 1235096247442870292,
"LOG_CHANNELS": {
"AUDIT": 1235096271350399076,
"MOD": 1235096291672068106,
"REPORTS": 1235096305160814652,
"GATE": 1235096247442870292,
"DEV": 1235095919788167269,
"PRIVATE": 1235108340791513129
},
"EMBED_COLORS": {
"DEFAULT": 16044058,
"INFO": 12634869,
"WARNING": 16634507,
"ERROR": 16067173,
"SUCCESS": 10407530,
"POLL": 14724968,
"CASE": 16217742,
"NOTE": 16752228
},
"EMBED_ICONS": {
"DEFAULT": "https://i.imgur.com/owW4EZk.png",
"INFO": "https://i.imgur.com/8GRtR2G.png",
"SUCCESS": "https://i.imgur.com/JsNbN7D.png",
"ERROR": "https://i.imgur.com/zZjuWaU.png",
"CASE": "https://i.imgur.com/c43cwnV.png",
"NOTE": "https://i.imgur.com/VqPFbil.png",
"POLL": "https://i.imgur.com/pkPeG5q.png",
"ACTIVE_CASE": "https://github.com/allthingslinux/tux/blob/main/assets/embeds/active_case.png?raw=true",
"INACTIVE_CASE": "https://github.com/allthingslinux/tux/blob/main/assets/embeds/inactive_case.png?raw=true",
"ADD": "https://github.com/allthingslinux/tux/blob/main/assets/emojis/added.png?raw=true",
"REMOVE": "https://github.com/allthingslinux/tux/blob/main/assets/emojis/removed.png?raw=true",
"BAN": "https://github.com/allthingslinux/tux/blob/main/assets/emojis/ban.png?raw=true",
"JAIL": "https://github.com/allthingslinux/tux/blob/main/assets/emojis/jail.png?raw=true",
"KICK": "https://github.com/allthingslinux/tux/blob/main/assets/emojis/kick.png?raw=true",
"TIMEOUT": "https://github.com/allthingslinux/tux/blob/main/assets/emojis/timeout.png?raw=true",
"WARN": "https://github.com/allthingslinux/tux/blob/main/assets/emojis/warn.png?raw=true"
}
}

2
poetry.lock generated
View file

@ -2324,4 +2324,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = ">=3.12,<4"
content-hash = "30272c710183da26e169ea88fd077632a69fac2a891ba3f9a862bc815f368141"
content-hash = "b7e79ee5391b21488b2a71b8a447ffd2cf76aa9ced53f6ed96da383bf77c1aa7"

View file

@ -34,6 +34,7 @@ sentry-sdk = {extras = ["httpx", "loguru"], version = "^2.7.0"}
types-aiofiles = "^24.1.0.20240626"
types-psutil = "^6.0.0.20240621"
typing-extensions = "^4.12.2"
pyyaml = "^6.0.2"
[tool.poetry.group.docs.dependencies]
mkdocs-material = "^9.5.30"

View file

@ -1,15 +1,15 @@
import base64
import json
import os
from pathlib import Path
from typing import Final
import yaml
from dotenv import load_dotenv, set_key
load_dotenv(verbose=True)
config_file = Path("config/settings.json")
config = json.loads(config_file.read_text())
config_file = Path("config/settings.yml")
config = yaml.safe_load(config_file.read_text())
class Constants:
@ -37,7 +37,7 @@ class Constants:
COG_IGNORE_LIST: Final[set[str]] = DEV_COG_IGNORE_LIST if DEV and DEV.lower() == "true" else PROD_COG_IGNORE_LIST
# Sentry-related constants
SENTRY_URL: Final[str | None] = os.getenv("SENTRY_URL")
SENTRY_URL: Final[str | None] = os.getenv("SENTRY_URL", "")
# Database constants
PROD_DATABASE_URL: Final[str] = os.getenv("PROD_DATABASE_URL", "")
@ -53,25 +53,20 @@ class Constants:
GITHUB_REPO: Final[str] = os.getenv("GITHUB_REPO", "")
GITHUB_TOKEN: Final[str] = os.getenv("GITHUB_TOKEN", "")
GITHUB_APP_ID: Final[int] = int(os.getenv("GITHUB_APP_ID", 0))
GITHUB_CLIENT_ID = os.getenv("GITHUB_CLIENT_ID")
GITHUB_CLIENT_SECRET = os.getenv("GITHUB_CLIENT_SECRET")
GITHUB_PUBLIC_KEY = os.getenv("GITHUB_PUBLIC_KEY")
GITHUB_CLIENT_ID = os.getenv("GITHUB_CLIENT_ID", "")
GITHUB_CLIENT_SECRET = os.getenv("GITHUB_CLIENT_SECRET", "")
GITHUB_PUBLIC_KEY = os.getenv("GITHUB_PUBLIC_KEY", "")
GITHUB_INSTALLATION_ID: Final[int] = int(os.getenv("GITHUB_INSTALLATION_ID", 0))
GITHUB_PRIVATE_KEY: str = base64.b64decode(os.getenv("GITHUB_PRIVATE_KEY_BASE64", "")).decode(
"utf-8",
GITHUB_PRIVATE_KEY: str = (
base64.b64decode(os.getenv("GITHUB_PRIVATE_KEY_BASE64", "")).decode("utf-8")
if os.getenv("GITHUB_PRIVATE_KEY_BASE64")
else ""
)
# Mailcow constants
MAILCOW_API_KEY: Final[str] = os.getenv("MAILCOW_API_KEY", "")
MAILCOW_API_URL: Final[str] = os.getenv("MAILCOW_API_URL", "")
# Channel constants
LOG_CHANNELS: Final[dict[str, int]] = config["LOG_CHANNELS"].copy()
if DEV and DEV.lower() == "true":
for key in LOG_CHANNELS:
LOG_CHANNELS[key] = LOG_CHANNELS["DEV"]
# Temp VC constants
TEMPVC_CATEGORY_ID: Final[str | None] = config["TEMPVC_CATEGORY_ID"]
TEMPVC_CHANNEL_ID: Final[str | None] = config["TEMPVC_CHANNEL_ID"]