From cd37bd1242074411a79e287f5053d9822f823c4b Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 5 Oct 2023 10:29:27 +0200 Subject: [PATCH] fix: fixed issues with timestamps Signed-off-by: moonleay --- .../lilJudd/extensions/MatchExtension.kt | 2 +- .../extensions/SendPlannerExtension.kt | 2 +- .../lilJudd/features/AvailabilityManager.kt | 23 +++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/extensions/MatchExtension.kt b/src/main/kotlin/net/moonleay/lilJudd/extensions/MatchExtension.kt index 9f2674d..ff47b9b 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/extensions/MatchExtension.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/extensions/MatchExtension.kt @@ -108,7 +108,7 @@ class MatchExtension : Extension() { role.id.value.toLong(), opponent, msg.id.value.toLong(), - (zdt.toEpochSecond() * 1000), + (zdt.toEpochSecond()), jobString ) ) diff --git a/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt b/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt index 7b85b1d..781de2c 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/extensions/SendPlannerExtension.kt @@ -105,7 +105,7 @@ class SendPlannerExtension : Extension() { -1, c.data.guildId.value?.value!!.toLong(), c.id.value.toLong(), - (TimeUtil.getWeekStamp().toEpochSecond() * 1000), + (TimeUtil.getWeekStamp().toEpochSecond()), msgStr ) ) diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt index 148c251..cc49d1c 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/AvailabilityManager.kt @@ -47,18 +47,21 @@ object AvailabilityManager : IFeature { Logger.out("Starting to update roles...") // ChannelID, Data - val messages = TimePlanningMessagesRepository.getWeek(TimeUtil.getWeekStamp().toEpochSecond() * 1000) + val messages = TimePlanningMessagesRepository.getWeek(TimeUtil.getWeekStamp().toEpochSecond()) .associateBy { it.channelID } val targetedRoles = PlanningNotifierRolesRepository.getAll().associateBy { it.channelID } + if (targetedRoles.isEmpty()) { + Logger.out("No saved roles. Canceling.") + return + } for (id in messages.keys) { val snf = Snowflake(id) // snf = Snowflake val data = messages[id]!! // this is the data of the table - if (Bot.bot.kordRef.getChannel(Snowflake(data.channelID)) == null) - continue // This channel does not exist anymore. - if (targetedRoles.isEmpty()) { - Logger.out("No saved roles. Canceling.") - return + if (Bot.bot.kordRef.getChannel(Snowflake(data.channelID)) == null) { + // This channel does not exist anymore. + Logger.out("Warning: Channel ${data.channelID} does not exist anymore. Skipping.") + continue } val roleData = targetedRoles[data.channelID] // Get the role data if (roleData == null) { @@ -71,15 +74,17 @@ object AvailabilityManager : IFeature { } suspend fun updateInChannel(snf: Snowflake) { + val stamp = TimeUtil.getWeekStamp().toEpochSecond() + Logger.out("Weekstamp: $stamp") val messageData = TimePlanningMessagesRepository.getWeekInChannel( - TimeUtil.getWeekStamp().toEpochSecond() * 1000, + stamp, snf.value.toLong() ) - val roleData = PlanningNotifierRolesRepository.getForChannel(snf.value.toLong()) if (messageData == null) { Logger.out("Could not find data for channel ${snf.value}") return } + val roleData = PlanningNotifierRolesRepository.getForChannel(snf.value.toLong()) if (roleData == null) { Logger.out("Role for channel ${messageData.channelID} does not exist") return // this took way to long to find out that this was the issue @@ -93,7 +98,7 @@ object AvailabilityManager : IFeature { return // This channel does not exist anymore. val c = Bot.bot.kordRef.getChannelOf(snf)!! // Get the channel as MessageChannel val weekday = ZonedDateTime.now().dayOfWeek // The current week day - val weekStamp = TimeUtil.getWeekStamp().toEpochSecond() * 1000 // The current week time stamp + val weekStamp = TimeUtil.getWeekStamp().toEpochSecond() // The current week time stamp Logger.out("It is week ${weekStamp} and day ${weekday}/${TimeUtil.getDayOfMonthInt(weekday)} of the week.") val g = Bot.bot.kordRef.getGuild(Snowflake(tpmd.serverID)) // Get all members with the role