87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
|
|
"""Microsoft Teams Team/Channel 嵌套配置解析。
|
|||
|
|
|
|||
|
|
支持 teams.{id}.channels.{id} 细分配置覆盖,
|
|||
|
|
通配符 fallback,层级继承 Channel > Team > Global。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from typing import Any
|
|||
|
|
|
|||
|
|
|
|||
|
|
def resolve_nested_config(
|
|||
|
|
config: dict[str, Any],
|
|||
|
|
team_id: str,
|
|||
|
|
channel_id: str = "",
|
|||
|
|
) -> dict[str, Any]:
|
|||
|
|
result: dict[str, Any] = {}
|
|||
|
|
|
|||
|
|
teams_config = config.get("teams", {}) or {}
|
|||
|
|
team_config = _resolve_team_entry(teams_config, team_id)
|
|||
|
|
if not team_config:
|
|||
|
|
return result
|
|||
|
|
|
|||
|
|
result["team_config"] = team_config
|
|||
|
|
|
|||
|
|
if channel_id:
|
|||
|
|
channels_config = team_config.get("channels", {}) or {}
|
|||
|
|
channel_config = _resolve_channel_entry(channels_config, channel_id)
|
|||
|
|
if channel_config:
|
|||
|
|
result["channel_config"] = channel_config
|
|||
|
|
|
|||
|
|
return result
|
|||
|
|
|
|||
|
|
|
|||
|
|
def _resolve_team_entry(
|
|||
|
|
teams_config: dict[str, Any],
|
|||
|
|
team_id: str,
|
|||
|
|
) -> dict[str, Any] | None:
|
|||
|
|
if team_id in teams_config:
|
|||
|
|
return teams_config[team_id]
|
|||
|
|
if "*" in teams_config:
|
|||
|
|
return teams_config["*"]
|
|||
|
|
return None
|
|||
|
|
|
|||
|
|
|
|||
|
|
def _resolve_channel_entry(
|
|||
|
|
channels_config: dict[str, Any],
|
|||
|
|
channel_id: str,
|
|||
|
|
) -> dict[str, Any] | None:
|
|||
|
|
if channel_id in channels_config:
|
|||
|
|
return channels_config[channel_id]
|
|||
|
|
if "*" in channels_config:
|
|||
|
|
return channels_config["*"]
|
|||
|
|
return None
|
|||
|
|
|
|||
|
|
|
|||
|
|
def resolve_reply_style(
|
|||
|
|
config: dict[str, Any],
|
|||
|
|
team_id: str,
|
|||
|
|
channel_id: str = "",
|
|||
|
|
default: str = "thread",
|
|||
|
|
) -> str:
|
|||
|
|
nested = resolve_nested_config(config, team_id, channel_id)
|
|||
|
|
channel_config = nested.get("channel_config", {}) or {}
|
|||
|
|
if "reply_style" in channel_config:
|
|||
|
|
return channel_config["reply_style"]
|
|||
|
|
team_config = nested.get("team_config", {}) or {}
|
|||
|
|
if "reply_style" in team_config:
|
|||
|
|
return team_config["reply_style"]
|
|||
|
|
return config.get("reply_style", default)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def resolve_require_mention(
|
|||
|
|
config: dict[str, Any],
|
|||
|
|
team_id: str,
|
|||
|
|
channel_id: str = "",
|
|||
|
|
chat_type: str = "group",
|
|||
|
|
) -> bool | None:
|
|||
|
|
nested = resolve_nested_config(config, team_id, channel_id)
|
|||
|
|
channel_config = nested.get("channel_config", {}) or {}
|
|||
|
|
if "require_mention" in channel_config:
|
|||
|
|
return channel_config["require_mention"]
|
|||
|
|
team_config = nested.get("team_config", {}) or {}
|
|||
|
|
if "require_mention" in team_config:
|
|||
|
|
return team_config["require_mention"]
|
|||
|
|
return config.get("require_mention")
|