mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Support LightApp
message
This commit is contained in:
parent
584b5e9822
commit
a64c061377
@ -239,10 +239,21 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean): MutableList<ImMsgB
|
||||
elements.add(ImMsgBody.Elem(text = it.toJceData()))
|
||||
elements.add(ImMsgBody.Elem(text = ImMsgBody.Text(str = " ")))
|
||||
}
|
||||
is LightApp -> elements.add(
|
||||
ImMsgBody.Elem(
|
||||
lightApp = ImMsgBody.LightAppElem(
|
||||
data = byteArrayOf(1) + MiraiPlatformUtils.zip(it.content.toByteArray())
|
||||
)
|
||||
)
|
||||
)
|
||||
is RichMessage -> elements.add(
|
||||
ImMsgBody.Elem(
|
||||
richMsg = ImMsgBody.RichMsg(
|
||||
serviceId = it.serviceId,
|
||||
serviceId = when (it) {
|
||||
is XmlMessage -> 60
|
||||
is JsonMessage -> 1
|
||||
else -> error("unsupported RichMessage")
|
||||
},
|
||||
template1 = byteArrayOf(1) + MiraiPlatformUtils.zip(it.content.toByteArray())
|
||||
)
|
||||
)
|
||||
@ -274,6 +285,7 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean): MutableList<ImMsgB
|
||||
this.forEach(::transformOneMessage)
|
||||
|
||||
if (this.any<RichMessage>()) {
|
||||
// 08 09 78 00 A0 01 81 DC 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 98 03 00 A0 03 20 B0 03 00 C0 03 00 D0 03 00 E8 03 00 8A 04 02 08 03 90 04 80 80 80 10 B8 04 00 C0 04 00
|
||||
elements.add(ImMsgBody.Elem(generalFlags = ImMsgBody.GeneralFlags(pbReserve = "08 09 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00 98 03 00 A0 03 20 B0 03 00 C0 03 00 D0 03 00 E8 03 00 8A 04 02 08 03 90 04 80 80 80 10 B8 04 00 C0 04 00".hexToBytes())))
|
||||
} else elements.add(ImMsgBody.Elem(generalFlags = ImMsgBody.GeneralFlags(pbReserve = "78 00 F8 01 00 C8 02 00".hexToBytes())))
|
||||
|
||||
@ -343,7 +355,7 @@ internal class OnlineFriendImageImpl(
|
||||
internal fun MsgComm.Msg.toMessageChain(): MessageChain {
|
||||
val elements = this.msgBody.richText.elems
|
||||
|
||||
if (this.msgHead.fromUin == 1040400290L){
|
||||
if (this.msgHead.fromUin == 1040400290L) {
|
||||
println(this._miraiContentToString())
|
||||
}
|
||||
|
||||
@ -408,6 +420,10 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(message: MessageChainBuilde
|
||||
}
|
||||
}
|
||||
}
|
||||
it.lightApp != null -> {
|
||||
val content = MiraiPlatformUtils.unzip(it.lightApp.data, 1).encodeToString()
|
||||
message.add(LightApp(content))
|
||||
}
|
||||
it.richMsg != null -> {
|
||||
println(this._miraiContentToString())
|
||||
val content = MiraiPlatformUtils.unzip(it.richMsg.template1, 1).encodeToString()
|
||||
|
@ -16,9 +16,6 @@ import net.mamoe.mirai.utils.SinceMirai
|
||||
@OptIn(MiraiExperimentalAPI::class)
|
||||
class JsonMessage(override val content: String) : RichMessage {
|
||||
companion object Key : Message.Key<JsonMessage>
|
||||
|
||||
override val serviceId: Int
|
||||
get() = 1
|
||||
|
||||
// serviceId = 1
|
||||
override fun toString(): String = content
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2020 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/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.message.data
|
||||
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.SinceMirai
|
||||
|
||||
/**
|
||||
* 小程序, 如音乐分享
|
||||
*/
|
||||
@OptIn(MiraiExperimentalAPI::class)
|
||||
@SinceMirai("0.27.0")
|
||||
class LightApp constructor(override val content: String) : RichMessage {
|
||||
companion object Key : Message.Key<LightApp>
|
||||
|
||||
override fun toString(): String = content
|
||||
}
|
@ -133,6 +133,7 @@ fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = when (key)
|
||||
XmlMessage -> first<XmlMessage>()
|
||||
JsonMessage -> first<JsonMessage>()
|
||||
RichMessage -> first<RichMessage>()
|
||||
LightApp -> first<LightApp>()
|
||||
else -> null
|
||||
} as M?
|
||||
|
||||
|
@ -21,9 +21,6 @@ import net.mamoe.mirai.utils.SinceMirai
|
||||
interface RichMessage : MessageContent {
|
||||
companion object Key : Message.Key<RichMessage>
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
val serviceId: Int
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
val content: String
|
||||
}
|
@ -29,7 +29,7 @@ import kotlin.jvm.JvmName
|
||||
class XmlMessage constructor(override val content: String) : RichMessage {
|
||||
companion object Key : Message.Key<XmlMessage>
|
||||
|
||||
override val serviceId: Int get() = 60
|
||||
// override val serviceId: Int get() = 60
|
||||
|
||||
override fun toString(): String = content
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user