123
This commit is contained in:
20
session_bot/storage.py
Normal file
20
session_bot/storage.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class JsonStateStorage:
|
||||
def __init__(self, path: Path) -> None:
|
||||
self.path = path
|
||||
|
||||
def load(self) -> dict:
|
||||
if not self.path.exists():
|
||||
return {"actors": {}}
|
||||
with self.path.open("r", encoding="utf-8") as file:
|
||||
return json.load(file)
|
||||
|
||||
def save(self, payload: dict) -> None:
|
||||
self.path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with self.path.open("w", encoding="utf-8") as file:
|
||||
json.dump(payload, file, ensure_ascii=False, indent=2)
|
||||
Reference in New Issue
Block a user