[core] avoid potential null cast when refining OnlineShortVideoMsgInternal

This commit is contained in:
StageGuard 2023-08-25 22:16:27 +08:00
parent 5651d642fa
commit 4acd66711a
No known key found for this signature in database
GPG Key ID: F6FF8760A883492B

View File

@ -12,7 +12,6 @@ package net.mamoe.mirai.internal.message.data
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.contact.getMember
import net.mamoe.mirai.internal.asQQAndroidBot
import net.mamoe.mirai.internal.message.RefinableMessage
@ -44,18 +43,17 @@ internal class OnlineShortVideoMsgInternal(
val groupId = refineContext[RefineContextKey.GroupIdOrZero] ?: return null
val contact = when (sourceKind) {
net.mamoe.mirai.message.data.MessageSourceKind.FRIEND -> bot.getFriend(fromId)
net.mamoe.mirai.message.data.MessageSourceKind.GROUP -> bot.getGroup(groupId)
else -> return null // TODO: ignore processing stranger's video message
} as Contact
MessageSourceKind.FRIEND -> bot.getFriend(fromId) ?: error("Cannot find friend $fromId.")
MessageSourceKind.GROUP -> bot.getGroup(groupId) ?: error("Cannot find group $fromId.")
else -> return null // ignore processing stranger's video message
}
val sender = when (sourceKind) {
net.mamoe.mirai.message.data.MessageSourceKind.FRIEND ->
bot.getFriend(fromId) ?: error("Cannot find friend $fromId.")
net.mamoe.mirai.message.data.MessageSourceKind.GROUP -> {
MessageSourceKind.FRIEND -> bot.getFriend(fromId) ?: error("Cannot find friend $fromId.")
MessageSourceKind.GROUP -> {
val group = bot.getGroup(groupId) ?: error("Cannot find group $groupId.")
group.getMember(fromId) ?: error("Cannot find member $fromId of group $groupId.")
}
else -> return null // TODO: ignore processing stranger's video message
else -> return null // ignore processing stranger's video message
}
val shortVideoDownloadReq = bot.network.sendAndExpect(