1
0
Fork 0
mirror of https://code.lenaisten.de/Lenaisten/lenaverse-bot.git synced 2024-11-22 15:03:01 +00:00
lenaverse-bot/lenaverse_bot/core/config.py
Jörn-Michael Miehe 64cb7bd5a9 config rework, command_prefix, remove clutter
- _helpers.ev_command respects CONFIG.command_prefix
- restrict public replies to channel ids
2023-11-20 13:40:25 +01:00

65 lines
1.3 KiB
Python

import os
import tomllib
from typing import Annotated, Self
import discord
from pydantic import BaseModel, StringConstraints
StrippedStr = Annotated[str, StringConstraints(strip_whitespace=True)]
class Post(BaseModel):
# users authorized to posts
users: list[int]
# where to put posts
channel: int
def get_channel(
self,
client: discord.Client,
) -> discord.Thread | discord.TextChannel:
"""
Zielkanal für Posts finden
"""
channel = client.get_channel(self.channel)
assert isinstance(channel, discord.Thread | discord.TextChannel)
return channel
class InfoCommand(BaseModel):
description: StrippedStr = "..."
content: StrippedStr = ""
class FileCommand(InfoCommand):
filename: str = ""
class ClubInfo(BaseModel):
channels: list[int]
linktree: InfoCommand
join: FileCommand
class Config(BaseModel):
discord_token: str
command_prefix: str
post: Post
ev_info: ClubInfo
@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()