1111from .commands import CommandInvocation , CommandParser , CommandSpec , CommandArgument
1212from .storage import BotStorage
1313from .permissions import PermissionPolicy
14- from .config import BotLocalConfig , load_bot_local_config , save_bot_local_config
14+ from .config import BotLocalConfig , StorageConfig , load_bot_local_config , save_bot_local_config
1515from .models import (
1616 Event ,
1717 Message ,
@@ -37,6 +37,7 @@ class BaseBot(abc.ABC):
3737 # Storage configuration
3838 enable_storage = True
3939 storage_path : Optional [str ] = None # Defaults to "bot_data/{bot_name}.db"
40+ storage_config : Optional [StorageConfig ] = None
4041
4142 def __init__ (self , client : AsyncClient ) -> None :
4243 self .client = client
@@ -54,6 +55,10 @@ def __init__(self, client: AsyncClient) -> None:
5455 def set_runner (self , runner : "BotRunner" ) -> None :
5556 """Called by BotRunner to allow commands to signal runner actions."""
5657 self ._runner = runner
58+
59+ def set_storage_config (self , storage_config : Optional [StorageConfig ]) -> None :
60+ """Inject per-bot storage configuration from runner/config layer."""
61+ self .storage_config = storage_config
5762
5863 async def post_init (self ) -> None :
5964 """Hook for post-initialization logic. Override if needed.
@@ -76,9 +81,14 @@ async def _init_storage(self) -> None:
7681 return
7782 if self .storage_path is None :
7883 self .storage_path = f"bot_data/{ bot_name } .db"
84+ auto_cfg = self .storage_config or StorageConfig ()
7985 self .storage = BotStorage (
8086 db_path = self .storage_path ,
81- namespace = f"bot_{ bot_name } "
87+ namespace = f"bot_{ bot_name } " ,
88+ auto_cache = auto_cfg .auto_cache ,
89+ auto_flush_interval = auto_cfg .auto_flush_interval ,
90+ auto_flush_retry = auto_cfg .auto_flush_retry ,
91+ auto_flush_max_retries = auto_cfg .auto_flush_max_retries ,
8292 )
8393 logger .info (f"Initialized storage at { self .storage_path } " )
8494 # Initialize permissions helper
0 commit comments