forked from DiscordBots/lilJudd
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:
parent
5c488fa91d
commit
72670d4dd4
1 changed files with 22 additions and 12 deletions
|
@ -27,10 +27,13 @@ import dev.kord.common.entity.Permission
|
||||||
import dev.kord.core.behavior.channel.createMessage
|
import dev.kord.core.behavior.channel.createMessage
|
||||||
import dev.kord.rest.builder.message.create.actionRow
|
import dev.kord.rest.builder.message.create.actionRow
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.datetime.DayOfWeek
|
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
|
||||||
import net.moonleay.lilJudd.util.ButtonUtil
|
import net.moonleay.lilJudd.util.EmbedUtil
|
||||||
import net.moonleay.lilJudd.util.Logger
|
import net.moonleay.lilJudd.util.Logger
|
||||||
import net.moonleay.lilJudd.util.MessageUtil
|
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.ZoneId
|
||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
|
|
||||||
|
@ -58,10 +61,12 @@ class SendPlannerExtension : Extension() {
|
||||||
val res = this.respond {
|
val res = this.respond {
|
||||||
this.content = "OK."
|
this.content = "OK."
|
||||||
}
|
}
|
||||||
res.delete()
|
res.delete() // Delete the response
|
||||||
val c = this.getChannel().asChannel()
|
val c = this.getChannel().asChannel()
|
||||||
|
var msgStr = ""
|
||||||
var then =
|
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)
|
.withMinute(0).withSecond(0)
|
||||||
c.createMessage {
|
c.createMessage {
|
||||||
this.embeds.add(
|
this.embeds.add(
|
||||||
|
@ -75,7 +80,7 @@ class SendPlannerExtension : Extension() {
|
||||||
}
|
}
|
||||||
delay(1000)
|
delay(1000)
|
||||||
repeat(7) {
|
repeat(7) {
|
||||||
c.createMessage {
|
val msg = c.createMessage {
|
||||||
this.embeds.add(
|
this.embeds.add(
|
||||||
MessageUtil.getEmbedWithTable(
|
MessageUtil.getEmbedWithTable(
|
||||||
Color(0X4C4645),
|
Color(0X4C4645),
|
||||||
|
@ -90,21 +95,26 @@ class SendPlannerExtension : Extension() {
|
||||||
)
|
)
|
||||||
|
|
||||||
this.actionRow {
|
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)
|
then = then.plusDays(1).withHour(4).withMinute(0).withSecond(0)
|
||||||
Logger.out("Finished sending day $it")
|
Logger.out("Finished sending day $it")
|
||||||
delay(1000)
|
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}")
|
Logger.out("Finished with ${c.data.guildId.value}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMondayDayOfMonth(): Int {
|
|
||||||
val now = ZonedDateTime.now()
|
|
||||||
val monday = now.with(DayOfWeek.MONDAY)
|
|
||||||
return monday.dayOfMonth
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue