From a0e83ee89426cbdfacaa223fe0f4dcb88262043d Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Fri, 22 Sep 2023 20:09:43 +0200 Subject: [PATCH] Update episode release listener for enhanced notifications --- .../fr/ziedelth/listeners/EpisodesRelease.kt | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/fr/ziedelth/listeners/EpisodesRelease.kt b/src/main/kotlin/fr/ziedelth/listeners/EpisodesRelease.kt index 289f5f5..0223fdc 100644 --- a/src/main/kotlin/fr/ziedelth/listeners/EpisodesRelease.kt +++ b/src/main/kotlin/fr/ziedelth/listeners/EpisodesRelease.kt @@ -1,5 +1,7 @@ package fr.ziedelth.listeners +import fr.ziedelth.entities.EpisodeType +import fr.ziedelth.entities.LangType import fr.ziedelth.events.EpisodesReleaseEvent import fr.ziedelth.utils.Notifications import fr.ziedelth.utils.plugins.events.EventHandler @@ -10,6 +12,23 @@ class EpisodesRelease : Listener { private var lastDaySend = 0 private var lastSend = mutableListOf() + fun toString(triple: Triple): String { + val etName = when (triple.first.name) { + "EPISODE" -> "Épisode" + "SPECIAL" -> "Spécial" + "FILM" -> "Film" + else -> "Épisode" + } + + val ltName = when (triple.third.name) { + "SUBTITLES" -> "VOSTFR" + "VOICE" -> "VF" + else -> "VOSTFR" + } + + return "$etName ${triple.second} $ltName" + } + @EventHandler fun onEpisodesRelease(event: EpisodesReleaseEvent) { val currentDay = Calendar.getInstance()[Calendar.DAY_OF_YEAR] @@ -19,19 +38,20 @@ class EpisodesRelease : Listener { lastSend.clear() } - val animes = - event.episodes.mapNotNull { it.anime }.distinctBy { it.uuid }.filter { !lastSend.contains(it.uuid) } + val animes = event.episodes.map { it.anime to toString(Triple(it.episodeType!!, it.number!!, it.langType!!)) }.distinctBy { it.first?.uuid }.filter { !lastSend.contains(it.first?.uuid) } if (animes.isEmpty()) return - lastSend.addAll(animes.map { it.uuid }) - val animeNames = animes.mapNotNull { it.name }.sortedBy { it.lowercase() } - println("Sending notification for ${animes.size} animes: ${animeNames.joinToString(", ")}") + lastSend.addAll(animes.map { it.first!!.uuid }) + + val animeNames = animes.sortedBy { it.first!!.name!!.lowercase() } + val joinToString = animeNames.joinToString(", ") { "${it.first!!.name} - ${it.second}" } + println("Sending notification for ${animes.size} animes: $joinToString") - Notifications.send(body = animeNames.joinToString(", ")) + Notifications.send(body = joinToString) animes.forEach { Notifications.send( - title = it.name, - body = "Un nouvel épisode est sorti !", - topic = it.uuid.toString() + title = it.first!!.name, + body = "${it.second} est disponible !", + topic = it.first!!.uuid.toString() ) } }