lenaverse-bot/lenaverse_bot/core/config.py

43 lines
868 B
Python
Raw Normal View History

2023-11-19 15:41:19 +00:00
import os
import tomllib
from typing import Self
2023-11-19 16:32:12 +00:00
import discord
2023-11-19 15:41:19 +00:00
from pydantic import BaseModel
2023-11-19 18:01:06 +00:00
2023-11-19 18:36:29 +00:00
class Post(BaseModel):
channel: int
users: list[int]
2023-11-19 15:41:19 +00:00
2023-11-19 18:36:29 +00:00
def get_channel(
self,
client: discord.Client,
) -> discord.Thread | discord.TextChannel:
2023-11-19 16:32:12 +00:00
"""
Zielkanal für Posts finden
"""
2023-11-19 18:36:29 +00:00
channel = client.get_channel(self.channel)
assert isinstance(channel, discord.Thread | discord.TextChannel)
2023-11-19 16:32:12 +00:00
2023-11-19 18:36:29 +00:00
return channel
2023-11-19 16:32:12 +00:00
2023-11-19 15:41:19 +00:00
class Config(BaseModel):
discord_token: str
2023-11-19 16:32:12 +00:00
post: Post
2023-11-19 15:41:19 +00:00
@classmethod
def get(cls) -> Self:
cfg_path = os.getenv(
key="CONFIG_PATH",
default="/usr/local/etc/lenaverse-bot/lenaverse-bot.toml",
)
with open(cfg_path, "rb") as cfg_file:
return cls.model_validate(tomllib.load(cfg_file))
CONFIG = Config.get()