feature/ScheduleCommand #5

Merged
moonleay merged 7 commits from feature/ScheduleCommand into master 2024-01-19 21:47:20 +00:00
3 changed files with 495 additions and 0 deletions
Showing only changes of commit 98cdbebf79 - Show all commits

View file

@ -113,6 +113,7 @@ object Bot {
add(::SendPlannerExtension)
add(::MatchExtension)
add(::UpdateRolesExtension)
add(::RotationExtension)
}
this.presence {

View file

@ -0,0 +1,464 @@
/*
* lilJudd
* Copyright (C) 2024 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.extensions
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.enumChoice
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import dev.kord.common.Color
import dev.kord.rest.builder.message.embed
import kotlinx.datetime.Clock
import net.moonleay.lilJudd.data.api.splatoon3ink.Splatoon3ApiDataGrabber
import net.moonleay.lilJudd.extensions.component.SplatoonOnlineMode
import net.moonleay.lilJudd.util.TimeUtil
class RotationExtension : Extension() {
override val name = "rotation"
override val allowApplicationCommandInDMs: Boolean
get() = false
override suspend fun setup() {
publicSlashCommand(::RotationArguments) {
name = "rotation"
description = "Check the current rotations"
this.action {
val mode = this.arguments.mode
when (mode) {
SplatoonOnlineMode.ALL -> {
val regSched = Splatoon3ApiDataGrabber.getRegularMode(System.currentTimeMillis())
val regMaps = regSched.regularMatchSetting.vsStages
val regMap1 = regMaps[0]
val regMap2 = regMaps[1]
val serSched = Splatoon3ApiDataGrabber.getSeriesMode(System.currentTimeMillis())
val serMaps = serSched.bankaraMatchSettings!!.first().vsStages
val serMap1 = serMaps[0]
val serMap2 = serMaps[1]
val opnSched = Splatoon3ApiDataGrabber.getSeriesMode(System.currentTimeMillis())
val opnMaps = opnSched.bankaraMatchSettings!!.last().vsStages
val opnMap1 = opnMaps[0]
val opnMap2 = opnMaps[1]
val xSched = Splatoon3ApiDataGrabber.getXMode(System.currentTimeMillis())
val xMaps = xSched.xMatchSetting.vsStages
val xMap1 = xMaps[0]
val xMap2 = xMaps[1]
val salSched = Splatoon3ApiDataGrabber.getSalmonRun(System.currentTimeMillis())
val salMap = salSched.setting.coopStage.name
val salBoss = salSched.setting.boss.name
val salWeapons = salSched.setting.weapons
this.respond {
this.embed {
this.author {
this.name = "Current rotation for"
}
this.title = "All Modes"
this.description = "[[Open on website](https://splatoon3.ink/)]"
this.color = Color(0x1437FF)
this.thumbnail {
this.url = "https://static.moonleay.net/img/lilJudd/deepcut.png"
}
this.field {
this.name = "Regular (${
TimeUtil.getTimeFromJSONTime(
regSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(regSched.endTime, "UTC")})"
this.value =
"${regSched.regularMatchSetting.vsRule.name} on ${regMap1.name} & ${regMap2.name}"
this.inline = false
}
this.field {
this.name = "Series (${
TimeUtil.getTimeFromJSONTime(
serSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(serSched.endTime, "UTC")})"
this.value =
"${serSched.bankaraMatchSettings.first().vsRule.name} on ${serMap1.name} & ${serMap2.name}"
this.inline = false
}
this.field {
this.name = "Open (${
TimeUtil.getTimeFromJSONTime(
opnSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(opnSched.endTime, "UTC")})"
this.value =
"${opnSched.bankaraMatchSettings.last().vsRule.name} on ${opnMap1.name} & ${opnMap2.name}"
this.inline = false
}
this.field {
this.name = "X (${
TimeUtil.getTimeFromJSONTime(
xSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(xSched.endTime, "UTC")})"
this.value = "${xSched.xMatchSetting.vsRule.name} on ${xMap1.name} & ${xMap2.name}"
this.inline = false
}
this.field {
this.name = "Salmon Run (${
TimeUtil.getTimeFromJSONTimeLong(
salSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTimeLong(salSched.endTime, "UTC")})"
this.value =
"${salBoss} on ${salMap} with ${salWeapons[0].name}, ${salWeapons[1].name}, ${salWeapons[2].name} & ${salWeapons[3].name}"
this.inline = false
}
this.timestamp = Clock.System.now()
this.footer {
this.text = "Data provided by splatoon3.ink"
this.icon = "https://fedi.splatoon3.ink/favicon.png"
}
}
}
}
SplatoonOnlineMode.REGULAR -> {
val regSched = Splatoon3ApiDataGrabber.getRegularMode(System.currentTimeMillis())
val regMaps = regSched.regularMatchSetting.vsStages
val regMap1 = regMaps[0]
val regMap2 = regMaps[1]
val regSched2 =
Splatoon3ApiDataGrabber.getRegularMode(System.currentTimeMillis() + 1000 * 60 * 60 * 2)
val regMaps2 = regSched2.regularMatchSetting.vsStages
val regMap12 = regMaps2[0]
val regMap22 = regMaps2[1]
this.respond {
this.embed {
this.author {
this.name = "Current rotation for"
}
this.title = "Regular Mode"
this.description = "[[Open on website](https://splatoon3.ink/)]"
this.color = Color(0x18c81b)
this.thumbnail {
this.url = "https://static.moonleay.net/img/lilJudd/regular.png"
}
this.field {
this.name = "Current (${
TimeUtil.getTimeFromJSONTime(
regSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(regSched.endTime, "UTC")})"
this.value =
"${regSched.regularMatchSetting.vsRule.name} on ${regMap1.name} & ${regMap2.name}"
this.inline = false
}
this.field {
this.name = "${
TimeUtil.getTimeFromJSONTime(
regSched2.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(regSched2.endTime, "UTC")}"
this.value =
"${regSched2.regularMatchSetting.vsRule.name} on ${regMap12.name} & ${regMap22.name}"
this.inline = false
}
this.timestamp = Clock.System.now()
this.footer {
this.text = "Data provided by splatoon3.ink"
this.icon = "https://fedi.splatoon3.ink/favicon.png"
}
}
}
}
SplatoonOnlineMode.SERIES -> {
val serSched = Splatoon3ApiDataGrabber.getSeriesMode(System.currentTimeMillis())
val serMaps = serSched.bankaraMatchSettings!!.first().vsStages
val serMap1 = serMaps[0]
val serMap2 = serMaps[1]
val serSched2 =
Splatoon3ApiDataGrabber.getSeriesMode(System.currentTimeMillis() + 1000 * 60 * 60 * 2)
val serMaps2 = serSched2.bankaraMatchSettings!!.first().vsStages
val serMap12 = serMaps2[0]
val serMap22 = serMaps2[1]
this.respond {
this.embed {
this.author {
this.name = "Current rotation for"
}
this.title = "Ranked Series Mode"
this.description = "[[Open on website](https://splatoon3.ink/)]"
this.color = Color(0xE14412)
this.thumbnail {
this.url = "https://static.moonleay.net/img/lilJudd/bankara.png"
}
this.field {
this.name = "Current (${
TimeUtil.getTimeFromJSONTime(
serSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(serSched.endTime, "UTC")})"
this.value =
"${serSched.bankaraMatchSettings.first().vsRule.name} on ${serMap1.name} & ${serMap2.name}"
this.inline = false
}
this.field {
this.name = "${
TimeUtil.getTimeFromJSONTime(
serSched2.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(serSched2.endTime, "UTC")}"
this.value =
"${serSched2.bankaraMatchSettings.first().vsRule.name} on ${serMap12.name} & ${serMap22.name}"
this.inline = false
}
this.timestamp = Clock.System.now()
this.footer {
this.text = "Data provided by splatoon3.ink"
this.icon = "https://fedi.splatoon3.ink/favicon.png"
}
}
}
}
SplatoonOnlineMode.OPEN -> {
val opnSched = Splatoon3ApiDataGrabber.getSeriesMode(System.currentTimeMillis())
val opnMaps = opnSched.bankaraMatchSettings!!.last().vsStages
val opnMap1 = opnMaps[0]
val opnMap2 = opnMaps[1]
val opnSched2 =
Splatoon3ApiDataGrabber.getSeriesMode(System.currentTimeMillis() + 1000 * 60 * 60 * 2)
val opnMaps2 = opnSched2.bankaraMatchSettings!!.last().vsStages
val opnMap12 = opnMaps2[0]
val opnMap22 = opnMaps2[1]
this.respond {
this.embed {
this.author {
this.name = "Current rotation for"
}
this.title = "Ranked Open Mode"
this.description = "[[Open on website](https://splatoon3.ink/)]"
this.color = Color(0xE14412)
this.thumbnail {
this.url = "https://static.moonleay.net/img/lilJudd/bankara.png"
}
this.field {
this.name = "Current (${
TimeUtil.getTimeFromJSONTime(
opnSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(opnSched.endTime, "UTC")})"
this.value =
"${opnSched.bankaraMatchSettings.last().vsRule.name} on ${opnMap1.name} & ${opnMap2.name}"
this.inline = false
}
this.field {
this.name = "${
TimeUtil.getTimeFromJSONTime(
opnSched2.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(opnSched2.endTime, "UTC")}"
this.value =
"${opnSched2.bankaraMatchSettings.last().vsRule.name} on ${opnMap12.name} & ${opnMap22.name}"
this.inline = false
}
this.timestamp = Clock.System.now()
this.footer {
this.text = "Data provided by splatoon3.ink"
this.icon = "https://fedi.splatoon3.ink/favicon.png"
}
}
}
}
SplatoonOnlineMode.X -> {
val xSched = Splatoon3ApiDataGrabber.getXMode(System.currentTimeMillis())
val xMaps = xSched.xMatchSetting.vsStages
val xMap1 = xMaps[0]
val xMap2 = xMaps[1]
val xSched2 = Splatoon3ApiDataGrabber.getXMode(System.currentTimeMillis() + 1000 * 60 * 60 * 2)
val xMaps2 = xSched2.xMatchSetting.vsStages
val xMap12 = xMaps2[0]
val xMap22 = xMaps2[1]
this.respond {
this.embed {
this.author {
this.name = "Current rotation for"
}
this.title = "X Mode"
this.description = "[[Open on website](https://splatoon3.ink/)]"
this.color = Color(0x0ECB93)
this.thumbnail {
this.url = "https://static.moonleay.net/img/lilJudd/x.png"
}
this.field {
this.name = "Current (${
TimeUtil.getTimeFromJSONTime(
xSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(xSched.endTime, "UTC")})"
this.value = "${xSched.xMatchSetting.vsRule.name} on ${xMap1.name} & ${xMap2.name}"
this.inline = false
}
this.field {
this.name = "${
TimeUtil.getTimeFromJSONTime(
xSched2.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTime(xSched2.endTime, "UTC")}"
this.value =
"${xSched2.xMatchSetting.vsRule.name} on ${xMap12.name} & ${xMap22.name}"
this.inline = false
}
this.timestamp = Clock.System.now()
this.footer {
this.text = "Data provided by splatoon3.ink"
this.icon = "https://fedi.splatoon3.ink/favicon.png"
}
}
}
}
SplatoonOnlineMode.SALMON_RUN -> {
val salSched = Splatoon3ApiDataGrabber.getSalmonRun(System.currentTimeMillis())
val salMap = salSched.setting.coopStage.name
val salBoss = salSched.setting.boss.name
val salWeapons = salSched.setting.weapons
val salSched2 =
Splatoon3ApiDataGrabber.getSalmonRun(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 2)
val salMap2 = salSched2.setting.coopStage.name
val salBoss2 = salSched2.setting.boss.name
val salWeapons2 = salSched2.setting.weapons
this.respond {
this.embed {
this.author {
this.name = "Current rotation for"
}
this.title = "Salmon Run"
this.description = "[[Open on website](https://splatoon3.ink/salmonrun)]"
this.color = Color(0xEA4F03)
this.thumbnail {
this.url = "https://static.moonleay.net/img/lilJudd/grizz.png"
}
this.field {
this.name = "Current (${
TimeUtil.getTimeFromJSONTimeLong(
salSched.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTimeLong(salSched.endTime, "UTC")})"
this.value =
"${salBoss} on ${salMap} with ${salWeapons[0].name}, ${salWeapons[1].name}, ${salWeapons[2].name} & ${salWeapons[3].name}"
this.inline = false
}
this.field {
this.name = "${
TimeUtil.getTimeFromJSONTimeLong(
salSched2.startTime,
"UTC"
)
} - ${TimeUtil.getTimeFromJSONTimeLong(salSched2.endTime, "UTC")}"
this.value =
"${salBoss2} on ${salMap2} with ${salWeapons2[0].name}, ${salWeapons2[1].name}, ${salWeapons2[2].name} & ${salWeapons2[3].name}"
this.inline = false
}
this.timestamp = Clock.System.now()
this.footer {
this.text = "Data provided by splatoon3.ink"
this.icon = "https://fedi.splatoon3.ink/favicon.png"
}
}
}
}
}
}
}
}
inner class RotationArguments : Arguments() {
val mode by enumChoice<SplatoonOnlineMode> {
this.name = "mode"
this.description = "The mode you want to check the rotation for"
this.typeName = "en_US"
}
}
}

View file

@ -0,0 +1,30 @@
/*
* lilJudd
* Copyright (C) 2024 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.extensions.component
import com.kotlindiscord.kord.extensions.commands.application.slash.converters.ChoiceEnum
enum class SplatoonOnlineMode(override val readableName: String) : ChoiceEnum {
ALL("All Modes"),
REGULAR("Regular Battle"),
SERIES("Ranked Battle (Series)"),
OPEN("Ranked Battle (Open)"),
X("X Battle"),
SALMON_RUN("Salmon Run"),
}