From 03fa8a51a78c14535f7bb04f95ac2d266c1ceadd Mon Sep 17 00:00:00 2001 From: limited_dev Date: Wed, 28 Jun 2023 22:43:55 +0200 Subject: [PATCH] feat: save messageids to database Signed-off-by: limited_dev --- .../moonleay/lilJudd/features/TimeManager.kt | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt index 91fcd80..a920e02 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt @@ -30,9 +30,12 @@ import net.moonleay.lilJudd.Bot import net.moonleay.lilJudd.data.entry.PlanningNotifierRolesData import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles import net.moonleay.lilJudd.data.tables.TimePlanningChannels -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.selectAll import org.jetbrains.exposed.sql.transactions.transaction import java.time.ZoneId @@ -62,6 +65,8 @@ object TimeManager { // ChannelID, Data val roleList = mutableMapOf() + var msgStr = "" + transaction { for (tp in TimePlanningChannels.selectAll()) { channelList[Snowflake(tp[TimePlanningChannels.channelid])] = @@ -74,9 +79,9 @@ object TimeManager { pnr[PlanningNotifierRoles.serverid], pnr[PlanningNotifierRoles.channelid], pnr[PlanningNotifierRoles.hastimeroleid], - pnr[PlanningNotifierRoles.wantstobenotifid] + pnr[PlanningNotifierRoles.wantstobenotifiedid] ) - Logger.out("Have to ping roles: ${pnr[PlanningNotifierRoles.wantstobenotifid]}}") + Logger.out("Have to ping roles: ${pnr[PlanningNotifierRoles.wantstobenotifiedid]}}") } } Logger.out("${channelList.count()} Channels to notify with ${roleList.count()} Roles to ping!") @@ -86,7 +91,8 @@ object TimeManager { val c = Bot.bot.kordRef.getChannelOf(ch)!! c.createMessage { if (roleList[ch] != null) { - this.content = "<@&${Snowflake(roleList[ch]?.wantstobenotifid!!)}>" + this.content = + "The weekly planning starts now <@&${Snowflake(roleList[ch]?.wantstobenotifid!!)}>" } this.embeds.add( MessageUtil.getEmbed( @@ -100,7 +106,7 @@ object TimeManager { delay(2000) var then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(4).withMinute(0).withSecond(0) repeat(7) { - c.createMessage { + val msg = c.createMessage { this.embeds.add( MessageUtil.getEmbedWithTable( Color(0X4C4645), @@ -115,14 +121,25 @@ object TimeManager { ) 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[TimePlanningMessages.serverid] = c.data.guildId.value.toString() + it[TimePlanningMessages.channelid] = c.id.value.toString() + it[TimePlanningMessages.weekstamp] = TimeUtil.getWeekStamp().toOffsetDateTime().toString() + it[TimePlanningMessages.messageids] = msgStr + } get PlanningNotifierRoles.id + } Logger.out("Finished with ${c.data.guildId.value}") } Logger.out("Done! Until next Monday! <3 ")