From 1b2b35e10a08752e0279bc71049298281fddfcec Mon Sep 17 00:00:00 2001 From: limited_dev Date: Wed, 12 Jul 2023 13:12:55 +0200 Subject: [PATCH] fix: fixed errors with the TimeManager if there is no notifier role Signed-off-by: limited_dev --- .../moonleay/lilJudd/features/TimeManager.kt | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt index 0f469e7..43165db 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/features/TimeManager.kt @@ -51,20 +51,11 @@ import java.time.ZonedDateTime object TimeManager : IFeature { override val feat: FeatureEnum get() = FeatureEnum.TIMEPLANNINGFEATURE - /* /--------------- Seconds - | /------------- Minutes - | | /----------- Hours - | | | /--------- Days of months - | | | | /------- Months - | | | | | /----- (optional) Year - | | | | | | /--- (optional) Timezone offset - | | | | | | | / (optional) Week days - * * * * * * 0o *w*/ // Register the cronjob to run at 0:01 AM UTC every Monday override suspend fun registerThread() { Logger.out("Adding message scheduler...") - val scheduler = buildSchedule("0 1 0 * * * 0o 1w") // 0 0 4 * * * 0o 1w // 0o is UTC + val scheduler = buildSchedule("0 0 1 * * * 0o 1w") // 0 0 4 * * * 0o 1w // 0o is UTC scheduler.doInfinity { this.runThread() } @@ -77,7 +68,7 @@ object TimeManager : IFeature { // ChannelID, ServerID val channelList = mutableMapOf() // ChannelID, Data - val roleList = mutableMapOf() + val roleMap = mutableMapOf() var msgStr = "" @@ -89,7 +80,7 @@ object TimeManager : IFeature { } for (pnr in PlanningNotifierRoles.selectAll()) { - roleList[Snowflake(pnr[PlanningNotifierRoles.channelid])] = PlanningNotifierRolesData( + roleMap[Snowflake(pnr[PlanningNotifierRoles.channelid])] = PlanningNotifierRolesData( pnr[PlanningNotifierRoles.serverid], pnr[PlanningNotifierRoles.channelid], pnr[PlanningNotifierRoles.hastimeroleid], @@ -98,24 +89,35 @@ object TimeManager : IFeature { Logger.out("Have to ping roles: ${pnr[PlanningNotifierRoles.wantstobenotifiedid]}}") } } - Logger.out("${channelList.count()} Channels to notify with ${roleList.count()} Roles to ping!") + Logger.out("${channelList.count()} Channels to notify with ${roleMap.count()} Roles to ping!") for (ch in channelList.keys) { if (Bot.bot.kordRef.getChannel(ch) == null) continue // TODO: Check if the channel is valid in another shard val c = Bot.bot.kordRef.getChannelOf(ch)!! - c.createMessage { - if (roleList[ch] != null) { + if (roleMap != null && roleMap.keys.contains(ch) && roleMap[ch] != null) { + c.createMessage { this.content = - "The weekly planning starts now <@&${Snowflake(roleList[ch]?.wantstobenotifid!!)}>" - } - this.embeds.add( - MessageUtil.getEmbed( - Color(0X4C4645), - "Time Planning Feature", - "Do you have time on the following Days?", - "Automated Message" + "The weekly planning starts now <@&${Snowflake(roleMap[ch]?.wantstobenotifid!!)}>" + this.embeds.add( + MessageUtil.getEmbed( + Color(0X4C4645), + "Time Planning Feature", + "Do you have time on the following Days?", + "Automated Message" + ) ) - ) + } + } else { + c.createMessage { + this.embeds.add( + MessageUtil.getEmbed( + Color(0X4C4645), + "Time Planning Feature", + "Do you have time on the following Days?", + "Automated Message" + ) + ) + } } delay(2000) var then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(4).withMinute(0).withSecond(0)