/* * 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.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 net.moonleay.lilJudd.data.tables.TimePlanningMessages import net.moonleay.lilJudd.util.EmbedUtil import net.moonleay.lilJudd.util.Logger import net.moonleay.lilJudd.util.MessageUtil import net.moonleay.lilJudd.util.TimeUtil import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.transactions.transaction 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() { name = "sendplanner" description = "Send the planner for the current and x next weeks" this.action { if (!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() // Delete the response val c = this.getChannel().asChannel() var msgStr = "" var then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(TimeUtil.getMondayDayOfMonth()) .withHour(4) .withMinute(0).withSecond(0) 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) { val msg = 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(EmbedUtil.getTimePlannerButtons().components) } } msgStr += "${it}:${msg.id.value};" then = then.plusDays(1).withHour(4).withMinute(0).withSecond(0) Logger.out("Finished sending day $it/ This was manually triggered") delay(1000) } // Save the message ids transaction { TimePlanningMessages.insert { it[TimePlanningMessages.serverid] = c.data.guildId.value?.value!!.toLong() it[TimePlanningMessages.channelid] = c.id.value.toLong() it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000) it[TimePlanningMessages.messageids] = msgStr } get TimePlanningMessages.id } Logger.out("Finished with ${c.data.guildId.value}") } } } }