feat: added StatusUpdater to update the status of the bot

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2023-10-05 11:40:45 +02:00
parent e354ed9143
commit 5b4b3c9828

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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<String>()
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),
)
}
}