update and cleanup repo

This commit is contained in:
2026-05-26 15:32:01 -07:00
parent 5041d9fbb9
commit 0db899d0c3
72 changed files with 788 additions and 1884 deletions
+13 -17
View File
@@ -327,10 +327,10 @@ class Matrix(TablePluginMixin, Provider):
self._init_reason: Optional[str] = None
matrix_conf = (
self.config.get("provider",
{}).get("matrix",
{}) if isinstance(self.config,
dict) else {}
self.config.get("plugin",
{}).get("matrix",
{}) if isinstance(self.config,
dict) else {}
)
homeserver = matrix_conf.get("homeserver")
access_token = matrix_conf.get("access_token")
@@ -362,16 +362,16 @@ class Matrix(TablePluginMixin, Provider):
return False
if self._init_ok is False:
return False
matrix_conf = self.config.get("provider",
{}).get("matrix",
{})
matrix_conf = self.config.get("plugin",
{}).get("matrix",
{})
return bool(
matrix_conf.get("homeserver")
and matrix_conf.get("access_token")
)
def status_summary(self) -> Dict[str, Any]:
matrix_conf = self.config.get("provider", {}).get("matrix", {}) if isinstance(self.config, dict) else {}
matrix_conf = self.config.get("plugin", {}).get("matrix", {}) if isinstance(self.config, dict) else {}
homeserver = str(matrix_conf.get("homeserver") or "").strip()
room_id = str(matrix_conf.get("room_id") or "").strip()
detail = homeserver
@@ -439,7 +439,7 @@ class Matrix(TablePluginMixin, Provider):
full_metadata={
"room_id": room_id,
"room_name": room_name,
"provider": "matrix",
"plugin": "matrix",
# Selection metadata for table system and @N expansion
"_selection_args": ["-room-id", room_id],
},
@@ -450,9 +450,9 @@ class Matrix(TablePluginMixin, Provider):
def _get_homeserver_and_token(self) -> Tuple[str, str]:
matrix_conf = self.config.get("provider",
{}).get("matrix",
{})
matrix_conf = self.config.get("plugin",
{}).get("matrix",
{})
homeserver = matrix_conf.get("homeserver")
access_token = matrix_conf.get("access_token")
if not homeserver:
@@ -681,7 +681,7 @@ class Matrix(TablePluginMixin, Provider):
)
def upload(self, file_path: str, **kwargs: Any) -> str:
matrix_conf = self.config.get("provider",
matrix_conf = self.config.get("plugin",
{}).get("matrix",
{})
room_id = matrix_conf.get("room_id")
@@ -877,7 +877,3 @@ try:
except Exception:
# best-effort registration
pass
# Backward-compatible alias: tests and callers may import `plugins.matrix.cmdnat`.
from . import commands as cmdnat # noqa: E402
+35 -42
View File
@@ -58,8 +58,30 @@ def _extract_set_value_arg(args: Sequence[str]) -> Optional[str]:
return extract_arg_value(args, flags={"-set-value"})
def _get_matrix_config_block(config: Dict[str, Any]) -> Dict[str, Any]:
if not isinstance(config, dict):
return {}
plugins = config.get("plugin")
if not isinstance(plugins, dict):
return {}
matrix_cfg = plugins.get("matrix")
return matrix_cfg if isinstance(matrix_cfg, dict) else {}
def _ensure_matrix_config_block(config: Dict[str, Any]) -> Dict[str, Any]:
plugins = config.setdefault("plugin", {})
if not isinstance(plugins, dict):
plugins = {}
config["plugin"] = plugins
matrix_cfg = plugins.setdefault("matrix", {})
if not isinstance(matrix_cfg, dict):
matrix_cfg = {}
plugins["matrix"] = matrix_cfg
return matrix_cfg
def _update_matrix_config(config: Dict[str, Any], key: str, value: Any) -> bool:
"""Update the Matrix provider block in the shared config.
"""Update the Matrix plugin block in the shared config.
This method writes to the unified config store so changes persist between
sessions.
@@ -71,29 +93,13 @@ def _update_matrix_config(config: Dict[str, Any], key: str, value: Any) -> bool:
value_str = str(value)
current_cfg = load_config() or {}
providers = current_cfg.setdefault("provider", {})
if not isinstance(providers, dict):
providers = {}
current_cfg["provider"] = providers
matrix_cfg = providers.setdefault("matrix", {})
if not isinstance(matrix_cfg, dict):
matrix_cfg = {}
providers["matrix"] = matrix_cfg
matrix_cfg = _ensure_matrix_config_block(current_cfg)
matrix_cfg[key] = value_str
save_config(current_cfg)
# Keep the supplied config dict in sync for the running CLI
target_providers = config.setdefault("provider", {})
if not isinstance(target_providers, dict):
target_providers = {}
config["provider"] = target_providers
target_matrix = target_providers.setdefault("matrix", {})
if not isinstance(target_matrix, dict):
target_matrix = {}
target_providers["matrix"] = target_matrix
target_matrix = _ensure_matrix_config_block(config)
target_matrix[key] = value_str
return True
except Exception as exc:
@@ -103,13 +109,8 @@ def _update_matrix_config(config: Dict[str, Any], key: str, value: Any) -> bool:
def _parse_config_room_filter_ids(config: Dict[str, Any]) -> List[str]:
try:
if not isinstance(config, dict):
return []
providers = config.get("provider")
if not isinstance(providers, dict):
return []
matrix_conf = providers.get("matrix")
if not isinstance(matrix_conf, dict):
matrix_conf = _get_matrix_config_block(config)
if not matrix_conf:
return []
raw = None
# Support a few common spellings; `room` is the documented key.
@@ -138,16 +139,11 @@ def _parse_config_room_filter_ids(config: Dict[str, Any]) -> List[str]:
def _get_matrix_size_limit_bytes(config: Dict[str, Any]) -> Optional[int]:
"""Return max allowed per-file size in bytes for Matrix uploads.
Config: [provider=Matrix] size_limit=50 # MB
Config: [plugin=matrix] size_limit=50 # MB
"""
try:
if not isinstance(config, dict):
return None
providers = config.get("provider")
if not isinstance(providers, dict):
return None
matrix_conf = providers.get("matrix")
if not isinstance(matrix_conf, dict):
matrix_conf = _get_matrix_config_block(config)
if not matrix_conf:
return None
raw = None
@@ -236,7 +232,7 @@ def _resolve_room_identifier(value: str, config: Dict[str, Any]) -> Optional[str
conf_ids = _parse_config_room_filter_ids(config)
if conf_ids:
# Attempt to fetch names for the configured IDs
block = config.get("provider", {}).get("matrix", {})
block = _get_matrix_config_block(config)
if block and block.get("homeserver") and block.get("access_token"):
try:
m = _get_matrix_provider(config)
@@ -252,7 +248,7 @@ def _resolve_room_identifier(value: str, config: Dict[str, Any]) -> Optional[str
pass
# Last resort: attempt to ask the server for matching rooms (if possible)
block = config.get("provider", {}).get("matrix", {})
block = _get_matrix_config_block(config)
if block and block.get("homeserver") and block.get("access_token"):
try:
m = _get_matrix_provider(config)
@@ -631,7 +627,7 @@ def _resolve_upload_path(item: Any, config: Dict[str, Any]) -> Optional[str]:
url = _resolve_plugin_url(url, config)
try:
from API.HTTP import _download_direct_file
from API.HTTP import download_direct_file
base_tmp = None
if isinstance(config, dict):
@@ -642,7 +638,7 @@ def _resolve_upload_path(item: Any, config: Dict[str, Any]) -> Optional[str]:
)
output_dir = output_dir / "matrix"
output_dir.mkdir(parents=True, exist_ok=True)
result = _download_direct_file(url, output_dir, quiet=True)
result = download_direct_file(url, output_dir, quiet=True)
if (result and hasattr(result,
"path") and isinstance(result.path,
Path) and result.path.exists()):
@@ -691,10 +687,7 @@ def _show_settings_table(config: Dict[str, Any]) -> int:
matrix_conf = {}
try:
if isinstance(config, dict):
providers = config.get("provider")
if isinstance(providers, dict):
matrix_conf = providers.get("matrix") or {}
matrix_conf = _get_matrix_config_block(config)
except Exception:
pass