Skip to content

Commit

Permalink
Fix: Change The Way To Delay Sending Pictures For Detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekoer committed Oct 1, 2024
1 parent fbd235a commit a3c6da6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/main/kotlin/com/hcyacg/Nsfw.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ object Nsfw {
}

suspend fun load(event: GroupMessageEvent) {
val picUri = DataUtil.getImageLink(event.message) ?: return

logger.info { "监控中……" }
val picUri = DataUtil.getImageLink(event.message) ?: return
event.subject.sendMessage(At(event.sender).plus("检测中,请稍后"))

val requestBody = MultipartBody.Builder().setType(MultipartBody.FORM)
Expand Down
29 changes: 27 additions & 2 deletions src/main/kotlin/com/hcyacg/Pixiv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ object Pixiv : KotlinPlugin(

val searchImageWaitMap = ConcurrentHashMap<String, Long>()
val searchAnimeWaitMap = ConcurrentHashMap<String, Long>()
val nsfwWaitMap = ConcurrentHashMap<String, Long>()

globalEventChannel().subscribeGroupMessages {
content { group.id == 104967737L } reply {
println(this.message)
println(this.message.contentToString())
}

//测试成功
val getDetailOfId: Pattern =
Expand Down Expand Up @@ -100,8 +105,28 @@ object Pixiv : KotlinPlugin(
Trace.searchInfoByPic(this)
}

val detect: Pattern = Pattern.compile("(?i)^(${Command.detect})(\\n)?.+$")
content { detect.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString()) } reply { Nsfw.load(this) }
//(?i)^[@]\d+[ ][${Command.detect}](\n)?.+|(${Command.detect})?.+$
//(?i)^(${Command.detect})(\n)?.+$
//(?i)^(${Command.detect})(?:\n?.+)?$
val detect: Pattern = Pattern.compile("(?i)^(${Command.detect})(?:\\n?.+)?\$")
content {
detect.matcher(message.contentToString()).find()
&& !Setting.black.contains(group.id.toString())
&& (nsfwWaitMap["${this.group.id}-${this.sender.id}"] ?: 0) < System.currentTimeMillis()
} reply {
if (DataUtil.getImageLink(this.message) == null) {
nsfwWaitMap["${this.group.id}-${this.sender.id}"] = System.currentTimeMillis() + Config.waitTime * 1000
"请在${Config.waitTime}秒内发送检测图片"
} else {
Nsfw.load(this)
}
}
content {
(nsfwWaitMap["${this.group.id}-${this.sender.id}"] ?: 0) >= System.currentTimeMillis()
} reply {
nsfwWaitMap["${this.group.id}-${this.sender.id}"] = 0
Nsfw.load(this)
}

val setu: Pattern = Pattern.compile("(?i)^(${Command.setu})\$")
content { setu.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString()) } reply { SexyCenter.init(this) }
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/hcyacg/utils/DataUtil.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.hcyacg.utils;

import net.mamoe.mirai.message.data.Image
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.message.data.Image.Key.queryUrl
import net.mamoe.mirai.message.data.MessageChain
import java.io.UnsupportedEncodingException
import java.net.URLEncoder
import java.text.NumberFormat
Expand Down

0 comments on commit a3c6da6

Please sign in to comment.