feat: improved feature / cronjob system

Changes by silenium-dev

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-28 23:15:11 +02:00
parent 72670d4dd4
commit 15d2aec85e
3 changed files with 6 additions and 10 deletions

View file

@ -44,6 +44,8 @@ object Bot {
//The kord object gets set at app launch
lateinit var bot: ExtensibleBot
private val jobs = mutableListOf<Job>()
@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 {

View file

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

View file

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