Skip to content

Commit

Permalink
Merge pull request #74 from EvolvedGhost/master
Browse files Browse the repository at this point in the history
原版Mirai及Overflow多Onebot实现兼容与部分功能性升级
  • Loading branch information
Nekoer authored Apr 28, 2024
2 parents 47be075 + ebc6192 commit d119afe
Show file tree
Hide file tree
Showing 19 changed files with 379 additions and 288 deletions.
23 changes: 8 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
val kotlinVersion = "1.8.21"
val kotlinVersion = "1.9.20"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion

Expand All @@ -15,13 +15,9 @@ group = "com.hcyacg"
version = "1.7.8"

repositories {
// maven("https://maven.aliyun.com/repository/public")
// mavenLocal()
// maven("https://maven.aliyun.com/repository/gradle-plugin")
// maven("https://maven.aliyun.com/repository/central")
maven("https://maven.aliyun.com/repository/central")
maven("https://maven.aliyun.com/repository/gradle-plugin")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
mavenCentral()
// maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
}

mirai {
Expand All @@ -35,18 +31,15 @@ mirai {
}

dependencies {
implementation("org.apache.commons:commons-lang3:3.14.0")
val overflowVersion = "2.16.0-febc5da-SNAPSHOT"
// compileOnly("top.mrxiaom:overflow-core-api:$overflowVersion")
// testConsoleRuntime("top.mrxiaom:overflow-core:$overflowVersion")
testConsoleRuntime("top.mrxiaom:overflow-core:$overflowVersion")

implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("commons-codec:commons-codec:1.15")
implementation("org.apache.httpcomponents:httpclient:4.5.13")
implementation("org.jsoup:jsoup:1.15.3")
implementation("com.squareup.okhttp3:okhttp:5.0.0-alpha.10")
implementation("org.apache.httpcomponents:httpclient:4.5.14")
implementation("org.jsoup:jsoup:1.15.4")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.madgag:animated-gif-lib:1.4")
compileOnly("org.bytedeco:javacv-platform:1.5.7")
implementation("org.bytedeco:javacv-platform:1.5.10")
// compileOnly
implementation(kotlin("stdlib-jdk8"))

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-7.6.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion src/main/kotlin/com/hcyacg/Helper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Helper {
.plus(" ·看涩图 +tag ${Command.setu} loli").plus("\n")
.plus(" ·看萝莉 ${Command.lolicon} 查询条件 r18,查询条件最多三个用&分割,|为或者,例:少女|姐姐&黑丝|白丝&猫耳|狗耳;如果有r18则必须放在最后,开启18禁模式").plus("\n")
.plus(" ·通过tag查找排行榜 ${Command.tag}关键词-页码").plus("\n")
.plus(" ·检测图片的涩情程度并打上标签 检测[图片]")
.plus(" ·检测图片的涩情程度并打上标签 ${Command.detect}[图片]")
)
)

Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/hcyacg/Nsfw.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.math.RoundingMode
import java.net.InetSocketAddress
import java.net.Proxy
import java.text.DecimalFormat
import java.util.*
import java.util.concurrent.TimeUnit


Expand Down Expand Up @@ -103,17 +104,16 @@ object Nsfw {
suspend fun load(event: GroupMessageEvent) {
println("监控中……")
event.subject.sendMessage(At(event.sender).plus("检测中,请稍后"));

val picUri = DataUtil.getSubString(event.message.toString().replace("\\s*".toRegex(), "").replace(" ", ""), "[overflow:image,url=", "]")!!

val picUri = DataUtil.getImageLink(event.message) ?: return

val requestBody = MultipartBody.Builder().setType(MultipartBody.FORM)
val body = ImageUtil.getImage(picUri, CacheUtil.Type.NONSUPPORT).toByteArray()
val bodies = body.toRequestBody(
"multipart/form-data".toMediaTypeOrNull(),
0, body.size
)
requestBody.addFormDataPart("file", "${picUri}.jpeg", bodies)
val name = UUID.randomUUID().toString() + ".jpeg"
requestBody.addFormDataPart("file", name, bodies)
requestBody.addFormDataPart("network_type", "general")

var uri = "http://dev.kanotype.net:8003/deepdanbooru/upload"
Expand Down Expand Up @@ -147,7 +147,7 @@ object Nsfw {
uri = "http://${Config.deepdanbooru}/deepdanbooru"
val requestB = MultipartBody.Builder().setType(MultipartBody.FORM)

requestB.addFormDataPart("image","${picUri}.jpeg", bodies)
requestB.addFormDataPart("image" ,name, bodies)

headers.add("Content-Type", "multipart/form-data;boundary=ebf9f03029db4c2799ae16b5428b06bd1")
headers.add("Accept", "application/json")
Expand Down
57 changes: 43 additions & 14 deletions src/main/kotlin/com/hcyacg/Pixiv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import net.mamoe.mirai.event.globalEventChannel
import net.mamoe.mirai.event.subscribeGroupMessages
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
import java.io.ByteArrayInputStream
import java.util.concurrent.ConcurrentHashMap
import java.util.regex.Pattern

object Pixiv : KotlinPlugin(
Expand Down Expand Up @@ -55,7 +56,8 @@ object Pixiv : KotlinPlugin(
// AutoUpdate.load()



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

globalEventChannel().subscribeGroupMessages {

Expand All @@ -80,14 +82,26 @@ object Pixiv : KotlinPlugin(
findUserWorksById.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString())
} quoteReply { UserDetails.findUserWorksById(this) }
//测试成功
val searchInfoByPic: Pattern = Pattern.compile("(?i)^(${Command.searchInfoByPic})(\\n){0,1}.+\$")
content { searchInfoByPic.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString()) } quoteReply {
Trace.searchInfoByPic(
this
)
val searchInfoByPic: Pattern = Pattern.compile("(?i)^(${Command.searchInfoByPic})(?:\\n?.+)?\$")
content { searchInfoByPic.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString())
&& (searchAnimeWaitMap["${this.group.id}-${this.sender.id}"]?: 0) < System.currentTimeMillis()
} quoteReply {
if (DataUtil.getImageLink(this.message) == null) {
searchAnimeWaitMap["${this.group.id}-${this.sender.id}"] = System.currentTimeMillis() + Config.waitTime * 1000
"请在${Config.waitTime}秒内发送搜番图片"
} else {
Trace.searchInfoByPic(this)
}
}
content {
(searchAnimeWaitMap["${this.group.id}-${this.sender.id}"] ?: 0) >= System.currentTimeMillis()
} reply {
searchAnimeWaitMap["${this.group.id}-${this.sender.id}"] = 0
Trace.searchInfoByPic(this)
}

content { message.contentToString().contains("检测") && !Setting.black.contains(group.id.toString()) } reply { Nsfw.load(this) }
val detect: Pattern = Pattern.compile("(?i)^(${Command.detect})(\\n){0,1}.+$")
content { detect.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString()) } reply { 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 All @@ -99,10 +113,24 @@ object Pixiv : KotlinPlugin(
val tag: Pattern = Pattern.compile("(?i)^(${Command.tag})([\\s\\S]*)-([0-9]*[1-9][0-9]*)\$")
content { tag.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString()) } quoteReply { Tag.init(this) }
//测试成功
val picToSearch: Pattern = Pattern.compile("(?i)^(${Command.picToSearch})(\\n){0,1}.+$")
val picToSearch: Pattern = Pattern.compile("(?i)^(${Command.picToSearch})(?:\\n?.+)?\$")
content {
picToSearch.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString())
} quoteReply { SearchPicCenter.forward(this) }
picToSearch.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString()) &&
(searchImageWaitMap["${this.group.id}-${this.sender.id}"]?: 0) < System.currentTimeMillis()
} quoteReply {
if (DataUtil.getImageLink(this.message) == null) {
searchImageWaitMap["${this.group.id}-${this.sender.id}"] = System.currentTimeMillis() + Config.waitTime * 1000
"请在${Config.waitTime}秒内发送搜图图片"
} else {
SearchPicCenter.forward(this)
}
}
content {
(searchImageWaitMap["${this.group.id}-${this.sender.id}"] ?: 0) >= System.currentTimeMillis()
} reply {
searchImageWaitMap["${this.group.id}-${this.sender.id}"] = 0
SearchPicCenter.forward(this)
}

val lolicon: Pattern = Pattern.compile("(?i)^(${Command.lolicon})( ([^ ]*)( (r18))?)?\$")
content { lolicon.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString()) } quoteReply { LoliconCenter.load(this) }
Expand Down Expand Up @@ -153,10 +181,11 @@ object Pixiv : KotlinPlugin(

val lowPoly = Pattern.compile("(?i)^(${Command.lowPoly}).+\$")
content { lowPoly.matcher(message.contentToString()).find() && !Setting.black.contains(group.id.toString())} quoteReply {
val picUri = DataUtil.getSubString(this.message.toString().replace(" ", ""), "[overflow:image:{", "}.")!!
.replace("-", "")
val url = "https://gchat.qpic.cn/gchatpic_new/0/0-0-${picUri}/0?"
val byte = ImageUtil.getImage(url, CacheUtil.Type.NONSUPPORT).toByteArray()
val picUri = DataUtil.getImageLink(this.message)
if (picUri == null) {
"请输入正确的命令 ${Command.lowPoly}图片"
}
val byte = ImageUtil.getImage(picUri!!, CacheUtil.Type.NONSUPPORT).toByteArray()
val toExternalResource = LowPoly.generate(
ByteArrayInputStream(byte),
200,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/hcyacg/details/PicDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ object PicDetails {
.headers(headers.build()).get().build()
).execute()

output.writeBytes(response.body.byteStream().readBytes())
response.body?.byteStream()?.let { output.writeBytes(it.readBytes()) }

ZipUtil.unzip(dir.path + File.separator + "${ugoiraId}.zip", dir.path + File.separator + "image")

Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/com/hcyacg/initial/Command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ object Command: AutoSavePluginConfig("Command") {
@ValueDescription("搜索标签排行榜 tag-萝莉-页码")
var tag: String by value("tag-")

@ValueName("detect")
@ValueDescription("检测图片的涩情程度并打上标签")
var detect: String by value("检测")

@ValueName("help")
@ValueDescription("帮助")
var help: String by value("帮助")
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/com/hcyacg/initial/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ object Config : AutoSavePluginConfig("Config") {
@ValueDescription("开关 search:搜索图片的引擎开关 sexy:涩图库来源开关")
var enable: Enable by value()

@ValueName("waitTime")
@ValueDescription("等待时间 搜图搜番时指令与图片分开发送模式下的等待时间(秒)")
var waitTime: Int by value(60)

@ValueName("forward")
@ValueDescription("转发模式 rankAndTagAndUserByForward:排行榜、标签、作者三个变成转发模式; imageToForward:查看图片详情变成转发模式 可发送该作品的所有图片")
val forward: ForWard by value()
Expand Down Expand Up @@ -44,6 +48,10 @@ object Config : AutoSavePluginConfig("Config") {
@ValueDescription("本地图库目录")
val localImagePath: String by value(System.getProperty("user.dir") + File.separator + "image")

@ValueName("saucenaoEco")
@ValueDescription("Saucenao的省流经济模式 可以节约Token次数 也可避免部分Onebot实现产生浪费 可能降低准确度")
var saucenaoEco: Boolean by value(false)

@ValueName("google")
@ValueDescription("Google搜索配置项 镜像源和搜索显示的数量")
val googleConfig: GoogleConfig by value()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/hcyacg/initial/entity/GoogleConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import kotlinx.serialization.Serializable

@Serializable
data class GoogleConfig(
@SerialName("googleUrl")
val googleUrl:String = "https://www.google.com.hk",
@SerialName("googleImageUrl")
val googleImageUrl:String = "https://images.google.com",
@SerialName("resultNum")
val resultNum:Int = 2
)
4 changes: 1 addition & 3 deletions src/main/kotlin/com/hcyacg/science/Style2paints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ object Style2paints {
/**
* 获取图片的代码
*/
val picUri = DataUtil.getSubString(event.message.toString().replace(" ", ""), "[overflow:image:{", "}.")!!
.replace("-", "")
val url = "https://gchat.qpic.cn/gchatpic_new/0/0-0-${picUri}/0?"
val url = DataUtil.getImageLink(event.message) ?: return

val base64 = Base64.getEncoder().encodeToString(ImageUtil.getImage(url, CacheUtil.Type.NONSUPPORT).toByteArray())

Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/com/hcyacg/search/Ascii2d.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hcyacg.search
import com.hcyacg.initial.Config
import com.hcyacg.initial.Setting
import com.hcyacg.utils.CacheUtil
import com.hcyacg.utils.DataUtil
import com.hcyacg.utils.ImageUtil
import net.mamoe.mirai.event.events.GroupMessageEvent
import net.mamoe.mirai.message.data.At
Expand Down Expand Up @@ -64,7 +65,8 @@ object Ascii2d {
val sslsf = SSLConnectionSocketFactory(sc)
val httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build()

val ascii2d = "https://ascii2d.net/search/url/$picUri"

val ascii2d = "https://ascii2d.net/search/url/${DataUtil.urlEncode(picUri)}"
// val headers = mutableMapOf<String,String>()
// headers["User-Agent"] = "PostmanRuntime/7.28.4"

Expand Down
Loading

0 comments on commit d119afe

Please sign in to comment.