Deprecated.kt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/master/LICENSE
  8. */
  9. @file:JvmMultifileClass
  10. @file:JvmName("MessageUtils")
  11. @file:Suppress("unused")
  12. package net.mamoe.mirai.message.data
  13. import kotlinx.serialization.Polymorphic
  14. import kotlinx.serialization.SerialName
  15. import kotlinx.serialization.Serializable
  16. import net.mamoe.mirai.IMirai
  17. import net.mamoe.mirai.utils.safeCast
  18. /**
  19. * 兼容 2.6 以下的 [MessageOrigin]. 请使用 [MessageOrigin]
  20. * @since 2.3
  21. * @suppress Deprecated since 2.6
  22. */
  23. @Suppress("DEPRECATION_ERROR")
  24. @Serializable
  25. @SerialName(RichMessageOrigin.SERIAL_NAME)
  26. @Deprecated(
  27. "Use MessageOrigin instead.",
  28. replaceWith = ReplaceWith(
  29. "MessageOrigin",
  30. "net.mamoe.mirai.message.data.MessageOrigin",
  31. ),
  32. level = DeprecationLevel.ERROR
  33. )
  34. public class RichMessageOrigin
  35. @Deprecated(
  36. "Use MessageOrigin instead.",
  37. replaceWith = ReplaceWith(
  38. "MessageOrigin(origin, resourceId, kind)",
  39. "net.mamoe.mirai.message.data.MessageOrigin",
  40. ),
  41. level = DeprecationLevel.ERROR
  42. )
  43. constructor(
  44. /**
  45. * 原 [RichMessage].
  46. */
  47. public val origin: @Polymorphic RichMessage,
  48. /**
  49. * 如果来自长消息或转发消息, 则会有 [resourceId], 否则为 `null`.
  50. *
  51. * - 下载长消息 [IMirai.downloadLongMessage]
  52. * - 下载合并转发消息 [IMirai.downloadForwardMessage]
  53. */
  54. public val resourceId: String?,
  55. /**
  56. * 来源类型
  57. */
  58. @Suppress("DEPRECATION_ERROR")
  59. public val kind: RichMessageKind,
  60. ) : MessageMetadata, ConstrainSingle {
  61. @Suppress("DEPRECATION_ERROR")
  62. override val key: Key
  63. get() = Key
  64. override fun toString(): String {
  65. val resourceId = resourceId
  66. return if (resourceId == null) "[mirai:origin:$kind]"
  67. else "[mirai:origin:$kind,$resourceId]"
  68. }
  69. override fun contentToString(): String = ""
  70. override fun equals(other: Any?): Boolean {
  71. if (this === other) return true
  72. if (javaClass != other?.javaClass) return false
  73. @Suppress("DEPRECATION_ERROR")
  74. other as RichMessageOrigin
  75. if (origin != other.origin) return false
  76. if (resourceId != other.resourceId) return false
  77. if (kind != other.kind) return false
  78. return true
  79. }
  80. override fun hashCode(): Int {
  81. var result = origin.hashCode()
  82. result = 31 * result + (resourceId?.hashCode() ?: 0)
  83. result = 31 * result + kind.hashCode()
  84. return result
  85. }
  86. @Deprecated(
  87. "Use MessageOrigin instead.",
  88. replaceWith = ReplaceWith(
  89. "MessageOrigin",
  90. "net.mamoe.mirai.message.data.MessageOrigin",
  91. ),
  92. level = DeprecationLevel.ERROR
  93. )
  94. @Suppress("DEPRECATION_ERROR")
  95. public companion object Key : AbstractMessageKey<RichMessageOrigin>({ it.safeCast() }) {
  96. public const val SERIAL_NAME: String = "RichMessageOrigin"
  97. }
  98. }
  99. /**
  100. * 消息来源
  101. * @since 2.3
  102. * @suppress Deprecated since 2.6
  103. */
  104. @Deprecated(
  105. "Use MessageOriginKind",
  106. ReplaceWith("MessageOriginKind", "net.mamoe.mirai.message.data.MessageOriginKind"),
  107. level = DeprecationLevel.ERROR
  108. )
  109. public enum class RichMessageKind {
  110. /**
  111. * 长消息
  112. */
  113. LONG,
  114. /**
  115. * 合并转发
  116. * @see ForwardMessage
  117. */
  118. FORWARD,
  119. /**
  120. * 音乐分享
  121. * @see MusicShare
  122. * @since 2.4
  123. */
  124. MUSIC_SHARE,
  125. }