remove duplicate anime episodes from telegram report message

This commit is contained in:
milarin 2023-02-02 12:36:23 +01:00
parent c46d395f3f
commit 971ccca0d3

View File

@ -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 {