remove duplicate anime episodes from telegram report message
This commit is contained in:
parent
c46d395f3f
commit
971ccca0d3
14
telegram.go
14
telegram.go
@ -102,6 +102,8 @@ func sendTelegramAnimeEpMessage(animeEpisodes []model.AnimeEpisode) {
|
||||
return
|
||||
}
|
||||
|
||||
animeEpisodes = RemoveDuplicates(animeEpisodes)
|
||||
|
||||
b := new(strings.Builder)
|
||||
if err := TelegramOrganizeMessagePattern.Execute(b, animeEpisodes); err != nil {
|
||||
adverr.Println(adverr.Wrap("could not send telegram message", err))
|
||||
@ -110,6 +112,18 @@ func sendTelegramAnimeEpMessage(animeEpisodes []model.AnimeEpisode) {
|
||||
SendTelegramMessage(b.String())
|
||||
}
|
||||
|
||||
func RemoveDuplicates(animeEpisodes []model.AnimeEpisode) []model.AnimeEpisode {
|
||||
mapperFunc := func(animeEp model.AnimeEpisode) (model.Pair[anilist.MediaID, int], model.AnimeEpisode) {
|
||||
return model.Pair[anilist.MediaID, int]{First: animeEp.Anime.ID, Second: animeEp.Episode}, animeEp
|
||||
}
|
||||
|
||||
unmapperFunc := func(key model.Pair[anilist.MediaID, int], value model.AnimeEpisode) model.AnimeEpisode {
|
||||
return value
|
||||
}
|
||||
|
||||
return slices.OfMap(slices.ToMap(animeEpisodes, mapperFunc), unmapperFunc)
|
||||
}
|
||||
|
||||
func CheckSendConditions(animeEp model.AnimeEpisode) (bool, error) {
|
||||
listEntry, err := GetListEntry(animeEp.Anime)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user