Skip to content

Commit

Permalink
update: dynamic type unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
Colter23 committed Jun 26, 2022
1 parent cef3589 commit f47c915
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
24 changes: 22 additions & 2 deletions src/main/kotlin/top/colter/mirai/plugin/bilibili/data/Dynamic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ enum class DynamicType(val text: String) {
DYNAMIC_TYPE_LIVE_RCMD("直播"),
DYNAMIC_TYPE_PGC("番剧"),
DYNAMIC_TYPE_COMMON_SQUARE("动态"),
DYNAMIC_TYPE_NONE("动态被删除")
DYNAMIC_TYPE_COMMON_VERTICAL("动态"),
DYNAMIC_TYPE_NONE("动态被删除"),
DYNAMIC_TYPE_UNKNOWN("未知的动态"),
}


Expand Down Expand Up @@ -75,7 +77,7 @@ data class DynamicItem(
* DYNAMIC_TYPE_NONE 动态被删除
*/
@SerialName("type")
val type: DynamicType,
val typeStr: String,

@SerialName("id_str")
val idStr: String?,
Expand All @@ -89,6 +91,24 @@ data class DynamicItem(
val orig: DynamicItem? = null,
) {

val type: DynamicType get() =
when (typeStr){
"DYNAMIC_TYPE_WORD" -> DynamicType.DYNAMIC_TYPE_WORD
"DYNAMIC_TYPE_DRAW" -> DynamicType.DYNAMIC_TYPE_DRAW
"DYNAMIC_TYPE_ARTICLE" -> DynamicType.DYNAMIC_TYPE_ARTICLE
"DYNAMIC_TYPE_FORWARD" -> DynamicType.DYNAMIC_TYPE_FORWARD
"DYNAMIC_TYPE_AV" -> DynamicType.DYNAMIC_TYPE_AV
"DYNAMIC_TYPE_MUSIC" -> DynamicType.DYNAMIC_TYPE_MUSIC
"DYNAMIC_TYPE_LIVE" -> DynamicType.DYNAMIC_TYPE_LIVE
"DYNAMIC_TYPE_LIVE_RCMD" -> DynamicType.DYNAMIC_TYPE_LIVE_RCMD
"DYNAMIC_TYPE_PGC" -> DynamicType.DYNAMIC_TYPE_PGC
"DYNAMIC_TYPE_COMMON_SQUARE" -> DynamicType.DYNAMIC_TYPE_COMMON_SQUARE
"DYNAMIC_TYPE_COMMON_VERTICAL" -> DynamicType.DYNAMIC_TYPE_COMMON_VERTICAL
"DYNAMIC_TYPE_NONE" -> DynamicType.DYNAMIC_TYPE_NONE
else -> DynamicType.DYNAMIC_TYPE_UNKNOWN
}


val did: String get() = idStr?:"0"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import org.jetbrains.skia.*
import org.jetbrains.skia.paragraph.ParagraphBuilder
import org.jetbrains.skia.svg.SVGDOM
import top.colter.mirai.plugin.bilibili.BiliConfig
import top.colter.mirai.plugin.bilibili.BiliData
import top.colter.mirai.plugin.bilibili.data.LiveInfo
import top.colter.mirai.plugin.bilibili.tasker.DynamicMessageTasker
import top.colter.mirai.plugin.bilibili.utils.*


Expand Down Expand Up @@ -109,7 +111,9 @@ suspend fun LiveInfo.drawAvatar(): Image {
y += quality.subTitleFontSize + space * 0.5f
drawTextLine(textLineTime, x, y, Paint().apply { color = theme.subTitleColor })

//drawOrnament(if (BiliConfig.imageConfig.cardOrnament=="QrCode") "QrCode" else "Label", null, link, "")
val color = BiliData.dynamic[uid]?.color ?: BiliConfig.imageConfig.defaultColor
val colors = color.split(";", "").map { Color.makeRGB(it.trim()) }.first()
drawOrnament(if (BiliConfig.imageConfig.cardOrnament=="QrCode") "QrCode" else "Label", null, "https://live.bilibili.com/$roomId", colors, area)
}
}.makeImageSnapshot()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ object DynamicMessageTasker : BiliTasker() {
modules.moduleDynamic.major?.pgc?.title!!
}

DYNAMIC_TYPE_COMMON_VERTICAL,
DYNAMIC_TYPE_COMMON_SQUARE -> {
modules.moduleDynamic.major?.common?.title!!
}
Expand All @@ -88,6 +89,7 @@ object DynamicMessageTasker : BiliTasker() {
DYNAMIC_TYPE_NONE -> {
modules.moduleDynamic.major?.none?.tips!!
}
DYNAMIC_TYPE_UNKNOWN -> "未知的动态类型: $typeStr"
}

}
Expand Down Expand Up @@ -150,7 +152,10 @@ object DynamicMessageTasker : BiliTasker() {
}
DYNAMIC_TYPE_NONE,
DYNAMIC_TYPE_WORD,
DYNAMIC_TYPE_DRAW -> {
DYNAMIC_TYPE_DRAW,
DYNAMIC_TYPE_COMMON_VERTICAL,
DYNAMIC_TYPE_COMMON_SQUARE,
DYNAMIC_TYPE_UNKNOWN -> {
listOf(
DynamicMessage.Link("动态", DYNAMIC_LINK(did))
)
Expand Down Expand Up @@ -193,12 +198,6 @@ object DynamicMessageTasker : BiliTasker() {
)
}

DYNAMIC_TYPE_COMMON_SQUARE -> {
listOf(
DynamicMessage.Link("动态", DYNAMIC_LINK(did))
)
}

DYNAMIC_TYPE_LIVE -> {
listOf(
DynamicMessage.Link(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ object SendTasker : BiliTasker() {
DynamicType.DYNAMIC_TYPE_WORD,
DynamicType.DYNAMIC_TYPE_DRAW,
DynamicType.DYNAMIC_TYPE_COMMON_SQUARE,
DynamicType.DYNAMIC_TYPE_COMMON_VERTICAL,
DynamicType.DYNAMIC_TYPE_UNKNOWN,
DynamicType.DYNAMIC_TYPE_NONE -> DynamicFilterType.DYNAMIC

DynamicType.DYNAMIC_TYPE_FORWARD -> DynamicFilterType.FORWARD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ val DynamicItem.link: String
DYNAMIC_TYPE_WORD,
DYNAMIC_TYPE_DRAW,
DYNAMIC_TYPE_FORWARD,
DYNAMIC_TYPE_COMMON_SQUARE -> "https://t.bilibili.com/$idStr"
DYNAMIC_TYPE_COMMON_SQUARE,
DYNAMIC_TYPE_COMMON_VERTICAL,
DYNAMIC_TYPE_UNKNOWN -> "https://t.bilibili.com/$idStr"

DYNAMIC_TYPE_ARTICLE -> "https://www.bilibili.com/read/cv${modules.moduleDynamic.major?.article?.id}"
DYNAMIC_TYPE_AV -> "https://www.bilibili.com/video/${modules.moduleDynamic.major?.archive?.bvid}"
Expand Down
5 changes: 2 additions & 3 deletions src/test/kotlin/PluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.jetbrains.skia.*
import org.junit.Test
import top.colter.mirai.plugin.bilibili.client.BiliClient
import top.colter.mirai.plugin.bilibili.data.DynamicItem
import top.colter.mirai.plugin.bilibili.data.DynamicType
import top.colter.mirai.plugin.bilibili.data.ModuleAuthor
import top.colter.mirai.plugin.bilibili.data.ModuleDynamic
import top.colter.mirai.plugin.bilibili.draw.*
Expand Down Expand Up @@ -131,7 +130,7 @@ internal class PluginTest {
fun drawDynamicTest(): Unit = runBlocking {
val dynamic = DynamicItem(
// "DYNAMIC_TYPE_WORD",
DynamicType.DYNAMIC_TYPE_FORWARD,
"DYNAMIC_TYPE_FORWARD",
"652271005324017683",
true,
null,
Expand Down Expand Up @@ -286,7 +285,7 @@ internal class PluginTest {
),
orig = DynamicItem(
// "DYNAMIC_TYPE_WORD",
DynamicType.DYNAMIC_TYPE_WORD,
"DYNAMIC_TYPE_WORD",
"652271005324017683",
true,
null,
Expand Down

0 comments on commit f47c915

Please sign in to comment.