Use BOT_STATE_DIR for matrix state storage
This commit is contained in:
parent
b4fd06ef51
commit
145a3e70c3
4 changed files with 12 additions and 9 deletions
|
|
@ -49,7 +49,7 @@ class MatrixClientSettings(BaseSettings):
|
|||
user_id: str
|
||||
password: str
|
||||
device_name: str
|
||||
store_path: str
|
||||
store_path: Optional[str] = None
|
||||
verify_ssl: Optional[bool] = True
|
||||
|
||||
class Config:
|
||||
|
|
@ -60,7 +60,10 @@ class MatrixClientSettings(BaseSettings):
|
|||
class MatrixClient:
|
||||
def __init__(self, settings: MatrixClientSettings, join_rooms: List[str]):
|
||||
self.settings = settings
|
||||
self.store_path = pathlib.Path(settings.store_path)
|
||||
bot_state_dir = os.environ.get("BOT_STATE_DIR")
|
||||
if bot_state_dir is None:
|
||||
raise ValueError("BOT_STATE_DIR env var is required")
|
||||
self.store_path = pathlib.Path(bot_state_dir).joinpath("matrix")
|
||||
self.join_rooms = join_rooms
|
||||
self.credential_store = LocalCredentialStore(
|
||||
self.store_path.joinpath("credentials.json")
|
||||
|
|
@ -76,8 +79,7 @@ class MatrixClient:
|
|||
|
||||
self.greeting_sent = False
|
||||
|
||||
if self.store_path and not os.path.isdir(self.store_path):
|
||||
os.mkdir(self.store_path)
|
||||
self.store_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
async def start(self) -> None:
|
||||
await self.login()
|
||||
|
|
@ -108,7 +110,7 @@ class MatrixClient:
|
|||
self.client = AsyncClient(
|
||||
homeserver=self.settings.homeserver,
|
||||
user=self.settings.user_id,
|
||||
store_path=str(self.settings.store_path),
|
||||
store_path=str(self.store_path),
|
||||
config=self.client_config,
|
||||
ssl=self.settings.verify_ssl,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue