mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-25 23:10:12 +08:00
Make FlashImage
constructable from mirai-core
This commit is contained in:
parent
5cb93c9fa1
commit
985b0b4ba4
@ -1,60 +1,13 @@
|
|||||||
package net.mamoe.mirai.qqandroid.message
|
package net.mamoe.mirai.qqandroid.message
|
||||||
|
|
||||||
import net.mamoe.mirai.message.data.*
|
import net.mamoe.mirai.message.data.FriendFlashImage
|
||||||
|
import net.mamoe.mirai.message.data.GroupFlashImage
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.HummerCommelem
|
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.HummerCommelem
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
|
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
|
||||||
import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
|
import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray
|
||||||
|
|
||||||
fun FlashImage(image: Image) = when (image) {
|
|
||||||
is GroupImage -> GroupFlashImageImpl(image)
|
|
||||||
is FriendImage -> FriendFlashImageImpl(image)
|
|
||||||
else -> throw IllegalArgumentException("不支持的图片类型(Please use GroupImage or FriendImage)")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Image.flash() = FlashImage(this)
|
internal fun GroupFlashImage.toJceData() = ImMsgBody.Elem(
|
||||||
|
|
||||||
internal class GroupFlashImageImpl(
|
|
||||||
override val image: GroupImage
|
|
||||||
) : AbstractGroupFlashImage() {
|
|
||||||
|
|
||||||
private var stringValue: String? = null
|
|
||||||
get() {
|
|
||||||
return field ?: kotlin.run {
|
|
||||||
field = "[mirai:flash:${image.imageId}]"
|
|
||||||
field
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String = stringValue!!
|
|
||||||
|
|
||||||
override val length: Int get() = stringValue!!.length
|
|
||||||
|
|
||||||
override fun get(index: Int) = stringValue!![index]
|
|
||||||
|
|
||||||
override fun subSequence(startIndex: Int, endIndex: Int) = stringValue!!.subSequence(startIndex, endIndex)
|
|
||||||
|
|
||||||
override fun compareTo(other: String) = other.compareTo(stringValue!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
internal class FriendFlashImageImpl(
|
|
||||||
override val image: FriendImage
|
|
||||||
) : AbstractFriendFlashImage() {
|
|
||||||
|
|
||||||
private val stringValue = "flash"
|
|
||||||
|
|
||||||
override fun toString() = stringValue
|
|
||||||
|
|
||||||
override val length = stringValue.length
|
|
||||||
|
|
||||||
override fun get(index: Int) = stringValue.get(index)
|
|
||||||
|
|
||||||
override fun subSequence(startIndex: Int, endIndex: Int) = stringValue.subSequence(startIndex, endIndex)
|
|
||||||
|
|
||||||
override fun compareTo(other: String) = other.compareTo(stringValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun GroupFlashImageImpl.toJceData() = ImMsgBody.Elem(
|
|
||||||
commonElem = ImMsgBody.CommonElem(
|
commonElem = ImMsgBody.CommonElem(
|
||||||
serviceType = 3,
|
serviceType = 3,
|
||||||
businessType = 0,
|
businessType = 0,
|
||||||
@ -68,7 +21,7 @@ internal fun GroupFlashImageImpl.toJceData() = ImMsgBody.Elem(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
internal fun FriendFlashImageImpl.toJceData() = ImMsgBody.Elem(
|
internal fun FriendFlashImage.toJceData() = ImMsgBody.Elem(
|
||||||
commonElem = ImMsgBody.CommonElem(
|
commonElem = ImMsgBody.CommonElem(
|
||||||
serviceType = 3,
|
serviceType = 3,
|
||||||
businessType = 0,
|
businessType = 0,
|
||||||
|
@ -1,15 +1,56 @@
|
|||||||
|
@file:Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
|
||||||
package net.mamoe.mirai.message.data
|
package net.mamoe.mirai.message.data
|
||||||
|
|
||||||
|
import net.mamoe.mirai.utils.SinceMirai
|
||||||
|
import kotlin.jvm.JvmSynthetic
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 闪照
|
||||||
|
*
|
||||||
|
* @see Image.flash
|
||||||
|
*/
|
||||||
|
@SinceMirai("")
|
||||||
sealed class FlashImage : MessageContent {
|
sealed class FlashImage : MessageContent {
|
||||||
companion object Key : Message.Key<FlashImage>
|
companion object Key : Message.Key<FlashImage> {
|
||||||
|
operator fun invoke(image: Image): FlashImage {
|
||||||
|
return when (image) {
|
||||||
|
is GroupImage -> GroupFlashImage(image)
|
||||||
|
is FriendImage -> FriendFlashImage(image)
|
||||||
|
else -> throw IllegalArgumentException("不支持的图片类型(Please use GroupImage or FriendImage)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract val image : Image
|
/**
|
||||||
|
* 闪照的图片, 不同于普通的图片.
|
||||||
|
*/
|
||||||
|
abstract val image: Image
|
||||||
|
|
||||||
|
private var stringValue: String? = null
|
||||||
|
get() {
|
||||||
|
return field ?: kotlin.run {
|
||||||
|
field = "[mirai:flash:${image.imageId}]"
|
||||||
|
field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String = stringValue!!
|
||||||
|
override val length: Int get() = stringValue!!.length
|
||||||
|
override fun get(index: Int) = stringValue!![index]
|
||||||
|
override fun subSequence(startIndex: Int, endIndex: Int) = stringValue!!.subSequence(startIndex, endIndex)
|
||||||
|
override fun compareTo(other: String) = other.compareTo(stringValue!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class AbstractGroupFlashImage : FlashImage() {
|
@JvmSynthetic
|
||||||
abstract override val image: GroupImage
|
inline fun Image.flash(): FlashImage = FlashImage(this)
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractFriendFlashImage : FlashImage() {
|
@JvmSynthetic
|
||||||
abstract override val image: FriendImage
|
inline fun GroupImage.flash(): GroupFlashImage = FlashImage(this) as GroupFlashImage
|
||||||
}
|
|
||||||
|
@JvmSynthetic
|
||||||
|
inline fun FriendImage.flash(): FriendFlashImage = FlashImage(this) as FriendFlashImage
|
||||||
|
|
||||||
|
class GroupFlashImage internal constructor(override val image: GroupImage) : FlashImage()
|
||||||
|
|
||||||
|
class FriendFlashImage internal constructor(override val image: FriendImage) : FlashImage()
|
Loading…
Reference in New Issue
Block a user