From 84121fc562784e25daf26c30d897369b500ceb48 Mon Sep 17 00:00:00 2001 From: violine1101 Date: Fri, 19 Apr 2024 23:10:33 +0200 Subject: [PATCH] semi-hardcode message in ReopenAwaitingModule --- .../arisa/HelperMessageUpdateService.kt | 4 ++ .../arisa/modules/ReopenAwaitingModule.kt | 32 ++--------- .../arisa/registry/InstantModuleRegistry.kt | 3 +- .../arisa/modules/ReopenAwaitingModuleTest.kt | 53 +++++-------------- 4 files changed, 22 insertions(+), 70 deletions(-) diff --git a/src/main/kotlin/io/github/mojira/arisa/HelperMessageUpdateService.kt b/src/main/kotlin/io/github/mojira/arisa/HelperMessageUpdateService.kt index 4519d63a..bedf76c4 100644 --- a/src/main/kotlin/io/github/mojira/arisa/HelperMessageUpdateService.kt +++ b/src/main/kotlin/io/github/mojira/arisa/HelperMessageUpdateService.kt @@ -13,6 +13,10 @@ class HelperMessageUpdateService { private val helperMessagesFile = File("helper-messages.json") private var helperMessagesLastFetch = Instant.now().minusSeconds(UPDATE_INTERVAL_IN_SECONDS + 1) + init { + this.checkForUpdate() + } + fun checkForUpdate() { val currentTime = Instant.now() diff --git a/src/main/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModule.kt b/src/main/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModule.kt index 552ffceb..d5adec6b 100644 --- a/src/main/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModule.kt +++ b/src/main/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModule.kt @@ -6,11 +6,8 @@ import arrow.core.left import arrow.core.right import io.github.mojira.arisa.domain.ChangeLogItem import io.github.mojira.arisa.domain.Comment -import io.github.mojira.arisa.domain.CommentOptions import io.github.mojira.arisa.domain.Issue -import io.github.mojira.arisa.domain.Project import io.github.mojira.arisa.domain.User -import io.github.mojira.arisa.infrastructure.HelperMessageService import java.time.Instant import java.time.temporal.ChronoUnit @@ -26,7 +23,6 @@ class ReopenAwaitingModule( ) : Module { override fun invoke(issue: Issue, lastRun: Instant): Either = with(issue) { Either.fx { - log = "" assertEquals(resolution, "Awaiting Response").bind() assertCreationIsNotRecent(updated.toEpochMilli(), created.toEpochMilli()).bind() @@ -44,8 +40,8 @@ class ReopenAwaitingModule( reopen() } else { assertNotEquals(changeLog.maxByOrNull { it.created }?.author?.name, "arisabot") - if (comments.none { isKeepARMessage(it, project) }) { - addComment(CommentOptions(message)) + if (comments.none { isKeepARMessage(it) }) { + addRawBotComment(message) } } } @@ -81,28 +77,8 @@ class ReopenAwaitingModule( comment.visibilityValue == "staff" && (comment.body?.contains(keepARTag) ?: false) - var log: String = "" - - private fun isKeepARMessage(comment: Comment, project: Project): Boolean { - log += "isKeepAR message: ${comment.body}\n" - - if (comment.author.name != "arisabot") { - log += "author: ${comment.author.name}; contains message: false\n" - return false - } - - val keepARMessage = HelperMessageService.getMessageWithBotSignature( - project.key, - message, - null, - "en" - ) - log += "keep AR message: $keepARMessage\n" - - val result = comment.body?.contains(keepARMessage) ?: false - log += "contains message: $result\n" - return result - } + private fun isKeepARMessage(comment: Comment) = + comment.author.name == "arisabot" && comment.body?.contains(message) ?: false private fun getValidComments( comments: List, diff --git a/src/main/kotlin/io/github/mojira/arisa/registry/InstantModuleRegistry.kt b/src/main/kotlin/io/github/mojira/arisa/registry/InstantModuleRegistry.kt index cec3a65d..c4c0dffb 100644 --- a/src/main/kotlin/io/github/mojira/arisa/registry/InstantModuleRegistry.kt +++ b/src/main/kotlin/io/github/mojira/arisa/registry/InstantModuleRegistry.kt @@ -4,6 +4,7 @@ import com.uchuhimo.konf.Config import com.urielsalis.mccrashlib.CrashReader import io.github.mojira.arisa.ExecutionTimeframe import io.github.mojira.arisa.infrastructure.AttachmentUtils +import io.github.mojira.arisa.infrastructure.HelperMessageService import io.github.mojira.arisa.infrastructure.LanguageDetectionApi import io.github.mojira.arisa.infrastructure.config.Arisa import io.github.mojira.arisa.modules.AffectedVersionMessageModule @@ -209,7 +210,7 @@ class InstantModuleRegistry(config: Config) : ModuleRegistry(config) { config[Arisa.Modules.ReopenAwaiting.softARDays], config[Arisa.Modules.ReopenAwaiting.keepARTag], config[Arisa.Modules.ReopenAwaiting.onlyOPTag], - config[Arisa.Modules.ReopenAwaiting.message] + HelperMessageService.getMessage("MC", keys = listOf(config[Arisa.Modules.ReopenAwaiting.message])) ) ) diff --git a/src/test/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModuleTest.kt b/src/test/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModuleTest.kt index b6bc37a4..20baf604 100644 --- a/src/test/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModuleTest.kt +++ b/src/test/kotlin/io/github/mojira/arisa/modules/ReopenAwaitingModuleTest.kt @@ -2,7 +2,6 @@ package io.github.mojira.arisa.modules import arrow.core.right import io.github.mojira.arisa.domain.User -import io.github.mojira.arisa.infrastructure.HelperMessageService import io.github.mojira.arisa.utils.RIGHT_NOW import io.github.mojira.arisa.utils.mockChangeLogItem import io.github.mojira.arisa.utils.mockComment @@ -23,13 +22,16 @@ private val NEWBIE = getUser(name = "newbieUser", newUser = true) private val TEN_SECONDS_AGO = RIGHT_NOW.minusSeconds(10) private val TWO_YEARS_AGO = RIGHT_NOW.minus(730, ChronoUnit.DAYS) +private const val NOT_REOPEN_AR_MESSAGE = "This report is currently missing crucial information. " + + "Please take a look at the other comments to find out what we are looking for." + private val MODULE = ReopenAwaitingModule( setOf("staff", "global-moderators"), setOf("helper", "staff", "global-moderators"), 365, "MEQS_KEEP_AR", "ARISA_REOPEN_OP", - "not-reopen-ar" + NOT_REOPEN_AR_MESSAGE ) private val AWAITING_RESOLVE = mockChangeLogItem( created = TEN_SECONDS_AGO, @@ -43,39 +45,6 @@ private val OLD_AWAITING_RESOLVE = mockChangeLogItem( ) class ReopenAwaitingModuleTest : StringSpec({ - HelperMessageService.setHelperMessages( - """ - { - "variables": {}, - "messages": { - "not-reopen-ar": [ - { - "project": "mc", - "name": "Not reopen AR", - "message": "This bug report is old, please check it again! Thanks!", - "fillname": [] - } - ], - "i-am-a-bot": [ - { - "project": "mc", - "name": "I am a bot", - "message": "Beep boop", - "fillname": [] - } - ] - } - } - """.trimIndent() - ) - - val notReopenArMessage: String = HelperMessageService.getMessageWithBotSignature( - "MC", - "not-reopen-ar", - null, - "en" - ) - "should return OperationNotNeededModuleResponse when there is no resolution" { val updated = RIGHT_NOW.plusSeconds(3) val issue = mockIssue( @@ -826,7 +795,8 @@ class ReopenAwaitingModuleTest : StringSpec({ comments = listOf(tagComment, normalComment), changeLog = listOf(AWAITING_RESOLVE), reopen = { hasReopened = true; Unit.right() }, - addComment = { hasCommented = true; Unit.right() } + addComment = { hasCommented = true; Unit.right() }, + addRawBotComment = { hasCommented = true; Unit.right() } ) val result = MODULE(issue, TEN_SECONDS_AGO) @@ -849,7 +819,8 @@ class ReopenAwaitingModuleTest : StringSpec({ comments = listOf(comment), changeLog = listOf(OLD_AWAITING_RESOLVE), reopen = { hasReopened = true; Unit.right() }, - addComment = { hasCommented = true; Unit.right() } + addComment = { hasCommented = true; Unit.right() }, + addRawBotComment = { hasCommented = true; Unit.right() } ) val result = MODULE(issue, TEN_SECONDS_AGO) @@ -870,7 +841,7 @@ class ReopenAwaitingModuleTest : StringSpec({ visibilityValue = "staff" ) val arisaComment = getComment( - body = notReopenArMessage, + body = NOT_REOPEN_AR_MESSAGE, author = ARISA ) val normalComment = getComment() @@ -888,7 +859,6 @@ class ReopenAwaitingModuleTest : StringSpec({ result.shouldBeRight(ModuleResponse) hasReopened shouldBe false - MODULE.log shouldBe "test" hasCommented shouldBe false } @@ -903,7 +873,7 @@ class ReopenAwaitingModuleTest : StringSpec({ visibilityValue = "staff" ) val fakeComment = getComment( - body = notReopenArMessage, + body = NOT_REOPEN_AR_MESSAGE, author = RANDOM_USER ) val issue = mockIssue( @@ -913,7 +883,8 @@ class ReopenAwaitingModuleTest : StringSpec({ comments = listOf(tagComment, fakeComment), changeLog = listOf(AWAITING_RESOLVE), reopen = { hasReopened = true; Unit.right() }, - addComment = { hasCommented = true; Unit.right() } + addComment = { hasCommented = true; Unit.right() }, + addRawBotComment = { hasCommented = true; Unit.right() } ) val result = MODULE(issue, TEN_SECONDS_AGO)