Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make comment authors optional #832

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 updateAuthor: User?,
val getAuthorGroups: () -> List<String>?,
val getUpdateAuthorGroups: () -> List<String>?,
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 @@ -31,7 +31,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 @@ -66,7 +66,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 @@ -78,7 +78,7 @@ class ReopenAwaitingModule(
(comment.body?.contains(keepARTag) ?: false)

private fun isKeepARMessage(comment: Comment) =
comment.author.name == "arisabot" && comment.body?.contains(message) ?: false
comment.author?.name == "arisabot" && comment.body?.contains(message) ?: false

private fun getValidComments(
comments: List<Comment>,
Expand All @@ -87,7 +87,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