diff --git a/src/main/kotlin/net/moonleay/lilJudd/Bot.kt b/src/main/kotlin/net/moonleay/lilJudd/Bot.kt index 311616d..66208c7 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/Bot.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/Bot.kt @@ -31,6 +31,7 @@ import net.moonleay.lilJudd.buttons.component.EditButtonManager import net.moonleay.lilJudd.data.CredentialManager import net.moonleay.lilJudd.data.DB import net.moonleay.lilJudd.extensions.FeatureManageExtension +import net.moonleay.lilJudd.extensions.SendPlannerExtension import net.moonleay.lilJudd.extensions.VersionExtension import net.moonleay.lilJudd.features.TimeManager import net.moonleay.lilJudd.util.Logger @@ -86,6 +87,7 @@ object Bot { extensions { add(::VersionExtension) add(::FeatureManageExtension) + add(::SendPlannerExtension) //add(::TestExtension) // See comment in TestExtension.kt } diff --git a/src/main/kotlin/net/moonleay/lilJudd/extensions/FeatureManageExtension.kt b/src/main/kotlin/net/moonleay/lilJudd/extensions/FeatureManageExtension.kt index 582a079..7384c56 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/extensions/FeatureManageExtension.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/extensions/FeatureManageExtension.kt @@ -42,6 +42,8 @@ import org.jetbrains.exposed.sql.transactions.transaction class FeatureManageExtension : Extension() { override val name = "feature" + override val allowApplicationCommandInDMs: Boolean + get() = false /* * Note: This has to be rewritten at some point to better support more features diff --git a/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt b/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt new file mode 100644 index 0000000..4d3defb --- /dev/null +++ b/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt @@ -0,0 +1,123 @@ +/* + * 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.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 com.kotlindiscord.kord.extensions.utils.hasPermission +import dev.kord.common.Color +import dev.kord.common.entity.Permission +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 { + if (this.arguments.weeks == 0 || !this.member!!.asMember(this.guild!!.id) + .hasPermission(Permission.Administrator) + ) { + val res = this.respond { + this.content = "no." + } + res.delete() + return@action + } + val res = this.respond { + this.content = "OK." + } + res.delete() + 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 + } + } +} diff --git a/src/main/kotlin/net/moonleay/lilJudd/extensions/TestExtension.kt b/src/main/kotlin/net/moonleay/lilJudd/extensions/TestExtension.kt index c6d44c3..049b2e5 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/extensions/TestExtension.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/extensions/TestExtension.kt @@ -30,6 +30,9 @@ import net.moonleay.lilJudd.util.MessageUtil It is used in testing to test stuff, without having to wait for certain events to trigger. */ class TestExtension : Extension() { override val name = "test" + override val allowApplicationCommandInDMs: Boolean + get() = false + override suspend fun setup() { publicSlashCommand { name = "test" diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt index 403dec8..0da325b 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt @@ -119,7 +119,6 @@ object TimeManager { } } then = then.plusDays(1).withHour(4).withMinute(0).withSecond(0) - Logger.out("Finished sending day $it") delay(1000)