From 72670d4dd4e535c421f1f1c6a6ced040344ad511 Mon Sep 17 00:00:00 2001 From: limited_dev Date: Wed, 28 Jun 2023 22:52:44 +0200 Subject: [PATCH] feat: added saving of the messageids, chore: moved getMondayDayOfMonth function to TimeUtil Signed-off-by: limited_dev --- .../extensions/SendPlannerExtension.kt | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt b/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt index 2482bbf..f038602 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt @@ -27,10 +27,13 @@ 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.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 @@ -58,10 +61,12 @@ class SendPlannerExtension : Extension() { val res = this.respond { this.content = "OK." } - res.delete() + res.delete() // Delete the response val c = this.getChannel().asChannel() + var msgStr = "" var then = - ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4) + ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(TimeUtil.getMondayDayOfMonth()) + .withHour(4) .withMinute(0).withSecond(0) c.createMessage { this.embeds.add( @@ -75,7 +80,7 @@ class SendPlannerExtension : Extension() { } delay(1000) repeat(7) { - c.createMessage { + val msg = c.createMessage { this.embeds.add( MessageUtil.getEmbedWithTable( Color(0X4C4645), @@ -90,21 +95,26 @@ class SendPlannerExtension : Extension() { ) this.actionRow { - this.components.addAll(ButtonUtil.getTimePlannerButtons().components) + 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") delay(1000) } + + // Save the message ids + transaction { + TimePlanningMessages.insert { + it[serverid] = c.data.guildId.value.toString() + it[channelid] = c.id.value.toString() + it[weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString() + it[messageids] = msgStr + } get TimePlanningMessages.id + } Logger.out("Finished with ${c.data.guildId.value}") } } } - - fun getMondayDayOfMonth(): Int { - val now = ZonedDateTime.now() - val monday = now.with(DayOfWeek.MONDAY) - return monday.dayOfMonth - } }