diff --git a/project/MornyConfiguration.scala b/project/MornyConfiguration.scala index 1fb6b3e..9d8a1d2 100644 --- a/project/MornyConfiguration.scala +++ b/project/MornyConfiguration.scala @@ -8,7 +8,7 @@ object MornyConfiguration { val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono" val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s" - val VERSION = "2.0.0-alpha15" + val VERSION = "2.0.0-alpha16" val VERSION_DELTA: Option[String] = None val CODENAME = "guanggu" diff --git a/src/main/scala/cc/sukazyo/cono/morny/core/MornyConfig.java b/src/main/scala/cc/sukazyo/cono/morny/core/MornyConfig.java index 8ec087d..1e7db07 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/core/MornyConfig.java +++ b/src/main/scala/cc/sukazyo/cono/morny/core/MornyConfig.java @@ -102,12 +102,24 @@ public class MornyConfig { public final boolean commandLoginRefresh; public final boolean commandLogoutClear; + /* ======================================= * + * system: inline queries * + * ======================================= */ + + public final int inlineQueryCacheTimeMax; + /* ======================================= * * system: http server * * ======================================= */ public final int httpPort; + /* ======================================= * + * system: debug flags * + * ======================================= */ + + public final boolean debugMode; + /* ======================================= * * function: reporter * * ======================================= */ @@ -172,6 +184,8 @@ public class MornyConfig { this.medicationNotifyAt = prototype.medicationNotifyAt; if (prototype.httpPort < 0 || prototype.httpPort > 65535) throw new CheckFailure.UnavailableHttpPort(); this.httpPort = prototype.httpPort; + this.debugMode = prototype.debugMode; + this.inlineQueryCacheTimeMax = prototype.inlineQueryCacheTimeMax; } public static class CheckFailure extends RuntimeException { @@ -203,6 +217,8 @@ public class MornyConfig { @Nonnull public ZoneOffset medicationTimerUseTimezone = ZoneOffset.UTC; @Nonnull public final Set medicationNotifyAt = new HashSet<>(); public int httpPort = 30179; + public boolean debugMode = false; + public int inlineQueryCacheTimeMax = 300; } diff --git a/src/main/scala/cc/sukazyo/cono/morny/core/ServerMain.scala b/src/main/scala/cc/sukazyo/cono/morny/core/ServerMain.scala index 3a4147e..5138d71 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/core/ServerMain.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/core/ServerMain.scala @@ -30,7 +30,16 @@ object ServerMain { while (i < args.length) { args(i) match { - case "-d" | "--dbg" | "--debug" => Log.debug(true) + case "-d" | "--debug" => + Log.debug(true) + config.debugMode = true + case "--debug-run" => + config.debugMode = true + case "--dbg" => + Log.debug(true) + deprecatedArgs += "--dbg" -> "--verbose-logging" + case "--verbose-logging" | "--verbose" => + Log.debug(true) case "-t" | "--test" => mode_testRun = true case "--no-hello" | "-hf" | "--quiet" | "-q" => showHello = false @@ -110,10 +119,31 @@ object ServerMain { | ${deprecatedArgs map((d, n) => s"$d : use $n instead") mkString "\n "} |""".stripMargin - if (Log debug) + if (config.debugMode && Log.debug) + logger `warn` + """Coeur Debug mode enabled. + | + | The debug log will be outputted, and caches will be disabled. + | It will cause much unnecessary performance cost, may caused extremely slow down on your bot. + | Make sure that you are not in production environment. + | + | Since 2.0.0, this mode is the combined of the two following options: + | --debug-run enable coeur debug mode, that will disabled all the caches. + | --verbose-logging enable the logger to output debug/trace logs.""" + .stripMargin + else if (config.debugMode) + logger `warn` + """Coeur Debug mode enabled. + | + | All the bot caches will be disabled. + | It will cause much unnecessary performance cost, may caused extremely slow down on your bot. + | Make sure that you are not in production environment.""" + .stripMargin + else if (Log debug) logger `warn` """Debug log output enabled. - | It may lower your performance, make sure that you are not in production environment.""" + | It will output much more debug/trace logs, may lower your performance, + | so make sure that you are not in production environment.""" .stripMargin if (mode_echoVersion) { diff --git a/src/main/scala/cc/sukazyo/cono/morny/core/bot/event/MornyOnInlineQuery.scala b/src/main/scala/cc/sukazyo/cono/morny/core/bot/event/MornyOnInlineQuery.scala index 595715d..df62376 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/core/bot/event/MornyOnInlineQuery.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/core/bot/event/MornyOnInlineQuery.scala @@ -18,11 +18,14 @@ class MornyOnInlineQuery (using queryManager: MornyQueryManager) (using coeur: M val results: List[InlineQueryUnit[?]] = queryManager `query` update - var cacheTime = Int.MaxValue + var cacheTime = + if (coeur.config.debugMode) 0 + else coeur.config.inlineQueryCacheTimeMax var isPersonal = InlineQueryUnit.defaults.IS_PERSONAL val resultAnswers = ListBuffer[InlineQueryResult[?]]() for (r <- results) { - if (cacheTime > r.cacheTime) cacheTime = r.cacheTime + if (!coeur.config.debugMode) + if (cacheTime > r.cacheTime) cacheTime = r.cacheTime if (r isPersonal) isPersonal = true resultAnswers += r.result }