fix: fixed errors with the TimeManager if there is no notifier role
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
7ab73765e4
commit
1b2b35e10a
1 changed files with 26 additions and 24 deletions
|
@ -51,20 +51,11 @@ import java.time.ZonedDateTime
|
||||||
object TimeManager : IFeature {
|
object TimeManager : IFeature {
|
||||||
override val feat: FeatureEnum
|
override val feat: FeatureEnum
|
||||||
get() = FeatureEnum.TIMEPLANNINGFEATURE
|
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
|
// Register the cronjob to run at 0:01 AM UTC every Monday
|
||||||
override suspend fun registerThread() {
|
override suspend fun registerThread() {
|
||||||
Logger.out("Adding message scheduler...")
|
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 {
|
scheduler.doInfinity {
|
||||||
this.runThread()
|
this.runThread()
|
||||||
}
|
}
|
||||||
|
@ -77,7 +68,7 @@ object TimeManager : IFeature {
|
||||||
// ChannelID, ServerID
|
// ChannelID, ServerID
|
||||||
val channelList = mutableMapOf<Snowflake, Snowflake>()
|
val channelList = mutableMapOf<Snowflake, Snowflake>()
|
||||||
// ChannelID, Data
|
// ChannelID, Data
|
||||||
val roleList = mutableMapOf<Snowflake, PlanningNotifierRolesData>()
|
val roleMap = mutableMapOf<Snowflake, PlanningNotifierRolesData>()
|
||||||
|
|
||||||
var msgStr = ""
|
var msgStr = ""
|
||||||
|
|
||||||
|
@ -89,7 +80,7 @@ object TimeManager : IFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (pnr in PlanningNotifierRoles.selectAll()) {
|
for (pnr in PlanningNotifierRoles.selectAll()) {
|
||||||
roleList[Snowflake(pnr[PlanningNotifierRoles.channelid])] = PlanningNotifierRolesData(
|
roleMap[Snowflake(pnr[PlanningNotifierRoles.channelid])] = PlanningNotifierRolesData(
|
||||||
pnr[PlanningNotifierRoles.serverid],
|
pnr[PlanningNotifierRoles.serverid],
|
||||||
pnr[PlanningNotifierRoles.channelid],
|
pnr[PlanningNotifierRoles.channelid],
|
||||||
pnr[PlanningNotifierRoles.hastimeroleid],
|
pnr[PlanningNotifierRoles.hastimeroleid],
|
||||||
|
@ -98,16 +89,15 @@ object TimeManager : IFeature {
|
||||||
Logger.out("Have to ping roles: ${pnr[PlanningNotifierRoles.wantstobenotifiedid]}}")
|
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) {
|
for (ch in channelList.keys) {
|
||||||
if (Bot.bot.kordRef.getChannel(ch) == null)
|
if (Bot.bot.kordRef.getChannel(ch) == null)
|
||||||
continue // TODO: Check if the channel is valid in another shard
|
continue // TODO: Check if the channel is valid in another shard
|
||||||
val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(ch)!!
|
val c = Bot.bot.kordRef.getChannelOf<MessageChannel>(ch)!!
|
||||||
|
if (roleMap != null && roleMap.keys.contains(ch) && roleMap[ch] != null) {
|
||||||
c.createMessage {
|
c.createMessage {
|
||||||
if (roleList[ch] != null) {
|
|
||||||
this.content =
|
this.content =
|
||||||
"The weekly planning starts now <@&${Snowflake(roleList[ch]?.wantstobenotifid!!)}>"
|
"The weekly planning starts now <@&${Snowflake(roleMap[ch]?.wantstobenotifid!!)}>"
|
||||||
}
|
|
||||||
this.embeds.add(
|
this.embeds.add(
|
||||||
MessageUtil.getEmbed(
|
MessageUtil.getEmbed(
|
||||||
Color(0X4C4645),
|
Color(0X4C4645),
|
||||||
|
@ -117,6 +107,18 @@ object TimeManager : IFeature {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
} 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)
|
delay(2000)
|
||||||
var then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(4).withMinute(0).withSecond(0)
|
var then = ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withHour(4).withMinute(0).withSecond(0)
|
||||||
repeat(7) {
|
repeat(7) {
|
||||||
|
|
Loading…
Reference in a new issue