@@ -652,9 +652,55 @@ def __bool__(self) -> bool:
652652 return False
653653
654654
655+ class DummyConfig (dict ):
656+ def __init__ (self , initial = None ) -> None :
657+ super ().__init__ ()
658+ if initial :
659+ for key , value in initial .items ():
660+ self [key ] = value
661+
662+ @staticmethod
663+ def _wrap (value ):
664+ if isinstance (value , dict ) and not isinstance (value , DummyConfig ):
665+ return DummyConfig (value )
666+ return value
667+
668+ def __setitem__ (self , key , value ) -> None :
669+ super ().__setitem__ (key , self ._wrap (value ))
670+
671+ def __getitem__ (self , key ):
672+ if key in self :
673+ return super ().__getitem__ (key )
674+ return NullStub ()
675+
676+ def __getattr__ (self , name : str ):
677+ return self .get (name )
678+
679+
655680class DummyContext :
656681 def __init__ (self ) -> None :
657682 self ._star_manager = None
683+ self ._astrbot_root = Path (os .environ .get ("ASTRBOT_ROOT" , Path .cwd ())).resolve ()
684+ self ._data_root = self ._astrbot_root / "data"
685+ self ._plugin_data_dir = self ._data_root / "plugin_data"
686+ self ._plugin_data_dir .mkdir (parents = True , exist_ok = True )
687+ self ._config = DummyConfig (
688+ {
689+ "wake_prefix" : [],
690+ "dashboard" : {},
691+ "admins_id" : [],
692+ "admin_ids" : [],
693+ "platform_settings" : {
694+ "aiocqhttp" : {},
695+ "qqofficial" : {},
696+ "telegram" : {},
697+ "gewechat" : {},
698+ "wechatpadpro" : {},
699+ },
700+ "data_dir" : str (self ._data_root ),
701+ }
702+ )
703+ self .config = self ._config
658704
659705 def get_all_stars (self ):
660706 try :
@@ -684,6 +730,17 @@ def register_llm_tool(self, name: str, func_args, desc: str, func_obj) -> None:
684730 def unregister_llm_tool (self , name : str ) -> None :
685731 del name
686732
733+ def get_config (self , umo : str | None = None ):
734+ del umo
735+ return self ._config
736+
737+ def get_context_config (self ):
738+ return self ._config
739+
740+ def get_data_dir (self ) -> str :
741+ self ._plugin_data_dir .mkdir (parents = True , exist_ok = True )
742+ return str (self ._plugin_data_dir )
743+
687744 def __getattr__ (self , name : str ) -> NullStub :
688745 del name
689746 return NullStub ()
0 commit comments