From e0228c65cd7d947b267150ecf02f4d97d380e2c0 Mon Sep 17 00:00:00 2001 From: moonleay Date: Wed, 28 Jun 2023 23:15:26 +0200 Subject: [PATCH] feat: removed old Feature interface, removed manager temp, moved IFeature into .feature.component chore: add credits, add comments Signed-off-by: limited_dev --- src/main/kotlin/net/moonleay/lilJudd/Bot.kt | 22 ++++++++++---- .../lilJudd/features/AvailabilityManager.kt | 6 ++-- .../moonleay/lilJudd/features/TimeManager.kt | 1 + .../lilJudd/features/component/Feature.kt | 30 ------------------- .../{FeatureManager.kt => IFeature.kt} | 5 ++-- 5 files changed, 22 insertions(+), 42 deletions(-) delete mode 100644 src/main/kotlin/net/moonleay/lilJudd/features/component/Feature.kt rename src/main/kotlin/net/moonleay/lilJudd/features/component/{FeatureManager.kt => IFeature.kt} (88%) diff --git a/src/main/kotlin/net/moonleay/lilJudd/Bot.kt b/src/main/kotlin/net/moonleay/lilJudd/Bot.kt index 4090477..b8c138e 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/Bot.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/Bot.kt @@ -26,7 +26,9 @@ import dev.kord.core.event.interaction.ButtonInteractionCreateEvent import dev.kord.core.on import dev.kord.gateway.Intent import dev.kord.gateway.PrivilegedIntent -import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.launch import net.moonleay.botendo.build.BuildConstants import net.moonleay.lilJudd.buttons.component.EditButtonManager @@ -35,6 +37,7 @@ import net.moonleay.lilJudd.data.DB import net.moonleay.lilJudd.extensions.FeatureManageExtension import net.moonleay.lilJudd.extensions.SendPlannerExtension import net.moonleay.lilJudd.extensions.VersionExtension +import net.moonleay.lilJudd.features.AvailabilityManager import net.moonleay.lilJudd.features.TimeManager import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.MessageUtil @@ -73,11 +76,18 @@ object Bot { CredentialManager.dbPassword ) - // Register the TimePlanner thread - val coroutineJob = GlobalScope.launch { - TimeManager.registerThread() - //PlanningNotifier.registerThread() - } + // Register all the jobs + jobs.addAll( + listOf( + TimeManager, + AvailabilityManager, + ).map { + CoroutineScope(Dispatchers.Default).launch { + it.registerThread() + } + } + ) + // Thanks silenium-dev <3 // Add bot token to kord bot = ExtensibleBot(CredentialManager.token) { diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt index 8aa8ca7..943b1b5 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt @@ -29,6 +29,7 @@ import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData import net.moonleay.lilJudd.data.entry.TimePlanningMessagesData import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles import net.moonleay.lilJudd.data.tables.TimePlanningMessages +import net.moonleay.lilJudd.features.component.IFeature import net.moonleay.lilJudd.util.EmbedUtil import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.TimeUtil @@ -136,11 +137,10 @@ object AvailabilityManager : IFeature { 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 + val scheduler = buildSchedule("0 0 5 * * * 0o *") // 0 0 4 * * * 0o 1w // 0o is UTC scheduler.doInfinity { - + Logger.out("Starting to update roles...") this.runThread() } - Logger.out("Starting to update roles...") } } diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt index 519e162..5df369e 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt @@ -31,6 +31,7 @@ import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles import net.moonleay.lilJudd.data.tables.TimePlanningChannels import net.moonleay.lilJudd.data.tables.TimePlanningMessages +import net.moonleay.lilJudd.features.component.IFeature import net.moonleay.lilJudd.util.EmbedUtil import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.MessageUtil diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/component/Feature.kt b/src/main/kotlin/net/moonleay/lilJudd/features/component/Feature.kt deleted file mode 100644 index da04430..0000000 --- a/src/main/kotlin/net/moonleay/lilJudd/features/component/Feature.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * lilJudd - * Copyright (C) 2023 moonleay - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.moonleay.lilJudd.features.component - -import dev.kord.core.entity.Message - -interface Feature { - val feature: FeatureEnum - - fun enable(): Message - fun disable(): Message - - suspend fun registerThread() -} diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/component/FeatureManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/component/IFeature.kt similarity index 88% rename from src/main/kotlin/net/moonleay/lilJudd/features/component/FeatureManager.kt rename to src/main/kotlin/net/moonleay/lilJudd/features/component/IFeature.kt index 76af6f1..da5630a 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/component/FeatureManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/component/IFeature.kt @@ -18,7 +18,6 @@ package net.moonleay.lilJudd.features.component -object FeatureManager { - // See note in Feature.kt - val features = mutableListOf() +interface IFeature { + suspend fun registerThread() }