Skip to content

Commit

Permalink
修复文字模式无法解析直播动态
Browse files Browse the repository at this point in the history
  • Loading branch information
Colter23 committed Apr 7, 2022
1 parent c608c98 commit 453a619
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "top.colter"
version = "2.2.1"
version = "2.2.2-M1"

repositories {
mavenLocal()
Expand Down
26 changes: 14 additions & 12 deletions src/main/kotlin/top/colter/mirai/plugin/bilibili/Dynamic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ fun DynamicSketch.getContent(dynamicInfo: DynamicInfo): String {

fun DynamicLive.getContent(dynamicInfo: DynamicInfo): String {
if (dynamicInfo.link == "") {
dynamicInfo.link = "https://live.bilibili.com/$roomId"
dynamicInfo.link = "https://live.bilibili.com/${livePlayInfo.roomId}"
}
if (cover != "") {
dynamicInfo.images.add(cover)
if (livePlayInfo.cover != "") {
dynamicInfo.images.add(livePlayInfo.cover)
}
return buildString {
append("直播: $title")
append("直播: $livePlayInfo.title")
}
}

Expand Down Expand Up @@ -365,14 +365,16 @@ fun DynamicInfo.replaceTemplate(template: String): String {
//}

suspend fun getImageMessage(url: String, contact: Contact): Message {
var inputStream: InputStream? = null
return try {
inputStream = URL(url).openConnection().getInputStream()
inputStream.uploadAsImage(contact)
} catch (e: Exception) {
"获取图片失败".toPlainText()
} finally {
inputStream?.close()
return withContext(Dispatchers.IO) {
var inputStream: InputStream? = null
return@withContext try {
inputStream = URL(url).openConnection().getInputStream()
inputStream.uploadAsImage(contact)
} catch (e: Exception) {
"获取图片失败".toPlainText()
} finally {
inputStream?.close()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object PluginMain : KotlinPlugin(
JvmPluginDescription(
id = "top.colter.bilibili-dynamic-mirai-plugin",
name = "BilibiliDynamic",
version = "2.2.1"
version = "2.2.2-M1"
) {
author("Colter")
info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,54 +315,51 @@ data class DynamicSketchVest(
// DynamicType.LIVE
@Serializable
data class DynamicLive(
@SerialName("background")
val background: String,
@SerialName("broadcast_type")
val broadcastType: Int,
@SerialName("live_play_info")
val livePlayInfo: LivePlayInfo,
//@SerialName("live_record_info")
//val liveRecordInfo: LiveRecordInfo? = null,
@SerialName("style")
val style: Int,
@SerialName("type")
val type: Int
): DynamicContent("直播")

@Serializable
data class LivePlayInfo(
@SerialName("area_id")
val areaId: Int,
@SerialName("area_name")
val areaName: String,
@SerialName("cover")
val cover: String,
@SerialName("face")
val face: String,
@SerialName("hidden_status")
val hiddenStatus: String,
@SerialName("link")
val link: String,
@SerialName("live_id")
val liveId: Long,
@SerialName("live_start_time")
val liveStartTime: Long,
@SerialName("live_status")
val liveStatus: Int,
@SerialName("lock_status")
val lockStatus: String,
@SerialName("on_flag")
val onFlag: Int,
@SerialName("online")
val online: Int,
@SerialName("room_shield")
val roomShield: Int,
@SerialName("room_silent")
val roomSilent: Int,
@SerialName("roomid")
val roomId: Long,
@SerialName("round_status")
val roundStatus: Int,
@SerialName("short_id")
val shortId: Int,
@SerialName("slide_link")
val slideLink: String,
@SerialName("tags")
val tags: String,
@SerialName("parent_area_id")
val parentAreaId: Int,
@SerialName("parent_area_name")
val parentAreaName: String,
@SerialName("room_id")
val roomId: Int,
@SerialName("title")
val title: String,
@SerialName("try_time")
val tryTime: String,
@SerialName("uid")
val uid: Long,
@SerialName("uname")
val uname: String,
@SerialName("user_cover")
val userCover: String,
@SerialName("verify")
val verify: String,
): DynamicContent("直播")

@SerialName("watched_show")
val watchedShow: String,
)
@Serializable
data class LiveRecordInfo(
val info: String? = null
)

object DynamicType {
const val NONE = 0
Expand Down

0 comments on commit 453a619

Please sign in to comment.