Skip to content

Commit

Permalink
fix: lock status, stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
guimc233 committed Aug 2, 2024
1 parent 35aee49 commit 1858382
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import net.mamoe.mirai.message.data.Image
import net.mamoe.mirai.message.data.Image.Key.queryUrl
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.MessageSource.Key.recall
import net.mamoe.mirai.message.data.toMessageChain
import org.apache.commons.lang3.time.StopWatch
import java.io.ByteArrayInputStream
import java.io.File
Expand Down Expand Up @@ -60,14 +59,23 @@ object ImageOCRFilter {
return true
}
} else if (message is ForwardMessage) {
if (findImageToFilter(e, message.toMessageChain())) {
if (findImageToFilter(e, message.nodeList)) {
return true
}
}
}
return false
}

suspend fun findImageToFilter(e: GroupMessageEvent, m: List<ForwardMessage.Node>): Boolean {
for (fm in m) {
if (findImageToFilter(e, fm.messageChain)) {
return true
}
}
return false
}

suspend fun filterImage(e: GroupMessageEvent, m: Image): Boolean {
var muted = false
try {
Expand Down Expand Up @@ -176,7 +184,9 @@ object ImageOCRFilter {
return content
} finally {
// 确保锁被释放
lock.unlock()
if (lock.isLocked) {
lock.unlock()
}
}
}

Expand Down

0 comments on commit 1858382

Please sign in to comment.