@@ -654,27 +654,14 @@ def __bool__(self) -> bool:
654654
655655class DummyConfig (dict ):
656656 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 )
657+ super ().__init__ (initial or {})
658+
659+ def __missing__ (self , key ):
660+ del key
674661 return NullStub ()
675662
676663 def __getattr__ (self , name : str ):
677- return self . get ( name )
664+ return self [ name ]
678665
679666
680667class DummyContext :
@@ -683,25 +670,30 @@ def __init__(self) -> None:
683670 self ._astrbot_root = Path (os .environ .get ("ASTRBOT_ROOT" , Path .cwd ())).resolve ()
684671 self ._data_root = self ._astrbot_root / "data"
685672 self ._plugin_data_dir = self ._data_root / "plugin_data"
686- self ._plugin_data_dir .mkdir (parents = True , exist_ok = True )
687673 self ._config = DummyConfig (
688674 {
689675 "wake_prefix" : [],
690- "dashboard" : {} ,
676+ "dashboard" : DummyConfig () ,
691677 "admins_id" : [],
692678 "admin_ids" : [],
693- "platform_settings" : {
679+ "platform_settings" : DummyConfig (
680+ {
694681 "aiocqhttp" : {},
695682 "qqofficial" : {},
696683 "telegram" : {},
697684 "gewechat" : {},
698685 "wechatpadpro" : {},
699- },
686+ }
687+ ),
700688 "data_dir" : str (self ._data_root ),
701689 }
702690 )
703691 self .config = self ._config
704692
693+ def _ensure_plugin_data_dir (self ) -> Path :
694+ self ._plugin_data_dir .mkdir (parents = True , exist_ok = True )
695+ return self ._plugin_data_dir
696+
705697 def get_all_stars (self ):
706698 try :
707699 from astrbot .core .star .star import star_registry
@@ -735,11 +727,10 @@ def get_config(self, umo: str | None = None):
735727 return self ._config
736728
737729 def get_context_config (self ):
738- return self ._config
730+ return self .get_config ()
739731
740732 def get_data_dir (self ) -> str :
741- self ._plugin_data_dir .mkdir (parents = True , exist_ok = True )
742- return str (self ._plugin_data_dir )
733+ return str (self ._ensure_plugin_data_dir ())
743734
744735 def __getattr__ (self , name : str ) -> NullStub :
745736 del name
0 commit comments