Files
dc-nogi/bot/config.py
Minz 41b6b3f234 Remove post-reaction verification refetch
Was doing an extra fetch_message per reaction to confirm the
reaction stuck. Turned out to be unrelated to the earlier
missing-reactions bug (that was the scan-state resume issue), so
drop it to save the API calls.
2026-08-01 18:12:17 +02:00

41 lines
1.1 KiB
Python

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", [])],
)