Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: SuperFaceProtocol #2722

Merged
merged 24 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add: CodableMessage
  • Loading branch information
cssxsh committed Jul 17, 2023
commit 5da4e9ffdcd3c11280b9e1a55ed2a51f7dcaa941
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ private object MiraiCodeParsers : AbstractMap<String, MiraiCodeParser>(), Map<St
"face" to MiraiCodeParser(Regex("""(\d*)""")) { (id) ->
Face(id.toInt())
},
"superface" to MiraiCodeParser(Regex("""(\d*),(.*),(\d*)""")) { (face, id, type) ->
SuperFace(face.toInt(), id, type.toInt())
},
"image" to MiraiCodeParser(Regex("""(.*)""")) { (id) ->
Image(id)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -85,6 +85,7 @@ public interface MessageMetadata : SingleMessage {
* @see RichMessage 富文本
* @see ServiceMessage 服务消息, 如 JSON/XML
* @see Face 原生表情
* @see SuperFace 超级表情
* @see ForwardMessage 合并转发
* @see Voice 语音
* @see MarketFace 商城表情
Expand Down
15 changes: 14 additions & 1 deletion mirai-core-api/src/commonMain/kotlin/message/data/SuperFace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package net.mamoe.mirai.message.data

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.mamoe.mirai.message.code.CodableMessage
import net.mamoe.mirai.message.data.visitor.MessageVisitor
import net.mamoe.mirai.utils.MiraiExperimentalApi
import net.mamoe.mirai.utils.MiraiInternalApi
import net.mamoe.mirai.utils.NotStableForInheritance
Expand All @@ -30,7 +32,7 @@ public data class SuperFace @MiraiInternalApi constructor(
public val face: Int,
public val id: String,
@MiraiInternalApi public val type: Int
) : HummerMessage {
) : HummerMessage, CodableMessage {

public companion object Key :
AbstractPolymorphicMessageKey<MessageContent, SuperFace>(
Expand Down Expand Up @@ -94,6 +96,17 @@ public data class SuperFace @MiraiInternalApi constructor(
override fun toString(): String = contentToString()

override fun contentToString(): String = Face.names.getOrElse(face) { "[超级表情]" }

@MiraiExperimentalApi
@OptIn(MiraiInternalApi::class)
override fun appendMiraiCodeTo(builder: StringBuilder) {
builder.append("[mirai:superface:").append(face).append(',').append(id).append(',').append(type).append(']')
}

@MiraiInternalApi
override fun <D, R> accept(visitor: MessageVisitor<D, R>, data: D): R {
return visitor.visitSuperFace(this, data)
}
}

@JvmSynthetic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public interface MessageVisitor<in D, out R> {
public fun visitFlashImage(message: FlashImage, data: D): R
public fun visitPokeMessage(message: PokeMessage, data: D): R
public fun visitVipFace(message: VipFace, data: D): R
public fun visitSuperFace(message: SuperFace, data: D): R

// region MarketFace
public fun visitMarketFace(message: MarketFace, data: D): R
Expand Down Expand Up @@ -180,6 +181,10 @@ public abstract class AbstractMessageVisitor<in D, out R> : MessageVisitor<D, R>
return visitHummerMessage(message, data)
}

override fun visitSuperFace(message: SuperFace, data: D): R {
return visitHummerMessage(message, data)
}

public override fun visitMarketFace(message: MarketFace, data: D): R {
return visitHummerMessage(message, data)
}
Expand Down