Initial commit
This commit is contained in:
40
bot/config.py
Normal file
40
bot/config.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import json
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
token: str
|
||||
friend_id: int
|
||||
emoji: str
|
||||
days_back: int
|
||||
db_path: str
|
||||
log_level: str
|
||||
manual_guild_ids: List[int] = field(default_factory=list)
|
||||
|
||||
|
||||
def load_config(path: str = "config.json") -> Config:
|
||||
if not os.path.exists(path):
|
||||
raise FileNotFoundError(
|
||||
f"Config file not found: {path}. Copy config.example.json to config.json and fill it in."
|
||||
)
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
required = ["token", "friend_id", "emoji"]
|
||||
missing = [key for key in required if not data.get(key)]
|
||||
if missing:
|
||||
raise ValueError(f"Missing required config fields: {missing}")
|
||||
|
||||
return Config(
|
||||
token=data["token"],
|
||||
friend_id=int(data["friend_id"]),
|
||||
emoji=data["emoji"],
|
||||
days_back=int(data.get("days_back", 10)),
|
||||
db_path=data.get("db_path", "reactions.sqlite3"),
|
||||
log_level=data.get("log_level", "INFO"),
|
||||
manual_guild_ids=[int(g) for g in data.get("manual_guild_ids", [])],
|
||||
)
|
||||
Reference in New Issue
Block a user