Skip to content

Commit dce08c4

Browse files
committed
fix: readMicroBlogPicture
1 parent 6dce673 commit dce08c4

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/main/kotlin/xyz/cssxsh/arknights/weibo/Status.kt

+17-13
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,20 @@ private fun File.readMicroBlogHistory(type: BlogUser): List<MicroBlog> {
2020
}
2121

2222
private fun File.readMicroBlogPicture(type: BlogUser): List<MicroBlog> {
23-
return read<Temp<PictureData>>(type).data().blogs.fold(mutableMapOf<Long, MicroBlog>()) { acc, new ->
24-
acc.apply { compute(new.id) { _, old -> old?.copy(pictures = old.pictures + new.pictures) ?: new } }
25-
}.values.map { it.copy(user = PictureUser) }
23+
val map = mutableMapOf<Long, MicroBlog>()
24+
val epoch = 515483463L
25+
// XXX
26+
fun timestamp(id: Long): Long = (id shr 22) + epoch
27+
28+
read<Temp<PictureData>>(type).data().blogs.forEach { new ->
29+
map.compute(new.id) { _, old ->
30+
old?.copy(pictures = old.pictures + new.pictures) ?: new
31+
}
32+
}
33+
34+
return map.values.map {
35+
it.copy(created = OffsetDateTime.ofInstant(Instant.ofEpochSecond(timestamp(it.id)), it.created.offset))
36+
}
2637
}
2738

2839
private suspend fun getLongTextContent(id: Long): String {
@@ -33,7 +44,7 @@ private suspend fun getLongTextContent(id: Long): String {
3344
return content.replace("<br />", "\n").remove(SIGN)
3445
}
3546

36-
class MicroBlogData(override val dir: File): GameDataDownloader {
47+
class MicroBlogData(override val dir: File) : GameDataDownloader {
3748
val arknights get() = dir.readMicroBlogHistory(BlogUser.ARKNIGHTS)
3849
val byproduct get() = dir.readMicroBlogHistory(BlogUser.BYPRODUCT)
3950
val historicus get() = dir.readMicroBlogHistory(BlogUser.HISTORICUS)
@@ -78,7 +89,7 @@ val MicroBlog.images get() = pictures.map { image(pid = it) }
7889

7990
val MicroBlog.content get() = raw ?: text.replace("<br />", "\n").remove(SIGN)
8091

81-
val MicroBlog.url get() = Url("https://weibo.com/${user?.id ?: "detail"}/$bid")
92+
val MicroBlog.url get() = Url("https://weibo.com/${user?.id ?: "detail"}/${bid.ifBlank { id }}")
8293

8394
suspend fun MicroBlog.content(): String = if (isLongText) getLongTextContent(id = id) else content
8495

@@ -114,7 +125,7 @@ data class MicroBlog(
114125
@SerialName("id")
115126
val id: Long,
116127
@SerialName("bid")
117-
val bid: String,
128+
val bid: String = "",
118129
@SerialName("isLongText")
119130
val isLongText: Boolean = false,
120131
@SerialName("pic_ids")
@@ -165,13 +176,6 @@ data class LongTextContent(
165176
val ok: Int,
166177
)
167178

168-
private val PictureUser = MicroBlogUser(
169-
avatar = "",
170-
description = "",
171-
id = 0,
172-
name = "此微博被锁定为热门,机器人无法获取详情,请打开链接自行查看"
173-
)
174-
175179
private val PictureData.blogs get() = cards.flatMap { it.group }.flatMap { it.pictures }.map { it.blog }
176180

177181
@Serializable

src/main/kotlin/xyz/cssxsh/mirai/plugin/ArknightsSubscriber.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private suspend fun MicroBlog.toMessage(contact: Contact): Message = buildMessag
9191
}
9292

9393
private suspend fun sendMicroBlog(blog: MicroBlog) = sendToTaskContacts { contact ->
94-
appendLine("鹰角有新微博!@${blog.user?.name}")
94+
appendLine("鹰角有新微博!@${blog.user?.name ?: "此微博被锁定为热门,机器人无法获取详情,请打开链接自行查看"}")
9595
appendLine("时间: ${blog.created}")
9696
appendLine("链接: ${blog.url}")
9797

@@ -344,8 +344,9 @@ internal object ArknightsSubscriber : CoroutineScope by ArknightsHelperPlugin.ch
344344
logger.warning({ "订阅器 MicroBlogData 数据加载失败" }, it)
345345
}
346346

347-
val new = MicroBlogData.all.filterNot { it.id in history } + MicroBlogData.picture.filter {
348-
it.id > (MicroBlogData.arknights.maxOfOrNull(MicroBlog::id) ?: 0L)
347+
val new = with(MicroBlogData) {
348+
val max = arknights.maxOfOrNull { it.id } ?: Long.MAX_VALUE
349+
all.filterNot { it.id in history } + picture.filterNot { it.id <= max && it.id in history }
349350
}
350351
if (new.isNotEmpty()) {
351352
logger.info { "明日方舟 微博 订阅器 捕捉到结果" }
@@ -394,7 +395,7 @@ internal object ArknightsSubscriber : CoroutineScope by ArknightsHelperPlugin.ch
394395
if (new.isNotEmpty()) {
395396
logger.info { "明日方舟 公告 订阅器 捕捉到结果" }
396397
new.sortedBy { it.id }.forEach { announcement ->
397-
if (announcement.id in history) return@forEach
398+
if (announcement.id in history || announcement.date != LocalDate.now()) return@forEach
398399
runCatching {
399400
sendAnnouncement(announcement)
400401
}.onSuccess {

0 commit comments

Comments
 (0)