Skip to content

Commit

Permalink
Make comment authors optional
Browse files Browse the repository at this point in the history
  • Loading branch information
violine1101 committed Oct 7, 2024
1 parent aa3ea16 commit 53dba85
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/main/kotlin/io/github/mojira/arisa/Executor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,17 @@ private fun getSearchResultsFromJira(

return searchResult
.issues
.map {
it.toDomain(
jiraClient,
ProjectCache.getProjectFromTicketId(it.key),
config
)
.mapNotNull {
@Suppress("TooGenericExceptionCaught")
try {
it.toDomain(
jiraClient,
ProjectCache.getProjectFromTicketId(it.key),
config
)
} catch (exception: Exception) {
log.error("Error mapping bug report ${it.key}:" + exception.message + "\n" + exception.stackTrace)
null
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/io/github/mojira/arisa/domain/Comment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.time.Instant
data class Comment(
val id: String,
val body: String?,
val author: User,
val author: User?,
val getAuthorGroups: () -> List<String>?,
val created: Instant,
val updated: Instant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CommandModule(
) {
val issueKey = issue.key
val commentId = comment.id
val user = comment.author.name
val user = comment.author?.name
val commandStr = command.command
commandResult.fold(
{ exception ->
Expand Down Expand Up @@ -162,7 +162,7 @@ class CommandModule(
private fun userIsVolunteer(comment: Comment): Boolean {
// Ignore comments from the bot itself to prevent accidental infinite recursion and command
// injection by malicious user
if (ignoreOwnCommands && comment.author.name == botUserName) {
if (ignoreOwnCommands && comment.author?.name == botUserName) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HideImpostorsModule : Module {
.plus(1, ChronoUnit.DAYS)
.isAfter(Instant.now())

private fun userContainsBrackets(comment: Comment) = with(comment.author.displayName) {
private fun userContainsBrackets(comment: Comment) = with(comment.author?.displayName) {
this != null && matches("""\[(?:\p{L}|\p{N}|\s)+]\s.+""".toRegex())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RemoveBotCommentModule(
listOf("staff", "global-moderators").contains(comment.visibilityValue)

private fun shouldBeRemoved(comment: Comment) =
comment.author.name == botUserName &&
comment.author?.name == botUserName &&
isVolunteerRestricted(comment) &&
comment.body.equals(removalTag)
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ReopenAwaitingModule(
// regular users can reopen and have commented OR
(!onlyOp && isSoftAR) ||
// reporter has commented
validComments.any { it.author.name == reporter?.name }
validComments.any { it.author?.name == reporter?.name }
}

private fun isOPTag(comment: Comment) = comment.visibilityType == "group" &&
Expand All @@ -80,7 +80,7 @@ class ReopenAwaitingModule(
comment.visibilityValue == "staff" &&
(comment.body?.contains(keepARTag) ?: false)

private fun isKeepARMessage(comment: Comment, project: Project) = comment.author.name == "arisabot" &&
private fun isKeepARMessage(comment: Comment, project: Project) = comment.author?.name == "arisabot" &&
(
comment.body?.contains(
HelperMessageService.getMessageWithBotSignature(
Expand All @@ -99,7 +99,7 @@ class ReopenAwaitingModule(
lastRun: Instant
): List<Comment> = comments
.filter { it.created.isAfter(resolveTime) && it.created.isAfter(lastRun) }
.filter { !it.author.isNewUser() || it.author.name == reporter?.name }
.filter { it.author != null && (!it.author.isNewUser() || it.author.name == reporter?.name) }
.filter {
val roles = it.getAuthorGroups()
roles == null || roles.intersect(blacklistedRoles).isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class ShadowbanModule : Module {
private fun Issue.checkCommentsForShadowban(timeframe: ExecutionTimeframe): Int =
comments
.filter { it.isNotStaffRestricted() }
.filter { it.author.isNotVolunteer() }
.filter { it.author != null && it.author.isNotVolunteer() }
.filter {
timeframe.shadowbans[it.author.name]?.banTimeContains(it.created) ?: false
timeframe.shadowbans[it.author?.name]?.banTimeContains(it.created) ?: false
}
.map { it.restrict("${it.body}\n\n_Removed by Arisa -- User is shadowbanned_") }
.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DeleteCommentsCommand {
operator fun invoke(issue: Issue, userName: String): Int {
val comments = issue.comments
.filter { it.visibilityValue != "staff" }
.filter { it.author.name == userName }
.filter { it.author?.name == userName }

Thread {
comments
Expand Down

0 comments on commit 53dba85

Please sign in to comment.