mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 03:04:54 +08:00
add debug mode (controls caches) and max cache time limits.
- add coeur config debugMode - currently controls if set the cache time in inline queries - can be enabled by `--debug-run` - change old `--debug -d` startup param (which means enable debug logging) to `--verbose-logging --verbose` - set the new `--debug -d` as the combined of `--debug-run` and `--verbose-logging` - deprecated `--dbg`, currently, it still works as old behavior (like `--verbose`)
This commit is contained in:
parent
966c4dfa92
commit
025f152417
@ -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"
|
||||
|
||||
|
@ -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<Integer> medicationNotifyAt = new HashSet<>();
|
||||
public int httpPort = 30179;
|
||||
public boolean debugMode = false;
|
||||
public int inlineQueryCacheTimeMax = 300;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user