- 调整依赖导入顺序与清理冗余空行 - 修复setup wizard步骤存储逻辑 - 新增消息编辑/转发标记、卡片控件支持 - 完善目标校验、媒体上传、配对存储功能 - 优化流式响应与错误处理逻辑 - 增强SSRF防护与配置灵活性 - 新增/扩展内置命令与卡片处理能力 - 调整媒体大小限制与类型参数
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from googleapiclient.discovery import Resource
|
|
|
|
from yuxi.utils.logging_config import logger
|
|
|
|
|
|
async def list_spaces(
|
|
chat_service: Resource,
|
|
page_size: int = 50,
|
|
page_token: str | None = None,
|
|
filter_str: str | None = None,
|
|
) -> tuple[list[dict], str | None]:
|
|
kwargs: dict[str, Any] = {"pageSize": page_size}
|
|
if page_token:
|
|
kwargs["pageToken"] = page_token
|
|
if filter_str:
|
|
kwargs["filter"] = filter_str
|
|
try:
|
|
result = chat_service.spaces().list(**kwargs).execute()
|
|
return result.get("spaces", []), result.get("nextPageToken")
|
|
except Exception as e:
|
|
logger.warning(f"list_spaces failed: {e}")
|
|
return [], None
|
|
|
|
|
|
def list_peers(allow_from: list[str]) -> list[dict[str, Any]]:
|
|
peers: list[dict[str, Any]] = []
|
|
for entry in allow_from:
|
|
if entry == "*":
|
|
continue
|
|
normalized = normalize_id(entry)
|
|
peers.append({"id": normalized, "raw": entry, "type": "user"})
|
|
return peers
|
|
|
|
|
|
def list_groups(groups_config: dict[str, Any]) -> list[dict[str, Any]]:
|
|
groups: list[dict[str, Any]] = []
|
|
for space_name, cfg in groups_config.items():
|
|
if not isinstance(cfg, dict):
|
|
continue
|
|
groups.append(
|
|
{
|
|
"id": space_name,
|
|
"type": "space",
|
|
"name": cfg.get("name", space_name),
|
|
"enabled": cfg.get("enabled", True),
|
|
"requires_mention": cfg.get("require_mention", cfg.get("requireMention", False)),
|
|
}
|
|
)
|
|
return groups
|
|
|
|
|
|
def normalize_id(raw: str) -> str:
|
|
if not raw:
|
|
return ""
|
|
raw = raw.strip()
|
|
if raw.startswith("spaces/"):
|
|
return raw
|
|
if raw.startswith("users/"):
|
|
return raw
|
|
if raw.startswith("user:"):
|
|
return raw.replace("user:", "users/", 1)
|
|
if "@" in raw:
|
|
return f"users/{raw}"
|
|
return f"users/{raw}"
|