diff --git a/src/main/kotlin/net/taehui/twilight/system/DB.kt b/src/main/kotlin/net/taehui/twilight/system/DB.kt index 57724b4..15b6936 100644 --- a/src/main/kotlin/net/taehui/twilight/system/DB.kt +++ b/src/main/kotlin/net/taehui/twilight/system/DB.kt @@ -11,6 +11,7 @@ import org.apache.commons.io.FileUtils import org.apache.commons.io.FilenameUtils import java.io.IOException +import java.lang.IllegalArgumentException import java.nio.file.Files import java.nio.file.Path import java.sql.* @@ -776,14 +777,6 @@ StreamSupport.stream(comments.groupBy { Pair(it.avatar, it.noteID) }.toList().spliterator(), true) .use { parallel -> parallel.forEach { (avatarNoteID, comments) -> - val isP = comments.any { it.isP } - val hitPointsMode = comments.maxBy { - when (it.hitPointsMode) { - Component.HIGHEST_HIT_POINTS_MODE, Component.FAILED_HIT_POINTS_MODE -> 2 - Component.HIGHER_HIT_POINTS_MODE -> 1 - else -> 0 - } - }.hitPointsMode pool.connection.use { it.prepareStatement( """ @@ -794,11 +787,19 @@ dbStatement.setString(1, avatarNoteID.first) dbStatement.setString(2, avatarNoteID.second) dbStatement.setInt( - 3, (if (isP) Component.Handled.BAND1 else { - when (hitPointsMode) { + 3, (if (comments.any { comment -> comment.isP }) Component.Handled.BAND1 else { + when (comments.maxBy { comment -> + when (comment.hitPointsMode) { + Component.HIGHEST_HIT_POINTS_MODE, Component.FAILED_HIT_POINTS_MODE -> 2 + Component.HIGHER_HIT_POINTS_MODE -> 1 + Component.DEFAULT_HIT_POINTS_MODE -> 0 + else -> throw IllegalArgumentException(comment.hitPointsMode.toString()) + } + }.hitPointsMode) { Component.HIGHEST_HIT_POINTS_MODE, Component.FAILED_HIT_POINTS_MODE -> Component.Handled.HIGHEST_CLEAR Component.HIGHER_HIT_POINTS_MODE -> Component.Handled.HIGHER_CLEAR - else -> Component.Handled.CLEAR + Component.DEFAULT_HIT_POINTS_MODE -> Component.Handled.CLEAR + else -> Component.Handled.NOT } }).value ) @@ -977,7 +978,6 @@ val isPaused = rows.getBoolean("Is_Paused") val inputFlags = rows.getInt("Input_Flags") - val handled = getHandled(this.avatarID, noteID) }) } } @@ -995,6 +995,7 @@ object { val favor = favor val totalFavor = totalFavor + val handled = getHandled(avatarID, noteID) val comments = comments } } @@ -1936,12 +1937,19 @@ if (isP) { handled = Component.Handled.BAND1 } else { - if (hitPointsMode == Component.HIGHEST_HIT_POINTS_MODE) { - handled = Component.Handled.HIGHEST_CLEAR - } else if (hitPointsMode == Component.HIGHER_HIT_POINTS_MODE && handled != Component.Handled.HIGHEST_CLEAR) { - handled = Component.Handled.HIGHER_CLEAR - } else if (handled != Component.Handled.HIGHER_CLEAR && handled != Component.Handled.HIGHEST_CLEAR) { - handled = Component.Handled.CLEAR + when (hitPointsMode) { + Component.HIGHEST_HIT_POINTS_MODE -> handled = Component.Handled.HIGHEST_CLEAR + Component.HIGHER_HIT_POINTS_MODE -> { + if (handled != Component.Handled.HIGHEST_CLEAR) { + handled = Component.Handled.HIGHER_CLEAR + } + } + + Component.DEFAULT_HIT_POINTS_MODE -> { + if (handled != Component.Handled.HIGHER_CLEAR && handled != Component.Handled.HIGHEST_CLEAR) { + handled = Component.Handled.CLEAR + } + } } } pool.connection.use { diff --git a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt index ba263a5..63658e3 100644 --- a/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/PlatformSystem.kt @@ -54,7 +54,9 @@ var platformAvatars = emptyList() fun handleSystem() { - if (Configure.mode.platform) { + if (platform != null) { + logInfo("Platform is already running") + } else if (Configure.mode.platform) { try { fun doCallPlatformAvatars() { qwilightPlatform?.loadMembers()?.onSuccess { avatars -> @@ -123,6 +125,8 @@ } catch (e: Throwable) { logFault(e) } + } else { + logInfo("Platform is disabled") } } @@ -131,6 +135,7 @@ fun dispose() { platform?.shutdown() + platform = null } fun sendSiteYell(siteYellData: JSON.TwilightSiteYell) { diff --git a/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt b/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt index e89f2a4..de09122 100644 --- a/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt +++ b/src/main/kotlin/net/taehui/twilight/system/TVSystem.kt @@ -34,11 +34,13 @@ isDaemon = true } } - private var future: ScheduledFuture<*>? = null private var tv: WebDriver? = null + private var future: ScheduledFuture<*>? = null fun handleSystem() { - if (Configure.mode.tv) { + if (tv != null) { + logInfo("TV is already running") + } else if (Configure.mode.tv) { try { tv = EdgeDriver(EdgeOptions().apply { addArguments("--headless", "--no-sandbox") @@ -86,6 +88,8 @@ } catch (e: Throwable) { logFault(e) } + } else { + logInfo("TV is disabled") } } @@ -93,7 +97,8 @@ get() = "{Title: ${tv?.title}, Page: ${tv?.pageSource}, URL: ${tv?.currentUrl}, Handles: [${tv?.windowHandles?.joinToString()}]}" fun dispose() { - ses.shutdown() + future?.cancel(false) tv?.quit() + tv = null } } \ No newline at end of file diff --git a/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt b/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt index 186f6b0..1575d37 100644 --- a/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt +++ b/src/main/kotlin/net/taehui/twilight/www/WwwAvatar.kt @@ -15,7 +15,6 @@ import org.apache.hc.client5.http.classic.methods.HttpGet import org.apache.hc.client5.http.impl.classic.HttpClients import org.slf4j.LoggerFactory -import java.io.IOException import java.net.URLDecoder import java.nio.charset.StandardCharsets import java.nio.file.Files @@ -146,6 +145,7 @@ send(ctx, object { val favor = null val totalFavor = 0 + val handled = Component.Handled.NOT val comments = null }) } else {