1515import sys
1616import tempfile
1717import tomllib
18- from typing import Any , Iterator , Mapping , Self
18+ from typing import Any , Iterator , Mapping , Self , Sequence
1919import xdg_base_dirs
2020
2121
2525@dataclasses .dataclass (frozen = True )
2626class Config :
2727 log_level : int
28- bots : Mapping [ str , BotConfig ]
28+ bots : Sequence [ BotConfig ]
2929 # TODO: Add (prompt) templates.
3030
31- @classmethod
32- def default (cls ) -> Self :
33- return cls (logging .INFO , {})
34-
3531 @staticmethod
3632 def path () -> Path :
3733 return xdg_base_dirs .xdg_config_home () / PROGRAM / "config.toml"
3834
35+ @classmethod
36+ def default (cls ) -> Self :
37+ return cls (logging .INFO , [])
38+
3939 @classmethod
4040 def load (cls ) -> Self :
4141 path = cls .path ()
@@ -45,10 +45,9 @@ def load(cls) -> Self:
4545 except FileNotFoundError :
4646 return cls .default ()
4747 else :
48- bot_data = data .get ("bots" , {})
4948 return cls (
5049 log_level = logging .getLevelName (data ["log_level" ]),
51- bots = { k : BotConfig (** v ) for k , v in bot_data . items ()} ,
50+ bots = [ BotConfig (** v ) for v in data . get ( "bots" , [])] ,
5251 )
5352
5453
@@ -58,8 +57,9 @@ def load(cls) -> Self:
5857
5958@dataclasses .dataclass (frozen = True )
6059class BotConfig :
61- loader : str
62- kwargs : JSONObject | None = None
60+ factory : str
61+ name : str | None = None
62+ config : JSONObject | None = None
6363 pythonpath : str | None = None
6464
6565
@@ -157,3 +157,7 @@ def sql(name: str) -> str:
157157
158158def random_id (n : int ) -> str :
159159 return "" .join (_random .choices (_alphabet , k = n ))
160+
161+
162+ class UnreachableError (RuntimeError ):
163+ pass
0 commit comments