From 93ccce16d8047cbfa5aa8a14123094f3976dc693 Mon Sep 17 00:00:00 2001 From: cssxsh Date: Sun, 3 Sep 2023 22:21:16 +0800 Subject: [PATCH] add: SuperFaceProtocol (#2722) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add: protocol * fix: MsgElemInfoServtype37 * add: AnimatedStickerProtocolTest * add: ... * rename: SuperFace * add: face impl * add: SuperFace toCommData * fix: stickerId * fix: SuperFace constructor * add: api dump * add: CodableMessage * add: api dump * fix: names size * fix: type * add: MessageVisitorTest * add: TestMiraiCode * add: MessageVisitorTest * add: TestMiraiCode * fix: no data class * feat: try from * add: api dump * add: hashCode, equals * [core] 优化 SuperFace API * fix tests --------- Co-authored-by: Him188 --- .../android/api/android.api | 87 ++++++++++ .../compatibility-validation/jvm/api/jvm.api | 87 ++++++++++ .../kotlin/message/code/internal/impl.kt | 3 + .../commonMain/kotlin/message/data/Face.kt | 72 +++++++- .../kotlin/message/data/SingleMessage.kt | 3 +- .../kotlin/message/data/SuperFace.kt | 164 ++++++++++++++++++ .../message/data/visitor/MessageVisitor.kt | 5 + .../kotlin/message.data/MessageVisitorTest.kt | 15 ++ .../protocol/impl/SuperFaceProtocol.kt | 83 +++++++++ .../protocol/data/proto/HummerCommelem.kt | 15 +- .../kotlin/utils/MiraiCoreServices.kt | 4 + ....internal.message.protocol.MessageProtocol | 3 +- .../kotlin/message/code/TestMiraiCode.kt | 5 + .../protocol/MessageProtocolFacadeTest.kt | 3 +- .../protocol/impl/SuperFaceProtocolTest.kt | 62 +++++++ 15 files changed, 606 insertions(+), 5 deletions(-) create mode 100644 mirai-core-api/src/commonMain/kotlin/message/data/SuperFace.kt create mode 100644 mirai-core/src/commonMain/kotlin/message/protocol/impl/SuperFaceProtocol.kt create mode 100644 mirai-core/src/commonTest/kotlin/message/protocol/impl/SuperFaceProtocolTest.kt diff --git a/mirai-core-api/compatibility-validation/android/api/android.api b/mirai-core-api/compatibility-validation/android/api/android.api index 4d0973b4cf..c09a95146e 100644 --- a/mirai-core-api/compatibility-validation/android/api/android.api +++ b/mirai-core-api/compatibility-validation/android/api/android.api @@ -3467,6 +3467,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field BANG_BANG_TANG I public static final field BAN_ZHUAN_ZHONG I public static final field BAO_BAO I + public static final field BAO_FU I public static final field BAO_JI I public static final field BAO_JIN I public static final field BAO_QUAN I @@ -3496,6 +3497,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field CHI_GUA I public static final field CHI_TANG I public static final field CHONG_BAI I + public static final field CUO_HAO I public static final field Companion Lnet/mamoe/mirai/message/data/Face$Companion; public static final field DAN I public static final field DAN_GAO I @@ -3504,11 +3506,15 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field DA_KU I public static final field DA_LIAN I public static final field DA_XIAO I + public static final field DA_YUAN_ZHONG I + public static final field DA_ZHAN_HONG_TU I + public static final field DA_ZHAO_HU I public static final field DENG_LONG I public static final field DE_YI I public static final field DIAN_ZAN I public static final field DIAO_XIE I public static final field DING_GUA_GUA I + public static final field DUI_HAO I public static final field E I public static final field FAN I public static final field FA_DAI I @@ -3518,6 +3524,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field FEI_WEN I public static final field FEN_DOU I public static final field FO_XI I + public static final field FU_LUO_BO I public static final field GAN_BEI I public static final field GAN_GA I public static final field GONG_XI I @@ -3538,11 +3545,15 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field HE_XIE I public static final field HONG_BAO I public static final field HONG_BAO_BAO I + public static final field HONG_BAO_DUO_DUO I public static final field HUAI_XIAO I public static final field HUA_CHI I + public static final field HUA_DUO_LIAN I public static final field HUI_SHOU I public static final field HUI_TOU I + public static final field HU_HU_SHENG_WEI I public static final field HU_LIAN I + public static final field JIA_YI I public static final field JIA_YOU I public static final field JIA_YOU_BAO_BAO I public static final field JIA_YOU_BI_SHENG I @@ -3551,12 +3562,14 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field JING_KONG I public static final field JING_LI I public static final field JING_XI I + public static final field JING_XIA I public static final field JING_YA I public static final field JI_DONG I public static final field JI_E I public static final field JI_ZHANG I public static final field JU_HUA I public static final field JU_JUE I + public static final field JU_PAI_PAI I public static final field KAI_QIANG I public static final field KA_FEI I public static final field KEN_TOU I @@ -3589,6 +3602,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field MEI_GUI I public static final field MIAN_WU_BIAO_QING I public static final field MIAO_MIAO I + public static final field MING_BAI I public static final field MO_GUI_XIAO I public static final field MO_JIN_LI I public static final field MO_YU I @@ -3597,6 +3611,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field NA_DAO_HONG_BAO I public static final field NIU_A I public static final field NIU_QI_CHONG_TIAN I + public static final field NI_ZHEN_BANG_BANG I public static final field NO I public static final field O I public static final field OK I @@ -3625,12 +3640,14 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field QUAN_TOU I public static final field RANG_WO_KANG_KANG I public static final field RENG_GOU I + public static final field RE_HUA_LE I public static final field SAO_RAO I public static final field SE I public static final field SERIAL_NAME Ljava/lang/String; public static final field SHAN_DIAN I public static final field SHAN_LIAN I public static final field SHENG_LI I + public static final field SHENG_QI I public static final field SHENG_RI_KUAI_LE I public static final field SHI_AI I public static final field SHOU_QIANG I @@ -3639,8 +3656,10 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field SHUANG_XI I public static final field SHUI I public static final field SONG_HUA I + public static final field SUAN_Q I public static final field TAI_NAN_LE I public static final field TAI_YANG I + public static final field TIAN_PING I public static final field TIAN_YI_TIAN I public static final field TIAO_PI I public static final field TIAO_SHENG I @@ -3653,13 +3672,16 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field TUO_LIAN I public static final field TUO_SAI I public static final field WANG_WANG I + public static final field WAN_CHENG I public static final field WEI_QU I public static final field WEI_XIAO I public static final field WEN_HAO_LIAN I public static final field WO_BU_KAN I + public static final field WO_FANG_LE I public static final field WO_MEI_SHI I public static final field WO_SHOU I public static final field WO_SUAN_LE I + public static final field WO_XIANG_KAI_LE I public static final field WO_ZUI_MEI I public static final field WU_LIAN I public static final field WU_LIAO I @@ -3678,6 +3700,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field XI_GUA I public static final field XU I public static final field YANG_TUO I + public static final field YAN_HUA I public static final field YAO I public static final field YIN_XIAN I public static final field YI_WEN I @@ -3717,10 +3740,12 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field names [Ljava/lang/String; public static final field 不 I public static final field 不开心 I + public static final field 举牌牌 I public static final field 乒乓 I public static final field 亲亲 I public static final field 仔细分析 I public static final field 佛系 I + public static final field 你真棒棒 I public static final field 便便 I public static final field 偷看 I public static final field 偷笑 I @@ -3732,6 +3757,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 凋谢 I public static final field 击掌 I public static final field 刀 I + public static final field 加一 I public static final field 加油 I public static final field 加油必胜 I public static final field 加油抱抱 I @@ -3779,6 +3805,8 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 困 I public static final field 坏笑 I public static final field 大哭 I + public static final field 大展宏兔 I + public static final field 大怨种 I public static final field 大笑 I public static final field 太南了 I public static final field 太阳 I @@ -3790,8 +3818,10 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 好闪 I public static final field 委屈 I public static final field 嫌弃 I + public static final field 完成 I public static final field 害怕 I public static final field 害羞 I + public static final field 对号 I public static final field 小样儿 I public static final field 小纠结 I public static final field 尴尬 I @@ -3813,18 +3843,22 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 怄火 I public static final field 恭喜 I public static final field 悠闲 I + public static final field 惊吓 I public static final field 惊呆 I public static final field 惊喜 I public static final field 惊恐 I public static final field 惊讶 I public static final field 憨笑 I public static final field 我不看 I + public static final field 我想开了 I + public static final field 我方了 I public static final field 我最美 I public static final field 我没事 I public static final field 我酸了 I public static final field 扇脸 I public static final field 手枪 I public static final field 打call I + public static final field 打招呼 I public static final field 打脸 I public static final field 扔狗 I public static final field 托脸 I @@ -3863,6 +3897,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 无奈 I public static final field 无眼笑 I public static final field 无聊 I + public static final field 明白 I public static final field 晕 I public static final field 暗中观察 I public static final field 暴击 I @@ -3882,6 +3917,8 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 灯笼 I public static final field 炸弹 I public static final field 点赞 I + public static final field 烟花 I + public static final field 热化了 I public static final field 爆筋 I public static final field 爱你 I public static final field 爱心 I @@ -3894,6 +3931,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 玫瑰 I public static final field 瓢虫 I public static final field 生日快乐 I + public static final field 生气 I public static final field 甩头 I public static final field 疑问 I public static final field 白眼 I @@ -3905,25 +3943,30 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 示爱 I public static final field 礼物 I public static final field 祈祷 I + public static final field 福萝卜 I public static final field 笑哭 I public static final field 篮球 I public static final field 糊脸 I public static final field 糗大了 I public static final field 红包 I public static final field 红包包 I + public static final field 红包多多 I public static final field 羊驼 I public static final field 老色痞 I public static final field 胖三斤 I public static final field 胜利 I public static final field 脑阔疼 I public static final field 舔一舔 I + public static final field 舔屏 I public static final field 色 I + public static final field 花朵脸 I public static final field 花痴 I public static final field 茶 I public static final field 药 I public static final field 菊花 I public static final field 菜刀 I public static final field 菜狗 I + public static final field 虎虎生威 I public static final field 蛋 I public static final field 蛋糕 I public static final field 街舞 I @@ -3933,6 +3976,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 请 I public static final field 调皮 I public static final field 谢红包 I + public static final field 豹富 I public static final field 赞 I public static final field 足球 I public static final field 跳绳 I @@ -3945,7 +3989,9 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 送花 I public static final field 鄙视 I public static final field 酷 I + public static final field 酸Q I public static final field 钞票 I + public static final field 错号 I public static final field 闪电 I public static final field 闭嘴 I public static final field 问号脸 I @@ -5355,6 +5401,47 @@ public final class net/mamoe/mirai/message/data/SingleMessage$Serializer : kotli public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lnet/mamoe/mirai/message/data/SingleMessage;)V } +public final class net/mamoe/mirai/message/data/SuperFace : net/mamoe/mirai/message/code/CodableMessage, net/mamoe/mirai/message/data/HummerMessage { + public static final field Key Lnet/mamoe/mirai/message/data/SuperFace$Key; + public static final field SERIAL_NAME Ljava/lang/String; + public synthetic fun (IILjava/lang/String;ILkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun contentToString ()Ljava/lang/String; + public fun equals (Ljava/lang/Object;)Z + public static final fun from (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public static final fun fromOrNull (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public final fun getFace ()I + public final fun getId ()Ljava/lang/String; + public fun getKey ()Lnet/mamoe/mirai/message/data/MessageKey; + public final fun getName ()Ljava/lang/String; + public final fun getType ()I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; + public static final fun write$Self (Lnet/mamoe/mirai/message/data/SuperFace;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V +} + +public final class net/mamoe/mirai/message/data/SuperFace$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Lnet/mamoe/mirai/message/data/SuperFace$$serializer; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lnet/mamoe/mirai/message/data/SuperFace; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lnet/mamoe/mirai/message/data/SuperFace;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class net/mamoe/mirai/message/data/SuperFace$Key : net/mamoe/mirai/message/data/AbstractPolymorphicMessageKey { + public final fun from (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public final fun fromOrNull (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class net/mamoe/mirai/message/data/SuperFaceKt { + public static final synthetic fun toFace (Lnet/mamoe/mirai/message/data/SuperFace;)Lnet/mamoe/mirai/message/data/Face; + public static final synthetic fun toSuperFace (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public static final synthetic fun toSuperFaceOrNull (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; +} + public abstract interface class net/mamoe/mirai/message/data/UnsupportedMessage : net/mamoe/mirai/message/data/MessageContent { public static final field Companion Lnet/mamoe/mirai/message/data/UnsupportedMessage$Companion; public static final field SERIAL_NAME Ljava/lang/String; diff --git a/mirai-core-api/compatibility-validation/jvm/api/jvm.api b/mirai-core-api/compatibility-validation/jvm/api/jvm.api index ebe6d4a563..679b149693 100644 --- a/mirai-core-api/compatibility-validation/jvm/api/jvm.api +++ b/mirai-core-api/compatibility-validation/jvm/api/jvm.api @@ -3467,6 +3467,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field BANG_BANG_TANG I public static final field BAN_ZHUAN_ZHONG I public static final field BAO_BAO I + public static final field BAO_FU I public static final field BAO_JI I public static final field BAO_JIN I public static final field BAO_QUAN I @@ -3496,6 +3497,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field CHI_GUA I public static final field CHI_TANG I public static final field CHONG_BAI I + public static final field CUO_HAO I public static final field Companion Lnet/mamoe/mirai/message/data/Face$Companion; public static final field DAN I public static final field DAN_GAO I @@ -3504,11 +3506,15 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field DA_KU I public static final field DA_LIAN I public static final field DA_XIAO I + public static final field DA_YUAN_ZHONG I + public static final field DA_ZHAN_HONG_TU I + public static final field DA_ZHAO_HU I public static final field DENG_LONG I public static final field DE_YI I public static final field DIAN_ZAN I public static final field DIAO_XIE I public static final field DING_GUA_GUA I + public static final field DUI_HAO I public static final field E I public static final field FAN I public static final field FA_DAI I @@ -3518,6 +3524,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field FEI_WEN I public static final field FEN_DOU I public static final field FO_XI I + public static final field FU_LUO_BO I public static final field GAN_BEI I public static final field GAN_GA I public static final field GONG_XI I @@ -3538,11 +3545,15 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field HE_XIE I public static final field HONG_BAO I public static final field HONG_BAO_BAO I + public static final field HONG_BAO_DUO_DUO I public static final field HUAI_XIAO I public static final field HUA_CHI I + public static final field HUA_DUO_LIAN I public static final field HUI_SHOU I public static final field HUI_TOU I + public static final field HU_HU_SHENG_WEI I public static final field HU_LIAN I + public static final field JIA_YI I public static final field JIA_YOU I public static final field JIA_YOU_BAO_BAO I public static final field JIA_YOU_BI_SHENG I @@ -3551,12 +3562,14 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field JING_KONG I public static final field JING_LI I public static final field JING_XI I + public static final field JING_XIA I public static final field JING_YA I public static final field JI_DONG I public static final field JI_E I public static final field JI_ZHANG I public static final field JU_HUA I public static final field JU_JUE I + public static final field JU_PAI_PAI I public static final field KAI_QIANG I public static final field KA_FEI I public static final field KEN_TOU I @@ -3589,6 +3602,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field MEI_GUI I public static final field MIAN_WU_BIAO_QING I public static final field MIAO_MIAO I + public static final field MING_BAI I public static final field MO_GUI_XIAO I public static final field MO_JIN_LI I public static final field MO_YU I @@ -3597,6 +3611,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field NA_DAO_HONG_BAO I public static final field NIU_A I public static final field NIU_QI_CHONG_TIAN I + public static final field NI_ZHEN_BANG_BANG I public static final field NO I public static final field O I public static final field OK I @@ -3625,12 +3640,14 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field QUAN_TOU I public static final field RANG_WO_KANG_KANG I public static final field RENG_GOU I + public static final field RE_HUA_LE I public static final field SAO_RAO I public static final field SE I public static final field SERIAL_NAME Ljava/lang/String; public static final field SHAN_DIAN I public static final field SHAN_LIAN I public static final field SHENG_LI I + public static final field SHENG_QI I public static final field SHENG_RI_KUAI_LE I public static final field SHI_AI I public static final field SHOU_QIANG I @@ -3639,8 +3656,10 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field SHUANG_XI I public static final field SHUI I public static final field SONG_HUA I + public static final field SUAN_Q I public static final field TAI_NAN_LE I public static final field TAI_YANG I + public static final field TIAN_PING I public static final field TIAN_YI_TIAN I public static final field TIAO_PI I public static final field TIAO_SHENG I @@ -3653,13 +3672,16 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field TUO_LIAN I public static final field TUO_SAI I public static final field WANG_WANG I + public static final field WAN_CHENG I public static final field WEI_QU I public static final field WEI_XIAO I public static final field WEN_HAO_LIAN I public static final field WO_BU_KAN I + public static final field WO_FANG_LE I public static final field WO_MEI_SHI I public static final field WO_SHOU I public static final field WO_SUAN_LE I + public static final field WO_XIANG_KAI_LE I public static final field WO_ZUI_MEI I public static final field WU_LIAN I public static final field WU_LIAO I @@ -3678,6 +3700,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field XI_GUA I public static final field XU I public static final field YANG_TUO I + public static final field YAN_HUA I public static final field YAO I public static final field YIN_XIAN I public static final field YI_WEN I @@ -3717,10 +3740,12 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field names [Ljava/lang/String; public static final field 不 I public static final field 不开心 I + public static final field 举牌牌 I public static final field 乒乓 I public static final field 亲亲 I public static final field 仔细分析 I public static final field 佛系 I + public static final field 你真棒棒 I public static final field 便便 I public static final field 偷看 I public static final field 偷笑 I @@ -3732,6 +3757,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 凋谢 I public static final field 击掌 I public static final field 刀 I + public static final field 加一 I public static final field 加油 I public static final field 加油必胜 I public static final field 加油抱抱 I @@ -3779,6 +3805,8 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 困 I public static final field 坏笑 I public static final field 大哭 I + public static final field 大展宏兔 I + public static final field 大怨种 I public static final field 大笑 I public static final field 太南了 I public static final field 太阳 I @@ -3790,8 +3818,10 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 好闪 I public static final field 委屈 I public static final field 嫌弃 I + public static final field 完成 I public static final field 害怕 I public static final field 害羞 I + public static final field 对号 I public static final field 小样儿 I public static final field 小纠结 I public static final field 尴尬 I @@ -3813,18 +3843,22 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 怄火 I public static final field 恭喜 I public static final field 悠闲 I + public static final field 惊吓 I public static final field 惊呆 I public static final field 惊喜 I public static final field 惊恐 I public static final field 惊讶 I public static final field 憨笑 I public static final field 我不看 I + public static final field 我想开了 I + public static final field 我方了 I public static final field 我最美 I public static final field 我没事 I public static final field 我酸了 I public static final field 扇脸 I public static final field 手枪 I public static final field 打call I + public static final field 打招呼 I public static final field 打脸 I public static final field 扔狗 I public static final field 托脸 I @@ -3863,6 +3897,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 无奈 I public static final field 无眼笑 I public static final field 无聊 I + public static final field 明白 I public static final field 晕 I public static final field 暗中观察 I public static final field 暴击 I @@ -3882,6 +3917,8 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 灯笼 I public static final field 炸弹 I public static final field 点赞 I + public static final field 烟花 I + public static final field 热化了 I public static final field 爆筋 I public static final field 爱你 I public static final field 爱心 I @@ -3894,6 +3931,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 玫瑰 I public static final field 瓢虫 I public static final field 生日快乐 I + public static final field 生气 I public static final field 甩头 I public static final field 疑问 I public static final field 白眼 I @@ -3905,25 +3943,30 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 示爱 I public static final field 礼物 I public static final field 祈祷 I + public static final field 福萝卜 I public static final field 笑哭 I public static final field 篮球 I public static final field 糊脸 I public static final field 糗大了 I public static final field 红包 I public static final field 红包包 I + public static final field 红包多多 I public static final field 羊驼 I public static final field 老色痞 I public static final field 胖三斤 I public static final field 胜利 I public static final field 脑阔疼 I public static final field 舔一舔 I + public static final field 舔屏 I public static final field 色 I + public static final field 花朵脸 I public static final field 花痴 I public static final field 茶 I public static final field 药 I public static final field 菊花 I public static final field 菜刀 I public static final field 菜狗 I + public static final field 虎虎生威 I public static final field 蛋 I public static final field 蛋糕 I public static final field 街舞 I @@ -3933,6 +3976,7 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 请 I public static final field 调皮 I public static final field 谢红包 I + public static final field 豹富 I public static final field 赞 I public static final field 足球 I public static final field 跳绳 I @@ -3945,7 +3989,9 @@ public final class net/mamoe/mirai/message/data/Face : net/mamoe/mirai/message/c public static final field 送花 I public static final field 鄙视 I public static final field 酷 I + public static final field 酸Q I public static final field 钞票 I + public static final field 错号 I public static final field 闪电 I public static final field 闭嘴 I public static final field 问号脸 I @@ -5355,6 +5401,47 @@ public final class net/mamoe/mirai/message/data/SingleMessage$Serializer : kotli public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lnet/mamoe/mirai/message/data/SingleMessage;)V } +public final class net/mamoe/mirai/message/data/SuperFace : net/mamoe/mirai/message/code/CodableMessage, net/mamoe/mirai/message/data/HummerMessage { + public static final field Key Lnet/mamoe/mirai/message/data/SuperFace$Key; + public static final field SERIAL_NAME Ljava/lang/String; + public synthetic fun (IILjava/lang/String;ILkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun contentToString ()Ljava/lang/String; + public fun equals (Ljava/lang/Object;)Z + public static final fun from (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public static final fun fromOrNull (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public final fun getFace ()I + public final fun getId ()Ljava/lang/String; + public fun getKey ()Lnet/mamoe/mirai/message/data/MessageKey; + public final fun getName ()Ljava/lang/String; + public final fun getType ()I + public fun hashCode ()I + public fun toString ()Ljava/lang/String; + public static final fun write$Self (Lnet/mamoe/mirai/message/data/SuperFace;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V +} + +public final class net/mamoe/mirai/message/data/SuperFace$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Lnet/mamoe/mirai/message/data/SuperFace$$serializer; + public fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lnet/mamoe/mirai/message/data/SuperFace; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lnet/mamoe/mirai/message/data/SuperFace;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class net/mamoe/mirai/message/data/SuperFace$Key : net/mamoe/mirai/message/data/AbstractPolymorphicMessageKey { + public final fun from (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public final fun fromOrNull (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class net/mamoe/mirai/message/data/SuperFaceKt { + public static final synthetic fun toFace (Lnet/mamoe/mirai/message/data/SuperFace;)Lnet/mamoe/mirai/message/data/Face; + public static final synthetic fun toSuperFace (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; + public static final synthetic fun toSuperFaceOrNull (Lnet/mamoe/mirai/message/data/Face;)Lnet/mamoe/mirai/message/data/SuperFace; +} + public abstract interface class net/mamoe/mirai/message/data/UnsupportedMessage : net/mamoe/mirai/message/data/MessageContent { public static final field Companion Lnet/mamoe/mirai/message/data/UnsupportedMessage$Companion; public static final field SERIAL_NAME Ljava/lang/String; diff --git a/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt b/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt index 862d5348b6..3ca1412a73 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/code/internal/impl.kt @@ -111,6 +111,9 @@ private object MiraiCodeParsers : AbstractMap(), Map 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) }, diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/Face.kt b/mirai-core-api/src/commonMain/kotlin/message/data/Face.kt index ee0e34de92..4cac95c8f7 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/Face.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/Face.kt @@ -566,9 +566,55 @@ public data class Face(public val id: Int) : // used in delegation public const val 嫌弃: Int = XIAN_QI public const val CHI_TANG: Int = 324 public const val 吃糖: Int = CHI_TANG + public const val JING_XIA: Int = 325 + public const val 惊吓: Int = JING_XIA + public const val SHENG_QI: Int = 326 + public const val 生气: Int = SHENG_QI + public const val JIA_YI: Int = 327 + public const val 加一: Int = JIA_YI + public const val CUO_HAO: Int = 328 + public const val 错号: Int = CUO_HAO + public const val DUI_HAO: Int = 329 + public const val 对号: Int = DUI_HAO + public const val WAN_CHENG: Int = 330 + public const val 完成: Int = WAN_CHENG + public const val MING_BAI: Int = 331 + public const val 明白: Int = MING_BAI + public const val JU_PAI_PAI: Int = 332 + public const val 举牌牌: Int = JU_PAI_PAI + public const val YAN_HUA: Int = 333 + public const val 烟花: Int = YAN_HUA + public const val HU_HU_SHENG_WEI: Int = 334 + public const val 虎虎生威: Int = HU_HU_SHENG_WEI + public const val BAO_FU: Int = 336 + public const val 豹富: Int = BAO_FU + public const val HUA_DUO_LIAN : Int = 337 + public const val 花朵脸: Int = HUA_DUO_LIAN + public const val WO_XIANG_KAI_LE: Int = 338 + public const val 我想开了: Int = WO_XIANG_KAI_LE + public const val TIAN_PING : Int = 339 + public const val 舔屏: Int = TIAN_PING + public const val RE_HUA_LE: Int = 340 + public const val 热化了: Int = RE_HUA_LE + public const val DA_ZHAO_HU : Int = 341 + public const val 打招呼: Int = DA_ZHAO_HU + public const val SUAN_Q: Int = 342 + public const val 酸Q: Int = SUAN_Q + public const val WO_FANG_LE : Int = 343 + public const val 我方了: Int = WO_FANG_LE + public const val DA_YUAN_ZHONG: Int = 344 + public const val 大怨种: Int = DA_YUAN_ZHONG + public const val HONG_BAO_DUO_DUO: Int = 345 + public const val 红包多多: Int = HONG_BAO_DUO_DUO + public const val NI_ZHEN_BANG_BANG: Int = 346 + public const val 你真棒棒: Int = NI_ZHEN_BANG_BANG + public const val DA_ZHAN_HONG_TU: Int = 347 + public const val 大展宏兔: Int = DA_ZHAN_HONG_TU + public const val FU_LUO_BO: Int = 348 + public const val 福萝卜: Int = 348 @JvmField - public val names: Array = Array(325) { "[表情]" } + public val names: Array = Array(349) { "[表情]" } init { names[JING_YA] = "[惊讶]" @@ -823,6 +869,30 @@ public data class Face(public val id: Int) : // used in delegation names[JU_JUE] = "[拒绝]" names[XIAN_QI] = "[嫌弃]" names[CHI_TANG] = "[吃糖]" + names[JING_XIA] = "[惊吓]" + names[SHENG_QI] = "[生气]" + names[JIA_YI] = "[加一]" + names[CUO_HAO] = "[错号]" + names[DUI_HAO] = "[对号]" + names[WAN_CHENG] = "[完成]" + names[MING_BAI] = "[明白]" + names[JU_PAI_PAI] = "[举牌牌]" + names[YAN_HUA] = "[烟花]" + names[YAN_HUA] = "[烟花]" + names[HU_HU_SHENG_WEI] = "[虎虎生威]" + names[BAO_FU] = "[豹富]" + names[HUA_DUO_LIAN] = "[花朵脸]" + names[WO_XIANG_KAI_LE] = "[我想开了]" + names[TIAN_PING] = "[舔屏]" + names[RE_HUA_LE] = "[热化了]" + names[DA_ZHAO_HU] = "[打招呼]" + names[SUAN_Q] = "[酸Q]" + names[WO_FANG_LE] = "[我方了]" + names[DA_YUAN_ZHONG] = "[大怨种]" + names[HONG_BAO_DUO_DUO] = "[红包多多]" + names[NI_ZHEN_BANG_BANG] = "[你真棒棒]" + names[DA_ZHAN_HONG_TU] = "[大展宏兔]" + names[FU_LUO_BO] = "[福萝卜]" } } } \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/SingleMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/SingleMessage.kt index 564d4d693e..e8a15181d3 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/SingleMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/SingleMessage.kt @@ -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. @@ -85,6 +85,7 @@ public interface MessageMetadata : SingleMessage { * @see RichMessage 富文本 * @see ServiceMessage 服务消息, 如 JSON/XML * @see Face 原生表情 + * @see SuperFace 超级表情 * @see ForwardMessage 合并转发 * @see Voice 语音 * @see MarketFace 商城表情 diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/SuperFace.kt b/mirai-core-api/src/commonMain/kotlin/message/data/SuperFace.kt new file mode 100644 index 0000000000..79c980b981 --- /dev/null +++ b/mirai-core-api/src/commonMain/kotlin/message/data/SuperFace.kt @@ -0,0 +1,164 @@ +/* + * 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. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +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 +import net.mamoe.mirai.utils.safeCast + +/** + * 表示一个超级表情. + * + * 超级表情由[普通表情][Face]转换而来. 不是所有的普通表情都有对应的超级表情. + * + * 要构造超级表情, 使用 [SuperFace.from] 或 [SuperFace.fromOrNull]. + * 在 Kotlin 还可以使用对应扩展函数: [Face.toSuperFace] 或 [Face.toSuperFaceOrNull]. + * + * @see Face + * @since 2.16 + */ +@OptIn(MiraiExperimentalApi::class) +@Serializable +@SerialName(SuperFace.SERIAL_NAME) +@NotStableForInheritance +public class SuperFace @MiraiInternalApi constructor( + public val face: Int, + public val id: String, + @SerialName("sticker_type") + public val type: Int +) : HummerMessage, CodableMessage { + + public companion object Key : + AbstractPolymorphicMessageKey( + MessageContent, + { it.safeCast() }) { + + public const val SERIAL_NAME: String = "SuperFace" + + /** + * 将普通表情转换为超级表情. + * + * @throws IllegalArgumentException 无法转换时抛出 + **/ + @JvmStatic + public fun from(face: Face): SuperFace { + return fromOrNull(face = face) + ?: throw IllegalArgumentException("No SuperFace mapping from Face(id=${face.id}, name='${face.name}')") + } + + /** + * 将普通表情转换为超级表情. + * + * @return 无法转换时返回 null + **/ + @JvmStatic + @OptIn(MiraiInternalApi::class) + public fun fromOrNull(face: Face): SuperFace? { + val stickerId = when (face.id) { + Face.DA_CALL -> "1" + Face.BIAN_XING -> "2" + Face.KE_DAO_LE -> "3" + Face.ZI_XI_FEN_XI -> "4" + Face.JIA_YOU -> "5" + Face.WO_MEI_SHI -> "6" + Face.CAI_GOU -> "7" + Face.CHONG_BAI -> "8" + Face.BI_XIN -> "9" + Face.QING_ZHU -> "10" + Face.LAO_SE_PI -> "11" + Face.CHI_TANG -> "12" + Face.LAN_QIU -> "13" + Face.JING_XIA -> "14" + Face.SHENG_QI -> "15" + Face.LIU_LEI -> "16" + Face.DAN_GAO -> "17" + Face.BIAN_PAO -> "18" + Face.YAN_HUA -> "19" + Face.WO_XIANG_KAI_LE -> "20" + Face.TIAN_PING -> "21" + Face.HUA_DUO_LIAN -> "22" + Face.RE_HUA_LE -> "23" + Face.DA_ZHAO_HU -> "24" + Face.NI_ZHEN_BANG_BANG -> "25" + Face.SUAN_Q -> "26" + Face.WO_FANG_LE -> "27" + Face.DA_YUAN_ZHONG -> "28" + Face.HONG_BAO_DUO_DUO -> "29" + else -> return null + } + val stickerType = when (face.id) { + Face.LAN_QIU -> 2 + else -> 1 + } + + return SuperFace(face = face.id, id = stickerId, type = stickerType) + } + } + + override val key: MessageKey get() = Key + + public val name: String get() = contentToString().let { it.substring(1, it.length - 1) } + + override fun toString(): String = "[mirai:superface:$face,$id,$type]" + + override fun contentToString(): String = Face.names.getOrElse(face) { "[超级表情]" } + + @MiraiExperimentalApi + override fun appendMiraiCodeTo(builder: StringBuilder) { + builder.append("[mirai:superface:").append(face).append(',').append(id).append(',').append(type).append(']') + } + + @MiraiInternalApi + override fun accept(visitor: MessageVisitor, data: D): R { + return visitor.visitSuperFace(this, data) + } + + override fun hashCode(): Int { + var result = face.hashCode() + result = 31 * result + id.hashCode() + result = 31 * result + type.hashCode() + return result + } + + override fun equals(other: Any?): Boolean { + if (other !is SuperFace) return false + return face == other.face && id == other.id && type == other.type + } +} + +/** + * 将超级表情转换为普通表情 + * + * @since 2.16 + */ +@JvmSynthetic +public fun SuperFace.toFace(): Face = Face(id = face) + +/** + * 将普通表情转换为超级表情 + * + * @since 2.16 + * @throws IllegalArgumentException 无法转换时抛出 + */ +@JvmSynthetic +public fun Face.toSuperFace(): SuperFace = SuperFace.from(this) + +/** + * 将普通表情转换为超级表情, 在无法转换时返回 `null` + * + * @since 2.16 + */ +@JvmSynthetic +public fun Face.toSuperFaceOrNull(): SuperFace? = SuperFace.fromOrNull(this) \ No newline at end of file diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt b/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt index de1bae7905..958c613230 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/visitor/MessageVisitor.kt @@ -48,6 +48,7 @@ public interface MessageVisitor { 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 @@ -186,6 +187,10 @@ public abstract class AbstractMessageVisitor : MessageVisitor 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) } diff --git a/mirai-core-api/src/commonTest/kotlin/message.data/MessageVisitorTest.kt b/mirai-core-api/src/commonTest/kotlin/message.data/MessageVisitorTest.kt index 97d0b4d8c2..f0e3a60fa2 100644 --- a/mirai-core-api/src/commonTest/kotlin/message.data/MessageVisitorTest.kt +++ b/mirai-core-api/src/commonTest/kotlin/message.data/MessageVisitorTest.kt @@ -115,6 +115,10 @@ internal class MessageVisitorTest { return arrayOf("visitFace") + super.visitFace(message, data) } + override fun visitSuperFace(message: SuperFace, data: Unit): Array { + return arrayOf("visitSuperFace") + super.visitSuperFace(message, data) + } + override fun visitFileMessage(message: FileMessage, data: Unit): Array { return arrayOf("visitFileMessage") + super.visitFileMessage(message, data) } @@ -290,6 +294,17 @@ internal class MessageVisitorTest { FlashImage(createImage()).accept(GetCalledMethodNames) ) + assertContentEquals( + arrayOf( + "visitSuperFace", + "visitHummerMessage", + "visitMessageContent", + "visitSingleMessage", + "visitMessage", + ), + SuperFace.from(Face(Face.DA_CALL)).accept(GetCalledMethodNames) + ) + assertContentEquals( arrayOf( "visitPokeMessage", diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/SuperFaceProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/SuperFaceProtocol.kt new file mode 100644 index 0000000000..f18749391f --- /dev/null +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/SuperFaceProtocol.kt @@ -0,0 +1,83 @@ +/* + * 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. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.internal.message.protocol.impl + +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.collectGeneralFlags +import net.mamoe.mirai.internal.message.protocol.serialization.MessageSerializer +import net.mamoe.mirai.internal.network.protocol.data.proto.HummerCommelem +import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody +import net.mamoe.mirai.internal.utils.io.serialization.loadAs +import net.mamoe.mirai.internal.utils.io.serialization.toByteArray +import net.mamoe.mirai.message.data.* +import kotlin.text.toByteArray + +internal class SuperFaceProtocol : MessageProtocol() { + override fun ProcessorCollector.collectProcessorsImpl() { + add(Decoder()) + add(Encoder()) + + MessageSerializer.superclassesScope(MessageContent::class, SingleMessage::class) { + add(MessageSerializer(SuperFace::class, SuperFace.serializer())) + } + } + + private class Decoder : MessageDecoder { + override suspend fun MessageDecoderContext.process(data: ImMsgBody.Elem) { + if (data.commonElem == null) return + if (data.commonElem.serviceType != 37) return + + markAsConsumed() + + val proto = data.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype37.serializer()) + collect(SuperFace(face = proto.qsId, id = proto.stickerId.decodeToString(), type = proto.stickerType)) + } + } + + private class Encoder : MessageEncoder { + override suspend fun MessageEncoderContext.process(data: SuperFace) { + markAsConsumed() + + collect(ImMsgBody.Elem(commonElem = data.toCommData())) + processAlso(PlainText("/${data.name}")) + collectGeneralFlags { + ImMsgBody.Elem( + generalFlags = ImMsgBody.GeneralFlags( + pbReserve = ImMsgBody.Text(str = "[${data.name}]请使用最新版手机QQ体验新功能") + .toByteArray(ImMsgBody.Text.serializer()) + ) + ) + } + } + } + + companion object { + fun SuperFace.toCommData(): ImMsgBody.CommonElem { + return ImMsgBody.CommonElem( + serviceType = 37, + pbElem = HummerCommelem.MsgElemInfoServtype37( + packId = "1".encodeToByteArray(), + stickerId = id.encodeToByteArray(), + qsId = face, + sourceType = 1, + stickerType = type, + text = "/${name}".toByteArray(), + randomType = 1 + ).toByteArray(HummerCommelem.MsgElemInfoServtype37.serializer()), + businessType = type + ) + } + } +} \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/HummerCommelem.kt b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/HummerCommelem.kt index 24495ad866..c652522e80 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/HummerCommelem.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/HummerCommelem.kt @@ -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. @@ -242,6 +242,19 @@ internal class HummerCommelem : ProtoBuf { @ProtoNumber(4) @JvmField val buf: ByteArray = EMPTY_BYTE_ARRAY ) : ProtoBuf + @Serializable + internal class MsgElemInfoServtype37( + @ProtoNumber(1) @JvmField val packId: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(2) @JvmField val stickerId: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(3) @JvmField val qsId: Int = 0, + @ProtoNumber(4) @JvmField val sourceType: Int = 0, + @ProtoNumber(5) @JvmField val stickerType: Int = 0, + @ProtoNumber(6) @JvmField val resultId: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(7) @JvmField val text: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(8) @JvmField val surpriseId: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(9) @JvmField val randomType: Int = 0 + ) : ProtoBuf + @Serializable internal class MsgElemInfoServtype4( @ProtoNumber(1) @JvmField val imsgType: Int = 0, diff --git a/mirai-core/src/commonMain/kotlin/utils/MiraiCoreServices.kt b/mirai-core/src/commonMain/kotlin/utils/MiraiCoreServices.kt index 352b39bdc4..2a5956e936 100644 --- a/mirai-core/src/commonMain/kotlin/utils/MiraiCoreServices.kt +++ b/mirai-core/src/commonMain/kotlin/utils/MiraiCoreServices.kt @@ -61,6 +61,10 @@ internal object MiraiCoreServices { msgProtocol, "net.mamoe.mirai.internal.message.protocol.impl.MarketFaceProtocol" ) { net.mamoe.mirai.internal.message.protocol.impl.MarketFaceProtocol() } + Services.register( + msgProtocol, + "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" diff --git a/mirai-core/src/commonMain/resources/META-INF/services/net.mamoe.mirai.internal.message.protocol.MessageProtocol b/mirai-core/src/commonMain/resources/META-INF/services/net.mamoe.mirai.internal.message.protocol.MessageProtocol index ef877583ef..e06c7e590e 100644 --- a/mirai-core/src/commonMain/resources/META-INF/services/net.mamoe.mirai.internal.message.protocol.MessageProtocol +++ b/mirai-core/src/commonMain/resources/META-INF/services/net.mamoe.mirai.internal.message.protocol.MessageProtocol @@ -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,6 +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.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 diff --git a/mirai-core/src/commonTest/kotlin/message/code/TestMiraiCode.kt b/mirai-core/src/commonTest/kotlin/message/code/TestMiraiCode.kt index e9b97646e1..0055072b04 100644 --- a/mirai-core/src/commonTest/kotlin/message/code/TestMiraiCode.kt +++ b/mirai-core/src/commonTest/kotlin/message/code/TestMiraiCode.kt @@ -95,5 +95,10 @@ internal class TestMiraiCode : AbstractTest() { messageChainOf(RockPaperScissors.PAPER), "[mirai:rps:paper]".deserializeMiraiCode() ) + + assertEquals( + messageChainOf(SuperFace.from(Face(Face.LAN_QIU))), + "[mirai:superface:114,13,2]".deserializeMiraiCode() + ) } } \ No newline at end of file diff --git a/mirai-core/src/commonTest/kotlin/message/protocol/MessageProtocolFacadeTest.kt b/mirai-core/src/commonTest/kotlin/message/protocol/MessageProtocolFacadeTest.kt index 48efd0aad9..2f4a2bce42 100644 --- a/mirai-core/src/commonTest/kotlin/message/protocol/MessageProtocolFacadeTest.kt +++ b/mirai-core/src/commonTest/kotlin/message/protocol/MessageProtocolFacadeTest.kt @@ -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. @@ -28,6 +28,7 @@ internal class MessageProtocolFacadeTest : AbstractTest() { FlashImageProtocol ImageProtocol MarketFaceProtocol + SuperFaceProtocol MusicShareProtocol PokeMessageProtocol PttMessageProtocol diff --git a/mirai-core/src/commonTest/kotlin/message/protocol/impl/SuperFaceProtocolTest.kt b/mirai-core/src/commonTest/kotlin/message/protocol/impl/SuperFaceProtocolTest.kt new file mode 100644 index 0000000000..09a236755a --- /dev/null +++ b/mirai-core/src/commonTest/kotlin/message/protocol/impl/SuperFaceProtocolTest.kt @@ -0,0 +1,62 @@ +/* + * 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. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.internal.message.protocol.impl + +import net.mamoe.mirai.contact.MemberPermission +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +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.Face +import net.mamoe.mirai.message.data.SuperFace +import net.mamoe.mirai.utils.hexToBytes +import kotlin.test.BeforeTest +import kotlin.test.Test + +internal class SuperFaceProtocolTest : AbstractMessageProtocolTest() { + override val protocols: Array = arrayOf(SuperFaceProtocol(), TextProtocol()) + + @BeforeTest + fun `init group`() { + defaultTarget = bot.addGroup(123, 1230003).apply { + addMember(1230003, "user3", MemberPermission.OWNER) + } + } + + @Test + fun `group AnimatedSticker receive from Android client`() { + buildCodingChecks { + elem( + "AA 03 20 08 25 12 1A 0A 01 31 12 02 31 36 18 05 20 01 28 01 32 00 3A 07 2F E6 B5 81 E6 B3 AA 48 01 18 01".hexToBytes() + .loadAs(net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem.serializer()) + ) + elem( + "AA 03 23 08 25 12 1D 0A 01 31 12 02 31 33 18 72 20 01 28 02 32 01 35 3A 07 2F E7 AF AE E7 90 83 42 00 48 01 18 02".hexToBytes() + .loadAs(net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem.serializer()) + ) + message( + SuperFace.from(Face(Face.LAN_QIU)) + ) + }.doDecoderChecks() + } + + @TestFactory + fun `test serialization`(): DynamicTestsResult { + val data = SuperFace.from(Face(Face.LAN_QIU)) + val serialName = SuperFace.SERIAL_NAME + return runDynamicTests( + testPolymorphicInMessageContent(data, serialName), + testPolymorphicInSingleMessage(data, serialName), + testInsideMessageChain(data, serialName), + testContextual(data, serialName), + ) + } +} \ No newline at end of file