fix message link check

This commit is contained in:
jxxghp
2025-05-18 15:25:45 +08:00
parent c8dc30287c
commit 007bd24374
2 changed files with 18 additions and 1 deletions

View File

@@ -423,7 +423,7 @@ class MessageChain(ChainBase):
# 聊天
content = text
action = "Chat"
elif text.startswith("http"):
elif StringUtils.is_link(text):
# 链接
content = text
action = "Link"

View File

@@ -908,3 +908,20 @@ class StringUtils:
:return: 如果elem有效非None且长度大于0返回True否则返回False
"""
return elem is not None and len(elem) > 0
@staticmethod
def is_link(text: str) -> bool:
"""
检查文件是否为链接地址,支持各类协议
:param text: 要检查的文本
:return: 如果URL有效返回True否则返回False
"""
if not text:
return False
# 检查是否以http、https、ftp等协议开头
if re.match(r'^(http|https|ftp|ftps|sftp|ws|wss)://', text):
return True
# 检查是否为IP地址或域名
if re.match(r'^[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,})?$', text):
return True
return False