Template
Switch settings over to yaml and dataclasses.
This commit is contained in:
@@ -6,6 +6,8 @@ import os
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
from settings import settings
|
||||||
|
|
||||||
nextcord_logger = logging.getLogger("nextcord")
|
nextcord_logger = logging.getLogger("nextcord")
|
||||||
nextcord_logger.setLevel(logging.DEBUG)
|
nextcord_logger.setLevel(logging.DEBUG)
|
||||||
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
|
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!")
|
print(f"{bot.user.name} has connected to Discord!")
|
||||||
|
|
||||||
# Run Discord bot
|
# Run Discord bot
|
||||||
bot.run(bot.config.params.discord_token)
|
bot.run(settings.params.discord_token)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
+1
-4
@@ -5,13 +5,10 @@ description = ""
|
|||||||
authors = [{name="${REPO_OWNER}", email=""}]
|
authors = [{name="${REPO_OWNER}", email=""}]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cryptography>=43.0.3",
|
|
||||||
"nextcord>=2.6.0",
|
"nextcord>=2.6.0",
|
||||||
"pandas>=2.2.3",
|
|
||||||
"pymysql>=1.1.1",
|
|
||||||
"python-dotenv>=1.0.1",
|
"python-dotenv>=1.0.1",
|
||||||
"setuptools>=75.3.0",
|
|
||||||
"sqlmodel>=0.0.22",
|
"sqlmodel>=0.0.22",
|
||||||
|
"dataclass-wizard[yaml]>=0.22.3,<1.0.0",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
|||||||
+28
@@ -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)
|
||||||
Reference in New Issue
Block a user