From 023b8f44725d38f32ac53eef420caff81ce781a6 Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sun, 25 Sep 2022 16:04:07 +0800 Subject: [PATCH] build: 2.0.0-RC --- build.gradle.kts | 21 ++++++++++--------- .../xyz/cssxsh/mirai/pixiv/PixivClientPool.kt | 2 ++ .../xyz/cssxsh/mirai/pixiv/PixivConfig.kt | 2 +- .../xyz/cssxsh/mirai/pixiv/PixivHelper.kt | 7 +++---- .../cssxsh/mirai/pixiv/PixivHelperPlugin.kt | 2 +- .../xyz/cssxsh/mirai/pixiv/PixivHelperPool.kt | 2 +- .../xyz/cssxsh/mirai/pixiv/PixivProperty.kt | 8 +++++-- .../mirai/pixiv/command/PixivMethodCommand.kt | 1 - .../mirai/pixiv/command/PixivTaskCommand.kt | 6 +++--- .../mirai/pixiv/tools/ImageSearcherTest.kt | 9 -------- 10 files changed, 28 insertions(+), 32 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3c94434f..3b5647cd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "xyz.cssxsh.mirai.plugin" -version = "2.0.0-M8" +version = "2.0.0-RC" repositories { mavenLocal() @@ -16,8 +16,8 @@ repositories { } dependencies { - implementation("org.jsoup:jsoup:1.15.2") - implementation("xyz.cssxsh.pixiv:pixiv-client:1.2.4") { + implementation("org.jsoup:jsoup:1.15.3") + implementation("xyz.cssxsh.pixiv:pixiv-client:1.2.6") { exclude(group = "org.jetbrains.kotlin") exclude(group = "org.jetbrains.kotlinx") exclude(group = "org.slf4j") @@ -31,15 +31,16 @@ dependencies { compileOnly("net.mamoe:mirai-core:2.13.0-M1") compileOnly("net.mamoe:mirai-core-utils:2.13.0-M1") // dependsOn - compileOnly("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.4.3") - compileOnly("xyz.cssxsh.mirai:mirai-selenium-plugin:2.2.2") - compileOnly("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.7") + compileOnly("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.4.4") + compileOnly("xyz.cssxsh.mirai:mirai-selenium-plugin:2.2.3") + compileOnly("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.9") testImplementation(kotlin("test")) - testImplementation("net.mamoe:mirai-slf4j-bridge:1.2.0") - testImplementation("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.4.3") - testImplementation("xyz.cssxsh.mirai:mirai-selenium-plugin:2.2.2") - testImplementation("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.7") + testImplementation("org.slf4j:slf4j-simple:2.0.0") + testImplementation("net.mamoe:mirai-logging-slf4j:2.13.0-M1") + testImplementation("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.4.4") + testImplementation("xyz.cssxsh.mirai:mirai-selenium-plugin:2.2.3") + testImplementation("xyz.cssxsh.mirai:mirai-skia-plugin:1.1.9") } mirai { diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivClientPool.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivClientPool.kt index 836c3810..126935d4 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivClientPool.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivClientPool.kt @@ -80,6 +80,8 @@ public object PixivClientPool : ReadOnlyProperty, logger.warning { "Api 超时, 已忽略: ${throwable.message}" } true } + is java.net.UnknownHostException, + is java.net.NoRouteToHostException -> false is IOException -> { logger.warning { "Api 错误, 已忽略: $throwable" } true diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivConfig.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivConfig.kt index aa17e079..1ae3a2a8 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivConfig.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivConfig.kt @@ -46,7 +46,7 @@ internal fun initConfiguration() { ProfileFolder.mkdirs() ArticleFolder.mkdirs() UgoiraImagesFolder.mkdirs() - ExistsImagesFolder.mkdirs() + OtherImagesFolder.mkdirs() ExistsImagesFolder.mkdirs() logger.info { "CacheFolder: ${CacheFolder.absolutePath}" } logger.info { "BackupFolder: ${BackupFolder.absolutePath}" } diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelper.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelper.kt index 213aaae3..279a3141 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelper.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelper.kt @@ -14,13 +14,12 @@ import kotlin.coroutines.* * Pixiv 助手 * @see PixivHelperPool.helper */ -public class PixivHelper internal constructor(public val id: Long, parentCoroutineContext: CoroutineContext) : +public class PixivHelper internal constructor(public val id: Long, parentContext: CoroutineContext) : CoroutineScope { - private val logger by lazy { MiraiLogger.Factory.create(this::class, identity = "pixiv-helper-${id}") } + private val logger = MiraiLogger.Factory.create(this::class, identity = "pixiv-helper-${id}") - override val coroutineContext: CoroutineContext = - parentCoroutineContext + CoroutineName(name = "pixiv-helper-${id}") + override val coroutineContext: CoroutineContext = parentContext + CoroutineName(name = "pixiv-helper-${id}") public val client: PixivAuthClient by PixivClientPool diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPlugin.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPlugin.kt index a022afa6..dee75e07 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPlugin.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPlugin.kt @@ -10,7 +10,7 @@ import xyz.cssxsh.mirai.pixiv.command.* import xyz.cssxsh.mirai.pixiv.data.* public object PixivHelperPlugin : KotlinPlugin( - JvmPluginDescription(id = "xyz.cssxsh.mirai.plugin.pixiv-helper", version = "2.0.0-M8") { + JvmPluginDescription(id = "xyz.cssxsh.mirai.plugin.pixiv-helper", version = "2.0.0-M9") { name("pixiv-helper") author("cssxsh") diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPool.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPool.kt index 880006bd..3e612d64 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPool.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivHelperPool.kt @@ -24,7 +24,7 @@ public object PixivHelperPool : ReadOnlyProperty, Coroutin @Synchronized public fun helper(contact: Contact): PixivHelper { return helpers.getOrPut(contact.id) { - PixivHelper(id = contact.id, parentCoroutineContext = coroutineContext) + PixivHelper(id = contact.id, parentContext = coroutineContext) } } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivProperty.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivProperty.kt index 83bad933..38e40f60 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivProperty.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/PixivProperty.kt @@ -23,8 +23,6 @@ internal const val ERO_SFW_PROPERTY = "xyz.cssxsh.mirai.plugin.pixiv.ero.sfw" internal const val ERO_STANDARD_PROPERTY = "xyz.cssxsh.mirai.plugin.pixiv.ero.standard" -internal const val TAG_COOLING_PROPERTY = "xyz.cssxsh.mirai.plugin.pixiv.tag.cooling" - internal const val TAG_SFW_PROPERTY = "xyz.cssxsh.mirai.plugin.pixiv.tag.sfw" internal const val CACHE_CAPACITY_PROPERTY = "xyz.cssxsh.mirai.plugin.pixiv.cache.capacity" @@ -281,8 +279,14 @@ internal fun illust(pid: Long) = images(pid).resolve("${pid}.json") */ internal fun ugoira(pid: Long) = images(pid).resolve("${pid}.ugoira.json") +/** + * 从 [Contact] 上下文得到 [PixivHelper] + */ public val Contact.helper: PixivHelper by PixivHelperPool +/** + * 从 [CommandSender] 上下文得到 [PixivClientPool.AuthClient] + */ public fun CommandSender.client(): PixivClientPool.AuthClient { return when { isUser() -> PixivClientPool.get(id = subject.id) diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivMethodCommand.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivMethodCommand.kt index 17b69ecd..4dc84163 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivMethodCommand.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivMethodCommand.kt @@ -59,7 +59,6 @@ public object PixivMethodCommand : CompositeCommand( val json = File("cookie.json") sendMessage("加载 cookie 从 ${json.absolutePath}") val auth = pixiv.cookie { - @OptIn(ExperimentalSerializationApi::class) PixivJson.decodeFromString>(json.readText()).map { it.toCookie() } } diff --git a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivTaskCommand.kt b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivTaskCommand.kt index 6e4b79e9..00be30f5 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivTaskCommand.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/pixiv/command/PixivTaskCommand.kt @@ -102,7 +102,7 @@ public object PixivTaskCommand : CompositeCommand( } @SubCommand - @Description("定时任务,删除") + @Description("任务定时") public suspend fun CommandSender.cron(id: String, cron: Cron) { val message = try { when (val task = PixivScheduler[id]) { @@ -113,14 +113,14 @@ public object PixivTaskCommand : CompositeCommand( } } } catch (cause: Exception) { - "定时任务${id}删除失败,${cause.message}" + "任务${id}定时失败,${cause.message}" } sendMessage(message) } @SubCommand - @Description("定时任务,删除") + @Description("删除任务") public suspend fun CommandSender.delete(id: String) { val message = try { when (val task = PixivScheduler.remove(id)) { diff --git a/src/test/kotlin/xyz/cssxsh/mirai/pixiv/tools/ImageSearcherTest.kt b/src/test/kotlin/xyz/cssxsh/mirai/pixiv/tools/ImageSearcherTest.kt index ff2e78d4..afd1a9dd 100644 --- a/src/test/kotlin/xyz/cssxsh/mirai/pixiv/tools/ImageSearcherTest.kt +++ b/src/test/kotlin/xyz/cssxsh/mirai/pixiv/tools/ImageSearcherTest.kt @@ -1,21 +1,12 @@ package xyz.cssxsh.mirai.pixiv.tools -import io.ktor.client.features.* import kotlinx.coroutines.* import org.junit.jupiter.api.* -import java.io.* internal class ImageSearcherTest { private val picUrl = "" - init { - ImageSearcher.ignore = { - println(it) - it is IOException || it is HttpRequestTimeoutException - } - } - @Test fun json(): Unit = runBlocking { ImageSearcher.json(url = picUrl).also {