From 527513f5a78fa614b3f501f0e17fb853e8a1278a Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sat, 15 Oct 2022 21:58:43 +0800 Subject: [PATCH] build: 1.0.8 --- build.gradle.kts | 2 +- src/main/kotlin/xyz/cssxsh/mirai/novelai/NovelAiHelper.kt | 2 +- .../kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiCommand.kt | 4 ++-- .../xyz/cssxsh/mirai/novelai/command/NovelAiFuCommand.kt | 4 ++-- src/main/kotlin/xyz/cssxsh/novelai/NovelAiClient.kt | 4 +++- src/main/kotlin/xyz/cssxsh/novelai/ai/AIController.kt | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7f4e555..c27d69d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "xyz.cssxsh.mirai.novelai" -version = "1.0.7" +version = "1.0.8" repositories { mavenLocal() diff --git a/src/main/kotlin/xyz/cssxsh/mirai/novelai/NovelAiHelper.kt b/src/main/kotlin/xyz/cssxsh/mirai/novelai/NovelAiHelper.kt index 1395591..2567556 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/novelai/NovelAiHelper.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/novelai/NovelAiHelper.kt @@ -11,7 +11,7 @@ public object NovelAiHelper : KotlinPlugin( JvmPluginDescription( id = "xyz.cssxsh.mirai.plugin.novelai-helper", name = "novelai-helper", - version = "1.0.7", + version = "1.0.8", ) { author("cssxsh") } diff --git a/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiCommand.kt b/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiCommand.kt index 5099869..68fd6d2 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiCommand.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiCommand.kt @@ -55,7 +55,7 @@ public object NovelAiCommand : SimpleCommand( } } - val seed = random.nextLong(0, 2 shl 32 - 1) + val seed = random.nextLong(0, 2L shl 32 - 1) NovelAiHelper.logger.info(input.joinToString(", ", "generate image seed: $seed, tags: ")) val generate = try { NovelAiHelper.client.ai.generateImage(input = input.joinToString(",")) { @@ -74,6 +74,6 @@ public object NovelAiCommand : SimpleCommand( return } val image = generate.data.toExternalResource().use { subject.uploadImage(it) } - sendMessage(fromEvent.message.quote() + image + "\n$seed") + sendMessage(fromEvent.message.quote() + image + "\nseed=$seed") } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiFuCommand.kt b/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiFuCommand.kt index c1cee0e..25a72de 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiFuCommand.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/novelai/command/NovelAiFuCommand.kt @@ -57,7 +57,7 @@ public object NovelAiFuCommand : SimpleCommand( } } - val seed = random.nextLong(0, 2 shl 32 - 1) + val seed = random.nextLong(0, 2L shl 32 - 1) NovelAiHelper.logger.info(input.joinToString(", ", "generate image seed: $seed, tags: ")) val generate = try { client.ai.generateImage(input = input.joinToString(",")) { @@ -76,6 +76,6 @@ public object NovelAiFuCommand : SimpleCommand( return } val image = subject.uploadImage(generate.data.toExternalResource().toAutoCloseable()) - sendMessage(fromEvent.message.quote() + image + "\n$seed") + sendMessage(fromEvent.message.quote() + image + "\nseed=$seed") } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/cssxsh/novelai/NovelAiClient.kt b/src/main/kotlin/xyz/cssxsh/novelai/NovelAiClient.kt index 1a9b1d2..4ef5021 100644 --- a/src/main/kotlin/xyz/cssxsh/novelai/NovelAiClient.kt +++ b/src/main/kotlin/xyz/cssxsh/novelai/NovelAiClient.kt @@ -39,6 +39,8 @@ public open class NovelAiClient(internal val config: NovelAiClientConfig, intern HttpStatusCode.Conflict -> throw NovelAiApiException(error = response.body()) HttpStatusCode.InternalServerError -> throw NovelAiApiException(error = response.body()) } + if (response.status.value in 500..599) throw ServerResponseException(response, response.body()) + if ((response.contentLength() ?: 0) == 0L) throw ServerResponseException(response, response.body()) } } Auth { @@ -63,7 +65,7 @@ public open class NovelAiClient(internal val config: NovelAiClientConfig, intern BrowserUserAgent() ContentEncoding() defaultRequest { - if (!default) url(config.baseUrl) + if (default) url("https://api.novelai.net") else url(config.baseUrl) } engine { config { diff --git a/src/main/kotlin/xyz/cssxsh/novelai/ai/AIController.kt b/src/main/kotlin/xyz/cssxsh/novelai/ai/AIController.kt index e865fd0..b08fc5f 100644 --- a/src/main/kotlin/xyz/cssxsh/novelai/ai/AIController.kt +++ b/src/main/kotlin/xyz/cssxsh/novelai/ai/AIController.kt @@ -99,7 +99,7 @@ public class AIController(private val client: NovelAiClient) { "data" -> data = packet.decodeBase64Bytes().readBytes() } } - if (event.isEmpty()) { + if (data.isEmpty()) { throw NovelAiApiException(error = Json.decodeFromString(key)) }