diff --git a/build.gradle.kts b/build.gradle.kts index a53cfbf..2ff1f14 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { kotlin("jvm") version "1.8.22" kotlin("plugin.serialization") version "1.8.22" - id("net.mamoe.mirai-console") version "2.15.0" + id("net.mamoe.mirai-console") version "2.16.0-RC" id("me.him188.maven-central-publish") version "1.0.0-dev-3" } @@ -32,7 +32,7 @@ dependencies { testImplementation(kotlin("test")) testImplementation("net.mamoe.yamlkt:yamlkt-jvm:0.10.2") // - implementation(platform("net.mamoe:mirai-bom:2.14.0")) + implementation(platform("net.mamoe:mirai-bom:2.16.0-RC")) compileOnly("net.mamoe:mirai-console-compiler-common") testImplementation("net.mamoe:mirai-logging-slf4j") // diff --git a/src/main/kotlin/xyz/cssxsh/mirai/weibo/WeiboUtils.kt b/src/main/kotlin/xyz/cssxsh/mirai/weibo/WeiboUtils.kt index 794228a..d2f23f8 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/weibo/WeiboUtils.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/weibo/WeiboUtils.kt @@ -361,11 +361,30 @@ internal suspend fun MicroBlog.toMessage(contact: Contact): MessageChain = build if (WeiboHelperSettings.video && hasVideo) { supervisorScope { launch { + val video = try { + getVideo() + } catch (cause: Throwable) { + logger.warning({ "下载视频失败, $link" }, cause) + return@launch + } + + val cover = getCover().toExternalResource() + try { + val message = video.toExternalResource().use { + contact.uploadShortVideo(thumbnail = cover, video = it, fileName = mid) + } + contact.sendMessage(message) + return@launch + } catch (cause: Throwable) { + logger.warning({ "$contact 无法发送视频" }, cause) + } finally { + cover.close() + } + try { - val file = getVideo() contact as FileSupported - file.toExternalResource().use { contact.files.uploadNewFile(file.name, it) } - } catch (cause: Exception) { + video.toExternalResource().use { contact.files.uploadNewFile(video.name, it) } + } catch (cause: Throwable) { logger.warning({ "$contact 无法发送文件" }, cause) } }