From 15d2aec85e8b1b425d03180f36edc06c73b17351 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Wed, 28 Jun 2023 23:15:11 +0200 Subject: [PATCH] feat: improved feature / cronjob system Changes by silenium-dev Signed-off-by: limited_dev --- src/main/kotlin/net/moonleay/lilJudd/Bot.kt | 8 ++------ .../net/moonleay/lilJudd/features/AvailabilityManager.kt | 4 ++-- .../kotlin/net/moonleay/lilJudd/features/TimeManager.kt | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/Bot.kt b/src/main/kotlin/net/moonleay/lilJudd/Bot.kt index e7247a7..4090477 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/Bot.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/Bot.kt @@ -44,6 +44,8 @@ object Bot { //The kord object gets set at app launch lateinit var bot: ExtensibleBot + private val jobs = mutableListOf() + @OptIn(PrivilegedIntent::class) suspend fun start() { Logger.out("Starting Bot...") @@ -77,12 +79,6 @@ object Bot { //PlanningNotifier.registerThread() } - // Add a shutdown hook to cancel the coroutine when the application is terminated - Runtime.getRuntime().addShutdownHook(Thread { - coroutineJob.cancel() - }) - - // Add bot token to kord bot = ExtensibleBot(CredentialManager.token) { applicationCommands { diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt index 8961ef1..8aa8ca7 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt @@ -37,7 +37,7 @@ import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction import java.time.ZonedDateTime -object AvailabilityManager { +object AvailabilityManager : IFeature { // This runs during the cronjob. @OptIn(PrivilegedIntent::class) @@ -134,7 +134,7 @@ object AvailabilityManager { Logger.out("Done! Until tomorrow! <3 ") } - suspend fun registerThread() { + override suspend fun registerThread() { Logger.out("Adding availability scheduler...") val scheduler = buildSchedule("0 0 5 * * * 0o *w") // 0 0 4 * * * 0o 1w // 0o is UTC scheduler.doInfinity { diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt index a920e02..519e162 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt @@ -42,7 +42,7 @@ import java.time.ZoneId import java.time.ZonedDateTime -object TimeManager { +object TimeManager : IFeature { /* /--------------- Seconds | /------------- Minutes | | /----------- Hours @@ -53,7 +53,7 @@ object TimeManager { | | | | | | | / (optional) Week days * * * * * * 0o *w*/ - suspend fun registerThread() { + override suspend fun registerThread() { Logger.out("Adding message scheduler...") val scheduler = buildSchedule("0 0 4 * * * 0o 1w") // 0 0 4 * * * 0o 1w // 0o is UTC scheduler.doInfinity {