mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
change outdated-block to outdated-ignore
- and remove config field eventOutdatedTimestamp
This commit is contained in:
parent
30c5ae71cc
commit
b617b3e059
@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur
|
||||
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
|
||||
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
|
||||
|
||||
VERSION = 1.1.0
|
||||
VERSION = 1.1.1-alpha1
|
||||
|
||||
USE_DELTA = false
|
||||
VERSION_DELTA =
|
||||
|
@ -42,6 +42,18 @@ class MornyCoeur (using val config: MornyConfig) {
|
||||
|
||||
///<<< BLOCK END instance configure & startup stage 1
|
||||
|
||||
/** inner value: about why morny exit, used in [[daemon.MornyReport]]. */
|
||||
private var whileExit_reason: Option[AnyRef] = None
|
||||
/** About why morny exits. */
|
||||
def exitReason: Option[AnyRef] = whileExit_reason
|
||||
/** Stores when current Morny Coeur instance starts to initialize.
|
||||
*
|
||||
* The time is older than login but earlier than Coeur's daemons initialize.
|
||||
*
|
||||
* in milliseconds.
|
||||
*/
|
||||
val coeurStartTimestamp: Long = System.currentTimeMillis
|
||||
|
||||
/** [[TelegramBot]] account of this Morny */
|
||||
val account: TelegramBot = __loginResult.account
|
||||
/** [[account]]'s telegram username */
|
||||
@ -64,11 +76,6 @@ class MornyCoeur (using val config: MornyConfig) {
|
||||
//noinspection ScalaUnusedSymbol
|
||||
val events: MornyEventListeners = MornyEventListeners(using eventManager)
|
||||
|
||||
/** inner value: about why morny exit, used in [[daemon.MornyReport]]. */
|
||||
private var whileExit_reason: Option[AnyRef] = None
|
||||
def exitReason: Option[AnyRef] = whileExit_reason
|
||||
val coeurStartTimestamp: Long = ServerMain.systemStartupTime
|
||||
|
||||
///>>> BLOCK START instance configure & startup stage 2
|
||||
|
||||
daemons.start()
|
||||
|
@ -82,14 +82,15 @@ public class MornyConfig {
|
||||
* system: event ignore *
|
||||
* ======================================= */
|
||||
|
||||
public final boolean eventIgnoreOutdated;
|
||||
/**
|
||||
* morny 的事件忽略前缀时间<br>
|
||||
* Morny 是否忽略过期事件.
|
||||
* <br>
|
||||
* {@link cc.sukazyo.cono.morny.bot.event.MornyOnUpdateTimestampOffsetLock}
|
||||
* 会根据这里定义的时间戳取消掉比此时间更早的事件链
|
||||
* 过期事件即发生时间比 {@link MornyCoeur#coeurStartTimestamp()} 早的事件。
|
||||
* <br>
|
||||
* 如果此项设置为 true, 则 {@link cc.sukazyo.cono.morny.bot.event.MornyOnUpdateTimestampOffsetLock}
|
||||
* 会使事件时间比 {@link MornyCoeur#coeurStartTimestamp()} 早的事件跳过处理
|
||||
*/
|
||||
public final long eventOutdatedTimestamp;
|
||||
public final boolean eventIgnoreOutdated;
|
||||
|
||||
/* ======================================= *
|
||||
* system: command list automation *
|
||||
@ -138,8 +139,6 @@ public class MornyConfig {
|
||||
this.trustedMaster = prototype.trustedMaster;
|
||||
this.trustedChat = prototype.trustedChat;
|
||||
this.eventIgnoreOutdated = prototype.eventIgnoreOutdated;
|
||||
if (prototype.eventOutdatedTimestamp < 1) throw new CheckFailure.UnsetEventOutdatedTimestamp();
|
||||
this.eventOutdatedTimestamp = prototype.eventOutdatedTimestamp;
|
||||
this.commandLoginRefresh = prototype.commandLoginRefresh;
|
||||
this.commandLogoutClear = prototype.commandLogoutClear;
|
||||
this.dinnerTrustedReaders = prototype.dinnerTrustedReaders;
|
||||
@ -153,7 +152,6 @@ public class MornyConfig {
|
||||
|
||||
public static class CheckFailure extends RuntimeException {
|
||||
public static class NullTelegramBotKey extends CheckFailure {}
|
||||
public static class UnsetEventOutdatedTimestamp extends CheckFailure {}
|
||||
public static class UnavailableTimeInMedicationNotifyAt extends CheckFailure {}
|
||||
}
|
||||
|
||||
@ -170,7 +168,6 @@ public class MornyConfig {
|
||||
public long trustedMaster = -1L;
|
||||
public long trustedChat = -1L;
|
||||
public boolean eventIgnoreOutdated = false;
|
||||
public long eventOutdatedTimestamp = -1;
|
||||
public boolean commandLoginRefresh = false;
|
||||
public boolean commandLogoutClear = false;
|
||||
@Nonnull public final Set<Long> dinnerTrustedReaders = new HashSet<>();
|
||||
|
@ -12,8 +12,6 @@ object ServerMain {
|
||||
|
||||
private val THREAD_MORNY_INIT: String = "morny-init"
|
||||
|
||||
val systemStartupTime: Long = System.currentTimeMillis()
|
||||
|
||||
def main (args: Array[String]): Unit = {
|
||||
|
||||
val config = new MornyConfig.Prototype()
|
||||
@ -21,9 +19,8 @@ object ServerMain {
|
||||
var mode_echoHello = false
|
||||
var showHello = true
|
||||
|
||||
config.eventOutdatedTimestamp = systemStartupTime
|
||||
|
||||
val unknownArgs = ArrayBuffer[String]()
|
||||
val deprecatedArgs = ArrayBuffer[(String, String)]()
|
||||
|
||||
var i = 0
|
||||
while (i < args.length) {
|
||||
@ -35,7 +32,11 @@ object ServerMain {
|
||||
case "--only-hello" | "-ho" | "-o" | "-hi" => mode_echoHello = true
|
||||
case "--version" | "-v" => mode_echoVersion = true
|
||||
|
||||
case "--outdated-block" | "-ob" => config.eventIgnoreOutdated = true
|
||||
// deprecated: use --outdated-ignore instead
|
||||
case "--outdated-block" | "-ob" =>
|
||||
config.eventIgnoreOutdated = true
|
||||
deprecatedArgs += "--outdated-block" -> "--outdated-ignore"
|
||||
case "--outdated-ignore" | "-oig" => config.eventIgnoreOutdated = true
|
||||
|
||||
case "--api" | "-a" => i+=1 ; config.telegramBotApiServer = args(i)
|
||||
case "--api-files" | "files-api" | "-af" => i+=1; config.telegramBotApiServer4File = args(i)
|
||||
@ -94,6 +95,10 @@ object ServerMain {
|
||||
s"""Can't understand arg to some meaning
|
||||
| ${unknownArgs mkString "\n "}"""
|
||||
.stripMargin
|
||||
if (deprecatedArgs.nonEmpty) logger warn
|
||||
s"""Those arguments have been deprecated:
|
||||
| ${deprecatedArgs map ((d, n) => s"$d : use $n instead") mkString "\n "}
|
||||
|""".stripMargin
|
||||
|
||||
if (Log debug)
|
||||
logger warn
|
||||
|
@ -7,7 +7,7 @@ import com.pengrad.telegrambot.model.Update
|
||||
class MornyOnUpdateTimestampOffsetLock (using coeur: MornyCoeur) extends EventListener {
|
||||
|
||||
private def isOutdated (timestamp: Int): Boolean =
|
||||
timestamp < (coeur.config.eventOutdatedTimestamp/1000)
|
||||
coeur.config.eventIgnoreOutdated && (timestamp < (coeur.coeurStartTimestamp/1000))
|
||||
|
||||
override def onMessage (using update: Update): Boolean = isOutdated(update.message.date)
|
||||
override def onEditedMessage (using update: Update): Boolean = isOutdated(update.editedMessage.date)
|
||||
|
Loading…
Reference in New Issue
Block a user