Switch settings over to yaml and dataclasses.

This commit is contained in:
2025-03-16 15:08:20 -04:00
parent 9121627d12
commit 2ffc24eb86
3 changed files with 32 additions and 5 deletions
+3 -1
View File
@@ -6,6 +6,8 @@ import os
import nextcord
from nextcord.ext import commands
from settings import settings
nextcord_logger = logging.getLogger("nextcord")
nextcord_logger.setLevel(logging.DEBUG)
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
@@ -49,7 +51,7 @@ def main() -> None:
print(f"{bot.user.name} has connected to Discord!")
# Run Discord bot
bot.run(bot.config.params.discord_token)
bot.run(settings.params.discord_token)
if __name__ == "__main__":
+1 -4
View File
@@ -5,13 +5,10 @@ description = ""
authors = [{name="${REPO_OWNER}", email=""}]
readme = "README.md"
dependencies = [
"cryptography>=43.0.3",
"nextcord>=2.6.0",
"pandas>=2.2.3",
"pymysql>=1.1.1",
"python-dotenv>=1.0.1",
"setuptools>=75.3.0",
"sqlmodel>=0.0.22",
"dataclass-wizard[yaml]>=0.22.3,<1.0.0",
]
requires-python = ">=3.12"
+28
View File
@@ -0,0 +1,28 @@
"""File contains classes defining ${REPO_NAME} settings structure."""
from dataclasses import dataclass
from dataclass_wizard import YAMLWizard
CONFIG_LOCATION = "conf/config.yaml"
@dataclass
class Params:
"""Class defines start parameters that shouldn't be changed."""
discord_token: str
@dataclass
class Settings(YAMLWizard):
"""Class defines all configs required for ${REPO_NAME}."""
params: Params
def save(self) -> None:
"""Save settings to the yaml file."""
self.to_yaml_file(CONFIG_LOCATION)
settings = Settings.from_yaml_file(CONFIG_LOCATION)