Skip to content

Commit

Permalink
feat: support send video
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Sep 11, 2023
1 parent 3e4a1bb commit 27c9066
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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")
//
Expand Down
25 changes: 22 additions & 3 deletions src/main/kotlin/xyz/cssxsh/mirai/weibo/WeiboUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 27c9066

Please sign in to comment.