1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-17 09:09:23 +08:00

rename: SuperFace

This commit is contained in:
cssxsh 2023-07-05 02:11:00 +08:00
parent 8ef30d9e74
commit afaf0923fa
No known key found for this signature in database
GPG Key ID: 92849F91CA9D8ECE
6 changed files with 27 additions and 27 deletions
mirai-core-api/src/commonMain/kotlin/message/data
mirai-core/src
commonMain
commonTest/kotlin/message/protocol

View File

@ -16,45 +16,45 @@ import net.mamoe.mirai.utils.NotStableForInheritance
import net.mamoe.mirai.utils.safeCast
/**
* 动画表情
* 超级表情
*
* @see Face
*/
@OptIn(MiraiExperimentalApi::class)
@Serializable
@SerialName(AnimatedSticker.SERIAL_NAME)
@SerialName(SuperFace.SERIAL_NAME)
@NotStableForInheritance
public data class AnimatedSticker(
public data class SuperFace(
public val id: Int
) : HummerMessage {
public companion object Key :
AbstractPolymorphicMessageKey<MessageContent, AnimatedSticker>(
AbstractPolymorphicMessageKey<MessageContent, SuperFace>(
MessageContent,
{ it.safeCast() }) {
public const val SERIAL_NAME: String = "AnimatedSticker"
public const val SERIAL_NAME: String = "SuperFace"
/**
* 将普通表情转换为动画.
*
* @see Image.flash
* @see Face.animated
*/
@JvmStatic
public fun from(face: Face): AnimatedSticker = AnimatedSticker(face.id)
public fun from(face: Face): SuperFace = SuperFace(face.id)
}
override val key: MessageKey<AnimatedSticker> get() = Key
override val key: MessageKey<SuperFace> get() = Key
public val name: String get() = contentToString().let { it.substring(1, it.length - 1) }
override fun toString(): String = contentToString()
override fun contentToString(): String = Face.names.getOrElse(id) { "[动画表情]" }
override fun contentToString(): String = Face.names.getOrElse(id) { "[超级表情]" }
}
/**
* 将普通表情转换为动画.
* 将普通表情转换为超级表情.
*/
@JvmSynthetic
public inline fun Face.animated(): AnimatedSticker = AnimatedSticker.from(this)
public inline fun Face.animated(): SuperFace = SuperFace.from(this)

View File

@ -23,13 +23,13 @@ import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
import net.mamoe.mirai.message.data.*
import kotlin.text.toByteArray
internal class AnimatedStickerProtocol : MessageProtocol() {
internal class SuperFaceProtocol : MessageProtocol() {
override fun ProcessorCollector.collectProcessorsImpl() {
add(Decoder())
add(Encoder())
MessageSerializer.superclassesScope(MessageContent::class, SingleMessage::class) {
add(MessageSerializer(AnimatedSticker::class, AnimatedSticker.serializer()))
add(MessageSerializer(SuperFace::class, SuperFace.serializer()))
}
}
@ -41,12 +41,12 @@ internal class AnimatedStickerProtocol : MessageProtocol() {
markAsConsumed()
val proto = data.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype37.serializer())
collect(AnimatedSticker(proto.qsId))
collect(SuperFace(proto.qsId))
}
}
private class Encoder : MessageEncoder<AnimatedSticker> {
override suspend fun MessageEncoderContext.process(data: AnimatedSticker) {
private class Encoder : MessageEncoder<SuperFace> {
override suspend fun MessageEncoderContext.process(data: SuperFace) {
markAsConsumed()
val businessType = when (data.id) {

View File

@ -62,8 +62,8 @@ internal object MiraiCoreServices {
) { net.mamoe.mirai.internal.message.protocol.impl.MarketFaceProtocol() }
Services.register(
msgProtocol,
"net.mamoe.mirai.internal.message.protocol.impl.AnimatedStickerProtocol"
) { net.mamoe.mirai.internal.message.protocol.impl.AnimatedStickerProtocol() }
"net.mamoe.mirai.internal.message.protocol.impl.SuperFaceProtocol"
) { net.mamoe.mirai.internal.message.protocol.impl.SuperFaceProtocol() }
Services.register(
msgProtocol,
"net.mamoe.mirai.internal.message.protocol.impl.MusicShareProtocol"

View File

@ -15,7 +15,7 @@ net.mamoe.mirai.internal.message.protocol.impl.FlashImageProtocol
net.mamoe.mirai.internal.message.protocol.impl.IgnoredMessagesProtocol
net.mamoe.mirai.internal.message.protocol.impl.ImageProtocol
net.mamoe.mirai.internal.message.protocol.impl.MarketFaceProtocol
net.mamoe.mirai.internal.message.protocol.impl.AnimatedStickerProtocol
net.mamoe.mirai.internal.message.protocol.impl.SuperFaceProtocol
net.mamoe.mirai.internal.message.protocol.impl.MusicShareProtocol
net.mamoe.mirai.internal.message.protocol.impl.PokeMessageProtocol
net.mamoe.mirai.internal.message.protocol.impl.PttMessageProtocol

View File

@ -28,7 +28,7 @@ internal class MessageProtocolFacadeTest : AbstractTest() {
FlashImageProtocol
ImageProtocol
MarketFaceProtocol
AnimatedStickerProtocol
SuperFaceProtocol
MusicShareProtocol
PokeMessageProtocol
PttMessageProtocol

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@ -15,14 +15,14 @@ import net.mamoe.mirai.internal.testFramework.DynamicTestsResult
import net.mamoe.mirai.internal.testFramework.TestFactory
import net.mamoe.mirai.internal.testFramework.runDynamicTests
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
import net.mamoe.mirai.message.data.AnimatedSticker
import net.mamoe.mirai.message.data.SuperFace
import net.mamoe.mirai.message.data.Face
import net.mamoe.mirai.utils.hexToBytes
import kotlin.test.BeforeTest
import kotlin.test.Test
internal class AnimatedStickerProtocolTest : AbstractMessageProtocolTest() {
override val protocols: Array<out MessageProtocol> = arrayOf(AnimatedStickerProtocol(), TextProtocol())
internal class SuperFaceProtocolTest : AbstractMessageProtocolTest() {
override val protocols: Array<out MessageProtocol> = arrayOf(SuperFaceProtocol(), TextProtocol())
@BeforeTest
fun `init group`() {
@ -39,15 +39,15 @@ internal class AnimatedStickerProtocolTest : AbstractMessageProtocolTest() {
.loadAs(net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem.serializer())
)
message(
AnimatedSticker(id = Face.LIU_LEI)
SuperFace(id = Face.LIU_LEI)
)
}.doDecoderChecks()
}
@TestFactory
fun `test serialization`(): DynamicTestsResult {
val data = AnimatedSticker(0)
val serialName = AnimatedSticker.SERIAL_NAME
val data = SuperFace(0)
val serialName = SuperFace.SERIAL_NAME
return runDynamicTests(
testPolymorphicInMessageContent(data, serialName),
testPolymorphicInSingleMessage(data, serialName),