refactor: 更新 Subscribe 函数以收集并返回 RSS 订阅错误信息,增强用户反馈的准确性和可用性

This commit is contained in:
lixiangwuxian 2025-07-17 15:00:48 +08:00
parent 29f901a565
commit 9a02a39638

View File

@ -33,6 +33,7 @@ func TestRss(msg model.Message) (reply *model.Reply) {
func Subscribe(msg model.Message) (reply *model.Reply) { func Subscribe(msg model.Message) (reply *model.Reply) {
//提取url //提取url
var subscribedFeeds []string var subscribedFeeds []string
var errs []string
for _, data := range msg.StructuredMsg { for _, data := range msg.StructuredMsg {
if data.GetMessageType() == "text" { if data.GetMessageType() == "text" {
// 匹配RSS链接可选协议域名包含所有顶级域路径不一定以.xml结尾 // 匹配RSS链接可选协议域名包含所有顶级域路径不一定以.xml结尾
@ -41,6 +42,8 @@ func Subscribe(msg model.Message) (reply *model.Reply) {
for _, url := range urls { for _, url := range urls {
if title, err := SubscribeToFeed(url, msg.UserId, msg.GroupInfo.GroupId); err == nil { if title, err := SubscribeToFeed(url, msg.UserId, msg.GroupInfo.GroupId); err == nil {
subscribedFeeds = append(subscribedFeeds, title) subscribedFeeds = append(subscribedFeeds, title)
} else {
errs = append(errs, err.Error())
} }
} }
} }
@ -56,7 +59,7 @@ func Subscribe(msg model.Message) (reply *model.Reply) {
} }
return &model.Reply{ return &model.Reply{
ReplyMsg: "未找到有效的RSS链接(需要以.xml结尾", ReplyMsg: "未找到有效的RSS链接,相关错误信息:\n" + strings.Join(errs, "\n"),
ReferOriginMsg: true, ReferOriginMsg: true,
FromMsg: msg, FromMsg: msg,
} }