feat: added SendPlannerExtension

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-05 12:50:50 +02:00
parent 1cb043640a
commit 3d0b05cb1f
2 changed files with 117 additions and 0 deletions

View file

@ -31,6 +31,7 @@ import net.moonleay.lilJudd.buttons.component.EditButtonManager
import net.moonleay.lilJudd.data.CredentialManager import net.moonleay.lilJudd.data.CredentialManager
import net.moonleay.lilJudd.data.DB import net.moonleay.lilJudd.data.DB
import net.moonleay.lilJudd.extensions.FeatureManageExtension import net.moonleay.lilJudd.extensions.FeatureManageExtension
import net.moonleay.lilJudd.extensions.SendPlannerExtension
import net.moonleay.lilJudd.extensions.VersionExtension import net.moonleay.lilJudd.extensions.VersionExtension
import net.moonleay.lilJudd.features.TimePlanner import net.moonleay.lilJudd.features.TimePlanner
import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.Logger
@ -86,6 +87,7 @@ object Bot {
extensions { extensions {
add(::VersionExtension) add(::VersionExtension)
add(::FeatureManageExtension) add(::FeatureManageExtension)
add(::SendPlannerExtension)
//add(::TestExtension) // See comment in TestExtension.kt //add(::TestExtension) // See comment in TestExtension.kt
} }

View file

@ -0,0 +1,115 @@
/*
* 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.extensions
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.converters.impl.int
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.common.Color
import dev.kord.core.behavior.channel.createMessage
import dev.kord.rest.builder.message.create.actionRow
import kotlinx.coroutines.delay
import kotlinx.datetime.DayOfWeek
import net.moonleay.lilJudd.util.ButtonUtil
import net.moonleay.lilJudd.util.Logger
import net.moonleay.lilJudd.util.MessageUtil
import java.time.ZoneId
import java.time.ZonedDateTime
/* This extension has no proper use.
It is used in testing to test stuff, without having to wait for certain events to trigger. */
class SendPlannerExtension : Extension() {
override val name = "sendplanner"
override val allowApplicationCommandInDMs: Boolean
get() = false
override suspend fun setup() {
publicSlashCommand(::PlannerArgs) {
name = "sendplanner"
description = "Send the planner for the current and x next weeks"
this.action {
val res = this.respond {
this.content = "OK."
}
res.delete()
if (this.arguments.weeks == 0) {
return@action
}
val c = this.getChannel().asChannel()
var then =
ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4)
.withMinute(0).withSecond(0)
repeat(this.arguments.weeks) {
c.createMessage {
this.embeds.add(
MessageUtil.getEmbed(
Color(0X4C4645),
"Time Planning Feature",
"Do you have time on the following Days?",
"Automated Message"
)
)
}
delay(1000)
repeat(7) {
c.createMessage {
this.embeds.add(
MessageUtil.getEmbedWithTable(
Color(0X4C4645),
"",
"${then.dayOfWeek.name}, ${then.dayOfMonth}.${then.monthValue}.${then.year} /${it + 1}. weekday",
mapOf(
"Is available" to listOf(),
"May be available" to listOf(),
"Is not available" to listOf()
)
)
)
this.actionRow {
this.components.addAll(ButtonUtil.getTimePlannerButtons().components)
}
}
then = then.plusDays(1).withHour(4).withMinute(0).withSecond(0)
Logger.out("Finished sending day $it")
delay(1000)
}
Logger.out("Finished week $it")
}
Logger.out("Finished with ${c.data.guildId.value}")
}
}
}
fun getMondayDayOfMonth(): Int {
val now = ZonedDateTime.now()
val monday = now.with(DayOfWeek.MONDAY)
return monday.dayOfMonth
}
inner class PlannerArgs : Arguments() {
val weeks by int {
name = "weeks"
description = "Amount of weeks to send. Needs to be at least 1."
minValue = 1
}
}
}