diff --git a/.run/Morny Coeur [t][user_dev(env).u_q_c_r_m] [pr].run.xml b/.run/Morny Coeur [t][user_dev(env).u_q_c_r_m] [pr].run.xml
index 65e7599..3a7021c 100644
--- a/.run/Morny Coeur [t][user_dev(env).u_q_c_r_m] [pr].run.xml
+++ b/.run/Morny Coeur [t][user_dev(env).u_q_c_r_m] [pr].run.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.run/Morny Coeur [user_dev(env).u_q_c] [pr].run.xml b/.run/Morny Coeur [user_dev(env).u_q_c] [pr].run.xml
index 584308b..512244c 100644
--- a/.run/Morny Coeur [user_dev(env).u_q_c] [pr].run.xml
+++ b/.run/Morny Coeur [user_dev(env).u_q_c] [pr].run.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.run/Morny Coeur [user_dev(env).u_q_c_r_m] [pr].run.xml b/.run/Morny Coeur [user_dev(env).u_q_c_r_m] [pr].run.xml
index a1854ef..93befb3 100644
--- a/.run/Morny Coeur [user_dev(env).u_q_c_r_m] [pr].run.xml
+++ b/.run/Morny Coeur [user_dev(env).u_q_c_r_m] [pr].run.xml
@@ -5,7 +5,7 @@
-
+
@@ -17,4 +17,4 @@
-
+
\ No newline at end of file
diff --git a/src/main/scala/cc/sukazyo/cono/morny/core/MornyCoeur.scala b/src/main/scala/cc/sukazyo/cono/morny/core/MornyCoeur.scala
index 3633a83..ff5e9d2 100644
--- a/src/main/scala/cc/sukazyo/cono/morny/core/MornyCoeur.scala
+++ b/src/main/scala/cc/sukazyo/cono/morny/core/MornyCoeur.scala
@@ -187,7 +187,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
private var _httpServerContext: MornyHttpServerContext = MornyHttpServerContextImpl()
// Coeur Initializing Pre Event
- modules.foreach(it => it.onInitializingPre(OnInitializingPreContext(
+ tryCallModulesEvent("onInitializingPre", _.onInitializingPre(OnInitializingPreContext(
externalContext,
coeurStartTimestamp, account, username, userid, tasks, trusted,
eventManager, commands, queries,
@@ -238,7 +238,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
}
// Coeur Initializing Event
- modules.foreach(it => it.onInitializing(OnInitializingContext(
+ tryCallModulesEvent("onInitializing", _.onInitializing(OnInitializingContext(
externalContext,
coeurStartTimestamp, account, username, userid, tasks, trusted,
eventManager, commands, queries,
@@ -255,7 +255,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
initializeContext / this << watchDog
// Coeur Initializing Post Event
- modules.foreach(it => it.onInitializingPost(OnInitializingPostContext(
+ tryCallModulesEvent("onInitializingPost", _.onInitializingPost(OnInitializingPostContext(
externalContext,
coeurStartTimestamp, account, username, userid, tasks, trusted,
eventManager, commands, queries,
@@ -273,7 +273,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
configure_exitCleanup()
// Coeur Starting Event
- modules.foreach(it => it.onStarting(OnStartingContext(
+ tryCallModulesEvent("onStarting", _.onStarting(OnStartingContext(
initializeContext)))
logger `info` "start http server"
@@ -328,7 +328,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
})
// Coeur Starting Post Event
- modules.foreach(it => it.onStartingPost(OnStartingPostContext(
+ tryCallModulesEvent("onStartingPost", _.onStartingPost(OnStartingPostContext(
initializeContext)))
if config.commandLoginRefresh then
@@ -381,7 +381,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
}
def saveDataAll(): Unit = {
- modules.foreach(it => it.onRoutineSavingData)
+ tryCallModulesEvent("onRoutineSaveData", _.onRoutineSavingData)
logger `notice` "done all save action."
}
@@ -394,7 +394,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
private def exitCleanup (): Unit = {
// Morny Exiting
- modules.foreach(it => it.onExiting)
+ tryCallModulesEvent("onExiting", _.onExiting)
account.removeGetUpdatesListener()
logger `info` "stopped bot update listener"
@@ -404,12 +404,12 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
// Morny Exiting Post
if config.commandLogoutClear then
commands.automaticTGListRemove()
- modules.foreach(it => it.onExitingPost)
+ tryCallModulesEvent("onExitingPost", _.onExitingPost)
account.shutdown()
logger `info` "stopped bot account"
// Morny Exited
- modules.foreach(it => it.onExited)
+ tryCallModulesEvent("onExited", _.onExited)
logger `info` "done exit cleanup\nMorny will EXIT now"
}
@@ -424,6 +424,15 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
private case class LoginResult(account: TelegramBot, username: String, userid: Long)
+ private def tryCallModulesEvent (eventName: String, calls: MornyModule=>Unit): Unit =
+ modules.foreach { mod =>
+ try { calls(mod) }
+ catch case e: Exception =>
+ logger `error`
+ s"""Morny Coeur Lifecycle Event `$eventName` execution failed on module ${mod.id}
+ |${e.toLogString}""".stripMargin
+ }
+
private def login (skip_login: Boolean = false): Option[LoginResult] = {
val builder = TelegramBot.Builder(config.telegramBotKey)
diff --git a/src/main/scala/cc/sukazyo/cono/morny/medication_timer/MedicationTimer.scala b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/MedicationTimer.scala
index 0d809b0..59fa0de 100644
--- a/src/main/scala/cc/sukazyo/cono/morny/medication_timer/MedicationTimer.scala
+++ b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/MedicationTimer.scala
@@ -32,6 +32,7 @@ class MedicationTimer (using coeur: MornyCoeur) {
private var lastNotify_messageId: Option[Int] = None
+ private var isScheduleTaskRegistered = false
private val scheduleTask: RoutineTask = new RoutineTask {
override def name: String = DAEMON_THREAD_NAME_DEF
@@ -59,11 +60,15 @@ class MedicationTimer (using coeur: MornyCoeur) {
logger `notice` "Medication Timer disabled : related param is not complete set"
return;
coeur.tasks ++ scheduleTask
+ isScheduleTaskRegistered = true
logger `notice` "Medication Timer started."
def stop(): Unit =
- coeur.tasks % scheduleTask
- logger `notice` "Medication Timer stopped."
+ if isScheduleTaskRegistered then
+ coeur.tasks % scheduleTask
+ logger `notice` "Medication Timer stopped."
+ else
+ logger `notice` "Medication Timer have not run, skipped stop it."
private def sendNotification(): Unit = {
val sendResponse: SendResponse = SendMessage(notify_toChat, NOTIFY_MESSAGE).unsafeExecute
@@ -82,7 +87,7 @@ class MedicationTimer (using coeur: MornyCoeur) {
notify_toChat,
edited.messageId,
edited.text + s"\n-- $editTime --"
- ).entities((entities toArray)*).unsafeExecute
+ ).entities(entities.toArray*).unsafeExecute
lastNotify_messageId = None
true
}