fix: fixed issues with timestamps

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2023-10-05 10:29:27 +02:00
parent 4a0792af08
commit cd37bd1242
3 changed files with 16 additions and 11 deletions

View file

@ -108,7 +108,7 @@ class MatchExtension : Extension() {
role.id.value.toLong(), role.id.value.toLong(),
opponent, opponent,
msg.id.value.toLong(), msg.id.value.toLong(),
(zdt.toEpochSecond() * 1000), (zdt.toEpochSecond()),
jobString jobString
) )
) )

View file

@ -105,7 +105,7 @@ class SendPlannerExtension : Extension() {
-1, -1,
c.data.guildId.value?.value!!.toLong(), c.data.guildId.value?.value!!.toLong(),
c.id.value.toLong(), c.id.value.toLong(),
(TimeUtil.getWeekStamp().toEpochSecond() * 1000), (TimeUtil.getWeekStamp().toEpochSecond()),
msgStr msgStr
) )
) )

View file

@ -47,18 +47,21 @@ object AvailabilityManager : IFeature {
Logger.out("Starting to update roles...") Logger.out("Starting to update roles...")
// ChannelID, Data // ChannelID, Data
val messages = TimePlanningMessagesRepository.getWeek(TimeUtil.getWeekStamp().toEpochSecond() * 1000) val messages = TimePlanningMessagesRepository.getWeek(TimeUtil.getWeekStamp().toEpochSecond())
.associateBy { it.channelID } .associateBy { it.channelID }
val targetedRoles = PlanningNotifierRolesRepository.getAll().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) { for (id in messages.keys) {
val snf = Snowflake(id) // snf = Snowflake val snf = Snowflake(id) // snf = Snowflake
val data = messages[id]!! // this is the data of the table val data = messages[id]!! // this is the data of the table
if (Bot.bot.kordRef.getChannel(Snowflake(data.channelID)) == null) if (Bot.bot.kordRef.getChannel(Snowflake(data.channelID)) == null) {
continue // This channel does not exist anymore. // This channel does not exist anymore.
if (targetedRoles.isEmpty()) { Logger.out("Warning: Channel ${data.channelID} does not exist anymore. Skipping.")
Logger.out("No saved roles. Canceling.") continue
return
} }
val roleData = targetedRoles[data.channelID] // Get the role data val roleData = targetedRoles[data.channelID] // Get the role data
if (roleData == null) { if (roleData == null) {
@ -71,15 +74,17 @@ object AvailabilityManager : IFeature {
} }
suspend fun updateInChannel(snf: Snowflake) { suspend fun updateInChannel(snf: Snowflake) {
val stamp = TimeUtil.getWeekStamp().toEpochSecond()
Logger.out("Weekstamp: $stamp")
val messageData = TimePlanningMessagesRepository.getWeekInChannel( val messageData = TimePlanningMessagesRepository.getWeekInChannel(
TimeUtil.getWeekStamp().toEpochSecond() * 1000, stamp,
snf.value.toLong() snf.value.toLong()
) )
val roleData = PlanningNotifierRolesRepository.getForChannel(snf.value.toLong())
if (messageData == null) { if (messageData == null) {
Logger.out("Could not find data for channel ${snf.value}") Logger.out("Could not find data for channel ${snf.value}")
return return
} }
val roleData = PlanningNotifierRolesRepository.getForChannel(snf.value.toLong())
if (roleData == null) { if (roleData == null) {
Logger.out("Role for channel ${messageData.channelID} does not exist") Logger.out("Role for channel ${messageData.channelID} does not exist")
return // this took way to long to find out that this was the issue 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. return // This channel does not exist anymore.
val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(snf)!! // Get the channel as MessageChannel val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(snf)!! // Get the channel as MessageChannel
val weekday = ZonedDateTime.now().dayOfWeek // The current week day 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.") Logger.out("It is week ${weekStamp} and day ${weekday}/${TimeUtil.getDayOfMonthInt(weekday)} of the week.")
val g = Bot.bot.kordRef.getGuild(Snowflake(tpmd.serverID)) val g = Bot.bot.kordRef.getGuild(Snowflake(tpmd.serverID))
// Get all members with the role // Get all members with the role