From 594050dd619344005a395d70314cc8ad7da8c434 Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 5 Oct 2023 11:40:45 +0200 Subject: [PATCH] feat: added StatusUpdater to update the status of the bot Signed-off-by: moonleay --- .../moonleay/lilJudd/jobs/StatusUpdater.kt | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt diff --git a/src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt b/src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt new file mode 100644 index 0000000..7f70859 --- /dev/null +++ b/src/main/kotlin/net/moonleay/lilJudd/jobs/StatusUpdater.kt @@ -0,0 +1,68 @@ +/* + * 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.jobs + +import dev.inmo.krontab.KronScheduler +import dev.kord.common.entity.PresenceStatus +import kotlinx.coroutines.Job +import net.moonleay.lilJudd.Bot +import net.moonleay.lilJudd.data.api.Splatoon3Api +import net.moonleay.lilJudd.jobs.component.CronjobType +import net.moonleay.lilJudd.jobs.component.ICronjob +import net.moonleay.lilJudd.util.Logger + +object StatusUpdater : ICronjob { + override val jobName: String + get() = "StatusUpdater" + override val jobIncoming: String + get() = "/6 * * * *" //Every 10 seconds + override val jobType: CronjobType + get() = CronjobType.INFINITE + override val continueJob: Boolean + get() = true + override lateinit var cronjobJob: Job + override lateinit var scheduler: KronScheduler + + private var statusList = listOf() + private var index = 0 + + override suspend fun jobFunction() { + Logger.out("Updating status.") + Bot.bot.kordRef.editPresence { + this.status = PresenceStatus.DoNotDisturb + this.playing(statusList[index]) + } + ++index + if (index >= statusList.size) { + index = 0 + } + } + + fun refreshStatusList(timestamp: Long) { + statusList = listOf( + Splatoon3Api.getRegularMapsFormatted(timestamp), + Splatoon3Api.getSeriesModeFormatted(timestamp), + Splatoon3Api.getSeriesMapsFormatted(timestamp), + Splatoon3Api.getOpenModeFormatted(timestamp), + Splatoon3Api.getOpenMapFormatted(timestamp), + Splatoon3Api.getXModeFormatted(timestamp), + Splatoon3Api.getXMapFormatted(timestamp), + ) + } +}