mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-06 09:00:14 +08:00
Deprecate XmlMessage
and JsonMessage
in favour of ServiceMessage
This commit is contained in:
parent
4840a57b4a
commit
e3084c5f7d
@ -338,7 +338,8 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, bot: B
|
|||||||
/**
|
/**
|
||||||
* [JsonMessage]
|
* [JsonMessage]
|
||||||
*/
|
*/
|
||||||
1 -> list.add(JsonMessage(content))
|
1 -> @Suppress("DEPRECATION_ERROR")
|
||||||
|
list.add(JsonMessage(content))
|
||||||
/**
|
/**
|
||||||
* [LongMessage], [ForwardMessage]
|
* [LongMessage], [ForwardMessage]
|
||||||
*/
|
*/
|
||||||
@ -355,6 +356,7 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(groupIdOrZero: Long, bot: B
|
|||||||
// 104 新群员入群的消息
|
// 104 新群员入群的消息
|
||||||
else -> {
|
else -> {
|
||||||
if (element.richMsg.serviceId == 60 || content.startsWith("<?")) {
|
if (element.richMsg.serviceId == 60 || content.startsWith("<?")) {
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
list.add(XmlMessage(element.richMsg.serviceId, content))
|
list.add(XmlMessage(element.richMsg.serviceId, content))
|
||||||
} else list.add(ServiceMessage(element.richMsg.serviceId, content))
|
} else list.add(ServiceMessage(element.richMsg.serviceId, content))
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ package net.mamoe.mirai.message.data
|
|||||||
|
|
||||||
import net.mamoe.mirai.contact.Contact
|
import net.mamoe.mirai.contact.Contact
|
||||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||||
|
import net.mamoe.mirai.utils.PlannedRemoval
|
||||||
import net.mamoe.mirai.utils.SinceMirai
|
import net.mamoe.mirai.utils.SinceMirai
|
||||||
import kotlin.annotation.AnnotationTarget.*
|
import kotlin.annotation.AnnotationTarget.*
|
||||||
import kotlin.jvm.JvmMultifileClass
|
import kotlin.jvm.JvmMultifileClass
|
||||||
@ -40,7 +41,12 @@ interface RichMessage : MessageContent {
|
|||||||
|
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
@SinceMirai("0.30.0")
|
@SinceMirai("0.30.0")
|
||||||
fun share(url: String, title: String? = null, content: String? = null, coverUrl: String? = null): XmlMessage =
|
fun share(
|
||||||
|
url: String,
|
||||||
|
title: String? = null,
|
||||||
|
content: String? = null,
|
||||||
|
coverUrl: String? = null
|
||||||
|
): ServiceMessage =
|
||||||
buildXmlMessage(60) {
|
buildXmlMessage(60) {
|
||||||
templateId = 12345
|
templateId = 12345
|
||||||
serviceId = 1
|
serviceId = 1
|
||||||
@ -61,6 +67,20 @@ interface RichMessage : MessageContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PlannedRemoval("1.0.0")
|
||||||
|
@JvmName("share")
|
||||||
|
@Deprecated(
|
||||||
|
"for binary compatibility", level = DeprecationLevel.HIDDEN
|
||||||
|
)
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
@MiraiExperimentalAPI
|
||||||
|
fun shareDeprecated(
|
||||||
|
url: String,
|
||||||
|
title: String? = null,
|
||||||
|
content: String? = null,
|
||||||
|
coverUrl: String? = null
|
||||||
|
): XmlMessage = share(url, title, content, coverUrl) as XmlMessage
|
||||||
|
|
||||||
override val typeName: String
|
override val typeName: String
|
||||||
get() = "RichMessage"
|
get() = "RichMessage"
|
||||||
}
|
}
|
||||||
@ -120,8 +140,17 @@ open class ServiceMessage(@MiraiExperimentalAPI val serviceId: Int, final overri
|
|||||||
*
|
*
|
||||||
* @see LightApp 一些 json 消息实际上是 [LightApp]
|
* @see LightApp 一些 json 消息实际上是 [LightApp]
|
||||||
*/
|
*/
|
||||||
|
@PlannedRemoval("1.0.0")
|
||||||
|
@Deprecated("use ServiceMessage with serviceId 1",
|
||||||
|
level = DeprecationLevel.ERROR,
|
||||||
|
replaceWith = ReplaceWith("ServiceMessage"))
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
class JsonMessage(content: String) : ServiceMessage(1, content) {
|
class JsonMessage
|
||||||
|
@Deprecated("use ServiceMessage with serviceId 1",
|
||||||
|
level = DeprecationLevel.ERROR,
|
||||||
|
replaceWith = ReplaceWith("ServiceMessage(1, content)"))
|
||||||
|
constructor(content: String) : ServiceMessage(1, content) {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
companion object Key : Message.Key<JsonMessage> {
|
companion object Key : Message.Key<JsonMessage> {
|
||||||
override val typeName: String get() = "JsonMessage"
|
override val typeName: String get() = "JsonMessage"
|
||||||
@ -136,7 +165,12 @@ class JsonMessage(content: String) : ServiceMessage(1, content) {
|
|||||||
*
|
*
|
||||||
* @see buildXmlMessage 使用 DSL 构造一个 XML 消息
|
* @see buildXmlMessage 使用 DSL 构造一个 XML 消息
|
||||||
*/
|
*/
|
||||||
|
@PlannedRemoval("1.0.0")
|
||||||
|
@Deprecated("use ServiceMessage with serviceId 1",
|
||||||
|
level = DeprecationLevel.ERROR,
|
||||||
|
replaceWith = ReplaceWith("ServiceMessage"))
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
@SinceMirai("0.27.0")
|
@SinceMirai("0.27.0")
|
||||||
class XmlMessage @MiraiExperimentalAPI("Maybe replaced with an enum")
|
class XmlMessage @MiraiExperimentalAPI("Maybe replaced with an enum")
|
||||||
constructor(serviceId: Int = 60, content: String) : ServiceMessage(serviceId, content) {
|
constructor(serviceId: Int = 60, content: String) : ServiceMessage(serviceId, content) {
|
||||||
@ -182,10 +216,11 @@ commonElem=CommonElem#750141174 {
|
|||||||
/**
|
/**
|
||||||
* 构造一条 XML 消息
|
* 构造一条 XML 消息
|
||||||
*/
|
*/
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@SinceMirai("0.27.0")
|
@SinceMirai("0.27.0")
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
inline fun buildXmlMessage(serviceId: Int, block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): XmlMessage =
|
inline fun buildXmlMessage(serviceId: Int, block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
|
||||||
XmlMessage(serviceId, XmlMessageBuilder().apply(block).text)
|
XmlMessage(serviceId, XmlMessageBuilder().apply(block).text)
|
||||||
|
|
||||||
@Target(CLASS, FUNCTION, TYPE)
|
@Target(CLASS, FUNCTION, TYPE)
|
||||||
@ -261,4 +296,5 @@ class XmlMessageBuilder(
|
|||||||
@SinceMirai("0.27.0")
|
@SinceMirai("0.27.0")
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
@Deprecated("specify serviceId explicitly", ReplaceWith("buildXmlMessage(60, block)"))
|
@Deprecated("specify serviceId explicitly", ReplaceWith("buildXmlMessage(60, block)"))
|
||||||
inline fun buildXmlMessage(block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): XmlMessage = buildXmlMessage(60, block)
|
inline fun buildXmlMessage(block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
|
||||||
|
buildXmlMessage(60, block)
|
||||||
|
@ -198,7 +198,7 @@ internal inline fun <T> List<T>.indexOfFirst(offset: Int, predicate: (T) -> Bool
|
|||||||
|
|
||||||
@OptIn(MiraiExperimentalAPI::class)
|
@OptIn(MiraiExperimentalAPI::class)
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST", "DEPRECATION_ERROR")
|
||||||
internal fun <M : Message> MessageChain.firstOrNullImpl(key: Message.Key<M>): M? = when (key) {
|
internal fun <M : Message> MessageChain.firstOrNullImpl(key: Message.Key<M>): M? = when (key) {
|
||||||
At -> firstIsInstanceOrNull<At>()
|
At -> firstIsInstanceOrNull<At>()
|
||||||
AtAll -> firstIsInstanceOrNull<AtAll>()
|
AtAll -> firstIsInstanceOrNull<AtAll>()
|
||||||
@ -221,6 +221,7 @@ internal fun <M : Message> MessageChain.firstOrNullImpl(key: Message.Key<M>): M?
|
|||||||
OnlineMessageSource.Incoming.FromFriend -> firstIsInstanceOrNull<OnlineMessageSource.Incoming.FromFriend>()
|
OnlineMessageSource.Incoming.FromFriend -> firstIsInstanceOrNull<OnlineMessageSource.Incoming.FromFriend>()
|
||||||
OnlineMessageSource -> firstIsInstanceOrNull<OnlineMessageSource>()
|
OnlineMessageSource -> firstIsInstanceOrNull<OnlineMessageSource>()
|
||||||
XmlMessage -> firstIsInstanceOrNull<XmlMessage>()
|
XmlMessage -> firstIsInstanceOrNull<XmlMessage>()
|
||||||
|
LongMessage -> firstIsInstanceOrNull()
|
||||||
JsonMessage -> firstIsInstanceOrNull<JsonMessage>()
|
JsonMessage -> firstIsInstanceOrNull<JsonMessage>()
|
||||||
RichMessage -> firstIsInstanceOrNull<RichMessage>()
|
RichMessage -> firstIsInstanceOrNull<RichMessage>()
|
||||||
LightApp -> firstIsInstanceOrNull<LightApp>()
|
LightApp -> firstIsInstanceOrNull<LightApp>()
|
||||||
|
Loading…
Reference in New Issue
Block a user