feat: added saving of the messageids,

chore: moved getMondayDayOfMonth function to TimeUtil

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-28 22:52:44 +02:00
parent 5c488fa91d
commit 72670d4dd4

View file

@ -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
}
}