该提交实现了完整的ClickUp聊天渠道插件,包含以下核心功能: 1. 基础的@提及提取与格式化能力 2. 账号配对与会话管理 3. 消息流与流式回复支持 4. 重试限流与消息去重 5. 富文本格式转换与内容 sanitize 6. 安全策略与配置校验 7. Webhook接收与自动轮询回退 8. 消息收发、编辑、删除与回复 9. 频道与私信管理、反应功能 10. 完整的状态监控与健康检查
53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
import re
|
|
|
|
EMOJI_MAP = {
|
|
":smile:": "😀",
|
|
":laughing:": "😆",
|
|
":blush:": "😊",
|
|
":heart:": "❤️",
|
|
":thumbsup:": "👍",
|
|
":thumbsdown:": "👎",
|
|
":clap:": "👏",
|
|
":fire:": "🔥",
|
|
":rocket:": "🚀",
|
|
":check:": "✅",
|
|
":x:": "❌",
|
|
":warning:": "⚠️",
|
|
":bulb:": "💡",
|
|
":pushpin:": "📌",
|
|
":link:": "🔗",
|
|
":star:": "⭐",
|
|
":tada:": "🎉",
|
|
":thinking:": "🤔",
|
|
":eyes:": "👀",
|
|
":pray:": "🙏",
|
|
":100:": "💯",
|
|
}
|
|
|
|
|
|
def convert_emoji_shortcodes(text: str) -> str:
|
|
result = text
|
|
for shortcode, unicode_char in EMOJI_MAP.items():
|
|
result = result.replace(shortcode, unicode_char)
|
|
return result
|
|
|
|
|
|
def sanitize_for_clickup(text: str) -> str:
|
|
text = convert_emoji_shortcodes(text)
|
|
if len(text) > 40000:
|
|
text = text[:39997] + "..."
|
|
return text
|
|
|
|
|
|
def extract_plain_text(markdown_text: str) -> str:
|
|
text = markdown_text
|
|
text = re.sub(r"~~(.*?)~~", r"\1", text)
|
|
text = re.sub(r"\*\*(.*?)\*\*", r"\1", text)
|
|
text = re.sub(r"\*(.*?)\*", r"\1", text)
|
|
text = re.sub(r"`{1,3}[^`]*`{1,3}", "", text)
|
|
text = re.sub(r"\[([^\]]+)\]\([^\)]+\)", r"\1", text)
|
|
text = re.sub(r">\s?", "", text)
|
|
text = re.sub(r"[-*]\s", "", text)
|
|
text = re.sub(r"\d+\.\s", "", text)
|
|
return text.strip()
|