Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #160 from Z-Jais/master
Browse files Browse the repository at this point in the history
Update episode release listener for enhanced notifications
  • Loading branch information
Ziedelth authored Sep 22, 2023
2 parents 1e35bfa + a0e83ee commit 90d786b
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/main/kotlin/fr/ziedelth/listeners/EpisodesRelease.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,6 +12,23 @@ class EpisodesRelease : Listener {
private var lastDaySend = 0
private var lastSend = mutableListOf<UUID>()

fun toString(triple: Triple<EpisodeType, Int ,LangType>): 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]
Expand All @@ -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()
)
}
}
Expand Down

0 comments on commit 90d786b

Please sign in to comment.