Skip to content

Commit

Permalink
feat(bot): import from opml
Browse files Browse the repository at this point in the history
  • Loading branch information
indes committed Jul 8, 2019
1 parent e039351 commit 5dd5c80
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion bot/bot.go
Expand Up @@ -599,7 +599,41 @@ func makeHandle() {
if m.Document.MIME == "text/x-opml+xml" {

url, _ := B.FileURLByID(m.Document.FileID)
_, _ = GetOPMLByURL(url)
opml, err := GetOPMLByURL(url)
if err != nil {
_, _ = B.Send(m.Chat, "如果需要导入订阅,请发送正确的OPML文件。")
return
}
message, _ := B.Send(m.Chat, "处理中,请稍后。")
outlines, _ := opml.GetFlattenOutlines()
var failImportList []Outline
var successImportList []Outline

for _, outline := range outlines {
source, err := model.FindOrNewSourceByUrl(outline.XMLURL)
if err != nil {
failImportList = append(failImportList, outline)
continue
}
err = model.RegistFeed(m.Chat.ID, source.ID)
if err != nil {
failImportList = append(failImportList, outline)
continue
}
log.Printf("%d subscribe [%d]%s %s", m.Chat.ID, source.ID, source.Title, source.Link)
successImportList = append(successImportList, outline)
}

importReport := fmt.Sprintf("<b>导入成功:%d,导入失败:%d</b>", len(successImportList), len(failImportList))

_, err = B.Edit(message, importReport, &tb.SendOptions{
DisableWebPagePreview: true,
ParseMode: tb.ModeHTML,
})

if err != nil {
log.Println(err.Error())
}

} else {
_, _ = B.Send(m.Chat, "如果需要导入订阅,请发送正确的OPML文件。")
Expand Down

0 comments on commit 5dd5c80

Please sign in to comment.