实现了 Teams 机器人所需的全功能组件,包括: - 基础命令解析与帮助卡片生成 - 租户验证与访问控制 - 自定义 UA 与媒体工具 - 消息分块、批注处理与会话管理 - 防抖、缓存与配置路由能力 - 投票、配对、审计与运行时状态管理 - TTS 语音合成与卡片构建工具 - 群组管理与权限控制逻辑
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
"""Microsoft Teams 密钥输入规范化。
|
|
|
|
处理用户输入的密钥字符串,去除多余空格、换行,
|
|
检测是否已配置合法密钥。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def normalize_secret_input(raw: str) -> str:
|
|
"""规范化用户输入的密钥字符串。
|
|
|
|
- 去除首尾空白和换行
|
|
- 去除连续的空白行
|
|
- 去除不可见字符(保留 ASCII 可打印字符)
|
|
"""
|
|
if not raw:
|
|
return ""
|
|
|
|
cleaned = raw.strip()
|
|
lines = cleaned.splitlines()
|
|
cleaned = " ".join(line.strip() for line in lines if line.strip())
|
|
|
|
cleaned = "".join(c for c in cleaned if 32 <= ord(c) <= 126 or c in "\t")
|
|
|
|
return cleaned
|
|
|
|
|
|
def has_configured_secret(value: str, min_length: int = 8) -> bool:
|
|
"""检测密钥是否已配置且合法。
|
|
|
|
Returns True 如果密钥长度 >= min_length 且不是占位符。
|
|
"""
|
|
if not value or len(value) < min_length:
|
|
return False
|
|
|
|
placeholder_lower = value.lower()
|
|
placeholders = {
|
|
"your_app_password_here",
|
|
"replace_with_your_secret",
|
|
"changeme",
|
|
"password",
|
|
"secret",
|
|
}
|
|
if placeholder_lower in placeholders:
|
|
logger.warning("MSTeams: secret appears to be a placeholder value")
|
|
return False
|
|
|
|
return True
|