send a single telegram message for each torrent check instead of for individual torrent files
This commit is contained in:
parent
a541267c20
commit
f361203c73
@ -3,9 +3,11 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.milar.in/milarin/adverr"
|
||||
"git.milar.in/milarin/slices"
|
||||
"git.milar.in/nyaanime/logic"
|
||||
"git.milar.in/nyaanime/model"
|
||||
)
|
||||
@ -81,5 +83,11 @@ func CheckTorrents() {
|
||||
downloadedTorrents,
|
||||
)
|
||||
|
||||
downloadedAnimeEpisodes := slices.OfMap(downloadedTorrents, func(animeEp model.AnimeEpisode, torrentPrio *TorrentPriority) model.AnimeEpisode {
|
||||
return animeEp
|
||||
})
|
||||
sort.Slice(downloadedAnimeEpisodes, GetAnimeEpisodesSortFunc(downloadedAnimeEpisodes))
|
||||
SendTelegramAnimeEpMessage(TelegramDownloadMessagePattern, downloadedAnimeEpisodes)
|
||||
|
||||
log.Printf("check took %s. sleeping for %s\n", duration.Truncate(time.Millisecond), (PollRate - duration).Truncate(time.Millisecond))
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func DownloadTorrent(animeEp model.AnimeEpisode, torrent *model.ParsedTorrent) error {
|
||||
SendTelegramAnimeEpMessage(TelegramDownloadMessagePattern, animeEp)
|
||||
|
||||
if err := SetCurrentlyDownloading(animeEp); err != nil {
|
||||
return ErrLockFileCreationFailed.Wrap(err, animeEp.Anime.Title.Romaji, animeEp.Episode)
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ var (
|
||||
|
||||
TelegramBotToken = envvars.String("TELEGRAM_API_TOKEN", "")
|
||||
TelegramChatID = envvars.Int64("TELEGRAM_CHAT_ID", 0)
|
||||
TelegramDownloadMessagePatternStr = logic.EscSeqReplacer.Replace(envvars.String("TELEGRAM_DOWNLOAD_MESSAGE_PATTERN", `Download started\n\n{{.Title.UserPreferred}} episode {{.Episode}}`))
|
||||
TelegramDownloadMessagePatternStr = logic.EscSeqReplacer.Replace(envvars.String("TELEGRAM_DOWNLOAD_MESSAGE_PATTERN", `Download started{{range .}}\n{{.Anime.Title.UserPreferred}} episode {{.Episode}}{{end}}`))
|
||||
TelegramDownloadMessagePattern = template.Must(template.New("TELEGRAM_DOWNLOAD_MESSAGE_PATTERN").Parse(TelegramDownloadMessagePatternStr))
|
||||
|
||||
DownloadAll = envvars.Bool("DOWNLOAD_ALL_ANIMES", false)
|
||||
|
2
go.mod
2
go.mod
@ -10,7 +10,7 @@ require (
|
||||
git.milar.in/milarin/tprint v0.0.7
|
||||
git.milar.in/nyaanime/logic v0.0.0-20230115215841-53bbded00fe6
|
||||
git.milar.in/nyaanime/model v0.0.0-20230117081612-d3fc649dad67
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230115232356-54a23b868d71
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230117093342-b57ecf49e1f5
|
||||
github.com/PuerkitoBio/goquery v1.8.0
|
||||
github.com/fatih/color v1.13.0
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
|
||||
|
10
go.sum
10
go.sum
@ -14,16 +14,10 @@ git.milar.in/milarin/tprint v0.0.7 h1:dvm4l4BhXOie4vtnRMZii0WTLTz2wju8wyUPB/lNeV
|
||||
git.milar.in/milarin/tprint v0.0.7/go.mod h1:UwW/B+0cTCbN5hi0bQBE9rIRgLkq+x4V751rrS2KVoI=
|
||||
git.milar.in/nyaanime/logic v0.0.0-20230115215841-53bbded00fe6 h1:6GmcKt0TaHxATGbSpTgDExdRHiON5OwZlHVJCYU0gbA=
|
||||
git.milar.in/nyaanime/logic v0.0.0-20230115215841-53bbded00fe6/go.mod h1:cLuIBDTtpXdzprOIsz73r6ZCE5s0k+o6HA7fH9OuW/M=
|
||||
git.milar.in/nyaanime/model v0.0.0-20230115221845-51c282652aef h1:Bp1cMHgGnz5SAVWSL1hk1w7F75LGAkfwHqoTZnNQNbY=
|
||||
git.milar.in/nyaanime/model v0.0.0-20230115221845-51c282652aef/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg=
|
||||
git.milar.in/nyaanime/model v0.0.0-20230117081410-7701a09a0de0 h1:70QTQYoF3OYkJur6gCygb9D+2awYv2gNjWdWMCl/8FU=
|
||||
git.milar.in/nyaanime/model v0.0.0-20230117081410-7701a09a0de0/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg=
|
||||
git.milar.in/nyaanime/model v0.0.0-20230117081612-d3fc649dad67 h1:p69LqaWzN/2zsgw45tR1XbFxyayu9ffVlikiKE2ibRw=
|
||||
git.milar.in/nyaanime/model v0.0.0-20230117081612-d3fc649dad67/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg=
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230115231942-89b759a7829f h1:xJiFxbLRKyb+43Yfv3UaZO1GiRGAsakebz6mHKUaRdI=
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230115231942-89b759a7829f/go.mod h1:fqiJqSWxh1YVJkKhvQql/21HmQzv4elhC3SpH/2TybI=
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230115232356-54a23b868d71 h1:BwWlk7UuQ/Ii97/XUVijujH4nkYJwZ0dHpghQ04hQeo=
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230115232356-54a23b868d71/go.mod h1:fqiJqSWxh1YVJkKhvQql/21HmQzv4elhC3SpH/2TybI=
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230117093342-b57ecf49e1f5 h1:/CdnetuL/vNwo8VsPX2n4IQt81ozYCLDScgmkPser8c=
|
||||
git.milar.in/nyaanime/parsers v0.0.0-20230117093342-b57ecf49e1f5/go.mod h1:fqiJqSWxh1YVJkKhvQql/21HmQzv4elhC3SpH/2TybI=
|
||||
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
||||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
||||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
|
||||
|
@ -34,10 +34,15 @@ func SendTelegramMessage(text string) {
|
||||
}
|
||||
}
|
||||
|
||||
func SendTelegramAnimeEpMessage(messagePattern *template.Template, animeEp model.AnimeEpisode) {
|
||||
func SendTelegramAnimeEpMessage(messagePattern *template.Template, animeEps []model.AnimeEpisode) {
|
||||
if len(animeEps) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
b := new(strings.Builder)
|
||||
if err := messagePattern.Execute(b, animeEp); err != nil {
|
||||
if err := messagePattern.Execute(b, animeEps); err != nil {
|
||||
adverr.Println(adverr.Wrap("could not send telegram message", err))
|
||||
}
|
||||
|
||||
SendTelegramMessage(b.String())
|
||||
}
|
||||
|
12
utils.go
12
utils.go
@ -22,3 +22,15 @@ func Map2Table[K comparable](title string, m map[K]int) string {
|
||||
|
||||
return table.String()
|
||||
}
|
||||
|
||||
func GetAnimeEpisodesSortFunc(s []model.AnimeEpisode) func(i, j int) bool {
|
||||
return func(i, j int) bool {
|
||||
if s[i].Anime.ID < s[j].Anime.ID {
|
||||
return true
|
||||
} else if s[i].Anime.ID > s[j].Anime.ID {
|
||||
return false
|
||||
} else {
|
||||
return s[i].Episode <= s[j].Episode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user